opencv_python3使用cv2.imread()、cv2.imwrite()、cv2.imdecode、cv2.imencode读取中文路径报错问题

场景应用:https://blog.csdn.net/z564359805/article/details/84447377

import cv2
import numpy as np

# img_path图片路径需要更换
img=cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), -1)
# 以下这个不能处理图片放在中文名字的文件夹中,并且img如果返回None说明路径中有中文
# img = cv2.imread(img_path)
# img.shape返回(高度,宽度,通道数)的元组。
if img.shape[0] > img.shape[1]:
    dim = (600, 800)
else:
    dim = (800, 600)
# 修改图片尺寸后生成的图片
img_small = cv2.resize(img, dim)
# img_small_path生成的图片保存路径地址,这个不知道为啥返回None
status = cv2.imencode('.jpg', img_small)[1].tofile(img_small_path)
# 返回true或false,处理中文路径不是很好
# status = cv2.imwrite(img_small_path, img_small)

 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值