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)