I have the following code attempting to show an image:
import cv2 img = cv2.imread('img.tif',0) print(img.size) cv2.imshow('image',img) k = cv2.waitKey(0) if k == 27: # wait for ESC key to exit cv2.destroyAllWindows()
which returns an error identifying ‘img’ as a NoneType object.
In the same folder I have the same image converted to png via an online converter. Changing the second line to:
img = cv2.imread('img.png',0)
shows the image as expected.
Also in the same folder I have a different .tif file.
img = cv2.imread('altimg.tif',0)
shows the alternate image as expected.
This leads me to believe that path name is not my issue as is common with NoneType errors using imread. I have also tried using the full path name for each file. Again, the only issue came using ‘img.tif’.
‘img.tif’ opens with no issue in Windows Photo Viewer when opened from my file explorer. Here is that image:
I am wondering if there are any other properties of the img.tif I may be overlooking that is preventing it from opening using OpenCV. The image is 640×800 pixels and the file size is 750 KB. I have not seen anything indicating that either of these parameters would cause an issue.
I am using Python3.6 64bit on Windows 10. Thanks for any suggestions.