2016-03-14 56 views
1

我一直在試圖使用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 
+0

嘗試'cv2.drawKeypoints(灰,kp,img,flags = cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)'(沒有'img ='和'dummy') – Miki

+0

試過了。它沒有工作。仍然有!outImage.empty()錯誤 – Pedro

+1

然後沒有線索。祝你好運! ; d – Miki

回答

3

問題是讀取一個JPEG文件爲JPEG格式。只要我改變它,它的工作

0

只要檢查你的文件名。如果他們錯了,你不會得到好的錯誤消息,但只是得到NULL指針或其他什麼,並且程序只會提前給出這樣的消息...

0

路徑不存在!(如果擴展png格式是一樣的)

'\家\ gaiarsa \矩陣\ poste.jpg'

前檢查路徑使用它:

import os 
if not os.path.exists('path/file'): 
    print('Incorrect path or file missing') 
    exit(0)