From 9bcc0648ca6d6b275a5f2105ccff7e3566c46600 Mon Sep 17 00:00:00 2001 From: Chevalier Paul <paul.chevalier@student-cs.fr> Date: Wed, 26 Mar 2025 19:14:49 +0000 Subject: [PATCH] Edit gopro.py --- gopro.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/gopro.py b/gopro.py index e69de29..b46024d 100644 --- a/gopro.py +++ b/gopro.py @@ -0,0 +1,62 @@ +import cv2 +import numpy as np +import goprocam +from goprocam import GoPro +#modif +def list_cameras(): + """ Liste les caméras disponibles et retourne leurs indices. """ + index = 0 + available_cameras = [] + while True: + cap = cv2.VideoCapture(index) + if not cap.read()[0]: + break + else: + available_cameras.append(index) + cap.release() + index += 1 + return available_cameras + +def select_camera(): + cameras = list_cameras() + if not cameras: + print("Aucune caméra détectée.") + return None + print("Caméras disponibles :", cameras) + selected = int(input("Sélectionnez l'indice de votre GoPro : ")) + return selected if selected in cameras else None + +def record_video(camera_index): + cap = cv2.VideoCapture(camera_index) + if not cap.isOpened(): + print("Impossible d'accéder à la caméra.") + return + + fourcc = cv2.VideoWriter_fourcc(*'XVID') + out = cv2.VideoWriter('gopro_output.avi', fourcc, 30.0, (640, 480)) + + while True: + ret, frame = cap.read() + if not ret: + break + cv2.imshow('GoPro Video', frame) + out.write(frame) + + if cv2.waitKey(1) & 0xFF == ord('q'): + break + + cap.release() + out.release() + cv2.destroyAllWindows() + +if __name__ == "__main__": + print("Connexion à la GoPro...") + gopro = GoPro.GoPro() + gopro.webcamFOV("medium") + gopro.startWebcam() + + cam_index = select_camera() + if cam_index is not None: + record_video(cam_index) + else: + print("Sélection invalide.") \ No newline at end of file -- GitLab