[英]OpenCV Python can't read image from external HDD with white spaces in path
EDIT:编辑:
Meanwhile, I found out that the problem is the combination of OpenCV + Spaces in Path + External Disk.同时,我发现问题是路径+外部磁盘中的OpenCV + Spaces的组合。 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操作系统是 Windows
Already Tried:已经尝试过:
r"TEXT"
r"TEXT"
\\\\
to /
\\\\
更改为/
"\\"TEXT\\"\\"
"\\"TEXT\\"\\"
os
module os.path.normpath(PATH)
and os.path.join([HALF, HALF])
os
模块os.path.normpath(PATH)
和os.path.join([HALF, HALF])
I can't load images from my external HDD using Python-OpenCV .我无法使用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...我可以使用所有
os
和open
Python 函数,例如从硬盘读取.TXT
文件和list
/ walk
目录,但是当我尝试使用cv2.imread
加载图像cv2.imread
我得到一个None
对象...
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")
文件路径以 Python 友好的方式编写(使用“\\”而不是“”),它适用于使用
open(path, "rb")
以二进制形式读取图像
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...我还阅读了 OpenCV 文档并尝试了 Google 和 StackOverflow,但我没有找到任何有我问题的人,所以我对接下来要尝试的内容有点迷茫......
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'
While trying to figure this out by trial and error, I found something that doesn't quite solve the issue but is a almost-good-enough workaround.在尝试通过反复试验来解决这个问题时,我发现了一些不能完全解决问题但几乎足够好的解决方法。
If you copy-paste the script to somewhere in the HDD path and run it from inside, OpenCV can read the images normally.如果将脚本复制粘贴到硬盘路径中的某个位置并从内部运行它,OpenCV 可以正常读取图像。
As I said this is not yet ideal so if you have a solution to run scripts from inside the PC to open an external source image, please share.正如我所说,这还不理想,所以如果您有从 PC 内部运行脚本以打开外部源图像的解决方案,请分享。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.