Reputation: 113
How to retrieve the contour points - opencv ?
My Image has three Objects ( irregular shape ) i have found the contour of above three objects.
**My declaration - Contours **
vector<vector<Point>> contours;
So i got the object co-ordinates like below
contours.[size] = 3
[capacity ] = 14
+[0] {size = 330 }
+[1] {size = 240 }
+[2] {size = 654 }
here i have three contours, with size of 330, 240,654
Now my Doubt is how to Copy the each contour points of 3 objects to vector ?
I want to use this contour points in calcOpticalFlowPyrLK
function as prevPts
Or what can be done ?
Upvotes: 0
Views: 1042
Reputation: 50657
- A little bit more explanation of my above comment.
calcOpticalFlowPyrLK()
can directly use vector<Point>
or vector<Point2f>
for parameter prevPts
.
prevPts
– vector of 2D points for which the flow needs to be found; point coordinates must be single-precision floating-point numbers.
That said, you only need to use contours[0]
, contours[1]
and contours[2]
for the 3 objects (they are of type vector<Point>
) and pass them to calcOpticalFlowPyrLK()
.
Upvotes: 1
Reputation: 1203
herohuyongtao gave you the correct answer. You should give him recognition by selecting his answer as the correct answer.
I'll just add a small explanation : your contours is a vector of vector. It has 3 elements, and each of these elements is a vector of points (accessible by using .x and.y). That is exactly what is required by prevPts. By sending contour[i] to the function you are sending the i-th vector of points. See here :http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html
Upvotes: 0