Ask Your Question

Revision history [back]

The issue is with you declaring other vector variables i.e. contours_poly, boundRect, centers, radius before using findContours() function. The issue is that, the vector "contours" is still empty when you're calling "contours.size()", while declaring this vector variables. They should be declared after calling "findContours()" as follows:

vector<vector<Point> > contours;
vector<Vec4i> hierarchy;

findContours( frame_canny, contours, RETR_TREE, CHAIN_APPROX_SIMPLE );

vector<vector<Point>>  contours_poly( contours.size() );
vector<Rect> boundRect( contours.size() );
vector<Point2f>centers( contours.size() );
vector<float>radius( contours.size() );

I tested the revised code and it is working. I hope this helps.

The issue is with you You are declaring other vector variables i.e. contours_poly, boundRect, centers, radius before using findContours() function. The issue with this is that, the vector "contours" is still empty when you're calling "contours.size()", while declaring this vector variables. They should be declared after calling "findContours()" as follows:

vector<vector<Point> > contours;
vector<Vec4i> hierarchy;

findContours( frame_canny, contours, RETR_TREE, CHAIN_APPROX_SIMPLE );

vector<vector<Point>>  contours_poly( contours.size() );
vector<Rect> boundRect( contours.size() );
vector<Point2f>centers( contours.size() );
vector<float>radius( contours.size() );

I tested the revised code and it is working. I hope this helps.