Reputation: 61
i started on a project which inputs 2 images and detect the keypoints using sift and then checking the similarity of the 2 images
i actually completed the project without converting the image files to greycode but later i understood that converting images to grey code and then comparing gives more accurate results
so i wrote the code to convert the image to greycode but i am facing a problem
import cv2
import easygui
import sys
from matplotlib import pyplot as plt
print "image 1 :",sys.argv[1]
print "image 2 :",sys.argv[2]
print "******** comparing images please wait *********"
file1=sys.argv[1]
file2=sys.argv[2]
img1 = cv2.imread(file1,0)#queryImage
img2 = cv2.imread(file2,0)#trainImage
gray_image1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
gray_image2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
i am getting an error
image 1 : taj1.jpg
image 2 : taj2.jpg
******** comparing images please wait *********
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /root/opencv-3.3.0/opencv-3.3.0/modules/imgproc/src/color.cpp, line 10638
Traceback (most recent call last):
File "image_similarity.py", line 14, in <module>
gray_image1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
cv2.error: /root/opencv-3.3.0/opencv-3.3.0/modules/imgproc/src/color.cpp:10638: error: (-215) scn == 3 || scn == 4 in function cvtColor
how can i resolve it thanks in advance
Upvotes: 0
Views: 1024
Reputation: 10852
You don't need to convert it, if you load it as you do.
img1 = cv2.imread(file1,0)#queryImage
img2 = cv2.imread(file2,0)#trainImage
Second parameter=0 means you load it as gray scale image.
Upvotes: 1