Binja
Binja

Reputation: 121

How to access vector<vector<Point>> contours in opencv like matrix element?

My problem is I do not know how to access vector <vector <Point>> contour (this is 2D like matrix on OpenCV)

I want to do this. If Mat element does not consists in contours area I want to suppress that matrix elements. In order to do this I need to know contours element too.

Upvotes: 3

Views: 20192

Answers (3)

Jav_Rock
Jav_Rock

Reputation: 22245

You need a for loop for both the first and the second vector. Something Like this:

vector< vector<Point> > contours;

for(int i= 0; i < contours.size(); i++)
{
    for(int j= 0; j < contours[i].size();j++) // run until j < contours[i].size();
    {
        cout << contours[i][j] << endl; //do whatever
    }
}

Upvotes: 11

James Harper
James Harper

Reputation: 550

If you need all points rather than just the edge points, you can use drawContours(....,thickness=CV_FILLED) to dump this contour on a dummy Mat, then you can obtain those points by scanning the dummy Mat.

Upvotes: 0

Tae-Sung Shin
Tae-Sung Shin

Reputation: 20633

If my situation was so urgent, I would ask my question more carefully.

If I try hard to understand your question, you basically want to consider a contour in pixel level. In order to do that, you should draw the contour into a blank matrix with drawContour. And then compare two matrices or match a pixel in that matrix in case you want pixel by pixel.

Upvotes: 1

Related Questions