图像处理经常需要提取图片的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.
from PIL import Image import os fin = 'D:/test' fout = 'D:/test2' for file in os.listdir(fin): file_fullname = fin + '/' +file img = Image.open(file_fullname) a = [80, 100, 260, 300] box = (a) roi = img.crop(box) if fout not in os.listdir('D:/'): os.