两种切割裁剪,切割图片的方法
作者:互联网
1.使用opencv来切割,这个你可以把图片理解成为二维数组来玩
pip install opencv-python
代码:
import cv2 def cut_img(old_path,new_path,area): img = cv2.imread(old_path) cropped = img[area[1]:area[3],area[0]:area[2]] cv2.imwrite(new_path,cropped)View Code
2.使用pillow来切割,这个是封装起来了,直接传参坐标
pip install pillow
代码:
from PIL import Image def cut_img(old_path,new_path,area): img = Image.open(old_path) cropped = img.crop(area) cropped.save(new_path) cut_image("E://0.png","E://0_new.png",(0,0,400,400))View Code
------------------------------------------------------------------------------
以上代码未测试......
标签:old,切割,img,area,裁剪,cropped,new,path,图片 来源: https://www.cnblogs.com/wusen0601/p/15487818.html