Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Convert point vector to Mat

My question is very similar to this one... I'm trying to extract a sub matrix from a grayscale image wich is a polygon by 5 points , and convert it to a Mat.

This does not work:

std::vector<point> vert(5); vert.push_back(pt1); vert.push_back(pt2); vert.push_back(pt3); vert.push_back(pt4); vert.push_back(pt5);

Mat matROI = Mat(vert);

It shows me the following error message:

OpenCV Error: Bad number of channels (Source image must have 1, 3 or 4 channels) in cvConvertImage, file /home/user/opencv-2.4.6.1/modules/highgui/src/utils.cpp, line 611 terminate called after throwing an instance of 'cv::Exception' what(): /home/user/opencv-2.4.6.1/modules/highgui/src/utils.cpp:611: error: (-15) Source image must have 1, 3 or 4 channels in function cvConvertImage

I'm using OpenCV 2.4.6.1 and C++.

Thank you

Convert point vector to Mat

My question is very similar to this one... I'm trying to extract a sub matrix from a grayscale image wich is a polygon by 5 points , and convert it to a Mat.

This does not work:

std::vector<point> vert(5); vert.push_back(pt1); vert.push_back(pt2); vert.push_back(pt3); vert.push_back(pt4); vert(5);

vert.push_back(pt1);

vert.push_back(pt2);

vert.push_back(pt3);

vert.push_back(pt4);

vert.push_back(pt5);

Mat matROI = Mat(vert);

It shows me the following error message:

OpenCV Error: Bad number of channels (Source image must have 1, 3 or 4 channels) in cvConvertImage, file /home/user/opencv-2.4.6.1/modules/highgui/src/utils.cpp, line 611 terminate called after throwing an instance of 'cv::Exception' what(): /home/user/opencv-2.4.6.1/modules/highgui/src/utils.cpp:611: error: (-15) Source image must have 1, 3 or 4 channels in function cvConvertImage

I'm using OpenCV 2.4.6.1 and C++.

Thank you

click to hide/show revision 3
retagged

updated 2013-09-30 02:56:31 -0600

berak gravatar image

Convert point vector to Mat

My question is very similar to this one... I'm trying to extract a sub matrix from a grayscale image wich is a polygon by 5 points , and convert it to a Mat.

This does not work:

std::vector<point> vert(5);

vert.push_back(pt1);

vert.push_back(pt2);

vert.push_back(pt3);

vert.push_back(pt4);

vert.push_back(pt5);

Mat matROI = Mat(vert);

It shows me the following error message:

OpenCV Error: Bad number of channels (Source image must have 1, 3 or 4 channels) in cvConvertImage, file /home/user/opencv-2.4.6.1/modules/highgui/src/utils.cpp, line 611 terminate called after throwing an instance of 'cv::Exception' what(): /home/user/opencv-2.4.6.1/modules/highgui/src/utils.cpp:611: error: (-15) Source image must have 1, 3 or 4 channels in function cvConvertImage

I'm using OpenCV 2.4.6.1 and C++.

Thank you

Convert point vector to Mat

My question Hi, my objective is very similar to to obtain the right side of this one... I'm trying to extract a sub matrix from a grayscale image.

I thought I'd see the image wich is as a polygon by 5 points , because I have the coordinates of the vertices, and then transform the vector that has the vertices in a matrix (cvMat).

My thought is correct or is there a simpler way to get this submatrix?

With the following code I can draw the polygon but I need to convert it to a Mat.

This does not work:

std::vector<point> vert(5);

vert.push_back(pt1);

vert.push_back(pt2);

vert.push_back(pt3);

vert.push_back(pt4);

vert.push_back(pt5);

matrix.

Point normImgTop, normImgEyebrowInner, normImgCNoseTip, normImgCNoseBase, normImgTipOfChin, normImgTopLip, normImgDownLip, normImgBottom, normImgTopRight, normImgBottomRight;

(...)

        std::vector<Point> contour;
        Mat matROI roi(poseNormImg.rows, poseNormImg.cols, CV_8UC1);

        contour.push_back(normImgTop);
        contour.push_back(normImgEyebrowInner);
        contour.push_back(normImgCNoseTip);
        contour.push_back(normImgCNoseBase);
        contour.push_back(normImgTopLip);
        contour.push_back(normImgDownLip);
        contour.push_back(normImgTipOfChin);
        contour.push_back(normImgBottom);
        contour.push_back(normImgBottomRight);
        contour.push_back(normImgTopRight);

        const cv::Point *pts = Mat(vert);

It shows me the following error message:

OpenCV Error: Bad number (const cv::Point*) Mat(contour).data; int npts = Mat(contour).rows; std::cout << "Number of channels (Source image must have 1, 3 or 4 channels) in cvConvertImage, file /home/user/opencv-2.4.6.1/modules/highgui/src/utils.cpp, polygon vertices: " << npts << std::endl; // draw the polygon polylines(roi, &pts,&npts, 1, true, // draw closed contour (i.e. joint end to start) Scalar(0,255,0),// colour RGB ordering (here = green) 3, // line 611 terminate called after throwing an instance of 'cv::Exception' what(): /home/user/opencv-2.4.6.1/modules/highgui/src/utils.cpp:611: error: (-15) Source image must have 1, 3 or 4 channels in function cvConvertImage

thickness CV_AA, 0);

I'm using OpenCV 2.4.6.1 and C++.

Thank you