我想做一个关于logo检测的简单项目。所以我试着跟随opencvpython教程学习特征检测。OpenCV: Feature Matching
我写的代码如下。在ratio = 0.8
logo = cv.imread("T01/CocaCola_logo2.png", cv.IMREAD_GRAYSCALE)
img = cv.imread("T01/CocaCola.png", cv.IMREAD_GRAYSCALE)
orb = cv.ORB_create()
kp_logo, des_logo = orb.detectAndCompute(logo, None)
kp_img, des_img = orb.detectAndCompute(img, None)
FLANN_INDEX_LSH = 6
index_params = dict(algorithm=FLANN_INDEX_LSH,
table_number=6,
key_size=12,
multi_probe_level=1)
search_params = dict(checks=50)
flann = cv.FlannBasedMatcher(index_params, search_params)
match_flann = flann.knnMatch(des_logo, des_img, k=2)
good = []
for p, q in match_flann:
if p.distance > q.distance*ratio:
good.append(p)
try:
img_match = np.empty((max(logo.shape[0], img.shape[0]), logo.shape[1] + img.shape[1], 3), dtype=np.uint8)
cv.drawMatchesKnn(logo, kp_logo, img, kp_img, good,
outImg=img_match, matchColor=None, singlePointColor=(255, 255, 255), flags=2)
cv.imshow("flann matching", img_match)
cv.waitKey(0)
except:
print("...")
此代码无法正常工作。进程总是由drawMatchesKnn()错误处理。在我将try except添加到该函数之前,进程发生了一个系统错误:SystemError:返回了NULL,但没有设置错误
问题的原因是什么?我试着找了很久,但对我来说不容易。在
堆栈跟踪:
回溯(最近一次呼叫):
文件“C:/Users/choib/Desktop/openCVtest3/T01_ORBtest.py“,第73行,英寸
cv.图纸匹配(logo,kp_logo,img,kp_img,good,outImg=img_match,matchColor=None,singlePointColor=(255,255,255),flags=2)
SystemError:返回空值,但未设置错误