Detect custom shape OpenCV

折月煮酒 提交于 2021-02-07 19:04:26

问题


I want to find custom shape in OpenCV. Shape is previously defined. I want to detect if this shape is equal or not equal to the current shape using WebCam in real time.

How can I do that? How to compare pre-defined custom shape and current shape?


回答1:


As the commenters have eluded, you can use template matching to detect custom shapes.

So What Is Template Matching?

Template matching is a technique in digital image processing for finding small parts of an image which match a template image. It can be used in manufacturing as a part of quality control, a way to navigate a mobile robot, or as a way to detect edges in images.

Template Matching In OpenCV/Python

Template Matching is a method for searching and finding the location of a template image in a larger image. OpenCV comes with a function cv2.matchTemplate() for this purpose. It simply slides the template image over the input image (as in 2D convolution) and compares the template and patch of input image under the template image.

I have taken this text from here which is a tutorial on how to perform template matching in OpenCV. You can search for any "custom shape" that you define. It includes code samples for python.



来源:https://stackoverflow.com/questions/28428415/detect-custom-shape-opencv

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