Python 3.x Open CV不会过滤所有异常点

Python 3.x Open CV不会过滤所有异常点,python-3.x,opencv3.0,stereo-3d,homography,Python 3.x,Opencv3.0,Stereo 3d,Homography,我试图获得重要的关键点和两幅图像之间的对应关系。下面的代码获取关键点并计算基本矩阵和掩码。但是当我画出这些点的时候,它仍然给了我很多点,这些点并不接近于界线 dir1 = './INPUT/rectifiedimages/im1_rec.jpg' dir2 = './INPUT/rectifiedimages/im2_rec.jpg' image1 = cv2.imread(dir1, 0) # queryimage # left image image2 = cv2.imread(dir2

我试图获得重要的关键点和两幅图像之间的对应关系。下面的代码获取关键点并计算基本矩阵和掩码。但是当我画出这些点的时候,它仍然给了我很多点,这些点并不接近于界线

dir1 = './INPUT/rectifiedimages/im1_rec.jpg'
dir2 = './INPUT/rectifiedimages/im2_rec.jpg'

image1 = cv2.imread(dir1, 0)  # queryimage # left image
image2 = cv2.imread(dir2, 0)  # trainimage # right image


# Initiate SIFT detector
orb = cv2.ORB_create()
# find the keypoints and descriptors with SIFT
kp1, des1 = orb.detectAndCompute(image1,None)
kp2, des2 = orb.detectAndCompute(image2,None)

# BFMatcher with default params
bf      = cv2.BFMatcher()
matches = bf.knnMatch(des1, des2, k=2)


# Apply ratio test
good = []
for m,n in matches:
    if m.distance <= 1.*n.distance:
        good.append(m)


src_pts = np.float32([kp1[m.queryIdx].pt for m in good]).reshape(-1, 1, 2)
dst_pts = np.float32([kp2[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)
F, maskF = cv2.findFundamentalMat(src_pts, dst_pts, cv2.RANSAC, 1., 1.) # 
cv2.CV_FM_LMEDS cv2.RANSAC

#--- remove masked points outliers
good = [good[i] for i,v in enumerate(maskF) if v[0] == 1]

src_pts = np.float32([kp1[m.queryIdx].pt for m in good]).reshape(-1, 1, 2)
dst_pts = np.float32([kp2[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)
H, maskH     = cv2.findHomography(src_pts, dst_pts, cv2.FM_LMEDS, 0., 0.99)
mask = maskH

matchesMask = mask.ravel().tolist()[![enter image description here][1]][1]

# cv2.drawMatchesKnn expects list of lists as matches.
draw_params = dict(matchColor = (0,255,0), # draw matches in green color
               singlePointColor = (0,0,255),
               matchesMask = matchesMask, # draw only inliers
               flags = 0)

img3 = cv2.drawMatches(image1, kp1, image2, kp2,good, None,**draw_params)
dir1='。/INPUT/rectifiedimages/im1_rec.jpg'
dir2='。/INPUT/rectifiedimages/im2_rec.jpg'
image1=cv2.imread(dir1,0)#queryimage#左图像
image2=cv2.imread(dir2,0)#列车图像#右图像
#启动筛分检测器
orb=cv2.orb_create()
#使用SIFT查找关键点和描述符
kp1,des1=orb.detectAndCompute(图像1,无)
kp2,des2=orb.detectAndCompute(图像2,无)
#具有默认参数的BFMatcher
bf=cv2.BFMatcher()
匹配=bf.knnMatch(des1,des2,k=2)
#应用比率测试
好的=[]
对于匹配中的m,n:
如果m.距离