cv2.imread中文路径错误
时间: 2023-09-11 09:04:23 浏览: 158
解决python cv2.imread 读取中文路径的图片返回为None的问题
5星 · 资源好评率100%
cv2.imread函数在读取中文路径时会发生错误。这是因为cv2.imread函数无法处理含有中文字符的文件路径。为了解决这个问题,可以使用以下方法来处理中文路径错误。首先,可以使用np.fromfile函数来读取图片文件,并将数据类型设置为np.uint8,然后再使用cv2.imdecode函数解码读取到的数据。具体代码如下:
```python
import cv2 as cv
import numpy as np
path = r"F:\下载\psd27277.jpg"
img = cv.imdecode(np.fromfile(path, dtype=np.uint8), -1)
```
通过以上代码,可以成功读取含有中文字符的文件路径中的图片。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [解决cv2.imread不能读取中文路径的问题](https://blog.csdn.net/weixin_47151919/article/details/120995792)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [解决python cv2.imread 读取中文路径的图片返回为None的问题](https://download.csdn.net/download/weixin_38536576/13711676)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [【常见问题】python调用cv.imread()读取中文路径图像失败](https://blog.csdn.net/W9XM96/article/details/127423080)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文