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
|
|
@ -29,39 +29,40 @@ Queue management using [Ultralytics YOLOv8](https://github.com/ultralytics/ultra
|
|||
```python
|
||||
import cv2
|
||||
from ultralytics import YOLO, solutions
|
||||
|
||||
|
||||
model = YOLO("yolov8n.pt")
|
||||
cap = cv2.VideoCapture("path/to/video/file.mp4")
|
||||
|
||||
|
||||
assert cap.isOpened(), "Error reading video file"
|
||||
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
|
||||
|
||||
video_writer = cv2.VideoWriter("queue_management.avi", cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
|
||||
|
||||
|
||||
video_writer = cv2.VideoWriter("queue_management.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
|
||||
|
||||
queue_region = [(20, 400), (1080, 404), (1080, 360), (20, 360)]
|
||||
|
||||
queue = solutions.QueueManager(classes_names=model.names,
|
||||
reg_pts=queue_region,
|
||||
line_thickness=3,
|
||||
fontsize=1.0,
|
||||
region_color=(255, 144, 31))
|
||||
|
||||
|
||||
queue = solutions.QueueManager(
|
||||
classes_names=model.names,
|
||||
reg_pts=queue_region,
|
||||
line_thickness=3,
|
||||
fontsize=1.0,
|
||||
region_color=(255, 144, 31),
|
||||
)
|
||||
|
||||
while cap.isOpened():
|
||||
success, im0 = cap.read()
|
||||
|
||||
|
||||
if success:
|
||||
tracks = model.track(im0, show=False, persist=True,
|
||||
verbose=False)
|
||||
tracks = model.track(im0, show=False, persist=True, verbose=False)
|
||||
out = queue.process_queue(im0, tracks)
|
||||
|
||||
|
||||
video_writer.write(im0)
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
if cv2.waitKey(1) & 0xFF == ord("q"):
|
||||
break
|
||||
continue
|
||||
|
||||
|
||||
print("Video frame is empty or video processing has been successfully completed.")
|
||||
break
|
||||
|
||||
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
```
|
||||
|
|
@ -71,39 +72,40 @@ Queue management using [Ultralytics YOLOv8](https://github.com/ultralytics/ultra
|
|||
```python
|
||||
import cv2
|
||||
from ultralytics import YOLO, solutions
|
||||
|
||||
|
||||
model = YOLO("yolov8n.pt")
|
||||
cap = cv2.VideoCapture("path/to/video/file.mp4")
|
||||
|
||||
|
||||
assert cap.isOpened(), "Error reading video file"
|
||||
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
|
||||
|
||||
video_writer = cv2.VideoWriter("queue_management.avi", cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
|
||||
|
||||
|
||||
video_writer = cv2.VideoWriter("queue_management.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
|
||||
|
||||
queue_region = [(20, 400), (1080, 404), (1080, 360), (20, 360)]
|
||||
|
||||
queue = solutions.QueueManager(classes_names=model.names,
|
||||
reg_pts=queue_region,
|
||||
line_thickness=3,
|
||||
fontsize=1.0,
|
||||
region_color=(255, 144, 31))
|
||||
|
||||
|
||||
queue = solutions.QueueManager(
|
||||
classes_names=model.names,
|
||||
reg_pts=queue_region,
|
||||
line_thickness=3,
|
||||
fontsize=1.0,
|
||||
region_color=(255, 144, 31),
|
||||
)
|
||||
|
||||
while cap.isOpened():
|
||||
success, im0 = cap.read()
|
||||
|
||||
|
||||
if success:
|
||||
tracks = model.track(im0, show=False, persist=True,
|
||||
verbose=False, classes=0) # Only person class
|
||||
tracks = model.track(im0, show=False, persist=True, verbose=False, classes=0) # Only person class
|
||||
out = queue.process_queue(im0, tracks)
|
||||
|
||||
|
||||
video_writer.write(im0)
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
if cv2.waitKey(1) & 0xFF == ord("q"):
|
||||
break
|
||||
continue
|
||||
|
||||
|
||||
print("Video frame is empty or video processing has been successfully completed.")
|
||||
break
|
||||
|
||||
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue