Rotation and scale invariant template matching in OpenCV [duplicate]

狂风中的少年 提交于 2019-12-31 16:48:10

问题


Possible Duplicate:
scale and rotation Template matching

I have a template grayscale image , with white background and black shape over it. I also have several similar test images which vary in rotation and in shape. The test images are not same as template but they are similar.

I want to compare these two images and see if template matches , is most similar to, any of the test images. There are no distortions , no noise and no other defects in the images. Are there any tutorials on this topic ?


回答1:


Try the easiest method first.

If I understand you correctly you have some model - black shape over white background. You can treat it as blob - find it's mass center and rotation by computing principal axes angle - look there.

Then you must segment out shapes from other images. Then try to find the best corresponding shape with matchShapes() function - see there how to use it.

matchShapes() function makes scale and rotation invariant matching. The smallest match shapes result the better match.

Extending your question you can find mass center and rotation of best matching blob and find rotation, scale and displacement between your model and matched image.




回答2:


This is quite a complex subject. You generally have options such as Generalized Hough Transform and Normalized Grayscale Correlation to deal with template matching. Problem is they are not scale or rotation invariant in their simplest expression. You need to focus on problem at the time, the generalized solution is complex. I recommend simple template matching first. Then add "hacks" for rotation and scale. For rotation you can downscale (low res. matching) and template match with rotated models. This can also deal with scale.



来源:https://stackoverflow.com/questions/12601583/rotation-and-scale-invariant-template-matching-in-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!