1、图像裁剪:已知要裁剪的左上角(x1, y1)、右下角(x2, y2),代码如下:
cropImg = img[y1:y2,x1:x2]
2、图像边界扩充:
//复制边缘像素值 a = cv2.copyMakeBorder(img,50,50,50,50,cv2.BORDER_REPLICATE) //边界处像素翻折 a = cv2.copyMakeBorder(img,50,50,50,50,cv2.BORDER_REFLECT) //设置扩展像素为绿色 a = cv2.copyMakeBorder(img,50,50,50,50, cv2.BORDER_CONSTANT,value=[0,255,0])