I am trying to get the percent chance that an image is in another image in OpenCV.
Here are the images that I am comparing:
]2
Here is my code:
import cv2
import numpy as np
large_image = cv2.imread(r'Directory here')
#Cropping the image so that it's easier to compare
height = large_image.shape[0]
width = large_image.shape[1]
large_image = large_image[5:height-173,260:width-25]
small_image = cv2.imread(r'Directory here')
method = cv2.TM_SQDIFF_NORMED
# Read the images from the file
result = cv2.matchTemplate(small_image, large_image, method)
#BELOW IS ONLY IF YOU WANT TO SEE A RECTANGLE AROUND THE IMAGE
# We want the minimum squared difference
mn,_,mnLoc,_ = cv2.minMaxLoc(result)
# Draw the rectangle:
# Extract the coordinates of our best match
MPx,MPy = mnLoc
# Get the size of the template. This is the same size as the match.
trows,tcols = small_image.shape[:2]
# Draw the rectangle on large_image
cv2.rectangle(large_image, (MPx,MPy),(MPx+tcols,MPy+trows),(0,0,255),2)
# Display the original image with the rectangle around the match.
cv2.imshow('output',large_image)
cv2.waitKey(0)
Is this even possible with OpenCV?