Reference for ultralytics/solutions/queue_management.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/queue_management.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.solutions.queue_management.QueueManager
Bases: BaseSolution
Manages queue counting in real-time video streams based on object tracks.
This class extends BaseSolution to provide functionality for tracking and counting objects within a specified region in video frames.
Attributes:
Name | Type | Description |
---|---|---|
counts |
int
|
The current count of objects in the queue. |
rect_color |
Tuple[int, int, int]
|
RGB color tuple for drawing the queue region rectangle. |
region_length |
int
|
The number of points defining the queue region. |
annotator |
Annotator
|
An instance of the Annotator class for drawing on frames. |
track_line |
List[Tuple[int, int]]
|
List of track line coordinates. |
track_history |
Dict[int, List[Tuple[int, int]]]
|
Dictionary storing tracking history for each object. |
Methods:
Name | Description |
---|---|
initialize_region |
Initializes the queue region. |
process_queue |
Processes a single frame for queue management. |
extract_tracks |
Extracts object tracks from the current frame. |
store_tracking_history |
Stores the tracking history for an object. |
display_output |
Displays the processed output. |
Examples:
>>> cap = cv2.VideoCapture("Path/to/video/file.mp4")
>>> queue_manager = QueueManager(region=[100, 100, 200, 200, 300, 300])
>>> while cap.isOpened():
>>> success, im0 = cap.read()
>>> if not success:
>>> break
>>> out = queue.process_queue(im0)
Source code in ultralytics/solutions/queue_management.py
process_queue
Processes the queue management for a single frame of video.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im0
|
ndarray
|
Input image for processing, typically a frame from a video stream. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Processed image with annotations, bounding boxes, and queue counts. |
This method performs the following steps: 1. Resets the queue count for the current frame. 2. Initializes an Annotator object for drawing on the image. 3. Extracts tracks from the image. 4. Draws the counting region on the image. 5. For each detected object: - Draws bounding boxes and labels. - Stores tracking history. - Draws centroids and tracks. - Checks if the object is inside the counting region and updates the count. 6. Displays the queue count on the image. 7. Displays the processed output.
Examples:
>>> queue_manager = QueueManager()
>>> frame = cv2.imread("frame.jpg")
>>> processed_frame = queue_manager.process_queue(frame)