Reputation: 113
I am trying to use convertTo() in opencv C++. But an error pops saying
left of:convertTo must have class/struct/union
the program is below:
for (i = 0; i < height; i += 8)
{
for (j = 0; j < width; j += 8)
{
Mat block = dctImage(Rect(j, i, 8, 8));
vector<Mat> planes;
split(block, planes);
vector<Mat> outplanes(planes.size());
for (k = 0; k < planes.size(); k++) {
planes[k].convertTo(planes[k], CV_32FC1);
dct(planes[k], outplanes[k]);
outplanes[k].convertTo(outplanes[k], CV_8UC1);
}
}
}
Upvotes: 4
Views: 491
Reputation: 11721
The Left:of statement suggests that its null or undefined i.e. outplanes[k] does not contain what you think it should.
I did a quick search and it looks like this could be a compiler issue whereby it has difficulty understanding/interpreting the line ...
vector<Mat> outplanes(planes.size());
https://en.wikipedia.org/wiki/Most_vexing_parse
What is outplanes? Is it being instantiated correctly?
The 'Most_vexing_parse' article suggests helping the compiler with extra parenthesis
vector<Mat> outplanes((planes.size()));
Kinda depends on your code and what the outplanes method/class is actually doing, but i imagine it's not returning what you think it should be.
Upvotes: 1
Reputation: 2534
I'm not sure if .convertTo()
can handle the case of identical source and destination. You may want to try using a pair of temporary variables to get around your error message. Here is the relevant part from your example:
// ...
for (k = 0; k < planes.size(); k++) {
Mat planes_k, outplanes_k; // <-- Added temporaries.
planes[k].convertTo(planes_k, CV_32FC1);
dct(planes_k, outplanes_k);
outplanes_k.convertTo(outplanes[k], CV_8UC1);
}
// ...
UPDATE
According to the source code of .convertTo()
my suggestion isn't really required (thanks pointing this out, @boaz001).
Upvotes: 1