模板与不同的模板大小匹配

发布于 2025-01-27 12:09:57 字数 1104 浏览 2 评论 0 原文

我之前已经看过这样的问题,但是这些问题是指图像缩放,这意味着纵横比一直相同。我的目标是分析每个图像( 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()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文