I want to find slash (/) in my input image. When I crop slash(/) from an image and use template matching, in almost all cases, it works perfect; but if I use that template for another image with a little different shape of slash(/) it fails. You can see the example:
Here I use the template with another image and you can see it detects number 4 instead of (/)!
This is my question: How can I find object in my images similar to my template but with a little variety in slope or line thickness or ... ? Is there any way with template matching or do you suggest another methods according to your experience?
I will appreciate any related answer in advance.
CodePudding user response:
I think you are facing a limitation of template matching here. It seems like you are already using the right metric (normalised cross-correlation). Maybe one last thing you can do is to check for 5 templates: a 'perfect' one (take from a perfect image) and 4 rotated versions. Then, for each template you find the best match, and then compare the 5 best matches against each other to pick the best of them.
Depending on how much time you want to invest, and what robustness level you wish to accomplish, you can also use Neural Network ! It will b the more robust approach to this problem. Of course, there are some neural network trained for character detection, for instance here, and some available tutorial like this one.
If you don't want to use NN, you could think of another method which could work with line detection. A '/' character has a quite characteristic shape: a closed path, rotated with a certain angle, with 'inertia' around one single axis. That is easy to describe with some mathematical properties of the detected closed shape. This approach is called shape descriptor and is described (for instance) here. I think that if you have some knowledge on the size of the text, and pretty good image quality, then this 'low-level' approach has some potential. It often works really well.
I hope this helps you to solve your problem.