Reference for ultralytics/solutions/trackzone.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/trackzone.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.solutions.trackzone.TrackZone
Bases: BaseSolution
A class to manage region-based object tracking in a video stream.
This class extends the BaseSolution class and provides functionality for tracking objects within a specific region defined by a polygonal area. Objects outside the region are excluded from tracking. It supports dynamic initialization of the region, allowing either a default region or a user-specified polygon.
Attributes:
Name | Type | Description |
---|---|---|
region |
ndarray
|
The polygonal region for tracking, represented as a convex hull. |
Methods:
Name | Description |
---|---|
trackzone |
Processes each frame of the video, applying region-based tracking. |
Examples:
>>> tracker = TrackZone()
>>> frame = cv2.imread("frame.jpg")
>>> processed_frame = tracker.trackzone(frame)
>>> cv2.imshow("Tracked Frame", processed_frame)
Source code in ultralytics/solutions/trackzone.py
trackzone
Processes the input frame to track objects within a defined region.
This method initializes the annotator, creates a mask for the specified region, extracts tracks only from the masked area, and updates tracking information. Objects outside the region are ignored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im0
|
ndarray
|
The input image or frame to be processed. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The processed image with tracking id and bounding boxes annotations. |
Examples: