我一直在試圖使用SIFT檢測器大約一個星期,當我終於得到它的工作,我得到一個錯誤與cv2.drawKeypoints()
函數。代碼如下:DrawKeypoints函數不工作在OpenCV3.0/Python 2.7
import cv2
import numpy as np
img = cv2.imread('\\home\\gaiarsa\\matrix\\poste.jpg')
gray = cv2.imread('\\home\\gaiarsa\\matrix\\poste.jpg', 1)
sift = cv2.xfeatures2d.SIFT_create()
dummy = np.zeros((1,1))
kp = sift.detect(gray, None)
img = cv2.drawKeypoints(gray, kp,dummy, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imwrite('sift_keypoints.jpg', img)
我運行它後,我得到的錯誤:
OpenCV Error: Assertion failed (!outImage.empty()) in drawKeypoints, file /home/gaiarsa/opencv/modules/features2d/src/draw.cpp, line 113
Traceback (most recent call last):
File "sift.py", line 14, in <module>
img = cv2.drawKeypoints(gray, kp,dummy, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.error: /home/gaiarsa/opencv/modules/features2d/src/draw.cpp:113: error: (-215) !outImage.empty() in function drawKeypoints
當我嘗試去除函數的參數dummy
數組,我得到以下錯誤:
Traceback (most recent call last):
File "sift.py", line 14, in <module>
img = cv2.drawKeypoints(gray, kp, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
TypeError: Required argument 'outImage' (pos 3) not found
嘗試'cv2.drawKeypoints(灰,kp,img,flags = cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)'(沒有'img ='和'dummy') – Miki
試過了。它沒有工作。仍然有!outImage.empty()錯誤 – Pedro
然後沒有線索。祝你好運! ; d – Miki