gpt4 book ai didi

python - 由于文件路径中的特殊字符,OpenCv imwrite 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 11:20:16 25 4
gpt4 key购买 nike

当文件路径有特殊字符(例如“é”)时,我无法保存图像。

这是来自 Python 3 shell 的测试:

>>> cv2.imwrite('gel/test.jpg', frame)
True
>>> cv2.imwrite('gel/ééé/test.jpg', frame)
False
>>> cv2.imwrite('gel/eee/test.jpg', frame)
True

有什么想法吗?

谢谢!

编辑:

不幸的是,@PM2Ring 和@DamianLattenero 提出的所有建议似乎都不起作用:(

所以,我使用@cdarke 的解决方案,这是我的最终代码:

destination = 'gel/ééé/'
gel = 'test.jpg'
script_path = os.getcwd()
os.chdir(destination)
cv2.imwrite(gel, frame)
os.chdir(script_path)

最佳答案

可以先用OpenCV对图片进行编码,然后用numpy的tofile()方法保存,因为编码后的图片是一个一维的numpy ndarray:

is_success, im_buf_arr = cv2.imencode(".jpg", frame)

im_buf_arr.tofile('gel/ééé/test.jpg')

关于python - 由于文件路径中的特殊字符,OpenCv imwrite 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44330084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com