diff --git a/docs/en/guides/workouts-monitoring.md b/docs/en/guides/workouts-monitoring.md index 4e78f218..69ea55f0 100644 --- a/docs/en/guides/workouts-monitoring.md +++ b/docs/en/guides/workouts-monitoring.md @@ -8,6 +8,18 @@ keywords: Ultralytics, YOLOv8, Object Detection, Pose Estimation, PushUps, PullU Monitoring workouts through pose estimation with [Ultralytics YOLOv8](https://github.com/ultralytics/ultralytics/) enhances exercise assessment by accurately tracking key body landmarks and joints in real-time. This technology provides instant feedback on exercise form, tracks workout routines, and measures performance metrics, optimizing training sessions for users and trainers alike. +

+
+ +
+ Watch: Workouts Monitoring using Ultralytics YOLOv8 | Pushups, Pullups, Ab Workouts +

+ + ## Advantages of Workouts Monitoring? - **Optimized Performance:** Tailoring workouts based on monitoring data for better results. diff --git a/docs/en/usage/simple-utilities.md b/docs/en/usage/simple-utilities.md index f4d43286..7492f0eb 100644 --- a/docs/en/usage/simple-utilities.md +++ b/docs/en/usage/simple-utilities.md @@ -59,6 +59,28 @@ convert_coco(#(1)! For additional information about the `convert_coco` function, [visit the reference page](../reference/data/converter.md#ultralytics.data.converter.convert_coco) +### Get Bounding Box Dimensions + +```{.py .annotate } +from ultralytics.utils.plotting import Annotator +from ultralytics import YOLO +import cv2 + +model = YOLO('yolov8n.pt') # Load pretrain or fine-tune model + +# Process the image +source = cv2.imread('path/to/image.jpg') +results = model(source) + +# Extract results +annotator = Annotator(source, example=model.names) + +for box in results[0].boxes.xyxy.cpu(): + width, height, area = annotator.get_bbox_dimension(box) + print("Bounding Box Width {}, Height {}, Area {}".format( + width.item(), height.item(), area.item())) +``` + ### Convert Bounding Boxes to Segments With existing `x y w h` bounding box data, convert to segments using the `yolo_bbox2segment` function. The files for images and annotations need to be organized like this: diff --git a/ultralytics/utils/plotting.py b/ultralytics/utils/plotting.py index 0d4c456d..303fe30f 100644 --- a/ultralytics/utils/plotting.py +++ b/ultralytics/utils/plotting.py @@ -339,6 +339,21 @@ class Annotator: """Save the annotated image to 'filename'.""" cv2.imwrite(filename, np.asarray(self.im)) + def get_bbox_dimension(self, bbox=None): + """ + Calculate the area of a bounding box. + + Args: + bbox (tuple): Bounding box coordinates in the format (x_min, y_min, x_max, y_max). + + Returns: + angle (degree): Degree value of angle between three points + """ + x_min, y_min, x_max, y_max = bbox + width = x_max - x_min + height = y_max - y_min + return width, height, width * height + def draw_region(self, reg_pts=None, color=(0, 255, 0), thickness=5): """ Draw region line. @@ -364,13 +379,22 @@ class Annotator: cv2.circle(self.im, (int(track[-1][0]), int(track[-1][1])), track_thickness * 2, color, -1) def queue_counts_display(self, label, points=None, region_color=(255, 255, 255), txt_color=(0, 0, 0), fontsize=0.7): - """Displays queue counts on an image centered at the points with customizable font size and colors.""" + """ + Displays queue counts on an image centered at the points with customizable font size and colors. + + Args: + label (str): queue counts label + points (tuple): region points for center point calculation to display text + region_color (RGB): queue region color + txt_color (RGB): text display color + fontsize (float): text fontsize + """ x_values = [point[0] for point in points] y_values = [point[1] for point in points] center_x = sum(x_values) // len(points) center_y = sum(y_values) // len(points) - text_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, fontScale=fontsize, thickness=self.tf)[0] + text_size = cv2.getTextSize(label, 0, fontScale=fontsize, thickness=self.tf)[0] text_width = text_size[0] text_height = text_size[1] @@ -388,7 +412,7 @@ class Annotator: self.im, label, (text_x, text_y), - cv2.FONT_HERSHEY_SIMPLEX, + 0, fontScale=fontsize, color=txt_color, thickness=self.tf, @@ -595,30 +619,26 @@ class Annotator: line_color (RGB): Distance line color. centroid_color (RGB): Bounding box centroid color. """ - (text_width_m, text_height_m), _ = cv2.getTextSize( - f"Distance M: {distance_m:.2f}m", cv2.FONT_HERSHEY_SIMPLEX, 0.8, 2 - ) + (text_width_m, text_height_m), _ = cv2.getTextSize(f"Distance M: {distance_m:.2f}m", 0, 0.8, 2) cv2.rectangle(self.im, (15, 25), (15 + text_width_m + 10, 25 + text_height_m + 20), (255, 255, 255), -1) cv2.putText( self.im, f"Distance M: {distance_m:.2f}m", (20, 50), - cv2.FONT_HERSHEY_SIMPLEX, + 0, 0.8, (0, 0, 0), 2, cv2.LINE_AA, ) - (text_width_mm, text_height_mm), _ = cv2.getTextSize( - f"Distance MM: {distance_mm:.2f}mm", cv2.FONT_HERSHEY_SIMPLEX, 0.8, 2 - ) + (text_width_mm, text_height_mm), _ = cv2.getTextSize(f"Distance MM: {distance_mm:.2f}mm", 0, 0.8, 2) cv2.rectangle(self.im, (15, 75), (15 + text_width_mm + 10, 75 + text_height_mm + 20), (255, 255, 255), -1) cv2.putText( self.im, f"Distance MM: {distance_mm:.2f}mm", (20, 100), - cv2.FONT_HERSHEY_SIMPLEX, + 0, 0.8, (0, 0, 0), 2,