(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:
How do your images look like?
What do you mean exactly? Which images? I want to track this target in a stream of camera images (e.g. video)
But you did not show any real data.
added an image
Can you add the original image without doing any preprocessing?
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?
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.