Apply new Ruff actions to Python codeblocks (#13783)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
parent
c0305f4e15
commit
6bddeda34b
13 changed files with 95 additions and 99 deletions
|
|
@ -14,20 +14,7 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
|
||||
## Recipe Walk Through
|
||||
|
||||
1. Begin with the necessary imports
|
||||
|
||||
```python
|
||||
from pathlib import Path
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
from ultralytics import YOLO
|
||||
```
|
||||
|
||||
???+ tip "Ultralytics Install"
|
||||
|
||||
See the Ultralytics [Quickstart](../quickstart.md/#install-ultralytics) Installation section for a quick walkthrough on installing the required libraries.
|
||||
1. See the [Ultralytics Quickstart Installation section](../quickstart.md/#install-ultralytics) for a quick walkthrough on installing the required libraries.
|
||||
|
||||
***
|
||||
|
||||
|
|
@ -61,6 +48,10 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
3. Now iterate over the results and the contours. For workflows that want to save an image to file, the source image `base-name` and the detection `class-label` are retrieved for later use (optional).
|
||||
|
||||
```{ .py .annotate }
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
# (2) Iterate detection results (helpful for multiple images)
|
||||
for r in res:
|
||||
img = np.copy(r.orig_img)
|
||||
|
|
@ -86,6 +77,8 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
{ width="240", align="right" }
|
||||
|
||||
```{ .py .annotate }
|
||||
import cv2
|
||||
|
||||
# Create binary mask
|
||||
b_mask = np.zeros(img.shape[:2], np.uint8)
|
||||
|
||||
|
|
@ -178,12 +171,11 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
Additional steps required to crop image to only include object region.
|
||||
|
||||
{ align="right" }
|
||||
``` { .py .annotate }
|
||||
```{ .py .annotate }
|
||||
# (1) Bounding box coordinates
|
||||
x1, y1, x2, y2 = c.boxes.xyxy.cpu().numpy().squeeze().astype(np.int32)
|
||||
# Crop image to object region
|
||||
iso_crop = isolated[y1:y2, x1:x2]
|
||||
|
||||
```
|
||||
|
||||
1. For more information on bounding box results, see [Boxes Section from Predict Mode](../modes/predict.md/#boxes)
|
||||
|
|
@ -225,12 +217,11 @@ After performing the [Segment Task](../tasks/segment.md), it's sometimes desirab
|
|||
Additional steps required to crop image to only include object region.
|
||||
|
||||
{ align="right" }
|
||||
``` { .py .annotate }
|
||||
```{ .py .annotate }
|
||||
# (1) Bounding box coordinates
|
||||
x1, y1, x2, y2 = c.boxes.xyxy.cpu().numpy().squeeze().astype(np.int32)
|
||||
# Crop image to object region
|
||||
iso_crop = isolated[y1:y2, x1:x2]
|
||||
|
||||
```
|
||||
|
||||
1. For more information on bounding box results, see [Boxes Section from Predict Mode](../modes/predict.md/#boxes)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue