I am trying to work on my one of the requirements. I want to compare two images. In both the images there is main object which is key. I need to check if those keys are same or not. This is continuous requirement and every time I will get different images of keys to compare with original. The image and object(key) size is different. I need to analyze the Ridges and notches of keys in every image and based on that I need to give the result if the keys in the different images are same or how. I tried with Homography, OpenCV and Canny to check edges and similar points for the comparison but every time I got different result as image background is getting considered while comparing the image.
Note : I want to compare the objects similarity present in two different images and not the image comparison.
One approach I am thinking to start with where I will compare the edges of two images with Canny and then start checking the similar points with Homography but I am stuck as how to use below code for two or multiple images?
import numpy as np
image = cv2.imread('MyKey11.jpg')
original = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (3, 3), 0)
canny = cv2.Canny(blurred, 120, 255, 1)
kernel = np.ones((5,5),np.uint8)
dilate = cv2.dilate(canny, kernel, iterations=1)
# Find contours
cnts = cv2.findContours(dilate, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts if len(cnts) == 2 else cnts
# Iterate thorugh contours and filter for ROI
image_number = 0
for c in cnts:
x,y,w,h = cv2.boundingRect(c)
cv2.rectangle(image, (x, y), (x + w, y + h), (36,255,12), 2)
ROI = original[y:y+h, x:x+w]
image_number += 1
Please suggest the solution.