python图片处理

Posted Python程序设计教程

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python图片处理相关的知识,希望对你有一定的参考价值。

1、opencv

pip install opencv-python

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting opencv-python
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5c/6a/41f9afbe975851287a68a94ece3956e21f23da946643e59c44e1df5543a5/opencv_python-4.2.0.34-cp35-cp35m-macosx_10_9_x86_64.whl (49.1 MB)
     |████████████████████████████████| 49.1 MB 460 kB/s
Requirement already satisfied: numpy>=1.11.1 in /Users/tonghzgmailcom/opt/anaconda3/envs/env_zipline/lib/python3.5/site-packages (from opencv-python) (1.11.3)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.2.0.34

2、PIL

(env_python) D:\PycharmProjects\mypic>pip install Pillow


Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting Pillow
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/91/9e/1b45eed618c35010d8cc3ba57f12baf09af37054665b7cdf79aafa93ed75/Pillow-7.1.2-cp38-cp38-win_amd64.whl (2.0 MB)
     |████████████████████████████████| 2.0 MB 3.2 MB/s
Installing collected packages: Pillow
Successfully installed Pillow-7.1.2


#encoding:utf-8
from PIL import Image
img = Image.open('test.jpg')
print(img.size)
percm=118
swith = img.size[0]
sheight = img.size[1]
img = img.crop((swith-6*percm, sheight-5*percm, swith-percm, sheight-percm))
img.save('captcha.png')


以上是关于python图片处理的主要内容,如果未能解决你的问题,请参考以下文章

python常用代码片段总结

你如何在 python 中处理 graphql 查询和片段?

常用python日期日志获取内容循环的代码片段

python+spark程序代码片段

Android - 应用程序启动时片段 onCreate 崩溃

根据图片的url地址下载图片到本地保存代码片段