1.背景
项目需要,透过可视化的图片连接两张图的相似点检查SIFT之正确率
2.效果
3.代码
def drawMatchLine(Img1Path , Img2Path ):
# 读入图片
Img1 = cv2.imread(Img1Path)
Img2 = cv2.imread(Img2Path)
# 创建识别器
detector = cv2.xfeatures2d.SIFT_create(200)
# 计算KeyPoints
kp1 , des1 = detector.detectAndCompute(Img1,None)
kp2 , des2 = detector.detectAndCompute(Img2,None)
# BFMatcher
bf = cv2.BFMatcher()
matchers = bf.knnMatch(des1 , des2 , k=2)
# 相似列表
Match = []
for m,n in matchers:
if m.distance < 0.50*n.distance:
Match.append(m)
# 查看两张图片的宽及高
height1 , width1 = Img1.shape[:2]
height2 , width2 = Img2.shape[:2]
# 像素调整
vis = np.zeros((max(hei