# -*- 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]) + &
yolov5 自瞄改大哥版本
最新推荐文章于 2024-09-22 17:12:26 发布
本文详细描述了一个使用YOLO模型进行目标检测并在检测到人脸时控制鼠标移动的应用,涉及图像预处理、模型推理和鼠标控制技术。
摘要由CSDN通过智能技术生成