0

I`m using MSER feature detector to detect all the circles from an image and it works perfect but i have to get the center of those circles. Do you know any posibility to get the center? Here is the source code:

void main()
{

 Mat inImg = imread(CProfilessuro1012Desktop1.bmp);

 Mat textImg;
 cvtColor(inImg, textImg, CV_BGR2GRAY);

 vector vector Point  contours;
 vector Rect bboxes;
 Ptr MSER mser = MSERcreate(22, (int)(0.00001textImg.colstextImg.rows), (int)(0.00015textImg.colstextImg.rows), 1, 1); 
 mser-detectRegions(textImg, contours, bboxes); 

 for(int i=0;i1;i++)
    { for(int j=0;jcontours[i].size();j++)
     cout   x=contours[i][j].x y=contours[i][j].y endl;
    coutendl;
 }
 for (int i = 0; i  bboxes.size(); i++)
 {
    cout   x=bboxes[i].x y=bboxes[i].y endl;
  rectangle(inImg, bboxes[i], CV_RGB(0, 255, 0));
 }
 cout  contours[0].size()endl;
 imshow(, inImg);
 waitKey(0);

}

What I did:

float sumX = 0, sumY = 0;
int size = contours.size();
Point2f centroid;
if(size > 0){

    for(int i=0;i<size;i++)
    {
        for(int j=0;j<contours[i].size();j++)
        {
        sumX += contours[i][j].x;
        sumY += contours[i][j].y;
        }
         centroid.x = sumX/contours[i].size();
 centroid.y = sumY/contours[i].size();
 cout<<centroid.x<<" " <<centroid.y<<endl;
 sumX=0;
 sumY=0;
    }
Mahagney Saleh
  • 117
  • 2
  • 11
  • Hi there, can you please share what you have already tried? You'll get more response if you show you've actually thought about than simply asking us to write your code. Thanks! – Tdelang Aug 03 '15 at 09:12
  • this is what i tryed but I thought that there is an already implemented function .I wrote my function in the question but I`m not sure if that is the real center.... – Mahagney Saleh Aug 03 '15 at 09:47

1 Answers1

0

You can draw circles enclosing contours.

(x, y),radius = cv2.minEnclosingCircle(contour)
center = (int(x),int(y))
radius = int(radius)

For more Information, you can refer to https://docs.opencv.org/3.1.0/dd/d49/tutorial_py_contour_features.html