图片正常显示但是,cv2 读取图片libpng error: Read Error,
程序员文章站
2022-07-14 17:10:06
...
读取图片png 无法转换为np.array ,用 pil 读取图片再转换成 cv2
g = os.path.join(G_ROOT, name)
img_g = cv2.imread(g)
if img_g is None:#图片路径存在正常图片,但是cv2 读取图片报错
print(g)
img = Image.open(g)
img = np.asanyarray(img)
img_g = img[:, :, [2, 1, 0]] # 原本是RGB->BGR
per_image_Bmean = np.mean(img_g[:, :, 0])
per_image_Gmean = np.mean(img_g[:, :, 1])
per_image_Rmean = np.mean(img_g[:, :, 2])