guides/object-counting/ #8112
Replies: 78 comments 266 replies
-
Very cool and simple implementation! |
Beta Was this translation helpful? Give feedback.
-
hey can you tell me how and where to set the args in the above code |
Beta Was this translation helpful? Give feedback.
-
Hi,how can I use object counting with 3 lines and 3 different counters ? Line pedestrianline_pedestrian_1 = [(234,244),(131,218)] |
Beta Was this translation helpful? Give feedback.
-
hello, how can show the inn and out count of classes aswell. i want to do traffic monitoring so i want to get count of nunbers of truck,car,bycycles,bus,moving in and out how can i do that. |
Beta Was this translation helpful? Give feedback.
-
How can I integrate speed estimation of vehicles with in and out counting? |
Beta Was this translation helpful? Give feedback.
-
Hi can I use this to setup my laptop camera for live streaming analysis ? |
Beta Was this translation helpful? Give feedback.
-
User |
Beta Was this translation helpful? Give feedback.
-
Hello, I trained a YOLOv8 on my custom dataset of 3 classes. I need to count detections of each class and display them. I used your code but it is showing error: in <cell line: 27>() TypeError: 'int' object is not iterable Following is my code: MODEL= "/content/drive/MyDrive/content/runs/detect/train/weights/best.pt" model = YOLO(MODEL) classes_to_count = [0,1,2] cap = cv2.VideoCapture("/content/drive/MyDrive/DJI_0495.MP4") line_points = [(1126, 1118), (2786, 1118)] # Adjust these points as needed counter = object_counter.ObjectCounter() while cap.isOpened():
cap.release() ` |
Beta Was this translation helpful? Give feedback.
-
Just want to say this object counter is great! I am having trouble understanding how to keep count on how many of each class (i am tracking two classes) has been counted. Is it possible to do so? :) |
Beta Was this translation helpful? Give feedback.
-
Is there any possibility to crop a image of the objects touching the line? |
Beta Was this translation helpful? Give feedback.
-
It is excellent, and it works great. Thank you. It works great when I run the object count with the standalone video file. But in the same program, when I tried with the RSTP URL, I saw that sometimes objects suddenly disappear and are missing from the frame(Which gives the wrong count). Initially, I thought it was a problem with the feed, and I checked through the extended time with VLC player, and there was no interruption from the rstp feed. This happens only when I run through the object detection example with the feed. Do I have to do any specific settings I have to do? Initially, I thought this was an issue because of the CPU. Later, I moved my code to the Lambda machine, where it runs as CUDA. Still, I see the missing frames. I would appreciate any suggestions/guidance here. I have tried using nano and small models. One more question.. cv2.putText(im0, 'Arrival Count::' + str(arr_counter.in_counts + arr_counter.out_counts), arr_count_loc, Thank you. |
Beta Was this translation helpful? Give feedback.
-
Hi , I'm building a project in which I'm using a WEBRTC protocol to stream it via my input device then converting it to numpy arrays and then running the model on that AI model code which handles the actual detection of defects and their parameters.from ultralytics import YOLO def main():
if name == 'main': |
Beta Was this translation helpful? Give feedback.
-
Is it possible to make a counter that resets every 10 sec and post out the count at the 10sec mark and then start over, repeat. For like a video running 40-50min or more? counting different plants in video Would this work?
|
Beta Was this translation helpful? Give feedback.
-
when i upload model then procssing speed of output video is very low as compared to real video , so how to incease from ultralytics import YOLO Load your modelmodel = YOLO(r"D:\Suraj\yolov8l_walltie.pt") Setup video capturecap = cv2.VideoCapture(r"D:\Suraj\HWvideo.mp4") Define your line points for countingline_points = [(5, 400), (500, 400)] # Adjust these points as needed Initialize Object Counter with desired settingsqcounter = object_counter.ObjectCounter() while cap.isOpened():
cap.release() |
Beta Was this translation helpful? Give feedback.
-
my problem is, i have different classes of vehicle like bus,bike,truck,and threewheeler. now i want to detect this classes into the given image and i want to store count of different classes into a variable. please help me |
Beta Was this translation helpful? Give feedback.
-
Hello, can someone help me add the object counter in my code. Because I have been having trouble in debugging it to my code.
|
Beta Was this translation helpful? Give feedback.
-
how can we reset the out_counts and in_counts? Or how can we set in_counts or out_counts? |
Beta Was this translation helpful? Give feedback.
-
I have trained a yolov8 model for detecting the object i have its .pt weight file. Now when I used to predict it on the image it draw a rectangular box around the object and a confidence score type value on the top of the object and save that. That is fine . Now I want is that it only should plot only for those object whose confidence score greater than 0.8 . And after that I also want that which object class have how many count in that image. Like if there is image which have 2 dog and 3 cat. So it plot rectangular box around that if there threshold >=0.8 and in the end it tell there are total 5 object. 2 dog 3 cat . It should give total object and how many object of each class. Can somebody help me to write its code. |
Beta Was this translation helpful? Give feedback.
-
Below is the code to calculate number of object of every class in an image. I have provided the image instead of video. I want to consider all region of the image so i have given that by calculating the shape of the image. region_points = [(0, 0), (0,148), (240,0), (240,148)] results = model.track("check.jpeg", persist=True, show=False) Count objects in frameframe = counter.start_counting(x, results) Display the framecv2_imshow( frame) from collections import defaultdict Initialize counts dictionaryobject_counts = defaultdict(int) Accumulate counts per classfor r in results: Display countsfor class_id, count in object_counts.items(): |
Beta Was this translation helpful? Give feedback.
-
Hello , I have made an object tracking and counter project. I have modified logic of in and out count in object.counter.py suitable for my own use case. Now everything is working perfect but when I want to use vid_stride argument in my script for frame skipping , its not working . It by default give result for stride = 1 even when i use stride=5 in argument in my script. |
Beta Was this translation helpful? Give feedback.
-
Hello there, At the moment my code is making object detections outside of my specified region I have created upon the video, and I was hoping by creating a region of interest YOLO would not do detections anywhere else but inside of this region. This is however not working. Is there a way to force this somehow? import cv2 model = YOLO('bestleafseg.pt') Define line and region for countingline_start, line_end = (0, 756), (1920, 756) # Adjusted to 70% of the frame height cap = cv2.VideoCapture('C:\Users\Stell\Desktop\DVA 309\GX010009.MP4') counter = object_counter.ObjectCounter() counter.in_counts = {class_id: 0 for class_id in counter.names.keys()} seen_ids = set() start_time = time.time() Process videowhile cap.isOpened():
cap.release() print(f"Total plants crossed the line: {len(seen_ids)}") times = list(timestamps.values()) if times: |
Beta Was this translation helpful? Give feedback.
-
How to include multiple line in the object counting process? |
Beta Was this translation helpful? Give feedback.
-
Is it possible to do object counting on images? And how can you do that? |
Beta Was this translation helpful? Give feedback.
-
Hello, two questions:
Thank you |
Beta Was this translation helpful? Give feedback.
-
Can you tell me how I can save the count number of the objects printed to the video in the code above, i.e. "in count : out count : " to a txt file? |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, I am developing a car counting system where all vehicles move in a single direction. However, I’ve noticed an issue: when a car's center coordinate moves towards the left, it is counted as "in," and when it moves towards the right, it is counted as "out." It seems that the Region of Interest (ROI) line is divided in half, with one side designated for "in" and the other for "out." Since all cars are moving in a single direction, I need to modify the counting logic so that it only counts up (or down) rather than differentiating between "in" and "out." How can I adjust the counting arguments to accommodate this single-direction movement? Thank you for your help! |
Beta Was this translation helpful? Give feedback.
-
Hi,I want to know how I can use multiple GPUs in the follow code: track+object Counting import cv2 model = YOLO("yolov8n.pt") Define line pointsline_points = [(20, 400), (1080, 400)] Video writervideo_writer = cv2.VideoWriter("object_counting_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h)) Init Object Countercounter = solutions.ObjectCounter( while cap.isOpened():
cap.release() |
Beta Was this translation helpful? Give feedback.
-
Hello glenn, I am using 7 classes to detect defects in product. I am using the specific class for counting individual classes. I want to include tracking id for each defect class in video for rejection purpose. And then how to write the tracking id and count of each class in text file? |
Beta Was this translation helpful? Give feedback.
-
Hello, Specifically, I need to: Count the number of detected birds in each image. |
Beta Was this translation helpful? Give feedback.
-
Hi, I want to have multiple line counters and track multiple paths for different classes. For instance, I want to have 2 line counters at different regions, one for cars and the other for pedestrians. So, I have created separate trackers and counters to keep separate counts line wise. But the problem which I am facing currently is the “total count box” which appears in the top right corner of the video are overlapping, the cars count box is appearing over the person count box. So my main doubt is how to maintain separate count for cars going into different counter lines and how to change the position of the box which appears in the top right corner? Please review the code and let me know if I am doing it the right way and if it is possible to do it with 1 tracker variable or multiple like I used. PS: I might also want to have a 3rd line counter at a different position on the video to count the number of cars which turns and goes right (on intersecting roads). So I can have a track of how many cars went straight, how many cars took the right turning after going straight, and how many pedestrians were there on the road. It would be like analytics dashboard.
Complete repo: https://github.com/SudhanshuBlaze/multi_vehicle_count/tree/main |
Beta Was this translation helpful? Give feedback.
-
guides/object-counting/
Object Counting Using Ultralytics YOLOv8
https://docs.ultralytics.com/guides/object-counting/
Beta Was this translation helpful? Give feedback.
All reactions