Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Displaying radius of a circle

Hi everybody, I am learning OpenCV now and I have wrote a simple program which displays the bounding circle of a contour. Now I would like to know, how can I display in the same image the radius of that circle. I leave an image where you can see the bounding circle of a contour and where I would like to draw the radius of that circle. Any help would be apreciated.

Thanks in advance.

image description

Displaying radius of a circle

Hi everybody, I am learning OpenCV now and I have wrote a simple program which displays the bounding circle of a contour. Now I would like to know, how can I display in the same image the radius of that circle. I leave an image where you can see the bounding circle of a contour and where I would like to draw the radius of that circle. Any help would be apreciated.

Thanks in advance.advance. This is the code I've got:

void CirculoMin(int, void* ) { Mat thresh_output; vector<vector<point> > contornos; vector<vec4i> jerarquia;

  threshold( imgThresh,thresh_output, 50, 50, THRESH_TRUNC );
 findContours( thresh_output, contornos, jerarquia, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

vector<vector<Point> > contours_poly( contornos.size() );
vector<Rect> boundRect( contornos.size() );
vector<Point2f>centro( contornos.size() );
vector<float>radio( contornos.size() );

for( uint i = 0; i < contornos.size(); i++ ){

      approxPolyDP( Mat(contornos[i]), contours_poly[i], 3, true );
      minEnclosingCircle( (Mat)contours_poly[i], centro[i], radio[i] );

}

Mat dibujo = Mat::zeros( thresh_output.size(), CV_8UC3 );

for( uint i = 0; i< contornos.size(); i++ ){

   Scalar R = Scalar(0,0,255); /*color rojo*/
   Scalar G = Scalar(0,255,0);/*color verde*/
   Scalar B = Scalar(255,0,0);/*color azul*/

   drawContours( dibujo, contours_poly, i, G, 1, 8, vector<Vec4i>(), 0, Point() );

   if((int)radio[i] >= 15){        
       circle( dibujo, centro[i], (int)radio[i], R, 2, 8, 0 );        
   }//if

}//for

imshow( "Círculo mínimo", dibujo );

}

image description