guides/object-counting/ #8112
Replies: 82 comments 281 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 , 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.
-
Hello there! Can YOLOv8 be used to train individual people? For example, if I train the model with data for 10 different people using their names, will YOLOv8 be able to detect each person individually? |
Beta Was this translation helpful? Give feedback.
-
Is there a way for me to specify the location in the frame to display the counter ? Right now, it is at extreme right of my video. I would like the counter to be at the center left. |
Beta Was this translation helpful? Give feedback.
-
I tried line counting using v8.2 but it still gives me values in OUT counter even though all my objects are moving in one direction from RIGHT to LEFT. I thought v8.2 fixes this issue. |
Beta Was this translation helpful? Give feedback.
-
actually the code was working fine but i cant predict/set the line probably i tried many times but i cant? can you help me for that ? how we can calculate to set the line in video |
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