将 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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...