读取与写入带有中文名的图像
# 读取图像
# 两种形式都可
image_path = "测试.jpg"
image_path = pathlib.Path("测试.jpg")
# 注意这里是rgb通道顺序
image = cv2.imdecode(
np.fromfile(image_path, dtype=np.uint8),
1
)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
mask_pred = cv2.imdecode(
np.fromfile(mask_pred_path, dtype=np.uint8),
0
)
# 写入图像
# 两种形式都可
image_path = "测试.jpg"
image_path = pathlib.Path("测试.jpg")
cv2.imencode('.jpg', image)[1].tofile(
image_path
)
cv2.imencode('.png', mask)[1].tofile(
mask_path
)