How to detect objects in real time with a cv2 image? #2803
Answered
by
glenn-jocher
shershunov
asked this question in
Q&A
-
I want to detect objects in a cv2 image in real time. I have a code that captures the screen using the mfc library. How do I send an image to yolov5 at maximum speed? If you can help me, I will be very grateful! from cv2 import imshow, waitKey, destroyAllWindows
from mss import mss
from numpy import array
with mss() as sct:
monitor = {"top": 0, "left": 0, "width": 600, "height": 600}
while True:
img = array(sct.grab(monitor))
imshow("Detect", img)
if waitKey(1) & 0xFF == ord("q"):
destroyAllWindows()
break |
Beta Was this translation helpful? Give feedback.
Answered by
glenn-jocher
Apr 16, 2021
Replies: 1 comment 15 replies
-
@HamkiWhite you can use YOLOv5 PyTorch Hub models for inference in your loop. PyTorch HubInference with YOLOv5 and PyTorch Hub: import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
# Image
img = 'https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg'
# Inference
results = model(img) |
Beta Was this translation helpful? Give feedback.
15 replies
Answer selected by
shershunov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@HamkiWhite you can use YOLOv5 PyTorch Hub models for inference in your loop.
PyTorch Hub
Inference with YOLOv5 and PyTorch Hub: