如何让YoloV5通过抓屏检测?
How to make YoloV5 detect by screen grab?
我正在使用以下工具从打开的应用程序中实时抓取屏幕截图。我怎样才能 运行 detect.py 只检测来自我的抓取屏幕的输入?谢谢
我的抓屏
import cv2 as cv
import numpy as np
import numpy as np
import cv2
from mss import mss
from PIL import Image
bounding_box = {'top': 340, 'left': 800, 'width': 350, 'height': 400}
sct = mss()
while True:
sct_img = sct.grab(bounding_box)
scr_img = np.array(sct_img)
#cv2.imshow('screen', scr_img) # display screen in box
cv.imshow('Testing', scr_img)
if (cv2.waitKey(1) & 0xFF) == ord('q'):
cv2.destroyAllWindows()
break
YoloV5 detect.py
现在它只检测图像而不是我的实时抓屏
# PyTorch Hub
import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
# Images
dir = 'https://ultralytics.com/images/'
imgs = [dir + f for f in ('zidane.jpg', 'bus.jpg')] # batch of images
# Inference
results = model(imgs)
results.print() # or .show(), .save()
预期结果:
只需将屏幕抓取传递给模型:
import cv2 as cv
import numpy as np
import numpy as np
import cv2
from mss import mss
from PIL import Image
# PyTorch Hub
import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
bounding_box = {'top': 340, 'left': 800, 'width': 350, 'height': 400}
sct = mss()
while True:
sct_img = sct.grab(bounding_box)
scr_img = np.array(sct_img)
#cv2.imshow('screen', scr_img) # display screen in box
scr_img = model(scr_img)
cv.imshow('Testing', scr_img)
if (cv2.waitKey(1) & 0xFF) == ord('q'):
cv2.destroyAllWindows()
break
我正在使用以下工具从打开的应用程序中实时抓取屏幕截图。我怎样才能 运行 detect.py 只检测来自我的抓取屏幕的输入?谢谢
我的抓屏
import cv2 as cv
import numpy as np
import numpy as np
import cv2
from mss import mss
from PIL import Image
bounding_box = {'top': 340, 'left': 800, 'width': 350, 'height': 400}
sct = mss()
while True:
sct_img = sct.grab(bounding_box)
scr_img = np.array(sct_img)
#cv2.imshow('screen', scr_img) # display screen in box
cv.imshow('Testing', scr_img)
if (cv2.waitKey(1) & 0xFF) == ord('q'):
cv2.destroyAllWindows()
break
YoloV5 detect.py
现在它只检测图像而不是我的实时抓屏
# PyTorch Hub
import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
# Images
dir = 'https://ultralytics.com/images/'
imgs = [dir + f for f in ('zidane.jpg', 'bus.jpg')] # batch of images
# Inference
results = model(imgs)
results.print() # or .show(), .save()
预期结果:
只需将屏幕抓取传递给模型:
import cv2 as cv
import numpy as np
import numpy as np
import cv2
from mss import mss
from PIL import Image
# PyTorch Hub
import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
bounding_box = {'top': 340, 'left': 800, 'width': 350, 'height': 400}
sct = mss()
while True:
sct_img = sct.grab(bounding_box)
scr_img = np.array(sct_img)
#cv2.imshow('screen', scr_img) # display screen in box
scr_img = model(scr_img)
cv.imshow('Testing', scr_img)
if (cv2.waitKey(1) & 0xFF) == ord('q'):
cv2.destroyAllWindows()
break