Python 2.7 使用ORB图像功能匹配时出现OpenCV python错误
我试图使用OpenCV ORB匹配两个图像,如中所述 这是我的密码:Python 2.7 使用ORB图像功能匹配时出现OpenCV python错误,python-2.7,opencv,image-processing,feature-detection,orb,Python 2.7,Opencv,Image Processing,Feature Detection,Orb,我试图使用OpenCV ORB匹配两个图像,如中所述 这是我的密码: import numpy as np import cv2 import six import pyparsing import dateutil from matplotlib import pyplot as plt import timeit import os import sys img1_path = 'img1.jpg' img2_path = 'img2.jpg' img1 = cv2.imread(i
import numpy as np
import cv2
import six
import pyparsing
import dateutil
from matplotlib import pyplot as plt
import timeit
import os
import sys
img1_path = 'img1.jpg'
img2_path = 'img2.jpg'
img1 = cv2.imread(img1_path,0) # queryImage
img2 = cv2.imread(img2_path,0) # trainImage
orb = cv2.ORB()
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
FLANN_INDEX_LSH = 6
index_params= dict(algorithm = FLANN_INDEX_LSH,
table_number = 6, # 12
key_size = 12, # 20
multi_probe_level = 1) #2
search_params = dict(checks = 50)
flann = cv2.FlannBasedMatcher(index_params, search_params)
matches = flann.knnMatch(des1,des2,k=2)
if len(matches)>0:
print "%d total matches found" % (len(matches))
else:
print "No matches were found - %d" % (len(good))
sys.exit()
# store all the good matches as per Lowe's ratio test.
good = []
for m,n in matches:
if m.distance < 0.6*n.distance:
good.append(m)
当img2明显是img1的较小子映像时,就会发生这种情况
(如果img2是原始图像,img1是修改后的图像,则表示有人向原始图像添加了详细信息)
如果我在文件名img1、img2之间切换,那么脚本运行时不会出现问题
查询图像(img1)必须小于或等于列车图像(img2)?必须检查匹配列表中的每个成员是否确实存在两个邻居。这与图像大小无关
good = []
for m_n in matches:
if len(m_n) != 2:
continue
(m,n) = m_n
if m.distance < 0.6*n.distance:
good.append(m)
good=[]
对于匹配中的m_n:
如果len(m_n)!=2:
持续
(m,n)=m_n
如果m.距离<0.6*n.距离:
好。追加(m)
good = []
for m_n in matches:
if len(m_n) != 2:
continue
(m,n) = m_n
if m.distance < 0.6*n.distance:
good.append(m)