1234567891011121314151617181920212223242526272829303132 |
- import cv2
- from ultralytics import YOLO
- # Load a model
- model = YOLO('yolov8n-obb.pt') # load an official model
- # Open the input video
- cap = cv2.VideoCapture('obb.mp4')
- if not cap.isOpened():
- raise Exception("Error: Could not open video.")
- while cap.isOpened():
- # Read a frame from the input video
- success, frame = cap.read()
- if success:
- results = model.predict(source=frame, verbose=False)
- for result in results:
- boxs = result.obb.xyxyxyxy.cpu().numpy().astype(int)
- for box in boxs:
- color = (0, 255, 0)
- image = cv2.polylines(frame, [box], True, color, 1)
- cv2.imshow("Obb example", frame)
- key = cv2.waitKey(1)
- if key & 0xff == ord('q'):
- break
- cap.release()
- cv2.destroyAllWindows()
|