-
-
Notifications
You must be signed in to change notification settings - Fork 15.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to do object detection on video or streaming data #2045
Comments
@Surayuth see README for inference examples on videos and streaming sources: Inferencedetect.py runs inference on a variety of sources, downloading models automatically from the latest YOLOv5 release and saving results to $ python detect.py --source 0 # webcam
file.jpg # image
file.mp4 # video
path/ # directory
path/*.jpg # glob
rtsp://170.93.143.139/rtplive/470011e600ef003a004ee33696235daa # rtsp stream
rtmp://192.168.1.105/live/test # rtmp stream
http://112.50.243.8/PLTV/88888888/224/3221225900/1.m3u8 # http stream |
@glenn-jocher, thank you for your guide. With the webcam as source, is there any way to show/display the detect result directly? And get the coordinate of the objects? |
@meadlai For returning results in a python environment you probably want to use a YOLOv5 PyTorch Hub model: import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
# Image
img = 'https://ultralytics.com/images/zidane.jpg'
# Inference
results = model(img)
results.pandas().xyxy[0]
# xmin ymin xmax ymax confidence class name
# 0 749.50 43.50 1148.0 704.5 0.874023 0 person
# 1 433.50 433.50 517.5 714.5 0.687988 27 tie
# 2 114.75 195.75 1095.0 708.0 0.624512 0 person
# 3 986.00 304.00 1028.0 420.0 0.286865 27 tie See PyTorch Hub tutorial for details: YOLOv5 Tutorials
|
@meadlai here is the code what you are looking for.. import torch class OD:
Create a new object and execute.detector = OD(capture_index=0, model_name='320_yolo_400.pt') |
https://github.com/gustavozantut/yolov5_live_results streaming output frames results in real time |
|
@wb-08 how does mss() compare to our official screenshot example? |
@glenn-jocher , but it doesn't work correctly for the video |
@wb-08 yes the example is for an image, but that can be dropped into a for loop obviously and turned into a video. |
@glenn-jocher , maybe into while loop? |
@wb-08 got it. I tried it out, mss seems to be much faster than the PIL image grab method. This is about 30 ms vs 400 ms for tutorial method: import time
import cv2
import mss
import numpy
with mss.mss() as sct:
# Part of the screen to capture
monitor = sct.monitors[0]
while "Screen capturing":
last_time = time.time()
# Get raw pixels from the screen, save it to a Numpy array
img = numpy.array(sct.grab(monitor))
# Display the picture
cv2.imshow("OpenCV/Numpy normal", img)
# Display the picture in grayscale
# cv2.imshow('OpenCV/Numpy grayscale',
# cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY))
print("fps: {}".format(1 / (time.time() - last_time)))
# Press "q" to quit
if cv2.waitKey(25) & 0xFF == ord("q"):
cv2.destroyAllWindows()
break |
@AyushExel this mss screenshot loader works really well, we should integrate into StreamLoader with detect.py reserved source name like this:
|
may be better: |
@zombob not a bad idea. We're super busy and haven't had time to work on this feature yet, but if you'd like to help with a PR that would be great! |
Fixed this , PR link: #9542
|
if I want to detection in youtube live stream video or RTMP server then what should i do ?? |
Just specify "--source {link_here}" when calling detect.py. YouTube works, rtsp too , not sure about rtmp. |
@gustavozantut yes, you can use the YOLOv5 detector to perform object detection on youtube live-streaming videos or RTMP servers. You just need to specify the source URL when calling
Note that you should specify the streaming link and not the webpage's link. For RTMP servers, I'm not completely sure, but you may be able to use the same command, just replace the source URL with your RTMP server URL. |
Hello, |
@fatmaboodai yes, it is possible to achieve real-time object detection as an overlay within a Chrome browser window by using the YOLOv5 model. You can capture the screen recording and pass it to the model for object detection. Then, you can use browser-based technologies such as WebRTC, HTML5 canvas, or WebGL to overlay the detected boxes onto the tab you are viewing inside the Chrome browser. This would involve a combination of capturing the screen, processing the frames with YOLOv5, and rendering the results as an overlay in the browser window. |
Just another question: |
@fatmaboodai Yes, you can achieve the same goal using your custom YOLOv8-based model. You can capture the screen recording, pass it to your custom model for object detection, and then use browser-based technologies to overlay the detected boxes onto the Chrome browser window. The process would be similar to what I described earlier, but using your custom YOLOv8-based model for object detection instead of YOLOv5. |
Thank you so much i really appreciate it🙏🏽🙏🏽 |
@fatmaboodai you're welcome! If you have any more questions or need further assistance, feel free to ask. Good luck with your project! |
❔Question
I'm new to this framework. Can someone guide me on how to do object detection on video and streaming data using yolov5. My problem is I want to detect objects from a video game in real-time(when I'm playing the game). Do I have to capture a screen every second and then pass the screen to the model?
Thanks.
Additional context
The text was updated successfully, but these errors were encountered: