python-PIL模块的使用
PIL基本功能介绍
from PIL import Image
from PIL import ImageEnhance img = Image.open(r'E:\img\f1.png')
img.show()
#图像二值化
img = img.convert('L')
# 图像放大
img = img.resize((img.width * int(3), img.height * int(4)), Image.ANTIALIAS)
# # 对比度增强
enh_con = ImageEnhance.Contrast(img)
contrast = 2
img_contrasted = enh_con.enhance(contrast)
# 亮度增强
enh_bri = ImageEnhance.Brightness(img_contrasted)
brightness = 2.5
image_brightened = enh_bri.enhance(brightness)
#色度增强
enh_col = ImageEnhance.Color(img)
color = 50
image_colored = enh_col.enhance(color)
# # 锐度增强
enh_sha = ImageEnhance.Sharpness(img)
sharpness = 2
image_sharped = enh_sha.enhance(sharpness)
image_sharped.save(r'E:\img\f22.png', dpi=(300, 300), quality=95)
# image_sharped.save(r'E:\img\f22.png') # 图片汉字识别
img2 = Image.open(r'E:\img\f22.png')
code2 = pytesseract.image_to_string(img2, lang='chi_sim')
# print(code2)
# 图片裁剪
image_cro = Image.open(r'E:\img\f24.png')
image_cropped = image_cro.crop(res)
image_cropped.save(u'E:\img\\f25.png')
对图片进行黑白化处理
img_main = Image.open(u'E:/login1.png')
img_main = img_main.convert('L')
threshold1 = 138
table1 = []
for i in range(256):
if i < threshold1:
table1.append(0)
else:
table1.append(1)
img_main = img_main.point(table1, "1")
img_main.save(u'E:/login3.png')
计算小图在大图的坐标
def get_screenxy_from_bmp(main_bmp, son_bmp):
# 获取屏幕上匹配指定截图的坐标->(x,y,width,height) img_main = Image.open(main_bmp)
img_main = img_main.convert('L')
threshold1 = 138
table1 = []
for i in range(256):
if i < threshold1:
table1.append(0)
else:
table1.append(1)
img_main = img_main.point(table1, "1") img_son = Image.open(son_bmp)
img_son = img_son.convert('L')
threshold2 = 138
table2 = []
for i in range(256):
if i < threshold2:
table2.append(0)
else:
table2.append(1)
img_son = img_son.point(table2, "1") datas_a = list(img_main.getdata())
datas_b = list(img_son.getdata())
for i, item in enumerate(datas_a):
if datas_b[0] == item and datas_a[i + 1] == datas_b[1]:
yx = divmod(i, img_main.size[0])
main_start_pos = yx[1] + yx[0] * img_main.size[0] match_test = True
for n in range(img_son.size[1]):
main_pos = main_start_pos + n * img_main.size[0]
son_pos = n * img_son.size[0] if datas_b[son_pos:son_pos + img_son.size[0]] != datas_a[main_pos:main_pos + img_son.size[0]]:
match_test = False
break
if match_test:
return (yx[1], yx[0], img_son.size[0], img_son.size[1])
return False
ImageGrab实现屏幕截图
im = ImageGrab.grab()
im.save('D:/as1.png') # # # # 参数说明
# # # # 第一个参数 开始截图的x坐标
# # # # 第二个参数 开始截图的y坐标
# # # # 第三个参数 结束截图的x坐标
# # # # 第四个参数 结束截图的y坐标
bbox = (897, 131, 930, 148)
im = ImageGrab.grab(bbox)
im.save('D:/as2.png')
python-PIL模块的使用的更多相关文章
- Python PIL模块笔记
利用python pil 实现给图片上添加文字 图片中添加文字#-*- coding: utf-8 -*- from PIL import Image,ImageDraw,ImageFont ttfo ...
- python PIL模块学习
PIL PIL:Python Imaging Library.对于图像识别,大量的工作在于图像的处理,处理效果好,那么才能很好地识别,因此,良好的图像处理是识别的基础. PIL安装 安装推荐别人的吧, ...
- centos 安装python PIL模块
转载:https://www.cnblogs.com/ccdc/p/4069112.html 1.安装 使用yum安装缺少类库: #尤其重要,否则会报错 yum install python-deve ...
- python中PIL模块
Image模块 Image模块是在Python PIL图像处理中常见的模块,对图像进行基础操作的功能基本都包含于此模块内.如open.save.conver.show-等功能. open类 Image ...
- 使用Python的PIL模块来进行图片对比
使用Python的PIL模块来进行图片对比 在使用google或者baidu搜图的时候会发现有一个图片颜色选项,感觉非常有意思,有人可能会想这肯定是人为的去划分的,呵呵,有这种可能,但是估计人会累死, ...
- Python使用PIL模块生成随机验证码
PIL模块的安装 pip3 install pillow 生成随机验证码图片 import random from PIL import Image, ImageDraw, ImageFont fro ...
- python 第三方模块 转 https://github.com/masterpy/zwpy_lst
Chardet,字符编码探测器,可以自动检测文本.网页.xml的编码. colorama,主要用来给文本添加各种颜色,并且非常简单易用. Prettytable,主要用于在终端或浏览器端构建格式化的输 ...
- python 常用模块(转载)
转载地址:http://codeweblog.com/python-%e5%b8%b8%e7%94%a8%e6%a8%a1%e5%9d%97/ adodb:我们领导推荐的数据库连接组件bsddb3:B ...
- python 各模块
01 关于本书 02 代码约定 03 关于例子 04 如何联系我们 1 核心模块 11 介绍 111 内建函数和异常 112 操作系统接口模块 113 类型支持模块 114 正则表达式 115 语言支 ...
- python 导入模块 import 理解
--python 导入模块 import 理解 -----------------------------------2014/03/18 python 导入一个模块的过程要求有一个叫做“路径搜索”的 ...
随机推荐
- Counting blessings can actually increase happiness and health by reminding us of the good things in life.
Counting blessings can actually increase happiness and health by reminding us of the good things in ...
- leetcode 355 Design Twitte
题目连接 https://leetcode.com/problems/design-twitter Design Twitte Description Design a simplified vers ...
- Wince 6.0获取设备的分辨率 自动设置窗体位置
调用微软提供给wince的API “coredll.dll” [DllImport("coredll.dll")] public static extern int GetSys ...
- php使用GD库实现图片水印和缩略图——给图片添加文字水印
今天呢,就来学习一下在php中使用PD库来实现对图片水印的文字水印方法,不需要PS哦! 首先,准备素材 (1)准备一张图片 (2)准备一张水印(最好是透明的,即背景是白色底) (3)准备一中字体(在电 ...
- ADO.NET #3-1 (GridView + DataReader + SqlCommand)完全手写Code Behind
[C#] ADO.NET #3-1 (GridView + DataReader + SqlCommand)完全手写.后置程序代码 之前有分享过一个范例 [C#] ADO.NET #3 (GridVi ...
- pta 编程题20 旅游规划
其它pta数据结构编程题请参见:pta 题目 这个最短路径问题只需要求两点之间的最短路径,因而在Dijikstra算法中当求出目标点的最短路径之后跳出循环即可. #include <iostre ...
- 【洛谷4009】汽车加油行驶问题(SPFA乱搞)
点此看题面 大致题意:给定一个\(N*N\)的方形网格,其中1表示这个格子有油库,0表示这个格子没油库,且汽车加满油可以行驶\(k\)条网格边.如果遇到油库必须加满油并花费\(A\)元,如果\(X\) ...
- JavaScript操作Array对象常用的方法
转换方法 因为JavaScript内部机制(继承),所有的对象都具有toLocalString() .toString().valueOf()方法,Array也不例外so:var colors = ...
- 2018.2.5 PHP如何写好一个程序用框架
随着PHP标准和Composer包管理工具的面世,普通开发者撸一个框架已经不再是什么难事了. 无论是路由管理.ORM管理.还是视图渲染都有许许多多优秀的包可以使用.我们就像堆积木一样把这些包用comp ...
- SCSI add-single-device and remove-single-device
众所周知,SATA和SCSI是支持热插拔的,但是新装了这类支持热插拔的驱动器,系统不会马上识别的,往往我们需要重启系统来识别,但是有另外一种方法可以很方面的让系统识别新的设备. 作为系统管理员,需要了 ...