问题
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