So I am trying to create a Python Program to detect similar details in two images using Python's OpenCV. I have the two images and they are in my current directory, and they exist (see the code in lines 6-17). But I am getting the following error when I try running it.
import numpy as np
import matplotlib.pyplot as plt
import cv2
import ospath1 = "WIN_20171207_13_51_33_Pro.jpg"
path2 = "WIN_20171207_13_51_43_Pro.jpg"if os.path.isfile(path1):img1 = cv2.imread('WIN_20171207_13_51_33_Pro.jpeg',0)
else:print ("The file " + path1 + " does not exist.")if os.path.isfile(path2):img2 = cv2.imread('WIN_20171207_13_51_43_Pro.jpeg',0)
else:print ("The file " + path2 + " does not exist.")orb = cv2.ORB_create()kpl1, des1 = orb.detectAndCompute(img1,None)
kpl2, des2 = orb.detectAndCompute(img2,None)bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)matches = bf.match(des1, des2)
matches = sorted(matches, key=lambda x:x.distance)img3 = cv2.drawMatches(img1,kpl1,img2,kpl2,matches[:10],None, flags=2)plt.imshow (img3)
plt.show()
Here is the error I keep on getting...
Traceback (most recent call last):File "C:\Users\jweir\source\repos\BruteForceFeatureDetection\BruteForceFeatureDetection\BruteForceFeatureDetection.py", line 31, in <module>plt.imshow (img3)File "C:\Program Files\Python36\lib\site-packages\matplotlib\pyplot.py", line 3080, in imshow**kwargs)File "C:\Program Files\Python36\lib\site-packages\matplotlib\__init__.py", line 1710, in innerreturn func(ax, *args, **kwargs)File "C:\Program Files\Python36\lib\site-packages\matplotlib\axes\_axes.py", line 5194, in imshowim.set_data(X)File "C:\Program Files\Python36\lib\site-packages\matplotlib\image.py", line 600, in set_dataraise TypeError("Image data cannot be converted to float")
TypeError: Image data cannot be converted to float
Can someone please explpain to me why I am getting this error, what it means, and how to fix it.