From 24e5c3eceee1a784194b7314ab9ac2865f0d36c5 Mon Sep 17 00:00:00 2001 From: Dan Birman Date: Fri, 24 Nov 2023 19:03:49 -0800 Subject: [PATCH] fix: import cv2 conditionally on use of Video tools --- API/oursin/camera.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/API/oursin/camera.py b/API/oursin/camera.py index 92a804e0..d6f7e60d 100644 --- a/API/oursin/camera.py +++ b/API/oursin/camera.py @@ -6,7 +6,6 @@ import PIL from PIL import Image -import cv2 import numpy as np import io @@ -350,6 +349,11 @@ async def capture_video(self, file_name, start_rotation, end_rotation, frame_rat -------- >>> await urchin.camera.main.capture_video('output.mp4', start_rotation=[22.5, 22.5, 225], end_rotation=[22.5, 22.5, 0]) """ + try: + import cv2 + except: + raise Exception('Please install cv2 by running `pip install opencv-python` in your terminal to use the Video features') + fourcc = cv2.VideoWriter_fourcc(*'mp4v') out = cv2.VideoWriter(file_name, fourcc, frame_rate, size)