资源简介
为方便,只有源码,请自行安装包,请注意:OpenCV-Python-contirb 3.4.216 不要用4.-几的。代码中图片路径改一下运行即可
代码片段和文件信息
# coding: utf-8
import numpy as np
import cv2
leftgray = cv2.imread(r‘E:\pyProjects\cv-learning\7.jpg‘)
rightgray = cv2.imread(r‘E:\pyProjects\cv-learning\11.jpg‘)
SIZE=(600480)
leftgray=cv2.resize(leftgraySIZE)
rightgray=cv2.resize(rightgraySIZE)
hmerge = np.hstack((leftgrayrightgray)) #水平拼接
cv2.imshow(“gray“ hmerge) #拼接显示为gray
cv2.waitKey(0)
hessian = 900
surf = cv2.xfeatures2d.SIFT_create(hessian) # 将Hessian Threshold设置为400阈值越大能检测的特征就越少
kp1 des1 = surf.detectAndCompute(leftgray None) # 查找关键点和描述符
kp2 des2 = surf.detectAndCompute(rightgray None)
img3 = cv2.drawKeypoints(leftgraykp1leftgraycolor=(2550255)) #画出特征点,并显示为红色圆圈
img4 = cv2.drawKeypoints(rightgraykp2rightgraycolor=(2550255)) #画出特征点,并显示为红色圆圈
hmerge = np.hstack((img3 img4)) #水平拼接
cv2.imshow(“point“ hmerge) #拼接显示为gray
cv2.waitKey(0)
FLANN_INDEX_KDTREE = 0 # 建立FLANN匹配器的参数
indexParams = dict(algorithm=FLANN_INDEX_KDTREE trees=5) # 配置索引,密度树的数量为5
searchParams = dict(checks=50) # 指定递归次数
# FlannbasedMatcher:是目前最快的特征匹配算法(最近邻搜索)
flann = cv2.FlannbasedMatcher(indexParams searchParams) # 建立匹配器
matches = flann.knnMatch(des1 des2 k=2) # 得出匹配的关键点
good = []
# 提取优秀的特征点
for m n in matches:
if m.distance < 0.4* n.distance: # 如
评论
共有 条评论