yolov5 自瞄改大哥版本

本文详细描述了一个使用YOLO模型进行目标检测并在检测到人脸时控制鼠标移动的应用,涉及图像预处理、模型推理和鼠标控制技术。
摘要由CSDN通过智能技术生成
# -*- coding = utf-8 -*-
# @Time : 2022/10/28 17:56
# @Author : cxk
# @File : z_detect5.py
# @Software : PyCharm
import pydirectinput
import ctypes
import sys
import ctypes
import signal

import argparse
import win32con
import win32api

from mss import mss
from pynput import mouse

from z_captureScreen import capScreen

from models.experimental import attempt_load
from utils.datasets import letterbox
from utils.utils import *

from z_ctypes import SendInput, mouse_input

PROCESS_PER_MONITOR_DPI_AWARE = 2
ctypes.windll.shcore.SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE)

import time

def click_mouse():
    ctypes.windll.user32.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    time.sleep(0.05)  # 按下时间间隔可以根据需要调整
    ctypes.windll.user32.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

def pre_process(img0, img_sz, half, device):
    """
    img0: from capScreen(), format: HWC, BGR
    """
    # padding resize
    img = letterbox(img0, new_shape=img_sz)[0]
    # convert
    img = img[:, :, ::-1].transpose(2, 0, 1)  # BGR -> RGB, HWC -> CHW
    img = np.ascontiguousarray(img)

    # preprocess
    img = torch.from_numpy(img).to(device)
    img = img.half() if half else img.float()  # uint8 to fp16/32
    img /= 255.0  # 0-255 to 0.0-1.0
    if img.ndimension() == 3:
        img = img.unsqueeze(0)
    return img


def inference_img(img, model, augment, conf_thres, iou_thres, classes, agnostic):
    """
    推理,模型参数,...
    """
    # inference
    pred = model(img, augment=augment)[0]
    # apply NMS
    pred = non_max_suppression(pred, conf_thres, iou_thres, classes, agnostic)
    return pred


def calculate_position(xyxy):
    """
    计算中心坐标
    """
    c1, c2 = (xyxy[0], xyxy[1]), (xyxy[2], xyxy[3])
    # print('\n左上点坐标:(' + str(c1[0]) + ',' + str(c1[1]) + &
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值