【python】PIL和opencv读取图片后进行裁剪

PIL:

from PIL import Image

img = Image.open('test.jpg')
img.crop(50,60,170,150)  # (left, upper, right, lower)
img.save('img_cro.jpg')

opencv:

import cv2

img = cv2.imread('test.jpg')
img_crop = img[60:150, 50:170]   # 裁剪坐标为[y0:y1, x0:x1]
cv2.imwrite('img_crop.jpg')

【python】PIL和opencv读取图片后进行裁剪_第1张图片

你可能感兴趣的:(python,python)