<pre>#euraxluo 5.15
#obj_1
#跳一跳的外挂
from PIL import Image
import subprocess
import time
import random
import os def jump(distance):
press_time = distance*2.353
press_time = max(press_time,200)
press_time = int(press_time)
point = (random.randint(500,600),random.randint(1000,1200))
cmd = 'adb shell input swipe {x1} {y1} {x2} {y2} {time}'.format(
x1=point[0],
y1=point[1],
x2=point[0]+random.randint(1,5),
y2=point[1]+random.randint(1,5),
time = press_time )
os.system(cmd)
return press_time def get_screenshot():
#jietu,baocun jump.png
#调用os模块
process=subprocess.Popen('adb shell screencap -p',shell=True,stdout=subprocess.PIPE)
screenshot = process.stdout.read()#读取图片信息
screenshot = screenshot.replace(b'\r\n',b'\n')#去除干扰信息
with open('jump.png','wb') as f:#保存为图片
f.write(screenshot) def find_a_and_b(img_path):#寻找起点和终点
img = Image.open(img_path)
w,h = img.size #图片尺寸
img_pixel = img.load() #图片的像素矩阵
start_p = None for i in range(int(h/5),int(h*2/3),50): #以50为步长扫描
first_pixel = img_pixel[0,i] for j in range(1,w):#循环查找,如果遇到非纯色。为棋盘
pixel = img_pixel[j,i]
if pixel[0] != first_pixel[0] or pixel[1] !=first_pixel[1] or pixel[2] !=first_pixel[2]:#确定棋盘
start_p = i - 50
break
if start_p:
break #找到棋子
left = 0
right = 0
a_point_y_max = 0
bz = True
for i in range(start_p,int(h*2/3)):#限制棋子的扫描范围
for j in range(int(w/9),int(w*8/9),10):#限制棋子的扫描范围 去掉边界1/9
pixel = img_pixel[j,i] if (50<pixel[0]<60)and(53<pixel[1]<63)and(95<pixel[2]<110):
print(pixel[0],pixel[1],pixel[2])
if bz:
left = j
bz = False right = j
a_point_y_max = max(i,a_point_y_max)#a_point 的纵坐标 a_point_x = (left + right) // 2 #a_point 的横坐标
a_point_y = a_point_y_max - 10 #根据不同分辨路确定 #找棋盘
#限制棋盘的扫描范围 if a_point_x < w/2: #棋子在左边
b_start_x = a_point_x + 50
b_end_x = 690
else:
b_start_x = 30
b_end_x = a_point_x - 50
#找棋盘的顶点
for i in range(start_p,start_p+200):#y轴大致位置循环至下200px
first_pixel = img_pixel[0,i]#背景色的rgb
for j in range(b_start_x,b_end_x,5):#棋子的边界坐标循环至边界
pixel = img_pixel[j,i]
if abs(pixel[0] - first_pixel[0])+abs(pixel[1] - first_pixel[1])+abs(pixel[2] - first_pixel[2])>15:
if bz:
left = j
right = j
bz = False
else:
right = j
if not bz:
break
b_x = (720-(right+left)//2)
b_top = img_pixel[b_x,i+30]
#从定点往下找
for k in range(i+250,i,-1):
pixel = img_pixel[b_x,k]
if abs(pixel[0] - first_pixel[0]) + abs(pixel[1] - first_pixel[1]) + abs(pixel[2] - first_pixel[2]) < 12:
break b_y=(i+k)//2+80
return (a_point_x,a_point_y),(b_x+20,b_y) def run():
oper = input('请连接手机,确定开始?y/n')
if oper != 'y':
exit('结束')
while True:
# screenshout
get_screenshot() # 获取截图
a,b=find_a_and_b('jump.png')
distance = ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5#计算距离 jump(distance)#按压
time.sleep(random.randrange(1,2))#随机休眠 if __name__ == '__main__':
run()
# find_a_and_b('jump.png')</pre>

python,pil库的小应用的更多相关文章

  1. Python PIL 库的应用

    PIL (Python Image Library) 库是Python 语言的一个第三方库,PIL库支持图像存储.显示和处理,能够处理几乎所有格式的图片. 一.PIL库简介 1. PIL库主要有2个方 ...

  2. Python PIL库学习笔记

    1.PIL简介 Python Imaging Library(缩写为PIL)(在新的版本中被称为Pillow)是Python编程语言的开源库,它增加了对打开,操作和保存许多不同图像文件格式的支持.它适 ...

  3. 使用Python PIL库中的Image.thumbnail函数裁剪图片

    今天,是我来到博客园的第五天,发现自己还没有头像,想着上传ubuntu系统中我很喜欢的一个背景图片来当头像,但是因为图片过大,上传失败了.那么,我们如何使用python中强大的PIL库来进行图片裁剪呢 ...

  4. python PIL 库处理文件

    通过PIL库提供的API接口可以很方便的处理图像,功能十分强大: 最近有一个替换png背景色的需求,替换背景色的同时又不能够覆盖原来的文字,之前利用perl 的CD 模块一直没能够正确处理,最终用PI ...

  5. python PIL库的使用

    )PIL可以做很多和图像处理相关的事情: 图像归档(Image Archives).PIL非常适合于图像归档以及图像的批处理任务.你可以使用PIL创建缩略图,转换图像格式,打印图像等等. 图像展示(I ...

  6. Python PIL库之Image注解(API)

    http://blog.csdn.net/xiezhiyong3621/article/details/8499543 class Image Methods defined here: __geta ...

  7. 基于Python PIL实现简单图片格式转化器

    基于Python PIL实现简单图片格式转化器 目录 基于Python PIL实现简单图片格式转化器 1.简介 2.前期资料准备 2.1.1如何实现图片格式转换? 2.1.2如何保存需要大小的图片? ...

  8. 一秒钟带你走进P图世界-----(python)PIL库的使用

    python-----PIL库的使用 一.什么是PIL库 1.PIL(Python Image Library)库是python语言的第三方库,具有强大的图像处理能力,不仅包含了丰富的像素.色彩操作功 ...

  9. Python之PIL库的运用、GIF处理

    一.PIL库简介 PIL(Python Image Library)库是Python语言的第三方库,它支持图像存储.显示和处理,它能够处理几乎所有图片格式,可以完成对图像的缩放.剪裁.折叠以及像图片添 ...

随机推荐

  1. Hello vue.js的随笔记录

    数据双向绑定的script在组件定义位置后面才顶用. 使用它的话,引用js就好,比较简单. 声明一个vm对象,new Vue({}).这个构造里传一个对象,包含el:界面元素,data:数据,meth ...

  2. Android四大组件之 --- Service入门

    在前面了解了什么是多线程和异步消息处理机制后,我们来看一下到底什么是Service. 1. 什么是service(service的作用)一个服务是一个具有较长生命周期但没有用户界面的程序,例如:一个正 ...

  3. 运行python脚本时,报错InsecurePlatformWarning: A true SSLContext object is not available,解决方法

    今天,要在新环境里运行一个python脚本,遇到下面的报错: /usr/lib/python2.7/site-packages/urllib3/util/ssl_.py:160: InsecurePl ...

  4. spring-data-mongodb 使用原生aggregate语句

    除了特殊注释外,本文的测试结果均基于 spring-data-mongodb:1.10.6.RELEASE(spring-boot-starter:1.5.6.RELEASE),MongoDB 3.0 ...

  5. Vue语法学习第二课——指令

    指令,是指在Vue中,带有-v前缀的特殊特性 指令特性的值预期是单个JavaScript表达式(v-for例外) <p v-if="seen">看得到</p> ...

  6. bootstrap-edittable 使用笔记之 (select, data,text, number)

    可编辑列表的数据格式可以指定,常用的有select, data, text, number.代码如下. 前端代码: <table id="tb_product" class= ...

  7. vue+element-ui实现表格编辑(增加或删除行,删除单行或删除多行)

    <template> <div class="app-container"> <div class="filter-container&qu ...

  8. 【POI】java对excel的读写操作

    在工作中需要将mongo中的数据导出到excel中,所以根据需要学习了poi.以下为学习内容的总结: 1.POI是什么? poi是Apache团队开发的专门面对用java处理Excel文档的工具. 官 ...

  9. Jenkins-client模式配置

    Jenkins配置master-slave模式 本来想着先写一篇jenkins安装的流程,但是现在jenkins做的已经非常完善了,有.war文件,直接在tomcat启动即可,所以这里就不多说了,小白 ...

  10. DatePickerAndroid用法

    一.代码/** * Sample React Native App * https://github.com/facebook/react-native */ 'use strict'; import ...