Reformat Markdown code blocks (#12795)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
parent
2af71d15a6
commit
fceea033ad
128 changed files with 1067 additions and 1018 deletions
|
|
@ -48,7 +48,7 @@ There are two types of instance segmentation tracking available in the Ultralyti
|
|||
cap = cv2.VideoCapture("path/to/video/file.mp4")
|
||||
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
|
||||
|
||||
out = cv2.VideoWriter('instance-segmentation.avi', cv2.VideoWriter_fourcc(*'MJPG'), fps, (w, h))
|
||||
out = cv2.VideoWriter("instance-segmentation.avi", cv2.VideoWriter_fourcc(*"MJPG"), fps, (w, h))
|
||||
|
||||
while True:
|
||||
ret, im0 = cap.read()
|
||||
|
|
@ -63,38 +63,35 @@ 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)])
|
||||
annotator.seg_bbox(mask=mask, mask_color=colors(int(cls), True), det_label=names[int(cls)])
|
||||
|
||||
out.write(im0)
|
||||
cv2.imshow("instance-segmentation", im0)
|
||||
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
if cv2.waitKey(1) & 0xFF == ord("q"):
|
||||
break
|
||||
|
||||
out.release()
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
```
|
||||
|
||||
=== "Instance Segmentation with Object Tracking"
|
||||
|
||||
```python
|
||||
from collections import defaultdict
|
||||
|
||||
import cv2
|
||||
from ultralytics import YOLO
|
||||
from ultralytics.utils.plotting import Annotator, colors
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
track_history = defaultdict(lambda: [])
|
||||
|
||||
model = YOLO("yolov8n-seg.pt") # segmentation model
|
||||
model = YOLO("yolov8n-seg.pt") # segmentation model
|
||||
cap = cv2.VideoCapture("path/to/video/file.mp4")
|
||||
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
|
||||
|
||||
out = cv2.VideoWriter('instance-segmentation-object-tracking.avi', cv2.VideoWriter_fourcc(*'MJPG'), fps, (w, h))
|
||||
out = cv2.VideoWriter("instance-segmentation-object-tracking.avi", cv2.VideoWriter_fourcc(*"MJPG"), fps, (w, h))
|
||||
|
||||
while True:
|
||||
ret, im0 = cap.read()
|
||||
|
|
@ -111,14 +108,12 @@ 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))
|
||||
annotator.seg_bbox(mask=mask, mask_color=colors(track_id, True), track_label=str(track_id))
|
||||
|
||||
out.write(im0)
|
||||
cv2.imshow("instance-segmentation-object-tracking", im0)
|
||||
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
if cv2.waitKey(1) & 0xFF == ord("q"):
|
||||
break
|
||||
|
||||
out.release()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue