I've already seen questions like this before, but those ones refer to image scaling, which means aspect ratio is same all the time. My goal is to analyze each image (Image 1 Image 2) and determine the template location (X and Y coordinates) and size (width and height of the recognized one as precise as possible) and write them into variables using single not warped reference. I'm not really into programming, that's just something I need for my project. I know the basics, so there's no need to explain a lot, if there's not big of a deal. I would really appreciate any help. Explanation
UPD:
import cv2
import numpy as np
img1 = cv2.imread('template.png')
img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
img2 = cv2.imread('image.png')
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
orb = cv2.ORB_create(nfeatures=500)
kp1, des1 = orb.detectAndCompute(img1, None)
kp2, des2 = orb.detectAndCompute(img2, None)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.match(des1, des2)
matches = sorted(matches, key=lambda x: x.distance)
match_img = cv2.drawMatches(img1, kp1, img2, kp2, matches[:50], None)
cv2.imshow('', match_img)
cv2.waitKey()
CodePudding user response:
I think you can refer to my github.
I implemented a fast image alignment algorithm on Fastest_Image_Pattern_Matching repo.
https://github.com/DennisLiu1993/Fastest_Image_Pattern_Matching
Transporting C code to python code may be an issue for you, but just find the corresponded function.