Ask Your Question

(Best) way to track a circle with a cross inside

Hi,

I am currently trying to find a solution on how to track a specific target which looks like this:

It is just a circle with a cross inside.

I am using opencv 2.4.8 in ROS Indigo on Ubuntu 14.04 Currently I am at this point:

• apply Canny-Edge-detection on the frames
• find and draw contours (drawing mostly for debugging purposes)
• for each contour calculate the eccentricity like this:

I wanted to use the eccentricity to filter out most of the fitted ellipses which are very narrow and are not even close to a circle. But I can not calculate moments from the ellipses, but only from the contours. And I have no idea if this comes even close to what I want to achieve.

Is there another possibility to calculate the eccentricity or the roundness of the fitted ellipses? I think the I tried googling it and this was the most promising approach.

Am I at least on a right way to get this working anytime? Or is there another approach which would work better and/or more stable. I need a robust tracking algorithm which also works in non-perfect lightning conditions and also works if the circle is no perfect circle anymore in the picture (because the camera is not always perfectly perpendicular to the circle)

I already sorted out the following methods, which all do not work for some reasons

• Shape-Matching
• Template-Matching
• Hough Circle Transform (at most perfect circles are detected) HoughCircles example

If there are more information I should provide or something I should clarify, please feel free to ask. Sorry if this post should be a little messy, I hope you got me anyway.

EDIT: Here is an image from my webcam:

On the left side, there is just the input image after Canny-Edge-detection. In the right picture you can see the original input with contours (green) and some fitted ellipses (blue). At first I want to filter out these very stretched 'ellipses' at the edges of the paper for example.

EDIT2: Added another image before any processing and an image to show my problems with HoughCircles:

raw input

edit retag close merge delete

Comments

How do your images look like?

( 2016-04-25 10:04:17 -0500 )edit

What do you mean exactly? Which images? I want to track this target in a stream of camera images (e.g. video)

( 2016-04-26 09:06:27 -0500 )edit

But you did not show any real data.

( 2016-04-27 02:15:45 -0500 )edit

added an image

( 2016-04-27 03:06:45 -0500 )edit

Can you add the original image without doing any preprocessing?

( 2016-04-27 09:00:07 -0500 )edit

Im not sure what you mean by only perfect circles are detected by HoughCircles. I can get it to detect circles, ellipses, squares, triangles. It is looking for 3 gradient pixels and triangulating them. You would be surprised how many shapes that will actually detect if you know how to configure the parameters. Unfortunately most just copy/paste the code and scratch their heads as to why it doesnt work. Well....in programming, numbers mean things. Best to know what every number/parameter represents. Can you post a non processed image so I can run it through my app?

( 2016-04-27 09:13:21 -0500 )edit

I tried to detect it with HoughCircles and it gave me many circles apart from the real outer circle, I will add an image in my original post to show what I got. I also tried tweaking it with at least one paramter which (according to the tutorial/documentation AFAIR) should be used to sort out false positive circles. This sorted out the one real circle in my image at first. I also read that HoughCircles is very sensitive if the picture is viewed from another angle, so if the circle is not perfectly circular anymore.

However, I managed to sort out most of the false positive ellipses with another formula for eccentricity (just divide the axis lengths, google helps) and by filtering by area.

So currently I have a comparatively stable approach, but I am open to new methods of course.

( 2016-04-28 02:41:30 -0500 )edit

3 answers

Sort by ยป oldest newest most voted

as an initial try i made some changes on squares.cpp like seen here. it is true that the code to find circles is almost same :)

EDIT:

here you can find my trial code. it is still crude but may be you will improve it.

more

Comments

Excellent!

( 2016-04-28 12:29:41 -0500 )edit

Very nice, thanks for another approach!

( 2016-04-29 04:56:40 -0500 )edit

Here is the result. The marking is not ideal, but it will detect it. I could not get the circles center to line up correctly, so this is the best result I could achieve.

more

Comments

1

i suggest you to delete this answer before downvotes.

( 2016-04-28 11:14:25 -0500 )edit

Thank you for your concern. I do not care at all about downvotes, that is a popularity contest for little kids imo. Truth is the truth...opinion is irrelevant.

( 2016-04-28 11:18:16 -0500 )edit

OK. then +1 from my side. your answer at least shows that HoughCircles is not a good solution.

( 2016-04-28 11:30:40 -0500 )edit

True....as the pic is now. Sometimes it is easier to process the image to fit the algorithm, rather than try to fit an algorithm to an image. Just my opinion. I would increase the height of and or skew/transform the image to make the circle a circle again. Then run HoughCircles or whatever detection algorithm works. :o)

( 2016-04-28 12:02:12 -0500 )edit
1

@jmbapps How did you do it? I think that an answer should contains some explanation better if with a bit of code... not for votes but for users :)

( 2016-04-29 03:41:27 -0500 )edit

Thanks for your input! But in my case, it wouldn't just be possible (or at least I do not know how to achieve it) to fit the image to the algorithm... I want to track my target from different angles and distances in a stream of camera frames, so it would be hard to fit the image for every frame...

( 2016-04-29 04:55:14 -0500 )edit

@pklab the code is the easy part, it is the parameters that must be adjusted for accuracy. I adjust the last two parameters way up to about 190 for minRadius and 200 for maxRadius, since the circle is huge. @lucis yes, different/changing angles is difficult, hough circles likes the same parameters over and over. :o)

( 2016-04-29 09:16:19 -0500 )edit

do you really need the ellipse? or just the corners of the cross is sufficient?

warning: it has not been tested on other orientation

f1 = cv2.goodFeaturesToTrack (
cv2.pyrDown(img), 3,
0.95,
50.)*2.

features = cv2.goodFeaturesToTrack (
img, 10,
0.33,
50.)

for f in f1:
cv2.circle(img, tuple(f[0]), 5, (255))

for f in features:
cv2.circle(img, tuple(f[0]), 2, (255))

more

Stats

Asked: 2016-04-25 09:31:55 -0500

Seen: 4,868 times

Last updated: Apr 30 '16