Episode 31 | Speed Estimation using Ultralytics YOLOv8
Summary
TLDRThis video demonstrates how to use Ultralytics YOLOv8 for vehicle speed estimation. It walks through the Ultralytics documentation on setting up a speed estimation pipeline, explaining the code needed to track objects over video frames and calculate speed based on pixel movement and frame rate. The video shows sample footage of traffic scenes, running the code to display estimated speeds overlayed, around 30km/hr in one clip and 90-100km/hr matching speed limit signs in the other. It encourages trying the open-sourced code yourself for custom applications like traffic control, autonomous navigation or surveillance.
Takeaways
- 😀 Uses YOLOv8 model from Ultralytics for object detection
- 🚗 Applies tracking to detected objects over frames to estimate speed
- 📝 Calculates speed by tracking pixel distance traveled across frames
- ⏱ Frame rate from video/camera needed to convert pixel distances to speed
- 🎥 Shows examples using traffic/driving videos to estimate vehicle speeds
- 🛣️ Gets reasonable speed estimates on highway video based on speed limit signs
- 📊 Speed estimates not highly accurate due to unknown real-world distances
- ⚙️ Can be used for various applications like traffic control and navigation
- 🖥 Runs inference and tracking on live webcam or pre-recorded video
- 💡 Suggestions welcomed to improve speed estimation system
Q & A
What model is used for object detection in the speed estimation application?
-A pre-trained YOLOv8 model from Ultralytics is used for object detection.
How is speed estimated using object detection?
-By tracking detected objects over multiple frames, calculating the pixel distance traveled, and using the frames per second rate to estimate speed.
What are some use cases for speed estimation?
-Managing traffic flow, precise autonomous vehicle navigation, enhanced surveillance and security.
Why may the speed estimate not be completely accurate?
-Because only the pixel distance traveled is known, not the real-world distance, so it is only an estimate.
How could the speed estimation be improved?
-By using sensors to get real-world distance traveled rather than just pixel distance, or by calibrating the video footage to real-world distances.
What information is needed to estimate speed?
-Detected and tracked objects over time, distance traveled in pixels between frames, and frames per second rate.
Can a custom trained model be used instead of YOLOv8?
-Yes, you can train your own custom object detection model and integrate it into the speed estimation pipeline.
Does the speed estimate vary based on hardware?
-Yes, GPU speed can affect the speed estimation, with faster GPUs potentially producing more accurate estimates.
Where can the code for speed estimation be found?
-The code is available in the Ultralytics documentation and GitHub repo.
What libraries are used for speed estimation?
-The core libraries are Ultralytics for object detection and tracking, OpenCV for image processing, and NumPy/Python for the pipeline.
Outlines
😊 Introducing speed estimation with YOLOv8 in Ultralytics
The first paragraph introduces the topic of speed estimation using a YOLOv8 model from Ultralytics to detect cars and estimate their speed from videos. It outlines the process of using object detection and tracking over frames to calculate speed based on pixel distance traveled over time.
👍 Showing sample speed estimation results on traffic videos
The second paragraph shows sample results of speed estimation on two traffic video samples - one with a closeup view estimating around 30km/hr, and one from a highway estimating around 90-100km/hr. It evaluates the accuracy to be reasonably good and suggests trying it on your own videos.
Mindmap
Keywords
💡Speed estimation
💡YOLO model
💡Object tracking
💡Pixel distance
💡Frames per second
💡Traffic monitoring
💡Autonomous navigation
💡Surveillance
💡Custom models
💡GPU speed
Highlights
We'll use a YOLOv8 model for object detection to track cars over frames and estimate their speed
Speed estimation helps with traffic control, autonomous navigation, and enhanced surveillance
We track detected objects over time to calculate the distance they travel across frames
Combining object tracking with frame rate, we can estimate speed in pixels per second
The code can work with a video file or webcam stream for real-time speed estimation
We draw a line to trigger speed calculation when objects cross it
Close-up traffic view initially shows speeds around 30 km/h which seems reasonable
Highway view correctly estimates speeds around 90-100 km/h matching signs
Varying speeds demonstrate accuracy, like slower traffic merging onto highway
Improvements could better handle dense traffic with more missed detections
Try this on your own videos to estimate speed for custom objects
Use these speed estimation techniques in your own applications
Throw suggestions to improve the system in the comments
Follow ultralytics on YouTube for more machine learning content
Use this speed estimation tutorial in your own projects for inspiration
Transcripts
hey guys WC to video in this video here we're going to see how we can do speed estimation with
ultra ltic we're going to use a YOLO V8 model a pre-trend model for detecting cars and then we're
going to do beat estimation of cars driving in different videos we're going to show you a bunch
of different examples I'm going to show you how you can set up the code and also the alter ltic
documentation so let's just jump straight into it and see how it works so let start inside our alter
litics documentation if we go inside this guides tab we can find all the guides and also the real
world projects that we have you can also find them on our GitHub but right now let's scroll down to
the real world projects we have a lot of different tutorials in here you can directly go in and copy
paste Coast nit using your own applications and projects if you scroll a bit further down we can
now see we have this speed estimation first of all you can read about what is speed estimation
what can be used for and so on so the basic idea behind speed estimation is that we're going to
use a Yol V8 model from ultral litics for optic detection then we're going to apply tracking on
top of that so we're actually tracking our Optics over a number of frames so we track our Optics
over time with that information we can actually use it to calculate and estimate the speed that
the cars and objects are moving with so it can act like be an arbitrary object it doesn't have to be
cars it can be whatever object that you have you can also train your own custom models and use it
directly in here as well once we have all trct objects in the frame we also know like how many
frames per seconds we get from either a video or our webcam stream by using that information we
actually like know the whole time frame so we get our detections over time so now we actually have
all the information for calculating and estimating our speed so we have our track objects over time
we also know the distance in the frame that it has traveled once we have that information
together with knowing the number of frames per seconds either from our camera the the video
that we're processing could be like for a CCTV camera sitting alongside Highway for example
then we have all the information we can calculate this speed and at least estimate it because right
now we're just talking about a pixel distance and not like a real world absolute distance so
here we can see some of the advantages of speed estimation so efficient traffic control ACC ACC
speed estimation AIDS in managing traffic flow and so on precise autonomous navigation and also
enhanced surveillance security so it can either be like how far are like people walking around
inside a store could also be like how fast our car is driving at a highway which is probably
like the best use case for this specific speed estimation application so we're going to show a
couple of examples for videos on a highway where we can see the results for the speed estimations
real well applications transportation and here we can see the coast nit you can directly take
it cover paste it into your own python script and use it in your own applications and projects we
just need to specify our model could also be our own custom model that we are trained with ultra
ltic so just be aware here that the speed is an estimate we can't really get like very accurate
values because again we can't really know the exact distance that the car has traveled in the
real world only based on pixels so that is one of the main problems with this one here but again we
will get estimates we get a rough estimate and we kind of like know how Optics are moving and
also how fast so speed will be an estimate and not may not be completely accurate Additionally
the estimation can vary depending on GPU speed here we can see the different arguments that
you can set for the speed estimation function I'm going to show you that in just a second and
we also have our model of track for tracking our objects over a number of frames so let's
just some straight into the code here I've copy pasted codit from the AL L documentation directly
in here in an empty python script from scratch so again we're just creating an instance of our
YOLO model right now we're just going to go with the medium model you need to specify the video
have here or if you want to use your webcam you can also do that again then we're just going to
set everything up we are going to have a video writer so we can see the results later on the
only modification that I've done to the code from the alter L documentation is that we're going to
have some line points and I'm just going to have a horizontal line in the middle of the image and
it's basically just to determine when do we want to actually like calculate the speed of our track
objects once it's Crossing that lines then we're going to set up our speed es theator we can set
the different arguments that I talked about so we have our points we have the names and we also want
to specify that we want to view the image while it's doing inference we have a [ __ ] here just
reading in frames from a video or from a webcam we track the objects here over number frames we're
going to estimate the speed with our tracks and also with our image and that's pretty much it this
is how we can do speed estimation with ultra ltic so let's now just go over a couple of examples I
have some video files over here to the left that we going go through so this is the first example
that we're going to run through it's more like a close off traffic view then we're also going
to have another video here which is basically like a view further away we probably want to be
able to detect every single car here in the image but we're going to get way more um detections out
here then we're going to have the line and try to see how the speed is on the highway so yeah let's
just copy path here and let's go in and run it so I'm going to copy the relative path paste it
in up here is the only thing that you have to do and then you can run it on your own wi dreams as
well use it in your own applications and projects let's now run the program here and see the results
for our speed estimation so this is the closeup video of these cars driving now I have to cross
this line before we're going to do the speed calculations we see that the cars are driving
around 30 km per hour both going out and in of damage so this is probably pretty pretty accurate
again um sometimes we get some mispredictions here we have 56 kilm per hour so it's not like very
exact all the time but most of them is act like around 30 km per hour which makes sense in this
traffic scenario so this is act like a pretty nice example let's go in and grab the other one so that
will be this video here just copy the relative path just swap it out everything that you have to
do and we can now run our program again and see the results so this is a bit more further W view
let's see how it performs so we're going to miss a lot of detections but if we act like able to track
the cars and they're Crossing this line we're going to estimate the speed on average here when
I'm just taking a look at it it is around like 90 to 100 kilm per hour right now it's going like
relatively fast because I have a GPU just proc procing every single frame but it's also going to
store a video in your directory so we can go in and take a look at that afterwards but it looks
pretty good here on the highway around 90 90 km per hour it's a bit dense traffic so let's go and
take a look at the video we have speed estimation avi file explorer let's now open it up and take a
look at it so the car here is actually like moving pretty fast in the video as well so it was not
really just my GPU let's take a look at it here 97 120 km 80 km here so that could actually like
be pretty close to uh to the ground Turf we can see we have a a traffic sign here saying 100 km
per hour so this is like the maximum speed limit so this could actually be pretty pretty close like
we have some guys here driving like 908 km per hours here we can see that we have some examples
with 55 and also 63 here but this is more like a Runway to the highway uh before they're going to
merge down here um further on here we can see we have a traffic sign saying 80 so's just take a
look at that so it's actually like going in the opposite direction but we can see here here once
the car start out they have like a value of 80 and also over here they're driving 64 to 70 km
per hour so that's pretty much it for this video here definitely try it out on your own computer
you can just take the code name it from the ultra L documentation test it out on your own videos if
you have any suggestions to how this system here could be improved definitely throw it
down in the comment section and also follow allytics here on YouTube so I hope you have
learned a ton this video here and that you can use this in your own projects and applications
maybe getting some inspiration and then just see in the next video Until Then happy learning
تصفح المزيد من مقاطع الفيديو ذات الصلة
What Are Speed and Velocity? | Physics in Motion
3D-Drucker SPEED erklärt! 30% schneller drucken! (inkl. Bambu CHT Guide)
The BEST GoPro Settings for LOW LIGHT & Indoors | Hero 13, Hero 12 & older
Fisika SMA - Gerak Lurus (2) - Kelajuan dan Kecepatan Sesaat, Kelajuan dan Kecepatan Rata-rata (I)
GCSE Physics Revision "Velocity"
GCSE Physics Revision "Speed"
5.0 / 5 (0 votes)