obr与flann一起使用报错
import cv2
import numpy as np
#读两个文件
img1=cv2.imread('math/opencv_search.jpg')
img2=cv2.imread('math/opencv_orig.jpg')
#灰度化
g1=cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
g2=cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
#建立特征检测器
orb=cv2.ORB_create()
#计算描述子与特征点
kp1,des1=orb.detectAndCompute(g1,None)
kp2,des2=orb.detectAndCompute(g2,None)
#创建匹配器
index_params=dict(algorithm=1,trees=5)
search_params=dict(checks=50)
flann=cv2.FlannBasedMatcher(index_params,search_params)
#对描述子进行匹配计算
matches = flann.knnMatch(np.asarray(des1, np.float32), np.asarray(des2, np.float32), k=2)
good=[]
for i,(m,n) in enumerate(matches):
if m.distance<0.7*n.distance:
good.append(m)
ret=cv2.drawMatches(img1,kp1,img2,kp2,[good],None)
cv2.imshow('img3',ret)
cv2.waitKey(0)
cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'drawMatches'
Overload resolution failed:
- Can't parse 'matches1to2'. Sequence item with index 0 has a wrong type
- Can't parse 'matches1to2'. Sequence item with index 0 has a wrong type
- drawMatches() missing required argument 'matchesThickness' (pos 7)
- drawMatches() missing required argument 'matchesThickness' (pos 7)
把int改成float
可以正常使用
ret=cv2.drawMatches(img1,kp1,img2,kp2,[good],None) 你这里边的参数是不是写反了,kp1和kp2