ConvertTo does not work in opencv

I am trying to use convertTo () in opencv c ++. But error message appears

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);
        }
    }
}
+4
source share
2 answers

I'm not sure I .convertTo()can handle the case of an identical source and destination. You can try to use a couple of temporary variables to get around the 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,.convertTo() my suggestion is really not required (thanks, pointing it out, @ boaz001).

+1
source

Left: of , null undefined outplanes [k] , , , .

, , , / ...

vector<Mat> outplanes(planes.size());

https://en.wikipedia.org/wiki/Most_vexing_parse

? ?

"Most_vexing_parse"

vector<Mat> outplanes((planes.size()));

, / outplanes, , , , , .

+1

Source: https://habr.com/ru/post/1623851/


All Articles