📌  相关文章
📜  *** AttributeError: module 'cv2.cv2' has no attribute 'drawKeypoints' - C 编程语言(1)

📅  最后修改于: 2023-12-03 15:29:07.083000             🧑  作者: Mango

AttributeError: module 'cv2.cv2' has no attribute 'drawKeypoints' - C 编程语言

问题描述: 在使用opencv库的drawKeypoints函数时,报错"AttributeError: module 'cv2.cv2' has no attribute 'drawKeypoints'"

问题原因: cv2在3.x版本后,将drawKeypoints函数移除,使用drawMatchesKnn函数代替。

解决方法: 将cv2.drawKeypoints(img, kp, outImage[, color[, flags]])函数改为cv2.drawMatchesKnn()函数即可。

import cv2

img = cv2.imread('test.jpg')
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

surf = cv2.SURF(400)
kp, des = surf.detectAndCompute(gray, None)

img=cv2.drawMatchesKnn(img, kp, img, kp, None, flags=2)

cv2.imshow("result", img)
cv2.waitKey(0)