栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 软件开发 > 后端开发 > Python

自瞄

Python 更新时间:发布时间: 百科书网 趣学号

自瞄框框可新开个线程,然后启动这个即可,有点耗内存,录像不知为啥显示不出来。

def draw():
    global data
    while True:
        for i in range(xlen):
                win32gui.SetPixel(dc, x+i, y, 255)
                win32gui.SetPixel(dc, x+i, y+ylen, 255)
        for i in range(ylen):
            win32gui.SetPixel(dc, x, y+i, 255)
            win32gui.SetPixel(dc, x+xlen, y+i, 255)
        for man in data:
            _x = int(x+man[0].item())
            _y = int(y+man[1].item())
            _xlen = int((man[2].item()-man[0].item())/2)
            _ylen = int((man[3].item()-man[1].item())/2)
            _x = int(_x+_xlen/2)
            _y = int(_y+_ylen/2)
            for i in range(_xlen):
                win32gui.SetPixel(dc, _x+i, _y, 255)
                win32gui.SetPixel(dc, _x+i, _y+_ylen, 255)
            for i in range(_ylen):
                win32gui.SetPixel(dc, _x, _y+i, 255)
                win32gui.SetPixel(dc, _x+_xlen, _y+i, 255)

自瞄代码

import torch
import pyautogui
import win32gui
import sys
import threading
import time
from pynput import keyboard
dc = win32gui.GetDC(0)
x=300 #起点x位置
y=274 #起点y位置
xlen = 424#边框长度
ylen = 268
star_x =x + int(xlen/2)#准星位置
star_y= y + int(ylen/2)
data = torch.Tensor([])
device = torch.device('cuda')
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
model.classes=[0]
def shot():
    a = time.time()
    img = pyautogui.screenshot(region=[x,y,xlen,ylen])
    results = model(img)
    data = (results.xyxy[0]).clone().type(torch.int)
    if len(data) !=0:
        item_x = 0
        item_y = 0
        min = sys.maxsize 
        for man in data:
            _x = x+man[0].item()
            _y = y+man[1].item()
            _xlen = man[2].item()-man[0].item()
            _ylen = man[3].item()-man[1].item()
            _x = _x+_xlen/2
            _y = _y+_ylen/4
            if ((_x-star_x)*(_x-star_x) + (_y-star_y)*(_y-star_y))
转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/273295.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号