# Convert point vector to Mat

Hi, my objective is to obtain the right side of this image.

I thought I'd see the image as a polygon 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 matrix.

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

(...)

std::vector<Point> contour;
Mat 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 = (const cv::Point*) Mat(contour).data;
int npts = Mat(contour).rows;
std::cout << "Number of 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 thickness
CV_AA, 0);


I'm using OpenCV 2.4.6.1 and C++.

Thank you

edit retag close merge delete

hmm, the error seems to come from cvConvertImage, you don't show enough code ?

( 2013-09-30 02:57:49 -0500 )edit

( 2013-09-30 10:53:00 -0500 )edit

Sort by ยป oldest newest most voted

I can recommend you.

Mat image_src;
Mat lung_left( image_src, Rect( 55, 100, 195, 290)); // Rect( , , , ) crop image from x,y to x+i, y+j


Tell me, how it works for you.

more

Hi, I already have submatrixs obtained like that, the problem is that this submatrix is not a rectangle, its a polygon.

( 2013-09-30 13:25:33 -0500 )edit

You have to change your code to below.

       std::vector<Point> contour;

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);

vector<vector<Point>> contours;
contours.push_back(contour):
// draw the polygon
polylines(roi, contours, true, Scalar(255), CV_AA);

more

Hi, thank you for your answer. This codes gives me the same result, "just" the draw. Do you know how can I convert it to a Mat?

( 2013-09-30 14:17:35 -0500 )edit

With this code I was able to get the left side! How can I obtain the right one?...

    std::vector&lt;Point&gt; contour;
Mat 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);

vector&lt; vector&lt;Point&gt; &gt; contours;

contours.push_back(contour);

// draw the polygon
polylines(roi, contours, true, Scalar(255), CV_AA);


( 2013-09-30 14:37:07 -0500 )edit

Official site

GitHub

Wiki

Documentation