如何解决将 cv2.findHomography 限制在一个平面上
实际上这是我在堆栈溢出中的第一个问题,所以我们开始:
我正在尝试使用 orb.detectAndCompute 和 cv2.findHomography 对齐两个文本图像。大多数情况下它工作正常,但在某些情况下,输出是扭曲的 3D 并且单词似乎从页面中弹出(主要是当页面不包含足够的句子时)。 由于我使用的是扫描图像,我实际上只需要在一个平面上旋转和调整图像。因此我的问题是:有没有办法限制 cv2.findHomography 只在一个平面上匹配和移动?
非常感谢!
夏妮。
以下是我在python中使用的代码:
#loading images:
overlayed = cv2.imread('Master_reshape.png')
newImg = cv2.imread('Student-ID-Number-9-1.png')
#gray scale
gray_newImg = cv2.cvtColor(newImg,cv2.COLOR_BGR2GRAY)
gray_overlayed = cv2.cvtColor(overlayed,cv2.COLOR_BGR2GRAY)
MAX_FEATURES = 500
GOOD_MATCH_PERCENT = 0.15
orb = cv2.ORB_create(MAX_FEATURES)
keypoints1,descriptors1 = orb.detectAndCompute(gray_newImg,None)
keypoints2,descriptors2 = orb.detectAndCompute(gray_overlayed,None)
# Match features.
matcher = cv2.DescriptorMatcher_create(cv2.DESCRIPTOR_MATCHER_BRUTEFORCE_HAMMING)
matches = matcher.match(descriptors1,descriptors2,None)
# Sort matches by score
matches.sort(key=lambda x: x.distance,reverse=False)
# Remove not so good matches
numGoodMatches = int(len(matches) * GOOD_MATCH_PERCENT)
matches = matches[:numGoodMatches]
# Extract location of good matches
points1 = np.zeros((len(matches),2),dtype=np.float32)
points2 = np.zeros((len(matches),dtype=np.float32)
for i,match in enumerate(matches):
points1[i,:] = keypoints1[match.queryIdx].pt
points2[i,:] = keypoints2[match.trainIdx].pt
# Find homography
h,mask = cv2.findHomography(points1,points2,cv2.RANSAC)
# Use homography
height,width = gray_overlayed.shape
aligned = cv2.warpPerspective(gray_newImg,h,(width,height))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。