Ask Your Question
1

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

asked 2016-04-25 09:31:55 -0600

lucis_lupinum gravatar image

updated 2016-04-28 02:44:24 -0600

Hi,

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

target

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:

formula

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: output

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 flag offensive close merge delete

Comments

How do your images look like?

FooBar gravatar imageFooBar ( 2016-04-25 10:04:17 -0600 )edit

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

lucis_lupinum gravatar imagelucis_lupinum ( 2016-04-26 09:06:27 -0600 )edit

But you did not show any real data.

FooBar gravatar imageFooBar ( 2016-04-27 02:15:45 -0600 )edit

added an image

lucis_lupinum gravatar imagelucis_lupinum ( 2016-04-27 03:06:45 -0600 )edit

Can you add the original image without doing any preprocessing?

Balaji R gravatar imageBalaji R ( 2016-04-27 09:00:07 -0600 )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?

jmbapps gravatar imagejmbapps ( 2016-04-27 09:13:21 -0600 )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.

lucis_lupinum gravatar imagelucis_lupinum ( 2016-04-28 02:41:30 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
1

answered 2016-04-28 12:19:23 -0600

updated 2016-04-30 11:34:31 -0600

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 :)

image description

EDIT:

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

image description

image description

edit flag offensive delete link more

Comments

Excellent!

jmbapps gravatar imagejmbapps ( 2016-04-28 12:29:41 -0600 )edit

Very nice, thanks for another approach!

lucis_lupinum gravatar imagelucis_lupinum ( 2016-04-29 04:56:40 -0600 )edit
0

answered 2016-04-28 11:00:47 -0600

jmbapps gravatar image

updated 2016-04-28 11:17:09 -0600

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.

image description

edit flag offensive delete link more

Comments

1

i suggest you to delete this answer before downvotes.

sturkmen gravatar imagesturkmen ( 2016-04-28 11:14:25 -0600 )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.

jmbapps gravatar imagejmbapps ( 2016-04-28 11:18:16 -0600 )edit

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

sturkmen gravatar imagesturkmen ( 2016-04-28 11:30:40 -0600 )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)

jmbapps gravatar imagejmbapps ( 2016-04-28 12:02:12 -0600 )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 :)

pklab gravatar imagepklab ( 2016-04-29 03:41:27 -0600 )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...

lucis_lupinum gravatar imagelucis_lupinum ( 2016-04-29 04:55:14 -0600 )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)

jmbapps gravatar imagejmbapps ( 2016-04-29 09:16:19 -0600 )edit
0

answered 2016-06-02 15:50:36 -0600

peb gravatar image

image description

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))
edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 12,598 times

Last updated: Apr 30 '16