问题
How can I match a masked image using matchTemplate() in OpenCV with C++?
This is my masked template image:
And this is my source image:
回答1:
Look at opencv example. You gotta call the matchTemplate function:
matchTemplate( img, templ, result, match_method );
回答2:
matchTemplate's fifth argument is a mask array which you can use for this purpose. In your case, you'll want a binary mask. That is, a Mat with:
- depth
CV_8U, and - dimensions equal to your template image, and
- the pixels you want to ignore from your template set to 0, and
- the pixels you want to be used set to a non-zero value (typically 1)
来源:https://stackoverflow.com/questions/16029844/matching-template-images-with-masks-using-opencv-and-c