Count People in Zone | Using YOLOv5, YOLOv8, and Detectron2 | Computer Vision
Unlock the power of object detection with this comprehensive tutorial on detecting and counting objects in a polygon zone. Discover three real-world examples, including detecting customers in a shopping mall alley, people at the edge of a subway station, and counting people in a market square. Learn how to use YOLOv8, Detectron2, and YOLOv5 to achieve your object detection goals. With the help of the powerful Supervision library, building advanced analytics has never been easier. This tutorial is perfect for beginners, taking you step by step through each process. Plus, we've included a Jupyter Notebook for you to follow along, making the learning process effortless. Boost your computer vision skills with this educational and engaging video!
Chapters:
0:00 Introduction
1:22 Setting up the Python environment
4:53 Simple YOLOv8 Shopping Mall Example
13:22 Simple Detectron2 Subway Example
17:46 Advanced YOLOv5 Market Square Example
20:56 Conclusion
Resources:
🌏 Roboflow: roboflow.com
🌌 Roboflow Universe: universe.roboflow.com
🤩 Supervision documentation: roboflow.github.io/supervision
⭐ Supervision repository: github.com/roboflow/supervision
📓 Detect and Count Objects in Polygon Zone with YOLOv5 / YOLOv8 / Detectron2 + Supervision Notebook: colab.research.google.com/git...
Stay updated with the projects I'm working on at github.com/roboflow and github.com/SkalskiP! ⭐
Пікірлер: 152
Very good tutorials you are publishing. Thanks!
been looking forward to this one!
@SkalskiP
Жыл бұрын
Hi it's Peter from video ;) Thanks for patience!
Nice! This reminds me of a roboflow universe project where someone managed to use the predefined polygon on feeding area in an aquarium to count and track incoming dwarf shrimp
Thank you so much sir , this is very helpful for my project. Once again a big thanks for providing source code too .
Great video for learning the YOLOv8, thanks.
@Roboflow
Жыл бұрын
Great to hear that! 👋
Just wanted to say a big thanks for the tutorial. It was super helpful! And, btw, you rock! 😎 So, anything else you wanna show us? Here's my wishlist: * Show object Track ID * Smooth path like in Data From Sky 🔥
@SkalskiP
Жыл бұрын
Hi once again :) Did you saw this tutorial: kzread.info/dash/bejne/gYdp06tyiaXRls4.html We've done tracking id there. What do you mean by Smooth path?
legend! keep up the good work!
@Roboflow
Жыл бұрын
Thanks a lot 🙏🏻
Golly gee this makes me happy as can be
This is so cool, thanks for sharing
@Roboflow
9 ай бұрын
My pleasure
This is so awesome! Could you do one for oil palm tree counting / detection ?
really cool stuff!
@SkalskiP
Жыл бұрын
Thanks a lot!
This is so awesome man, thanks so much for making this. I'm making an analysis tool for Beach Volleyball with what i'm learning from your videos! Could you do another zone analysis for Soccer where you detect if a player is offside?
@Roboflow
Жыл бұрын
Thanks a lot! Offside is actually not that easy to make. I tried haha
@pottoker612
Жыл бұрын
i clicked the wrng link, ended up cloning a github suppository
Thanks for the video! so useful. Can we use Supervision to only convert different annotation formats? like PASCAL VOC to yolo or the other way.
Thank you very much for the videos, they are very useful! If it is worth a suggestion, it would be nice to use SLAM and object detection for OAK-D. ( By the way I am subscribed ;)
@SkalskiP
Жыл бұрын
Hi 👋! It's Peter from the video. Thanks a lot for the trust. I'll do my best to keep you entertained and informed. OAK is for sure on my list of projects to do soon.
Thank you from Manhattan ©2024
@Roboflow
Жыл бұрын
You welcome!
Thanks man, I have a question that, can we find out the direction of the people join the polygon or go out the polygon
Hello Brother ! Thanks a lot for the video , I just want some help regarding on how we can trial and error for the polygon zones. I just can't figure out how to make one when I tried on my own for some other stock video but also unlike yours I can't see any coordinates in my images when I run them.. I believe it will take to next level If I'm able to figure that part out. Kudos to your work keep making content !
In line detections=detections[detections.class_id==0] , the error is coming AttributeError: module 'numpy' has no attribute 'bool'. `np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here. i tried all the methods can u pls help !
@harshwardhankurale310
5 ай бұрын
any solution? stuck on the same!
@AliRaza-sl1zu
4 ай бұрын
same😔
Another video with more detail on supervision.utils.draw_line would be epic. The candies conveyor belt lesson was great but it was very quick!
You don’t have to hold my hand but it would be pretty chill to hold hands in terms of how you measured the coordinates for the polygon. Any tools you can recommend for that? I have editing apps I can use but if there’s a more automated way like with Python or something? Gettin greedy here but it would be very helpful to hear if you had a special way for that or if it’s part of the grind. …
Just amazing what supervision is becoming! I was wondering howto combine this with tracking. Count how many people visited inside polygon?
@SkalskiP
Жыл бұрын
Hi it is Peter from the video! Reading comments like this makes me super excited.
@Roboflow
Жыл бұрын
We do not have that feature build in yet... So there are two things you can do. Add feature request here: github.com/roboflow/supervision/issues or add your question in our discussions page github.com/roboflow/supervision/discussions ;)
Sorry, I want to ask if count objects can be done on an image.?
Congrats! It's really nice and instructive work, but i have a question. How would that be possible, if I want to skip some frames(vid_stride) in the video because of slow video processing? Like, look once in every 4 frames.
@Roboflow
Жыл бұрын
Hi! It is relatively easy to implement, but I'll also add that idea to our roadmap. As for your question. Could you post it here: github.com/roboflow/supervision/discussions/categories/q-a YT comments are quite terrible when it comes to code discussions. I'll try to help you.
thank u so much ❤ , but i cant execute the full video, "AttributeError: module 'numpy' has no attribute 'bool'." same error in the track&count object video , i changed from np.float/np.bool to float/float , please can u help me !
found it really helpful, can we find the time spent by certain person in certain spot market space ?? is it ijclushsive in yolo v5?
@Roboflow
Жыл бұрын
That’s great to hear! As for your question, not yet, but we have such feature on our roadmap. You can still do it using our zones, but it would require work on your side.
Nice work you changed the poygon and it looks good btw. Lots of effort put in by @SkalskiP. I was watching him on twitch while he was working on last demo. Nice work and thanks for sharing :)
@SkalskiP
Жыл бұрын
Hi :) Oh this is so sweet. I feel weird when people praise me, but at the same time thank you very much for that. It's nice to know that people see substance in what I do. And yeeees... When you see me use that library on YT video everything looks so effortless, but Twitch stream tells the real story! Blood sweat, tiers and NumPy! Haha Btw I'll stream today too!
Thanks, it was so amazing. I have one question. I'll be so grateful if you could help: 1) I watched the video that explained how to train yolov5 with the custom dataset. I used that notebook and exported the best.pt file, containing model weights. My question is: how to use it for inference? - I used model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt') # PyTorch but It loads the original .pt file, not my custom one.
@SkalskiP
Жыл бұрын
Hi 👋! It's Peter from the video. I took a look in YOLOv5 docs and this is what I found: model = torch.hub.load('ultralytics/yolov5', 'custom', path='path/to/best.pt'). Looks exactly like the line you pasted. Are you sure that 'best.pt' is sufficient as path? I'll try to pass global path to that file. If that doesn't help. Let me know and I'll try to help.
Greetings. I wanted to know if there is anyway to fill the polygons with a specific color?
👏👏👏👏👏 Takk
Hello Brother, do you have any idea about ? Object removed does not work in automated checkout in zone based detection. If we define zone from capture frame of top camera, and object is placed outside of one zone boundary. zone boundary lies between refrigerator and outside position. When object is removed from zone, its still show object added into zone.
@Roboflow
5 ай бұрын
It is a bit hard to tell from this description. I recommend you open new discussion here: github.com/roboflow/supervision/discussions
Is there moving zone annotator in supervision
thanks for making such useful content like this! i was wondering, how do we define the polygon zone? is there a technique to be used to get the specific number of x & y val?
@SkalskiP
Жыл бұрын
Hi 👋it's Peter from the video. What I like to do is to load the image to some editor like Gimp and design my zone there. I'm actually a bit unhappy that I didn't show that on the video. I know that we plan to release a short blog post / video showing people how they can do it. Maybe even build some interactive tool in Python to make it even easier.
@hazimbajammal6112
Жыл бұрын
@@SkalskiP Hi Peter, would love to understand about it through the planned short blog post! thanks for making these videos, and thank you for your reply!
@Roboflow
Жыл бұрын
@Hazim Bajammal We have just launched PolygonZone, an open-source web application for calculating the coordinates of polygons on an image: blog.roboflow.com/polygonzone/ Let us know if this is helpful to you!
@kimjongun7574
8 ай бұрын
Hi
12:47 Person excluded by the trolley. Possible Solution: add pose estimation and make the bounding box of person enlarged by this pose? Havent tried yet. Will update here when it works.
@SkalskiP
Жыл бұрын
Hi, it is Peter from the video 👋That is one of the possible solutions. I think we should go for something simpler first. Try different model size for example. Notice that I used yolov8s model. I'd test yolov8l or yolov8x first.
@abdshomad
Жыл бұрын
@@SkalskiP Thank you. I mean, integrate the Track ID into the supervision. So we can just add track=true to the argument. As for smoothed path, I saw in your ByteTrack video that the path it draws is rough. It would be beautiful if we can draw the track in smoothed curve. Like this: kzread.info/dash/bejne/m6aVsbSDksyoZ9o.html
Thank you! But one quick question, If needs to detect another object, I need to create a new dataset and new train? Regards
@Roboflow
10 ай бұрын
Good question! If you plan to use models like YOLO than yes. There are also zero shot detectors. But much slower… Much Much slower…
Thanks, this is very helpful, how can I get the total of number of the detected instances? I'm trying to count the total number of fish fingerlings in a basin using YOLOv7 instance segmentation.
@SkalskiP
Жыл бұрын
Hi it's Peter from the video! 👋Are you interested in total count of individual objects seen in the whole video? Or total visible right now?
@christian.js.1997
Жыл бұрын
Hello sir @@SkalskiP, I'm interested in counting the individual objects seen in the whole video, the video input will be at least 10 seconds. My model needs to match the correct count of the total number of fingerlings in a basin. I'm done with the instance segmentation but got stuck on displaying the total number of fish detected. 😁
@SkalskiP
Жыл бұрын
@@christian.js.1997 did you managed to run the tracker on the whole video?
@christian.js.1997
Жыл бұрын
Oh thanks, I'll try to run it, is the tracker compatible with YOLOv7?
brother, error comes like AttributeError: module 'numpy' has no attribute 'bool'. `np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
Is counting using yolov7 model difficult than using yolov8 model.
@Roboflow
Жыл бұрын
Counting itself not :/ Installing and making the model work with the rest of the tools. Yes. YOLOv7 does not have any pip package. All you can do is run inference through the script.
I want to draw the image recognition zone as I want. Is it possible?
Hi. Nice video. Could you please also explain if someone wants to have a total number of passengers? e.g. in the platform video, how would we count the total number of passengers at the platform?
@Roboflow
Жыл бұрын
Hi 👋🏻! It is on my TODO. We will add more Supervision videos soon.
@Exploring_World247
Жыл бұрын
@@Roboflow thanks i am waiting and i am also working on it.
@Roboflow
Жыл бұрын
@@Exploring_World247 let us know how it goes :)
I'm working on project where I plan to estimate a behavior of separate objects by tracking directions and speed of movement and recognize some specific behavioral patterns. I'm new in that field and I have analyzed your colab notebooks, they are very Very VERY helpful. I need your suggestions. Based on your tracking and counting tutorial presented in previous video I collect track coordinates and can draw a paths of every moving objects, postprocess them and extract useful information. That project was based on supervision 0.1.0, yolov8, ByteTrack. Now I plan to track behaviour of moving objects i a polygon and in polygon example you use supervision 0.2.0, syntax was a little bit changed. What do you suggest: stay on supervision 1 and add polygons to previous project. Or move to this video project with supervision 2 and add ByteTrack to it?
@Roboflow
Жыл бұрын
I was waited that something like that will happen… supervision is still not officially released. And the syntax and names may change… I’m so sorry if that caused you some trouble. I suggest to stay on the version that is as new as possible. I’ll do my best to help you out.
@vcarvewood4545
Жыл бұрын
@@Roboflow dzięki, za poradę. I tak wiele mi pomogleś. Pozdrawiam z Wilna :)
@Roboflow
Жыл бұрын
@@vcarvewood4545 pozdrawiam ;)
@vcarvewood4545
Жыл бұрын
@@Roboflow Man, it works, I can track and count and capture the paths of different objects in different zones, super-duuuuuper. You are amazing, YOLOv8+Supervision+ByteTrack+Peter = powerful toolkit.
@Roboflow
Жыл бұрын
@@vcarvewood4545 I love to hear that 💜
This was very cool. Can you make a video on distance measurement between the detections using a threshold showing the distance. it would be very cool like clear idea of how we can show social distancing and other cool stuffs?!
@Roboflow
Жыл бұрын
We have distance calculation on our timeline. But I’m afraid... that most likely won’t happen to fast.
Could you please explain how to count objects detected in images?
thanks for your amazing videos i was wondering how to get coordinates of an object using cv?
@SkalskiP
Жыл бұрын
Hi it is Peter from the video. Could you be a bit more specific? What do you mean using OpenCV?
@shahinamini7047
Жыл бұрын
@@SkalskiP not specially opencv with any framework just export x y z coordinates
@SkalskiP
Жыл бұрын
@@shahinamini7047 are you interested in whole bbox or some specific point like center?
@Roboflow
Жыл бұрын
If you want to calculate the coordinates of polygon points, we have just open-sourced a tool to make his easier! blog.roboflow.com/polygonzone/ Let us know if this is helpful to you!
is there a way to do all this in vscode
Hi bro..Thanks for your tutorial. I have a question. Is it possible to move the counter to other locations on the frame?
@Roboflow
Жыл бұрын
It is but than you don’t use PolygonZoneAnnotator. You use PolygonZone to trigger and count and then use draw utils to draw zone “manually” and text in custom location.
@amalks8676
Жыл бұрын
@@Roboflow Thank for the reply bro👍
@Roboflow
Жыл бұрын
@@amalks8676 👍
H brother currently im using a laptop can you suggest a computer spec that run it locally
@SkalskiP
Жыл бұрын
Hi it is Peter from the video :) It is pretty hard question. I have RTX 3080, and depending on the configuration I can get even 80 fps on it.
@omoklamok
Жыл бұрын
@@SkalskiP oh i see how about the processor AMD is ok and memory 15GB enough? i tried the cloud it used 8GB but the amount of training data kinda small
please do you have any idea how can i do this with yolov7
@Roboflow
Жыл бұрын
The processing pipeline with Supervision stays the same regardless of the model. The main problem is to run YOLOv7 in SDK mode. I suggest you take a look at this project to run YOLOv7 github.com/kadirnar/yolov7-pip
how can i work this on vs code..? is it posiible..? sir plz reply
Day 1
How to access the model in Roboflow????
Can you make a video on person re identification.
How to use images instead of video?
Thanks for the video friend, very enlightening. If I want to implement this technique on android to detect objects from the cell phone?
@Roboflow
Жыл бұрын
Hi, thanks a lot! And you would like to process the video locally or transfer it to server for processing?
@jonatapaulino
Жыл бұрын
@@Roboflow Oops, thanks for her answer. It will be locally because it will be in an application built by me. I think remotely would lose even more quality.
@Roboflow
Жыл бұрын
@@jonatapaulino You would need to convert your model to TensorFlow Light, and you should be able to run it on android
@jonatapaulino
Жыл бұрын
@@Roboflow I already did that, but what happens is the loss of fps, oh, I don't know how to overcome this loss.
@Roboflow
Жыл бұрын
@@jonatapaulino what is the FPS you get?
the counting functionality are working in a specific zone or can i move the camera around to count people?
@Roboflow
Жыл бұрын
They are static on the frame. Moving the zone is a lot more complicated to implement.
@gbo10001
Жыл бұрын
@@Roboflow can you give some guidelines how to start working on it in order to achieve that?
@Roboflow
Жыл бұрын
@@gbo10001 you mean build zones that could work for moving camera?
@gbo10001
Жыл бұрын
@@Roboflow making zones is the only way to count objects in a video?
@Roboflow
Жыл бұрын
@@gbo10001 you want to count objects in the whole video? You don’t need zones to do that.
thank you very much for your wonderfull video!, so can you show me how to play the result video after detect!!, i can't do it :( :(
@Roboflow
Жыл бұрын
Are you using Google Colab?
@thanhtrungnguyen6853
Жыл бұрын
@@Roboflow yes sir, it just show imagine
@Roboflow
Жыл бұрын
@@thanhtrungnguyen6853 that should work just fine: stackoverflow.com/questions/49394737/exporting-data-from-google-colab-to-local-machine
Epic as fuck!!!
how about tracking one person throught different zones ?
@sugaryxo
Жыл бұрын
great video btw 😮🎉
@Roboflow
Жыл бұрын
@@sugaryxo thanks a lot. We do not support that yet in Supervision but it is possible to write custom code and do it.
how to take video from webcam?
@Roboflow
Жыл бұрын
Take a look at this vid: kzread.info/dash/bejne/g4psl8eSf8Wdl84.html
Thank you for your teach. But, your link do not response. How can I get your code?
@Roboflow
6 ай бұрын
Link to code is in the description. I just checked and the link works :)
@changjunlee2759
6 ай бұрын
@@Roboflow Yes, I did. Thank you...
NameError: name 'MARKET_SQUARE_VIDEO_PATH' is not defined
@Roboflow
Жыл бұрын
Looks like you did not run all notebooks cells. The value of `MARKET_SQUARE_VIDEO_PATH` is set in one of the top cells.
@VictoriaAlfredSmythe
Жыл бұрын
@@Roboflow Thank you, will check
@Roboflow
Жыл бұрын
@@VictoriaAlfredSmythe let me know if it worked!
is it possible to identify type and quantity of inventory in a shop?
@Roboflow
Жыл бұрын
Yup! With good camera angles and high resolution it is 100% possible. I worked on projects like that.
Do video on visual prompt from landingai
@Roboflow
Жыл бұрын
I'll add that to the long list :)