Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3593132
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Python/Ruby

2022-02-11 17:17:48

import os

import random

import time

import cv2

sign=False

start_x=0

start_y=0

end_x=0

end_y=0

distance=0

def get_screenshot():

    # 截取手机的屏幕

    os.system('adb shell screencap -p /sdcard/01.png')

    # 把模拟器里面的文件或文件夹传到电脑上

    os.system('adb pull /sdcard/01.png d://python//picture')

def jump(distance):

    # 设置按压时间,系数为1.35

    press_time = int(distance * 2.45)

    # 生成随机手机屏幕模拟触摸点,防止成绩无效

    # 生成随机整数(0-9),最终数值为(0-90)

    rand =外汇跟单gendan5.com random.randint(0, 9) * 10

    # adb长按操作,即在手机屏幕上((320-410),(410-500))坐标处长按press_time毫秒

    cmd = ('adb shell input swipe %i %i %i %i ' + str(press_time)) % (320 + rand, 410 + rand, 320 + rand, 410 + rand)

    # 输出adb命令

    print(cmd)

    # 执行adb命令

    os.system(cmd)

def get_point(event, x, y, flags, param):

    # 鼠标单击事件

    global sign

    global start_x

    global start_y

    global end_x

    global end_y

    global distance

    if event == cv2.EVENT_LBUTTONDOWN:

        # 输出坐标

        print('坐标值: ', x, y)

        # 在传入参数图像上画出该点

        #cv2.circle(param, (x, y), 1, (255, 255, 255), thickness=-1)

        img = param.copy()

        # 输出坐标点的像素值

        print('像素值:',param[y][x]) # 注意此处反转,(纵,横,通道)

        # 显示坐标与像素

        text = "("+str(x)+','+str(y)+')'+str(param[y][x])

        # 说明是第一次

        if(sign ==False):

            start_x=x

            start_y=y

            sign = True

        else:

            end_x=x

            end_y=y

            distance=((start_x-end_x)**2 +(start_y-end_y)**2)**0.5

            print(distance)

            jump(distance)

            sign = False

if __name__ == "__main__":

    # 定义两幅图像

    font = cv2.FONT_HERSHEY_SIMPLEX

    # 显示图像

    while(True):

        start_time = time.time()

        get_screenshot()

        image = cv2.imread('picture/01.png')

        image=cv2.resize(image,(500,1020))

        # image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)

        # 定义两个窗口 并绑定事件 传入各自对应的参数

        cv2.namedWindow('image')

        cv2.setMouseCallback('image', get_point, image)

        cv2.resizeWindow("image",500,1020)

        cv2.putText(image, "FPS: "+ str(round(1.0 / (time.time() - start_time),1)), (50, 50), font, 1, (180, 100, 255), 2, cv2.LINE_AA)

        cv2.imshow('image', image)

        print("FPS: ", 1.0 / (time.time() - start_time))  # FPS = 1 / time to process loop

        if cv2.waitKey(20) & 0xFF == 27:

            break

阅读(772) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~