图像处理经常需要提取图片的ROI,本文使用Python提取图片的ROI. 使用的Module是PIL (Pillow),一个图像处理库,用到的函数为类 Image 中的 crop 方法. 函数原型为: Image.crop(box=None) Returns a rectangular region from this image. The box is a 4-tuple defining the left, upper, right, and lower pixel coordinate.
图片坐标和数组坐标是相反的,坐标原点位于左上角 import numpy as np import cv2 height, width = 150, 200 img = np.zeros((height, width, 3), np.uint8) img[:, :] = [255, 255, 255] # Pixel position to draw at row, col = 20, 100 # Draw a square with position 20, 100 as the top le