我尝试比较ORB
和BRISK
在图片之间匹配功能的效果。我已将以下函数写入每种方法选择的RANSAC
特征匹配:
def match_image_pair(img1, img2, method="ORB"):
detector = None
if method == "ORB":
detector = cv2.ORB()
elif method == "BRISK":
t = 30
octa = 1
pS = 1.0
detector = cv2.BRISK(thresh=t, octaves=octa, patternScale=pS)
if detector == None:
print "Dodgy method"
return
kp_orb, des_orb = detector.detectAndCompute(img1,None)
src_orb = [o.pt for o in kp_orb]
kp_orb_test, des_orb_test = detector.detectAndCompute(img2,None)
src_orb_test = [o.pt for o in kp_orb_test]
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.match(des_orb,des_orb_test)
print len(matches)
print len(src_orb), len(src_orb_test)
M, mask = cv2.findHomography(np.array(src_orb), np.array(src_orb_test), cv2.RANSAC,3.0)
matchesMask = mask.ravel().tolist()
matches = [m for m,mask in zip(matches,matchesMask) if mask]
return drawMatches(img1, kp_orb, img2, kp_orb_test, matches, match_meth=method)
如果method == "ORB"
,此函数可以正常工作,但method == "BRISK"
时出现异常:
1328
3650 1890
OpenCV Error: Assertion failed (npoints >= 0 && points2.checkVector(2) == npoint
s && points1.type() == points2.type()) in cv::findHomography, file ..\..\..\..\o
pencv\modules\calib3d\src\fundam.cpp, line 1074
Traceback (most recent call last):
File "match_with_ORB.py", line 134, in
match_image_pair(img, img_test, method="BRISK")
File "match_with_ORB.py", line 114, in match_image_pair
M, mask = cv2.findHomography(np.array(src_orb), np.array(src_orb_test), cv2.
RANSAC,3.0)
cv2.error: ..\..\..\..\opencv\modules\calib3d\src\fundam.cpp:1074: error: (-215)
npoints >= 0 && points2.checkVector(2) == npoints && points1.type() == points2.
type() in function cv::findHomography
我可以看到有1328个匹配,并且src_orb
和src_orb_test
列表分别有3650和1890个元素,因此我无法看到会导致异常的原因I& #39;我看到了。