How do contour "warpPerspective" and "warpAffine"

asked 2015-06-01 11:00:16 -0600

nistar gravatar image

updated 2015-06-01 11:34:59 -0600

findContours(imgBinary, allContours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));

I haved the allContours, and Matrix of Perspective and Affine Transformation

How do contours Perspective(2D) and Affine Transformation???

Which function use???

Use direct "perspectiveTransform", have error

vector<vector<Point> >contours1;
perspectiveTransform(allContours, contours1, H);
edit retag flag offensive close merge delete

Comments

perspectiveTransform takes single vector<point> arguments

berak gravatar imageberak ( 2015-06-02 01:26:25 -0600 )edit

But "allContours" is not vector<point> arguments.

How to change?

nistar gravatar imagenistar ( 2015-06-02 03:24:07 -0600 )edit

^^ yes, that's your problem. iterate over allcontours, and use allcontours[i] ?

berak gravatar imageberak ( 2015-06-02 03:35:19 -0600 )edit

Now, use

vector<point>contours1;

        for (int i = 0; i < allContours.size(); i++){

                perspectiveTransform(allContours[i], contours1, H);

        }

But also have error

nistar gravatar imagenistar ( 2015-06-02 03:41:38 -0600 )edit

image description

nistar gravatar imagenistar ( 2015-06-02 03:44:57 -0600 )edit

sorry, forgot to mention: you need a vector<Point2f> for both args, not a vector<Point>

(you'll probably need to re-pack the whole thing)

berak gravatar imageberak ( 2015-06-02 03:48:16 -0600 )edit

How to get each point coordinates of Contours???

I tried "allContours[i].[j]", but error

nistar gravatar imagenistar ( 2015-06-02 03:56:34 -0600 )edit

vector<point2f>contours1;

Also error.

I think that Data Types of Contours is not correct.

nistar gravatar imagenistar ( 2015-06-02 04:01:34 -0600 )edit

try:

Point p = allContours[i][j]; // w/o dot.

vector<Point2f> floatPoints;
floatPoints.push_back(Point2f(p.x, p.y));

(similar for contours1, both args need to be same type)

berak gravatar imageberak ( 2015-06-02 04:01:48 -0600 )edit

Last question, how to transforming Point2f into Point.

I would like to rewrite "allContours" that use new datos

allContours[i]=contours1

nistar gravatar imagenistar ( 2015-06-02 04:28:48 -0600 )edit