I get a problem but I don't understand why it doesn't work.
I'm working on MacOSX Sierra
and I'm using Python 2.7
and OpenCV 3.1
.
It's a very simple script :
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)
But when I run the script in the terminal, I get exactly this error :
(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
The dtype
is uint8
so I don't understand why I get this error.
If someone could help me ?
Thank you so much !