微信跳一跳python程序

#源码下载地址:https://files.cnblogs.com/files/cnfan/jump.rarimport os
import cv2
import numpy as np
import time
import random

# 使用的Python库及对应版本:
# python 3.6
# opencv-python 3.3.0
# numpy 1.13.3
# 用到了opencv库中的模板匹配和边缘检测功能

def get_screenshot(id):
    #os.system(‘adb shell /system/bin/screencap -p /sdcard/screenshot.png‘)#获取当前界面的手机截图
    #os.system(‘adb pull /sdcard/screenshot.png d:/fan/screenshot.png‘)#下载当前这个截图到当前电脑当前文件夹下
    os.system(‘adb shell screencap -p /sdcard/%s.png‘ % str(id))
    os.system(‘adb pull /sdcard/%s.png .‘ % str(id))

def jump(distance):
    # 这个参数还需要针对屏幕分辨率进行优化
    press_time = int(distance * 1.35)

    # 生成随机手机屏幕模拟触摸点
    # 模拟触摸点如果每次都是同一位置,成绩上传可能无法通过验证
    rand = random.randint(0, 9) * 10
    cmd = (‘adb shell input swipe %i %i %i %i ‘ + str(press_time))           % (320 + rand, 410 + rand, 320 + rand, 410 + rand)
    os.system(cmd)
    print(cmd)

def get_center(img_canny, ):
    # 利用边缘检测的结果寻找物块的上沿和下沿
    # 进而计算物块的中心点
    y_top = np.nonzero([max(row) for row in img_canny[400:]])[0][0] + 400
    x_top = int(np.mean(np.nonzero(canny_img[y_top])))

    y_bottom = y_top + 50
    for row in range(y_bottom, H):
        if canny_img[row, x_top] != 0:
            y_bottom = row
            break

    x_center, y_center = x_top, (y_top + y_bottom) // 2
    return img_canny, x_center, y_center

# 第一次跳跃的距离是固定的
jump(530)
time.sleep(1)

# 匹配小跳棋的模板
temp1 = cv2.imread(‘temp_player.jpg‘, 0)
w1, h1 = temp1.shape[::-1]
# 匹配游戏结束画面的模板
temp_end = cv2.imread(‘temp_end.jpg‘, 0)
# 匹配中心小圆点的模板
temp_white_circle = cv2.imread(‘temp_white_circle.jpg‘, 0)
w2, h2 = temp_white_circle.shape[::-1]

# 循环直到游戏失败结束
for i in range(1000):
    get_screenshot(0)
    img_rgb = cv2.imread(‘%s.png‘ % 0, 0)

    # 如果在游戏截图中匹配到带"再玩一局"字样的模板,则循环中止
    res_end = cv2.matchTemplate(img_rgb, temp_end, cv2.TM_CCOEFF_NORMED)
    if cv2.minMaxLoc(res_end)[1] > 0.95:
        print(‘Game over!‘)
        break

    # 模板匹配截图中小跳棋的位置
    res1 = cv2.matchTemplate(img_rgb, temp1, cv2.TM_CCOEFF_NORMED)
    min_val1, max_val1, min_loc1, max_loc1 = cv2.minMaxLoc(res1)
    center1_loc = (max_loc1[0] + 39, max_loc1[1] + 189)

    # 先尝试匹配截图中的中心原点,
    # 如果匹配值没有达到0.95,则使用边缘检测匹配物块上沿
    res2 = cv2.matchTemplate(img_rgb, temp_white_circle, cv2.TM_CCOEFF_NORMED)
    min_val2, max_val2, min_loc2, max_loc2 = cv2.minMaxLoc(res2)
    if max_val2 > 0.95:
        print(‘found white circle!‘)
        x_center, y_center = max_loc2[0] + w2 // 2, max_loc2[1] + h2 // 2
    else:
        # 边缘检测
        img_rgb = cv2.GaussianBlur(img_rgb, (5, 5), 0)
        canny_img = cv2.Canny(img_rgb, 1, 10)
        H, W = canny_img.shape

        # 消去小跳棋轮廓对边缘检测结果的干扰
        for k in range(max_loc1[1] - 10, max_loc1[1] + 189):
            for b in range(max_loc1[0] - 10, max_loc1[0] + 100):
                canny_img[k][b] = 0

        img_rgb, x_center, y_center = get_center(canny_img)

    # 将图片输出以供调试
    img_rgb = cv2.circle(img_rgb, (x_center, y_center), 10, 255, -1)
    # cv2.rectangle(canny_img, max_loc1, center1_loc, 255, 2)
    cv2.imwrite(‘last.png‘, img_rgb)

    distance = (center1_loc[0] - x_center) ** 2 + (center1_loc[1] - y_center) ** 2
    distance = distance ** 0.5
    jump(distance)
    time.sleep(1.3)

原文地址:https://www.cnblogs.com/cnfan/p/8400662.html

时间: 2024-08-29 11:25:34

微信跳一跳python程序的相关文章

.NET开发一个微信跳一跳辅助程序

昨天微信更新了,出现了一个小游戏"跳一跳",玩了一下 赶紧还蛮有意思的 但纯粹是拼手感的,玩了好久,终于搞了个135分拿了个第一名,没想到过一会就被朋友刷下去了,最高的也就200来分把,于是就想着要是开发个辅助就好了,于是简单想了一下最高游戏 先来说下这个游戏的界面和规则: 先看看界面 规则:按住屏幕 按一定时间松开就可以跳跃,跳跃到前方的图案中得1分,图按中间得2分(连续多个中间累加2分,比如第一个2分 第二个4分 第三个6分 最高累计32分) 其它规则不说明了 整理了下实现原理,其

微信_跳一跳辅助程序_Python_(带GitHub项目地址)

1.安装Python(推荐3.6) https://www.python.org/downloads/2.在github上下载脚本 [github项目地址](https://github.com/wangshub/wechat_jump_game) 3.安装ADB+配置PATH[adb全称Android Debug Bridge调试桥:PC与手机的链接工具] http://adbshell.com/downloads4.链接手机(限安卓)或安卓模拟器 DOS窗口输入adb devices验证设备

【辅助工具】Python实现微信跳一跳

最近迷上了微信跳一跳小游戏,正好也看到知乎上有大神分享了技术贴,我也参考了好多资料,原理就是通过abd命令截取图片,python计算两个点距离,然后转化按压时间,让电脑来完成游戏.我花了很长时间才把程序跑起来,作为一名技术小白我谈谈自己的认识,尽量让大家少走弯路. 先贴上大神的github地址:https://github.com/wangshub/wechat_jump_game 准备工具 abd驱动 安卓手机 打开手机调试模式 usb线连接好手机与电脑 实现原理 获取手机实时截图 点击起始位

python_微信 跳一跳

今天用python刷了一下微信跳一跳游戏得分数. 不是仅仅是玩一玩,而是为了把开发环境搭建好.(这个借口好) 参考: http://blog.csdn.net/LittleBeautiful/article/details/78955792 原文地址:https://www.cnblogs.com/lwbjyp/p/8213897.html

如何使用NSDL玩转微信跳一跳

目前网上介绍windows和IOS操作系统上玩微信跳一跳的有很多文章,但介绍Linux平台下的文章相对较少,所以动手操作下和大家分享,同时感谢wangshub在github上的分享: 1 下载wechat_jump_game-master 下载地址:https://github.com/wangshub/wechat_jump_game/archive/master.zip 2 解压安装并安装依赖包 pip3.4 install -r requirements.txt 操作如下:? 进入pyth

[python]通过微信公众号“Python程序员”,编写python代码

今天发现微信公众号中,居然可以编写python代码,很是惊喜,觉得蛮有趣的. 步骤如下: 1.关注微信公众号“Python程序员” 2.关注成功后,点击右下角的“潘多拉”->"Python终端“->"阅读原文”. 3.Python开发页面被打开,在下面的输入框内,输入python代码,点击确认即可. 可以用来练习python,是不是很有趣呢?

微信跳一跳

题目大意如下:微信跳一跳游戏,输入1,2,,0三个数字: 1代表跳到了下一个盒子但不在中心,得分为1,总分加1: 2代表跳到了下一个盒子且在中心:根据上次的得分计算:如果上一次得分为1,那此次得分为2,总分加2分,如果上一次得分为2,那此次得分为4,总分加4:以此类推:如上一次得分为8分,这次又跳到了盒子中心,那此次得分为10分,总分加10: 0代表没有跳到盒子上,游戏结束. ------------------------------------------------------------

用python玩微信跳一跳(win10+安卓)

一.前言 一场跨年的寒风席卷了整个北方,把我们带到了雪花烂漫的季节:一场"跳一跳"的风波也席卷了我们年轻人,好友们从此展开了如火如荼的较量.由此我们如何才能轻松战胜好友呢?这背后少不了我们强大的技术支持和耐心的调试,那让我们一起去尝试吧! 二.步骤 1.安装python(2.3版本都可以) 安装的时候要勾上"Add Python 3.6 to Path",然后在命令提示符窗口输入python 2.adb驱动安装 adb驱动下载地址:https://adb.clock

用Python玩微信跳一跳详细使用教程

github地址:https://github.com/wangshub/wechat_jump_game 工具介绍 Python 3 Android 手机 Adb 驱动 Python Matplot绘图 python3安装 安装pip 安装依赖包 在github地址将源码下载下来解压后,使用cd命令进入项目目录, 执行命令 pip install -r requirements.txt.会将依赖包下载下来. 下载好之后执行命令python -m pip list 安装adb驱动 下载adb驱动