我遇到了问题,但我不明白为什么它不起作用。
我正在MacOSX Sierra
工作,我正在使用Python 2.7
和OpenCV 3.1
。
这是一个非常简单的脚本:
import numpy as np
import cv2
#from matplotlib import pyplot as plt
#########################
# SIFT descriptors part #
#########################
img1 = cv2.imread('/Users/valentinjungbluth/Desktop/SIFT:SURF Algo/lampe.jpg',0)
img2 = cv2.imread('/Users/valentinjungbluth/Desktop/SIFT:SURF Algo/ville.jpg',0)
#img1 = cv2.cvtColor(IMG1, cv2.COLOR_BGR2GRAY)
#img2 = cv2.cvtColor(IMG2, cv2.COLOR_BGR2GRAY)
# Initiate SIFT detector
sift = cv2.xfeatures2d.SIFT_create()
print (img1.dtype)
kp1, des1 = sift.detectAndCompute(img1,None)
kp2, des2 = sift.detectAndCompute(img2,None)
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1,des2,k=2)
good = []
for m,n in matches :
if m.distance < 0.75*n.distance :
godd.append([m])
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,flags=2)
#kp = sift.detect(gray,None)
#img = cv2.drawKeypoints(gray,kp,img)
cv2.imwrite('matches.jpg',img3)
但是当我在终端中运行脚本时,我得到了这个错误:
(cv) MacBook-Pro-de-Valentin:SIFT:SURF Algo valentinjungbluth$ python image.py
uint8
OpenCV Error: Bad argument (image is empty or has incorrect depth (!=CV_8U)) in detectAndCompute, file /Users/valentinjungbluth/opencv_contrib/modules/xfeatures2d/src/sift.cpp, line 770
Traceback (most recent call last):
File "image.py", line 22, in <module>
kp2, des2 = sift.detectAndCompute(img2,None)
cv2.error: /Users/valentinjungbluth/opencv_contrib/modules/xfeatures2d/src/sift.cpp:770: error: (-5) image is empty or has incorrect depth (!=CV_8U) in function detectAndCompute
dtype
是uint8
所以我不明白为什么会收到此错误。
如果有人可以帮助我?
非常感谢你!