Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果能有爬去猫咪之类的宠物or动物就好了! #60

Open
WJFQ opened this issue Jun 22, 2018 · 4 comments
Open

如果能有爬去猫咪之类的宠物or动物就好了! #60

WJFQ opened this issue Jun 22, 2018 · 4 comments

Comments

@WJFQ
Copy link

WJFQ commented Jun 22, 2018

毕竟我上抖音只看这些 233

@huobaolajiao
Copy link

非常好的主意,腾讯ai也提供了物体识别的接口,https://ai.qq.com/product/visionimgidy.shtml#tag
比如识别https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1530030578368&di=417f6a3736c4c3cd8b98b3b2a2b5c7fe&imgtype=0&src=http%3A%2F%2Fimg22.mtime.cn%2Fup%2F2011%2F04%2F23%2F214229.96463684_500.jpg
这只猫,反馈是
宠物14.00%
狗13.00%
猫44.00%

这个结果很理想,可以自己试试

@Chasdreams
Copy link

只看宠物+1

@wush666
Copy link

wush666 commented Aug 16, 2019

嗯,毕竟宠物才是纯天然素颜无公害外加高清无码的,岂是那些化妆美颜滤镜撑起来的妖艳贱货可比

@Tiramisu-MH
Copy link

import subprocess #用于执行 shell 命令
import cv2
import time
import shutil #用于复制、移动、删除文件和目录等操作
import os #提供与操作系统进行交互的功能

# 指定设备序列号
device_serial = "xxx" #在 cmd 中运行 adb devices 查看并复制
# 定义计数器变量
count = 0 #本项目为测试项目,所以只刷 12 次就停止。如果不想,在整个代码中删掉 count 就可以了

while True:
    
    # 等待两秒
    time.sleep(2)

    # 指定时间戳
    timestamp = int(time.time())
    # 将时间戳转换为本地时间
    local_time = time.localtime(timestamp)
    # 将时间格式化为字符串
    time_str = time.strftime("%Y-%m-%d-%H-%M-%S", local_time)
    # 生成唯一的文件名
    screenshot_filename = f"douyin_screenshot_{time_str}.png"

    # 截取屏幕上正在播放的抖音视频的截图,并上传保存到计算机上
    screenshot_cmd = f"adb -s {device_serial} shell screencap -p /sdcard/{screenshot_filename}"
    subprocess.run(screenshot_cmd, shell=True)
    pull_cmd = f"adb -s {device_serial} pull /sdcard/{screenshot_filename} ."
    subprocess.run(pull_cmd, shell=True)

    # 加载截图并进行图像识别
    screenshot = cv2.imread(f"{screenshot_filename}") #注意写 f,用于将变量值嵌入到字符串中
    gray = cv2.cvtColor(screenshot, cv2.COLOR_BGR2GRAY)
    cat_cascade = cv2.CascadeClassifier("haarcascade_frontalcatface.xml")
    cats = cat_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30)) #参数解释在下方
    if len(cats) > 0:
        # 如果识别出小猫,则模拟点击点赞按钮
        # 测试使用设备:Redmi Note8,2340x1080,其他手机自行适配参数
        like_cmd = f"adb -s {device_serial} shell input tap 1004 1331"
        subprocess.run(like_cmd, shell=True)
        # 等待 2 秒
        time.sleep(1)
        # 屏幕上滑(参数解释见下文)
        swipe_cmd = f"adb -s {device_serial} shell input swipe 540 1500 540 1000 100"
        subprocess.run(swipe_cmd, shell=True)
    else:
        # 屏幕上滑
        swipe_cmd = f"adb -s {device_serial} shell input swipe 540 1500 540 1000 100"
        subprocess.run(swipe_cmd, shell=True)

    # 指定源文件路径和目标文件夹路径(这是为了把截的图存放到专门的文件夹中,用于检测识别准确度)
    source_file = f"{screenshot_filename}"
    target_folder = "cved" #文件夹自行创建,在本 python 脚本的文件夹中就可以

    # 构建目标文件路径
    target_file = os.path.join(target_folder, source_file)

    # 移动文件到目标文件夹
    shutil.move(source_file, target_file)

    # 计数器加 1
    count += 1

    # 完成 12 次截图,退出循环
    if count >= 12:
        break

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants