算法策略:获取小人的底座中心点的值做为起跳点。算法
1 获取小人的全部像素点中y坐标的最大值shell
2 在小人y坐标的最大值那些像素点中,计算出x的平均值,做为小人底座的x的值。ide
3 y坐标的最大值减去一个偏移值,就做为小人底座的y值。(注意:该偏移值不一样的设备是不一样的,同一台设备不一样场景下是同样的)idea
好比教师机的设备中最低点的值是(337,1131),中心值是 (337,1113),从而计算出偏移值为1131-1113=18spa
取屏幕宽和高的一半(x=540和y=960)3d
咱们会发现,目标格子的边沿(x=563,y=978)和这个是差很少的(y的误差是18,x的误差是23.blog
之后每次跳动的时候,假如已经知道目标格子的边沿,和目标坐标的x值,就能够很轻松计算出目标坐标的y值。ip
注意:每一个格子的宽和高的比例是相同的。ci
左:(563,847)input
右:(1015,847)
上:(788,720)
下:(788,978)
中:(788,847)
高和宽的比例:(978-720)/(1015-563) =258/452。假设该值为p
已经知道目标坐标的x值,求目标坐标的y值
operation.py
# 控制屏幕进行跳动 def jump(self, src, dst, press_time): press_time = int(press_time) cmd = "adb shell input swipe %d %d %d %d %d" % ( int(src[0]), int(src[1]), int(dst[0]), int(dst[1]), press_time ) print(cmd) os.system(cmd)
|
main.py
def test_jump(): algorithm = Algorithm() op = Operation() im = op.screen_cap() start_x, start_y, end_x, end_y = algorithm.find_point(im) start_point = (start_x, start_y) end_point = (end_x, end_y) distance = algorithm.euclidean_distance(start_point, end_point) press_time = algorithm.distance_to_time(distance) op.jump(start_point, end_point, press_time) |