Ask Your Question
0

perspectiveTransform on contours?

asked 2015-04-07 11:30:37 -0600

ClintFromVa gravatar image

updated 2015-04-07 13:36:07 -0600

Hi all,

I've got a contour for a flat, irregular shape with ~ten, 2D, points. I'd like to project just that contour, not the whole image, into a normal view and then find area, etc.

I know the contour is OK because drawContours has the expected result. The rotation matrix, Rot3D, works with warpPerspective on the full image (I play with the rotations for the background in a calibration step, then try to use the same rotation matrix here. It is a (3, 3, CV_32FC1) ).

I simplified everything to this code: `

////this builds a contour-like structure for testing...
vector<Point2f> foo = { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 1, 0 } };
vector<vector<Point2f>> bar;
bar = { foo, foo};
//which ought to work with this...
contours1.resize(bar.size());
for (int i = 0; i < bar.size(); i++) //for each vector of points in the list...
    perspectiveTransform(bar[i], contours1[i], Rot3D);//rotate them.

` which fails an assertion check: image description

No clue what that means...contours1 is a vector<vector<point>> ... Douh! could that be it...

OK, findContours produces <point> (i.e., two int), perspectiveTransform requires <point2f>

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-04-08 10:58:26 -0600

ClintFromVa gravatar image

I ended up scanning the contours point by point and multiplying each by the rotation matrix. Maybe there is some sort of typecast that operates on a vector and would have let me use perspectiveTransform, but I've no clue what it may be.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-04-07 11:30:37 -0600

Seen: 1,440 times

Last updated: Apr 08 '15