I couldn’t open different images with OpenCV altough I could open with PIL by the way I tried to open these images in PyCharm and in Spyder.How can I fix this problem? I deleted and reinstalled OpenCV but it didn’t work.
OpenCv Verssion: 4.8.0.76
Python Version:3.11.3 (tags/v3.11.3:f3909b8, Apr 4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)]
import cv2
image = cv2.imread(r"C:\Users\ozber\OneDrive\Masaüstü\images\kullan.jpg")
cv2.imshow("resim",image)
this is the code which I wrote.
Error message from PyCharm:
[ WARN:[email protected]] global loadsave.cpp:248 cv::findDecoder imread_('C:\Users\ozber\OneDrive\Masaüstü\images\kullan.jpg'): can't open/read file: check file path/integrity
Traceback (most recent call last):
File "C:\Users\ozber\AppData\Roaming\JetBrains\PyCharmCE2023.2\scratches\openCv.py", line 6, in <module>
cv2.imshow("resim",image)
cv2.error: OpenCV(4.8.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:971: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
Error Message from Spyder:
runfile('C:/Users/ozber/.spyder-py3/temp.py', wdir="C:/Users/ozber/.spyder-py3")
Traceback (most recent call last):
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File c:\users\ozber\.spyder-py3\temp.py:6
cv2.imshow("resim",image)
error: OpenCV(4.8.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:971: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
[ WARN:[email protected]] global loadsave.cpp:248 cv::findDecoder imread_('C:\Users\ozber\OneDrive\Masa端st端\images\kullan.jpg'): can't open/read file: check file path/integrity
but this code which I wrote in PIL works very well.
from PIL import Image
img=Image.open(r"C:\Users\ozber\OneDrive\Masaüstü\images\kullan.jpg")
img.show()
Have you tried if the image loads correctly when the path does not contain special characters (
ü
in this case)Thank you a lot.I changed name of the masaüstü folder as a “desktop” and it worked.