python opencv读取中文路径的完美替代
import cv2
import numpy as np
def cv2imread(img_path):
return cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), -1)
# 中文问题
def cv2imwrite(filename):
cv2.imencode('.jpg', img)[1].tofile(filename)
该博客介绍了如何使用自定义函数`cv2imread`和`cv2imwrite`来替代OpenCV中直接读取中文路径的方法。这两个函数分别用于读取和写入图像文件,有效解决了Python OpenCV在处理中文路径时可能出现的问题。
python opencv读取中文路径的完美替代
import cv2
import numpy as np
def cv2imread(img_path):
return cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), -1)
# 中文问题
def cv2imwrite(filename):
cv2.imencode('.jpg', img)[1].tofile(filename)
1269
2146

被折叠的 条评论
为什么被折叠?