cv2.imread 中文图片名或中文路径 返回None

cv2.imread 返回None

背景

同事给我传了一堆中文文件名的图片,我打算组合成视频进行AI 标注

解决办法

使用下面这个替代cv2.imread()

# 默认生成24帧率的视频
fps = 24
# size = (720, 1280)
size = (1280, 720)
currentTime = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
videoFileNameAndPath = f'Save-{currentTime}.avi'
print(f"video is {videoFileNameAndPath}")

writer = cv2.VideoWriter(videoFileNameAndPath, cv2.VideoWriter_fourcc(*'xvid'), fps, size, True)
picFile = ['H:\\中文的\\图片名称1.png','H:\\中文的\\图片名称2.png','H:\\中文的\\图片名称3.png','H:\\中文的\\图片名称4.png','H:\\中文的\\图片名称5.png','H:\\中文的\\图片名称6.png']
for pic in picFile:
    # cv_img = cv2.imread(pic)
    cv_img = cv2.imdecode(np.fromfile(pic, dtype=np.uint8), cv2.IMREAD_COLOR)
    writer.write(cv_img)

writer.release()

END

你可能感兴趣的:(AI,python,cv,python)