Home>

Template matching using python opencv

Link content

I'm referring to this site,

# Draw the range of the search window.
fig, ax = plt.subplots (facecolor = "w")
ax.add_patch (plt.Rectangle ((x, y), w, h, ec = "r", fc = "none"))
ax.imshow (cv2.cvtColor (img, cv2.COLOR_BGR2RGB))
plt.show ()
print ("similarity:", result [x, y]) # similarity: -0.0350026

Can this part be considered a subset of template matching? ?
In actual creation, the modified subset does not always maintain a square even if you first define a square, so I want the subset to be transformed by the input image, but the meaning of plt.Rectangle Tell me how to write a program

Link content

  • Answer # 1

      

    Can this part be considered a subset of template matching? ?

    Return value result of cv2.matchTemplate () contains the similarity between the template image and its area at each position when the search window is moved.
    The question code is the code that visualizes the result [x, y] by drawing the search window on the image to indicate where the search window is at the position of the image, and the template matching process itself It has nothing to do with.

    The template image does not need to be square, but can be any rectangular size.