在 Python 中使用 OpenCV 可以对图像进行剪裁。首先需要导入 OpenCV 库,然后使用 cv2.imread()
读取图片。然后使用 numpy
中的切片功能对图片进行剪裁。
代码示例如下:
import cv2
import numpy as np
img = cv2.imread('image.jpg')
height, width = img.shape[:2]
start_row, start_col = int(height * .25), int(width * .25)
end_row, end_col = int(height *