Ask Your Question

Revision history [back]

I am guessing your threshold detects an almost perfectly shaped white circle? If so, the width of the rectangle is almost the same as the circle diameter.

double area = contourArea(contours[0]); //0 because you only have 1 contour double side = sqrt((area * 4) / CV_PI) ;

Important, this will only work if your object is circle shaped.

click to hide/show revision 2
No.2 Revision

I am guessing your threshold detects an almost perfectly shaped white circle? If so, the width of the rectangle is almost the same as the circle diameter.

double area = contourArea(contours[0]); //0 because you only have 1 contour
double side = sqrt((area * 4) / CV_PI) ;

;

Important, this will only work if your object is circle shaped.