我之前已经看过这样的问题,但是这些问题是指图像缩放,这意味着纵横比一直相同。我的目标是分析每个图像( image 1 模板位置(x和y坐标)和大小(尽可能精确识别的宽度和高度),并使用单个未翘曲参考。
我并不是真的很喜欢编程,这只是我项目所需的东西。我知道基础知识,因此,如果没有大笔交易,则无需解释很多。我真的很感谢任何帮助。 说明 upd:upd:upd: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()
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()
发布评论