More than 2 years after I asked the question, (I didn't know I was looking for something like this on that time) I implemented this.
The key is to use border pursuit, and then Fourier descriptors.
Now Fourier descriptors are size invariant but not rotation invariant.
To make them rotation invariant, I read the excellent book "Feautre Extraction and Image Processing" byNixon and Aguado
However I suspect that on that time (as now too) I was looking for ways to find those patterns when the pattern was inside a bunch of other patterns
Unfortunately - unless the patters are quite separable, the above method won't work.
I am going to describe the process I implemented here in broad terms, if you need a clarification please say so and I will edit >that< part.
The steps I took for recognition of shapes (and it works with letters too) are:
- Gray Scaling
- Binarization (with histograms)
- Labeling
- Fourier Descriptor representation
- Fourier Descriptor Comparison
Once I finished those, the process was that I showed the camera a shape and take notes of its FD representation. Once I took notes of the shapes I wanted to recognize I edited my code (I know , not fancy- sorry) and introduced that as "models" for the step 5. I reckon that an "automatic" method would have been better though. Also take into account that I implemented this all by myself without using OpenCV functions but I think equivalent functions can be found, so if you do, share your knowledge
1. Gray Scaling
Here I simply scan the image pixel by pixel and multiplied the RGB elements to find the Y element. In theory this is:
Y=0.2990R+0.587G+0.114B but I used integer equivalent integer constants that were a multiply of these and later I shifted the result. This is because integer calculation is faster.
(At the same time, I built a histogram -since i was scanning the pixels already, - I know it is not good modular design but anyway it works. This histogram is going to be used in the next step
2. Binarization
I did not want to use a binarization in which I had to manually give a threshold so I use the histogram for automatic thresholding. In the case I am commenting I think I used the method called "Mode method" but I am not sure since I work in japanese actually. Anyway, the method is basically take the histogram that was constructed in the previous step and find the two tallest peaks. Then find the lowest valley between them and set the threshold there.
In a different application I have used the "Discriminant analysis Method". It also works well but I have not made comparisons
3. Labeling
Labeling involves a little complicated procedure. I am not sure I will be able to explain it here very well but it basically involves scanning the image pixel by pixel, processing only the white pixels (the blacks are background), then when finding ... (more)
Hi,
I would go on methods relative to shape-based detection like Chamfer matching:
Thank you for your comment. Is this method robust to rotation and scaling?
Right now I am reading about keypoints, SURF and SIFT. Can't say I see the light at the end of the tunnel yet...
In my opinion detection based upon keypoints won't help you much because there is no texture on images you show.
The basic Chamfer matching is not rotation nor scale invariant but there are extended methods that deal better with these cases and you can also manually rotate the images.
If your query images are relative simple (only basic shapes, no cluttered background, ...), you can try to detect the half-circle and the rectangle like Florian Castellane said.
Have you checked Halcon library?
Yes, I worked with halcon for a while. As you can see from my answer I solved this with pure C++ programming. But I don't remember the original motivation of my question so I suspect that I have not solved the difficult cases of finding patterns in ocluded positions.
Now I have a new question, although related. Please check it