Python 2.7: error in Canny Edge detection TypeError("Image data can not convert to float") -
i using canny edge detection algorithm in python 2.7.12 image (.jpg)
i used following code:
import cv2 import numpy np matplotlib import pyplot plt img = cv2.imread('35.jpg') edges = cv2.canny(img,150,200) plt.subplot(121),plt.imshow(img,cmap = 'gray') plt.title('original image'), plt.xticks([]), plt.yticks([]) plt.subplot(122),plt.imshow(edges,cmap = 'gray') plt.title('edge image'), plt.xticks([]), plt.yticks([]) plt.show()
but shows me error like
traceback (most recent call last): file "d:/python/test4.py", line 11, in <module> plt.subplot(121),plt.imshow(img,cmap = 'gray') file "c:\python27\lib\site-packages\matplotlib\pyplot.py", line 3157, in imshow **kwargs) file "c:\python27\lib\site-packages\matplotlib\__init__.py", line 1898, in inner return func(ax, *args, **kwargs) file "c:\python27\lib\site-packages\matplotlib\axes\_axes.py", line 5124, in imshow im.set_data(x) file "c:\python27\lib\site-packages\matplotlib\image.py", line 596, in set_data raise typeerror("image data can not convert float") typeerror: image data can not convert float
i saw many answers related unable rectify it. observed if save same image .png code run perfectly.what modifications should need in code run .jpg files? thanks.
i tried code.
problem occur when pass incorrect image path cv2.imread. otherwise, works fine. first of try check path image.
wiki
Comments
Post a Comment