Python代码库之截取图片任意区域(含代码)

安装cv2

pip3 install -i https://pypi.douban.com/simple opencv-python

截取部分图片


import cv2
#读取图片
newfile='/Users/Downloads/output/new.png'
image_path='/Users/Downloads/output/004.png'
img=cv2.imread(image_path)

x=185
y=65
h=850
w=560

cropImg = img[(y):(y + h), (x):(x + w)]
cv2.imwrite(newfile, cropImg)

x=747
y=65
h=850
w=560

cropImg = img[(y):(y + h), (x):(x + w)]
cv2.imwrite(newfile, cropImg)

更多精彩代码请关注我的专栏

  • selenium & python 源码大全
  • reportlab教程和源码大全
  • python源码大全

你可能感兴趣的:(Python代码库之截取图片任意区域(含代码))