guides/object-counting/ #8112
Replies: 187 comments 611 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.
-
I have a YOLOv8 model trained for object detection, and I want to count the total number of objects detected throughout a video. I've used a counting function, but it isn't producing the expected results. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your answer. How to keep track id history, what Settings is needed in the code, or what configuration to change
…---Original---
From: "Glenn ***@***.***>
Date: Tue, Oct 29, 2024 20:52 PM
To: ***@***.***>;
Cc: ***@***.******@***.***>;
Subject: Re: [ultralytics/ultralytics] guides/object-counting/ (Discussion#8112)
To improve reliability, consider implementing a buffer zone to confirm direction before counting. For reappearing objects, maintain a history of tracked IDs to avoid double counting. Adjusting the persistence logic might help manage these scenarios. For more details, refer to the Ultralytics documentation on object counting.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I keep getting im0 = counter.count(im0,tracks) the code is import cv2 video_path= "data/test1.mp4" model_path = 'models/person/yolo11m-obb.pt' MOdel setmodel_yolo = YOLO(model_path ) Count specific classes of objects in a video."""cap = cv2.VideoCapture(video_path) region_points = [(20, 400), (1080, 404), (1080, 360), (20, 360)] counter =solutions.ObjectCounter( while cap.isOpened():
cap.release() |
Beta Was this translation helpful? Give feedback.
-
Hi, my results with "count in line" are totally off. It confuses in and out while there is only one direction, I've wasted hours and this is crazy. It confuses in and out, and I don't understand why. Maybe someone can take a look? |
Beta Was this translation helpful? Give feedback.
-
What is the minimal code that I can use to have: yolo (defining parameters, if any) bytetrack (defining parameters, if any) get the coordinates of the boxes and id of the object then I'll define a geometric condition, let's say behind a line etc |
Beta Was this translation helpful? Give feedback.
-
If I want a target to be detected only once, is it possible? If so, how can I do it? |
Beta Was this translation helpful? Give feedback.
-
If I aim to utilize the camera for real-time counting instead of analyzing counts from recorded video, what approach should I take? |
Beta Was this translation helpful? Give feedback.
-
Hey there! |
Beta Was this translation helpful? Give feedback.
-
🎉 Big News Alert! 🚀 Ultralytics Solutions CLI is here from ultralytics>=8.3.28! Now, you can easily harness the power of advanced YOLO solutions straight from the command line. Simplify your workflow, and streamline object detection, tracking, counting, and more—all with just a few commands! Get ready to experience a whole new level of efficiency! 💥 CLI Usage Overview yolo SOLUTIONS SOLUTION_NAME ARGS
Examples yolo solutions count show=True # For object counting
yolo solutions source="path/to/video/file.mp4" # Specify a video file path Start exploring now and let Ultralytics Solutions CLI power up your projects! |
Beta Was this translation helpful? Give feedback.
-
Hi, when I use YOLO11 to detect the number of pedestrians entering the door, the number of people increases by 1 when the bottom center of the boxbounding passes through the line drawn at the bottom of the door. However, I encountered a problem where when multiple people enter together, due to obstruction, the number of people who are obstructed may not be recorded. Do you have any good solutions |
Beta Was this translation helpful? Give feedback.
-
Hi, I would like implementing a counting with people who in with tote bags(shopping bags) and people who out with tote bag(shopping bags). I have implementing the code mentioned in (https://docs.ultralytics.com/guides/object-counting/#advantages-of-object-counting) but doesn't work fine. Sometimes count people when out when really they are in. This is the my specification of my device that I have:
Please give me some tips for a better predection of the object and how to implement the object tote bags(shopping bags). I'll appreciate your help. |
Beta Was this translation helpful? Give feedback.
-
horizontal line crossed to the center point of bounding box then object count increment , some time object count not increment . from collections import defaultdict MODEL_PATH = r"object.pt" class ObjectCounter:
if name == "main":
|
Beta Was this translation helpful? Give feedback.
-
Hello, I would like to add negative samples during the training process. How should I proceed? Is the label of the negative sample image an empty txt file or do I not need labels |
Beta Was this translation helpful? Give feedback.
-
This line counter is working fine. But People entering from right side while It counting it as out. How to change the logic? So if people enter from right side, it should be count in. Open the video filecap = cv2.VideoCapture("49.mp4") Get video propertiesw, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS)) Define region points for a vertical line at the right edgeThese points create a vertical line (from bottom to top at the right side)region_points = [(w - 100, h), (w - 100, 0)] # Vertical line at the right side Set up video writer to save processed videovideo_writer = cv2.VideoWriter("object_counting_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h)) Initialize the Object Countercounter = solutions.ObjectCounter( Process the videowhile cap.isOpened():
Release resourcescap.release() |
Beta Was this translation helpful? Give feedback.
-
Hi, Object counting using function is very clean and easy to deploy. How do I get ride of printed output per frame info? def count_objects_in_region(video_path, output_video_path, model_path):
vid_id = 1 Here is output 0: 576x1024 3 sticklebacks, 14.4ms 0: 576x1024 3 sticklebacks, 11.6ms 0: 576x1024 1 stickleback, 11.2ms 0: 576x1024 2 sticklebacks, 10.6ms Any suggestion would be great help. Thank you in advance! |
Beta Was this translation helpful? Give feedback.
-
guides/object-counting/
Object Counting Using Ultralytics YOLO11, Ultralytics YOLOv8, YOLOv9, YOLOv10
CLI Usage
Python Usage
Documentation
https://docs.ultralytics.com/guides/object-counting/
Beta Was this translation helpful? Give feedback.
All reactions