yolov5监视应用
import numpy as np
import cv2 as cv
import cv2
from mss import mss
import torch
import win32gui
model = torch.hub.load('ultralytics/yolov5', 'custom', 'best.pt')
hwnd = win32gui.FindWindow(None, '视频文件.mp4 - VLC media player')
hwnd = win32gui.FindWindowEx(hwnd, 0, None, 'QWidgetClassWindow')
hwnd = win32gui.FindWindowEx(hwnd, 0, None, 'QStackedWidgetClassWindow')
hwnd = win32gui.FindWindowEx(hwnd, 0, None, None)
hwnd = win32gui.FindWindowEx(hwnd, 0, None, None)
hwnd = win32gui.FindWindowEx(hwnd, 0, None, None)
hwnd = win32gui.FindWindowEx(hwnd, 0, None, None)
bbox = win32gui.GetWindowRect(hwnd)
sct = mss()
number = 0
cv.namedWindow('testing', cv.WINDOW_NORMAL)
cv.resizeWindow('testing', 420, 240)
while True:
sct_img = sct.grab(bbox)
scr_img = np.array(sct_img)
results = model(scr_img)
results.render()
cv.imshow('testing', results.ims[0])
key = cv2.waitKey(25)
if key == 27:
cv2.destroyAllWindows()
break