Python-opencv sift特征提取 匹配

系统说明:Python3.5.1,opencv_contrib3.4.1,window7

import cv2
import numpy as np

img_orign = cv2.imread(‘picture_orign.jpg’)
img=cv2.imread(‘picture.jpg’)
rows,cols = img.shape[:2]
gray_orign= cv2.cvtColor(img_orign,cv2.COLOR_BGR2GRAY)
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

sift=cv2.xfeatures2d.SIFT_create()

kp1, des1 = sift.detectAndCompute(gray_orign, None)
kp2, des2 = sift.detectAndCompute(gray, None)

bf = cv2.BFMatcher()
matches = bf.knnMatch(des1, des2, k=2)

good = []
for m, n in matches:
if m.distance < 0.75* n.distance:
good.append([m])
img3 = cv2.drawMatchesKnn(img_orign, kp1, img, kp2, good[:20], None, flags=2)

cv2.imshow(‘img’,img3)
cv2.waitKey(0)
cv2.destroyAllWindows()

结果:
这里写图片描述
进一步想实现通过匹配得出两幅图像的旋转矩阵,待续…

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41038905/article/details/79971612
上一篇ValueError: Tensorflow error: “Tensor must be from the same graph as Tensor…”
下一篇np.concatenate拼接两幅图片时问题解决
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭