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