Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

you have a type problem here. the train (& test) data may only have a single channel.

if you want to put (2d) Points into it, you have to do it like:

    Mat trainData(nsamples, npoints * 2, CV_32F); // single channel, but cols*2 !
    for (size_t r=0; r < contours.size(); r++) {
        for (size_t c=0; c < contours[r].size(); c++) {
            traindata.at<float>(r, c*2) = contours[r][c].x;
            traindata.at<float>(r, c*2+1) = contours[r][c].y;
        }
   }

you have it's indeed a type problem here. the train (& test) data may only have a single channel.

if you want to put (2d) Points into it, you have to do it like:

    Mat trainData(nsamples, npoints * 2, CV_32F); // single channel, but cols*2 !
    for (size_t r=0; r < contours.size(); r++) {
        for (size_t c=0; c < contours[r].size(); c++) {
            traindata.at<float>(r, c*2) = contours[r][c].x;
            traindata.at<float>(r, c*2+1) = contours[r][c].y;
        }
   }