當(dāng)收到“ValueError: not enough values to unpack
我正在使用 Python (3) 和 OpenCV (3.3) 在網(wǎng)絡(luò)攝像頭上運(yùn)行實(shí)時(shí)對(duì)象檢測(cè),使用樣本圖像,然后與視頻流進(jìn)行特征匹配。我已經(jīng)使用 SIFT/SURF 讓它工作,但我正在嘗試使用 ORB 算法。在某些情況下,我收到以下錯(cuò)誤導(dǎo)致程序崩潰:for i, (m, n) in enumerate(matches):ValueError: not enough values to unpack (expected 2, got 1)我理解崩潰背后的原因,有時(shí)圖像之間有很好的匹配,有時(shí)沒有,導(dǎo)致不匹配。我的問題是,如何強(qiáng)制程序忽略并跳過沒有足夠值的情況并繼續(xù)運(yùn)行。有問題的主要代碼區(qū)域: for i, (m, n) in enumerate(matches): if m.distance < 0.7*n.distance: good.append(m)“匹配”輸出示例:[[<DMatch 0x11bdcc030>, <DMatch 0x11bbf20b0>], [<DMatch 0x11bbf2490>, <DMatch 0x11bbf24f0>], [<DMatch 0x11bbf2750>, <DMatch 0x11bbf25d0>], [<DMatch 0x11bbf2570>, <DMatch 0x11bbf2150>], etc etc完整代碼:import numpy as npimport cv2from matplotlib import pyplot as pltimport matplotlib.patches as mpatchesimport os, os.pathimport mathimport timefrom datetime import datetimestartTime = datetime.now()MIN_MATCH_COUNT = 10 # default=10img1 = cv2.imread('Pattern3_small.jpg',0) # queryImage# Create ORB object. You can specify params here or later.orb = cv2.ORB_create()cap = cv2.VideoCapture(0)# cap = cv2.VideoCapture("output_H264_30.mov")# find the keypoints and descriptors with SIFTkp1, des1 = orb.detectAndCompute(img1,None)pts_global = []dst_global = []position = []heading = []# plt.axis([0, 1280, 0, 720])tbl_upper_horiz = 1539tbl_lower_horiz = 343tbl_upper_vert = 1008tbl_lower_vert = 110# cv2.namedWindow("Frame", cv2.WINDOW_NORMAL)# cv2.resizeWindow("Frame", 600,350)while True: _, img2 = cap.read() # Start timer timer = cv2.getTickCount() # find the keypoints and descriptors with SIFT # kp1, des1 = sift.detectAndCompute(img1,None) kp2, des2 = orb.detectAndCompute(img2,None) FLANN_INDEX_KDTREE = 0 FLANN_INDEX_LSH = 6 # index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5) index_params= dict(algorithm = FLANN_INDEX_LSH, table_number = 6, # 12, 6 key_size = 12, # 20, 12 multi_probe_level = 1) #2, 1
查看完整描述