解决Python3不能读取中文命名的图片
今天在读取"浙K05521_262094.jpg"时,报错“error: (-215) dims <= 2 && step[0] > 0 in function cv::Mat::locateROI”。查阅资料后得知,Python不能读取中文命名的图片,后找到解决方案。
imread读取图片包含中文路径:
# 读取图像,解决imread不能读取中文路径的问题
def cv_imread(filePath):
cv_img=cv2.imdecode(np.fromfile(filePath,dtype=np.uint8),-1)
# imdecode读取的是rgb,如果后续需要opencv处理的话,需要转换成bgr,转换后图片颜色会变化
cv_img=cv2.cvtColor(cv_img,cv2.COLOR_RGB2BGR)
return cv_img
-
def cv_imread(file_path): -
cv_img=cv2.imdecode(np.fromfile(file_path,dtype=np.uint8),-1) -
return cv_img
# 保存图像 imwrite
def cv_imwrite(filename,src):
cv2.imencode('.jpg',src)[1].tofile(filename)
-
file = 'C:/测试.jpg'
-
import cv2
-
import numpy as np
-
img = cv2.imdecode(np.fromfile(file, dtype=np.uint8), -1)
-
cv2.imencode('.jpg',img)[1].tofile('C:/测试1.jpg')#保存
imread 函数第二各参数默认情况下读取彩色图片。
| Parameters: |
|
|---|
参考:
解决python3.x的opencv不能读取中文路径的图片
Python opencv处理图像时文件名含有中文问题
最后
以上就是刻苦冥王星最近收集整理的关于解决Python3不能读取中文命名的图片解决Python3不能读取中文命名的图片的全部内容,更多相关解决Python3不能读取中文命名内容请搜索靠谱客的其他文章。
发表评论 取消回复