I am trying to open .tif images, but I get this error:
Error:
cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-h2062vqd/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
Any idea what this is? I searching it however..
Thank you again for the code!!
Have you tried several tif?
You can try to check file exists and
frame = cv2.imread(path, 1) (1 for color, 0 for Gray)
Line 482 and following
def openFile(self):
print("open File Dialog")
path, _ = qt.QFileDialog.getOpenFileName(self, "Open File", self.image_file_path,"Image Files (*.tif *.tiff *.png *.jpg)")
if path:
if os.path.isfile(path):
self.image_file_path = path
print("file exists:",self.image_file_path)
isTest = True
self.updateFrame()
else:
print("file not exists")
def getFrame(self, path):
if isTest:
if os.path.isfile(path):
frame = cv2.imread(path, 1)
# OpenCV uses BGR as its default colour order for images
self.img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
else:
self.openFile()
else:
........
Yes many different .tif where tried.
I changed this line:
self.img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
with this line (that seems to work on a code without loading button)
self.img = cv2.imdecode(np.fromfile(frame, dtype=np.uint8), cv2.IMREAD_UNCHANGED)
but I get this error:
Error:
self.img = cv2.imdecode(np.fromfile(frame, dtype=np.uint8), cv2.IMREAD_UNCHANGED)
AttributeError: 'numpy.ndarray' object has no attribute 'flush'
I am trying with hours of google searching to figure out how to fix it...! Any ideas?
update: Ok, I will take a look. Thanks!!
(I posted the question and then I saw your last post with OrthoViewLite).
my numpy Version is 1.17.4
Your OrthoViewLite code is fantastic!!! Many thanks!! So I tested many .tif images. Some open, some others not. When .tif images do not open, the terminal shows me this message:
Error:
[ WARN:0] global /tmp/pip-req-build-h2062vqd/opencv/modules/imgcodecs/src/grfmt_tiff.cpp (457) readData OpenCV TIFF: TIFFRGBAImageOK: Sorry, can not handle images with 32-bit samples
no image!
you can try
frame = cv2.imread(path, cv2.IMREAD_UNCHANGED)
Mr. Axel_Erfurt it works! Amazing!!!! Thank you very much!!!
Where in the code can I read the label/filename (not the whole path) of the .tif file that I import?