代码
以裁成55*55为例
for i in range(0,403):a=i+1b=i+1img_name = str(a)img = cv2.imread("C:/Users/10230/Desktop/img_data/"+img_name+".png")cropped = img[0:55, 0:55] # 按坐标裁剪,坐标为[y0:y1, x0:x1]img_name2 = str(b)cv2.imwrite("../data/img_data/"+img_name2+".png", cropped)
借鉴该博主裁剪单张图片代码