EDIT 2:
Turns out the problem was that the path had Unicode symbols so the solution is in this post
EDIT 1:
Meanwhile, I found out that the problem is the combination of OpenCV + Spaces in Path + External Disk. Removing ANY of the elements solves the issue so the current target is just trying to find a solution for this combination.
OS is Windows
Problem:
I can't load images from my external HDD using Python-OpenCV.
I can use all the os
and open
Python functions such as read .TXT
files and list
/walk
directories from the HDD but when I try to load images using cv2.imread
I get a None
object...
The file path is written in a Python-friendly way (using "\" instead of "") and it works for reading the image as a binary with open(path, "rb")
Already Tried:
- r string
r"TEXT"
- Changing
\\
to/
- Double quotes
"\"TEXT\"\"
os
moduleos.path.normpath(PATH)
andos.path.join([HALF, HALF])
I also read the OpenCV documentation and tried Google and StackOverflow but I don't find anyone with my problem so I'm kind of lost about what to try next...
import cv2
image = cv2.imread("G:\\Fotografias e Vídeos\\[...]\\11009982_1254240047936434_1963406974405452579_n.jpg")
print(image)
cv2.imshow("d", image)
# Output
None
Traceback (most recent call last):
File "C:\Users\[NAME]\Documents\Python\test.py", line 4, in <module>
cv2.imshow("d", image)
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'