Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

polyLines is quite a tricky beast ;)

it expects a vector<vector<Point>> as input (also, integer Points, not float ones !)

here's a simple example:

Mat ocv = Mat(100,100,CV_8UC3,Scalar::all(40));
vector<vector<Point>> line2d(1);
line2d[0] = { { 50, 50 }, { 50, 20 }, { 20, 20 } };
polylines(ocv, line2d, true, Scalar(255, 0, 0), 2);

image description

your case is a bit more complicated, because you have to copy the float points into a new, integer point array:

 vector<vector<Point2f>> oldpts = ... //projected 
 vector<vector<Point>>(oldpts.size());
 for(size_t i=0; i<oldpts.size(); i++) {
     for(size_t j=0; j<oldpts[i].size(); j++) {
           newpts[i].push_back(oldpts[i][j]);
     }
 }
 polylines(colorImg, newpts, true, Scalar(255, 0, 0), 2);

(idk, maybe it's easier, to use many simple line() calls for this ?)

polyLines is quite a tricky beast ;)

it expects a vector<vector<Point>> as input (also, integer Points, not float ones !)

here's a simple example:

Mat ocv = Mat(100,100,CV_8UC3,Scalar::all(40));
vector<vector<Point>> line2d(1);
line2d[0] = { { 50, 50 }, { 50, 20 }, { 20, 20 } };
polylines(ocv, line2d, true, Scalar(255, 0, 0), 2);

image description

your case is a bit more complicated, because you have to copy the float points into a new, integer point array:array, before you can use polyLines():

 vector<vector<Point2f>> oldpts = ... //projected 
 vector<vector<Point>>(oldpts.size());
vector<vector<Point>> newpts(oldpts.size());
 for(size_t i=0; i<oldpts.size(); i++) {
     for(size_t j=0; j<oldpts[i].size(); j++) {
           newpts[i].push_back(oldpts[i][j]);
     }
 }
 polylines(colorImg, newpts, true, Scalar(255, 0, 0), 2);

(idk, maybe it's easier, to use many simple line() calls for this ?)

polyLines is quite a tricky beast ;)

it expects a vector<vector<Point>> as input (also, integer Points, not float ones !)

here's a simple example:

Mat ocv = Mat(100,100,CV_8UC3,Scalar::all(40));
vector<vector<Point>> line2d(1);
line2d[0] = { { 50, 50 }, { 50, 20 }, { 20, 20 } };
polylines(ocv, line2d, true, Scalar(255, 0, 0), 2);

image description

your case is a bit more complicated, because you have to copy the float points into a new, integer point array, before you can use polyLines():

 vector<vector<Point2f>> oldpts vector<Point2f> line2d[4] = ... //projected 
 vector<vector<Point>> newpts(oldpts.size());
newpts(4);
 for(size_t i=0; i<oldpts.size(); i<4; i++) {
     for(size_t j=0; j<oldpts[i].size(); j<line2d[i].size(); j++) {
           newpts[i].push_back(oldpts[i][j]);
newpts[i].push_back(line2d[i][j]);
     }
 }
 polylines(colorImg, newpts, true, Scalar(255, 0, 0), 2);

(idk, maybe it's easier, to use many simple line() calls for this ?)