我的老师给我们做了以下练习:
{1美元^
目前,我所做的唯一的步骤是使用cv2.cornerHarris()获取两幅图像的Harris角点,然后将图片放在彼此相邻的位置。在
现在我不知道如何得到角落本身和他们周围的区域,以生成一个模板,可以用于模板匹配。在
我希望如果我掌握了这个技巧,我也许能解决剩下的练习题。 也许你们中的一些人可以帮我?简短地解释一下它是如何工作的将是非常有益的,这样我可以学到更多:)
以下是我当前的代码:
import cv2
import numpy as np
churchLeft = cv2.imread("./Church/church_left.png")
churchRight = cv2.imread("./Church/church_right.png")
def doHarris(img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
dst = cv2.cornerHarris(gray, 2, 3, 0.01)
# result is dilated for marking the corners, not important
dst = cv2.dilate(dst, None)
# Threshold for an optimal value, it may vary depending on the image.
img[dst > 0.01 * dst.max()] = [0, 0, 255]
return img
churchLeftHarris = doHarris(churchLeft)
churchRightHarris = doHarris(churchRight)
hor = np.hstack((churchLeftHarris, churchRightHarris))
cv2.imshow('test', hor)
while (1):
k = cv2.waitKey(1) & 0xFF
if k == 27:
break
你可以试试我的代码:
相关问题 更多 >
编程相关推荐