python ‘PngImageFile‘ object has no attribute ‘shape‘
python 'PngImageFile' object has no attribute 'shape'Image.open打开的图片类型为’PngImageFile’,不能直接img.shape查看维度,要转成数组,即可查看def crop_img(img_path):save_path = r'E:\Code-\ir_detection\test_gan_neg_112_0422'img_n
·
python 'PngImageFile' object has no attribute 'shape'
Image.open打开的图片类型为’PngImageFile’,不能直接img.shape查看维度,要转成数组,即可查看
def crop_img(img_path):
save_path = r'E:\Code-\ir_detection\test_gan_neg_112_0422'
img_name = img_path.split('\\')[-1]
image = Image.open(img_path) #(128,128)
image = image.crop([8,8,120,120])
image = np.asarray(image)
print('image.shape',image.shape)
print('save_path', save_path+'\\'+img_name)
#image.save(save_path+'\\'+img_name)
#image = cv2.merge([image, image, image])
cv2.imwrite(save_path+'\\'+img_name, image)
另外,Image方法中的crop对应的四个点坐标为(x, y, x+w, y+h)
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)