| | import cv2 |
| | from ultralytics import YOLO |
| |
|
| | |
| | model = YOLO("yolo11n-pose.pt") |
| |
|
| | |
| | stream_url = "http://192.168.137.244:8080/video" |
| |
|
| | |
| | cap = cv2.VideoCapture(stream_url) |
| |
|
| | if not cap.isOpened(): |
| | print("Error: Cannot open video stream") |
| | exit() |
| |
|
| | |
| | width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) |
| | height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) |
| | fps = cap.get(cv2.CAP_PROP_FPS) |
| |
|
| | if width == 0 or height == 0: |
| | |
| | width, height = 640, 480 |
| | if fps == 0: |
| | fps = 20 |
| |
|
| | print(f"Stream opened: {width}x{height} at {fps} FPS") |
| |
|
| | |
| | out = cv2.VideoWriter("output_pose.mp4", cv2.VideoWriter_fourcc(*"mp4v"), fps, (height, width)) |
| |
|
| | while True: |
| | ret, frame = cap.read() |
| | if not ret: |
| | print("Failed to grab frame") |
| | break |
| |
|
| | |
| | rotated_frame = cv2.rotate(frame, cv2.ROTATE_90_CLOCKWISE) |
| |
|
| | |
| | results = model(rotated_frame, verbose=False, conf=0.3, iou=0.1) |
| |
|
| | |
| | annotated_frame = results[0].plot() |
| |
|
| | |
| | out.write(annotated_frame) |
| |
|
| | |
| | cv2.imshow("Pose Detection (rotated)", annotated_frame) |
| |
|
| | |
| | if cv2.waitKey(1) & 0xFF == ord("q"): |
| | break |
| |
|
| | |
| | cap.release() |
| | out.release() |
| | cv2.destroyAllWindows() |
| |
|