Annotations on images with metrics are cropped

Can someone help me pls?

Hi there! :blush:

It seems like you’re encountering an issue where annotations or metrics on your images are being cropped. This can often happen due to the text or bounding boxes extending beyond the image canvas. Here are a few suggestions to resolve this:

  1. Adjust Annotation Margins: If you’re using the Annotator class or similar tools for adding annotations, ensure there’s enough margin between the text and the edges of the image. For example, you can modify the margin parameter when drawing annotations or adjust the text placement.

    Here’s a snippet to help if you’re using cv2 for annotations:

    import cv2
    
    # Example of safe annotation placement
    text = "Example Text"
    text_size = cv2.getTextSize(text, fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=1, thickness=2)[0]
    text_x = max(10, image.shape[1] - text_size[0] - 20)  # Ensure text stays within bounds horizontally
    text_y = max(30, text_size[1] + 20)  # Ensure text stays within bounds vertically
    
    cv2.putText(image, text, (text_x, text_y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    
  2. Check Image Canvas Size: If your annotations are still being cropped, consider increasing the canvas size of your images. You can pad the images to provide extra space for annotations using tools like numpy or Pillow.

    Example with numpy:

    import numpy as np
    
    # Add padding to the image
    padded_image = np.pad(image, ((50, 50), (50, 50), (0, 0)), mode='constant', constant_values=255)  # Add white padding
    
  3. Validate Annotation Code: If you’re using a custom script or utility for annotation, double-check that no coordinates are being calculated outside the image dimensions. This could inadvertently lead to cropped text or bounding boxes.

  4. Use the Latest Version: If the issue persists, ensure you’re using the latest version of the Ultralytics package (ultralytics>=8.0.0). Sometimes, bugs are resolved in newer updates.

If none of these solve the problem, feel free to share the specific code snippet or process you’re using for the annotations. This will help us pinpoint the issue more effectively.

For more details on plotting or annotations, you can also refer to the Ultralytics plotting utilities documentation.

Let us know how it goes, and happy coding! :rocket:

Can you provide the output after running this command in terminal: yolo checks?