Ask Your Question
2

how to detect ellipse and get centers of ellipse

asked 2014-08-07 03:38:22 -0600

justrookie gravatar image

updated 2017-08-01 05:10:51 -0600

image description

I want to detect the four ellipses from the image above and get centers of each ellipse. I followed the page, and got the result show as follow bellow:image description

My question is how to get the four centers of ellipse.

edit retag flag offensive close merge delete

Comments

You already got ellipse center as given in the example box.center. Check out the documentation for draw ellipse. Also see image moment might be helpful.

Haris gravatar imageHaris ( 2014-08-07 03:51:01 -0600 )edit

@ Haris Yes, we can get the ellipse center from the box.center method. As we can see from the result image, we got more than four ellipses, but I just want the four ellipses located on corners.

justrookie gravatar imagejustrookie ( 2014-08-07 04:00:42 -0600 )edit
1

You mean you have to detect the circle at corners, then better to use Hough circle

Haris gravatar imageHaris ( 2014-08-07 05:26:53 -0600 )edit

Also, please use the samples of the opencv repo, not the attic. Those old samples are not fixed what so ever! Look here!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-07 06:03:33 -0600 )edit

@justrookie, like harris said, apply houghcircle and use that function to reduce the possible sizes of circles. Many results will disappear in an instant.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-07 06:04:39 -0600 )edit

@Haris and @StevenPuttemans Thank you for your reply, I know we can use the Hough method to detect circles and get center of circle, but what I want is the four centers of ellipse. Obviously, there are some differences between the two kinds of centers.

justrookie gravatar imagejustrookie ( 2014-08-07 08:13:37 -0600 )edit

I am sorry but there are not, those corner holes are circles, or close too, so it is that center you need right?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-07 08:24:50 -0600 )edit
1

@justrookie See the answer below, I think it will work, @StevenPuttemans I am just haris not harris..:), just joking...he..he..:)

Haris gravatar imageHaris ( 2014-08-07 09:35:29 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
6

answered 2014-08-07 12:33:58 -0600

You can try to use SimpleBlobDetector which is tuned to detect circular blobs.

Here is complete code for detection:

Mat image = imread("image.jpg");
Ptr<FeatureDetector> blobsDetector = FeatureDetector::create("SimpleBlob");
vector<KeyPoint> keypoints;
blobsDetector->detect(image, keypoints);

visualization:

Mat drawImage = image.clone();
for (size_t i = 0; i < keypoints.size(); ++i)
    circle(drawImage, keypoints[i].pt, 4, Scalar(255, 0, 255), -1); 
imwrite("result.png", drawImage);

and achieved results: detected corners

Check out the description of the algorithm and its parameters in the official docs.

edit flag offensive delete link more

Comments

Wow!!!!!The method is so amazing ! Thank you for your great idea.

justrookie gravatar imagejustrookie ( 2014-08-07 21:42:36 -0600 )edit

@justrookie Hi, I'm working on a leaf-area measurement tool using a very similar method as yours. Is your software available? Thanks!

redcurry gravatar imageredcurry ( 2017-02-07 13:26:34 -0600 )edit
2

answered 2014-08-07 09:31:36 -0600

Haris gravatar image

So you already got all the ellipse and you need to filter out four circle at the corners,

Based on the reference link in your question you already have contours with you, Now Filter the contours which close to ellipse,

you could do,

  • Create two binary image of zero pix value, one is to draw contours and another is for draw ellipse.

  • Scan through each contour and draw it to the binary image, at same time draw the ellipse to other binary for corresponding contour, here in both case use CV_FILLED as thickness.

  • Now perform botwise xor between these two binary and count non-zero pixel on the result. If the result is close to zero then the contour is identical to ellipse, else not.

  • Repeat above for every contour and filter out contour close to ellipse, and don't forget to clear the binary image before each contour iteration.

edit flag offensive delete link more

Comments

Interesting approach! I can see a small ellipse outside the big ellipse (down left) that is not one of the 4 ellipses needed. I think it can be filtered based on size (it is too small).

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-08-07 11:00:12 -0600 )edit

Yes, you can use contourArea for that.

Haris gravatar imageHaris ( 2014-08-07 11:17:20 -0600 )edit

@Haris Thank you for your solution, your method is a bit more complicated, but anyway it is a approach to get the problem done.

justrookie gravatar imagejustrookie ( 2014-08-07 21:47:54 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2014-08-07 03:38:22 -0600

Seen: 22,505 times

Last updated: Aug 07 '14