ultralytics 8.2.57 new Solutions Tests and Docs (#14408)

Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Muhammad Rizwan Munawar 2024-07-14 23:00:14 +05:00 committed by GitHub
parent 100a73b6e9
commit c67a3039c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 143 additions and 50 deletions

View file

@ -83,7 +83,7 @@ Measuring the gap between two objects is known as distance calculation within a
| `Name` | `Type` | `Default` | Description |
| ------------------ | ------- | --------------- | --------------------------------------------------------- |
| `names` | `dict` | `None` | Dictionary mapping class indices to class names. |
| `names` | `dict` | `None` | Dictionary of classes names. |
| `pixels_per_meter` | `int` | `10` | Conversion factor from pixels to meters. |
| `view_img` | `bool` | `False` | Flag to indicate if the video stream should be displayed. |
| `line_thickness` | `int` | `2` | Thickness of the lines drawn on the image. |

View file

@ -61,7 +61,7 @@ A heatmap generated with [Ultralytics YOLOv8](https://github.com/ultralytics/ult
colormap=cv2.COLORMAP_PARULA,
view_img=True,
shape="circle",
classes_names=model.names,
names=model.names,
)
while cap.isOpened():
@ -102,7 +102,7 @@ A heatmap generated with [Ultralytics YOLOv8](https://github.com/ultralytics/ult
view_img=True,
shape="circle",
count_reg_pts=line_points,
classes_names=model.names,
names=model.names,
)
while cap.isOpened():
@ -144,7 +144,7 @@ A heatmap generated with [Ultralytics YOLOv8](https://github.com/ultralytics/ult
view_img=True,
shape="circle",
count_reg_pts=region_points,
classes_names=model.names,
names=model.names,
)
while cap.isOpened():
@ -186,7 +186,7 @@ A heatmap generated with [Ultralytics YOLOv8](https://github.com/ultralytics/ult
view_img=True,
shape="circle",
count_reg_pts=region_points,
classes_names=model.names,
names=model.names,
)
while cap.isOpened():
@ -221,7 +221,7 @@ A heatmap generated with [Ultralytics YOLOv8](https://github.com/ultralytics/ult
colormap=cv2.COLORMAP_PARULA,
view_img=True,
shape="circle",
classes_names=model.names,
names=model.names,
)
results = model.track(im0, persist=True)
@ -251,7 +251,7 @@ A heatmap generated with [Ultralytics YOLOv8](https://github.com/ultralytics/ult
colormap=cv2.COLORMAP_PARULA,
view_img=True,
shape="circle",
classes_names=model.names,
names=model.names,
)
while cap.isOpened():
@ -273,7 +273,7 @@ A heatmap generated with [Ultralytics YOLOv8](https://github.com/ultralytics/ult
| Name | Type | Default | Description |
| ------------------ | ---------------- | ------------------ | ----------------------------------------------------------------- |
| `classes_names` | `dict` | `None` | Dictionary of class names. |
| `names` | `list` | `None` | Dictionary of class names. |
| `imw` | `int` | `0` | Image width. |
| `imh` | `int` | `0` | Image height. |
| `colormap` | `int` | `cv2.COLORMAP_JET` | Colormap to use for the heatmap. |
@ -348,7 +348,7 @@ from ultralytics import YOLO, solutions
model = YOLO("yolov8n.pt")
cap = cv2.VideoCapture("path/to/video/file.mp4")
heatmap_obj = solutions.Heatmap(colormap=cv2.COLORMAP_PARULA, view_img=True, shape="circle", classes_names=model.names)
heatmap_obj = solutions.Heatmap(colormap=cv2.COLORMAP_PARULA, view_img=True, shape="circle", names=model.names)
while cap.isOpened():
success, im0 = cap.read()
@ -381,7 +381,7 @@ from ultralytics import YOLO, solutions
model = YOLO("yolov8n.pt")
cap = cv2.VideoCapture("path/to/video/file.mp4")
heatmap_obj = solutions.Heatmap(colormap=cv2.COLORMAP_PARULA, view_img=True, shape="circle", classes_names=model.names)
heatmap_obj = solutions.Heatmap(colormap=cv2.COLORMAP_PARULA, view_img=True, shape="circle", names=model.names)
classes_for_heatmap = [0, 2] # Classes to visualize
while cap.isOpened():

View file

@ -64,7 +64,9 @@ There are two types of instance segmentation tracking available in the Ultralyti
clss = results[0].boxes.cls.cpu().tolist()
masks = results[0].masks.xy
for mask, cls in zip(masks, clss):
annotator.seg_bbox(mask=mask, mask_color=colors(int(cls), True), det_label=names[int(cls)])
color = colors(int(cls), True)
txt_color = annotator.get_txt_color(color)
annotator.seg_bbox(mask=mask, mask_color=color, label=names[int(cls)], txt_color=txt_color)
out.write(im0)
cv2.imshow("instance-segmentation", im0)
@ -110,7 +112,9 @@ There are two types of instance segmentation tracking available in the Ultralyti
track_ids = results[0].boxes.id.int().cpu().tolist()
for mask, track_id in zip(masks, track_ids):
annotator.seg_bbox(mask=mask, mask_color=colors(track_id, True), track_label=str(track_id))
color = colors(int(track_id), True)
txt_color = annotator.get_txt_color(color)
annotator.seg_bbox(mask=mask, mask_color=color, label=str(track_id), txt_color=txt_color)
out.write(im0)
cv2.imshow("instance-segmentation-object-tracking", im0)
@ -125,12 +129,12 @@ There are two types of instance segmentation tracking available in the Ultralyti
### `seg_bbox` Arguments
| Name | Type | Default | Description |
| ------------- | ------- | --------------- | -------------------------------------- |
| `mask` | `array` | `None` | Segmentation mask coordinates |
| `mask_color` | `tuple` | `(255, 0, 255)` | Mask color for every segmented box |
| `det_label` | `str` | `None` | Label for segmented object |
| `track_label` | `str` | `None` | Label for segmented and tracked object |
| Name | Type | Default | Description |
| ------------ | ------- | --------------- | -------------------------------------------- |
| `mask` | `array` | `None` | Segmentation mask coordinates |
| `mask_color` | `RGB` | `(255, 0, 255)` | Mask color for every segmented box |
| `label` | `str` | `None` | Label for segmented object |
| `txt_color` | `RGB` | `None` | Label color for segmented and tracked object |
## Note

View file

@ -70,7 +70,7 @@ Object counting with [Ultralytics YOLOv8](https://github.com/ultralytics/ultraly
counter = solutions.ObjectCounter(
view_img=True,
reg_pts=region_points,
classes_names=model.names,
names=model.names,
draw_tracks=True,
line_thickness=2,
)
@ -112,7 +112,7 @@ Object counting with [Ultralytics YOLOv8](https://github.com/ultralytics/ultraly
counter = solutions.ObjectCounter(
view_img=True,
reg_pts=region_points,
classes_names=model.names,
names=model.names,
draw_tracks=True,
line_thickness=2,
)
@ -154,7 +154,7 @@ Object counting with [Ultralytics YOLOv8](https://github.com/ultralytics/ultraly
counter = solutions.ObjectCounter(
view_img=True,
reg_pts=line_points,
classes_names=model.names,
names=model.names,
draw_tracks=True,
line_thickness=2,
)
@ -196,7 +196,7 @@ Object counting with [Ultralytics YOLOv8](https://github.com/ultralytics/ultraly
counter = solutions.ObjectCounter(
view_img=True,
reg_pts=line_points,
classes_names=model.names,
names=model.names,
draw_tracks=True,
line_thickness=2,
)
@ -226,7 +226,7 @@ Here's a table with the `ObjectCounter` arguments:
| Name | Type | Default | Description |
| -------------------- | ------- | -------------------------- | ---------------------------------------------------------------------- |
| `classes_names` | `dict` | `None` | Dictionary of class names. |
| `names` | `dict` | `None` | Dictionary of classes names. |
| `reg_pts` | `list` | `[(20, 400), (1260, 400)]` | List of points defining the counting region. |
| `count_reg_color` | `tuple` | `(255, 0, 255)` | RGB color of the counting region. |
| `count_txt_color` | `tuple` | `(0, 0, 0)` | RGB color of the count text. |
@ -283,7 +283,7 @@ def count_objects_in_region(video_path, output_video_path, model_path):
region_points = [(20, 400), (1080, 404), (1080, 360), (20, 360)]
video_writer = cv2.VideoWriter(output_video_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
counter = solutions.ObjectCounter(
view_img=True, reg_pts=region_points, classes_names=model.names, draw_tracks=True, line_thickness=2
view_img=True, reg_pts=region_points, names=model.names, draw_tracks=True, line_thickness=2
)
while cap.isOpened():
@ -334,7 +334,7 @@ def count_specific_classes(video_path, output_video_path, model_path, classes_to
line_points = [(20, 400), (1080, 400)]
video_writer = cv2.VideoWriter(output_video_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
counter = solutions.ObjectCounter(
view_img=True, reg_pts=line_points, classes_names=model.names, draw_tracks=True, line_thickness=2
view_img=True, reg_pts=line_points, names=model.names, draw_tracks=True, line_thickness=2
)
while cap.isOpened():

View file

@ -53,7 +53,7 @@ Queue management using [Ultralytics YOLOv8](https://github.com/ultralytics/ultra
queue_region = [(20, 400), (1080, 404), (1080, 360), (20, 360)]
queue = solutions.QueueManager(
classes_names=model.names,
names=model.names,
reg_pts=queue_region,
line_thickness=3,
fontsize=1.0,
@ -97,7 +97,7 @@ Queue management using [Ultralytics YOLOv8](https://github.com/ultralytics/ultra
queue_region = [(20, 400), (1080, 404), (1080, 360), (20, 360)]
queue = solutions.QueueManager(
classes_names=model.names,
names=model.names,
reg_pts=queue_region,
line_thickness=3,
fontsize=1.0,
@ -127,7 +127,7 @@ Queue management using [Ultralytics YOLOv8](https://github.com/ultralytics/ultra
| Name | Type | Default | Description |
| ------------------- | ---------------- | -------------------------- | ----------------------------------------------------------------------------------- |
| `classes_names` | `dict` | `model.names` | A dictionary mapping class IDs to class names. |
| `names` | `dict` | `model.names` | A dictionary mapping class IDs to class names. |
| `reg_pts` | `list of tuples` | `[(20, 400), (1260, 400)]` | Points defining the counting region polygon. Defaults to a predefined rectangle. |
| `line_thickness` | `int` | `2` | Thickness of the annotation lines. |
| `track_thickness` | `int` | `2` | Thickness of the track lines. |
@ -175,7 +175,7 @@ cap = cv2.VideoCapture("path/to/video.mp4")
queue_region = [(20, 400), (1080, 404), (1080, 360), (20, 360)]
queue = solutions.QueueManager(
classes_names=model.names,
names=model.names,
reg_pts=queue_region,
line_thickness=3,
fontsize=1.0,
@ -228,7 +228,7 @@ Example for airports:
```python
queue_region_airport = [(50, 600), (1200, 600), (1200, 550), (50, 550)]
queue_airport = solutions.QueueManager(
classes_names=model.names,
names=model.names,
reg_pts=queue_region_airport,
line_thickness=3,
fontsize=1.0,