diff --git a/Objet/__pycache__/display.cpython-311.pyc b/Objet/__pycache__/display.cpython-311.pyc index e338aeb771cf6f31bc02f04a2a5d165bef4efae2..7e6753e1edd62c86d99ae01c911a78f5c095fb43 100644 Binary files a/Objet/__pycache__/display.cpython-311.pyc and b/Objet/__pycache__/display.cpython-311.pyc differ diff --git a/Objet/__pycache__/gestion_clavier.cpython-311.pyc b/Objet/__pycache__/gestion_clavier.cpython-311.pyc index 1ddf70342171c8cbcc48e2f4f4ff1ab8c0a1abf7..279d5910c609a4f128b26975390f670ec592c273 100644 Binary files a/Objet/__pycache__/gestion_clavier.cpython-311.pyc and b/Objet/__pycache__/gestion_clavier.cpython-311.pyc differ diff --git a/Objet/__pycache__/parameters.cpython-311.pyc b/Objet/__pycache__/parameters.cpython-311.pyc index 19430169ef99b849616cfc7c91eb2a4806a4b41f..89ec17d9176eee6fa9295a78af3d991641e27c0b 100644 Binary files a/Objet/__pycache__/parameters.cpython-311.pyc and b/Objet/__pycache__/parameters.cpython-311.pyc differ diff --git a/Objet/__pycache__/ui.cpython-311.pyc b/Objet/__pycache__/ui.cpython-311.pyc index 85483b74d7c90215b7d944e0ec46495fae475754..d44d5867c48f7b92671def24eacf9b6e41e1e523 100644 Binary files a/Objet/__pycache__/ui.cpython-311.pyc and b/Objet/__pycache__/ui.cpython-311.pyc differ diff --git a/Objet/__pycache__/video_manager.cpython-311.pyc b/Objet/__pycache__/video_manager.cpython-311.pyc index 8643a0c9f14decf6e2fac57215d802b78fa5b6b9..5515052c6d606809864a20f978a948770d110a55 100644 Binary files a/Objet/__pycache__/video_manager.cpython-311.pyc and b/Objet/__pycache__/video_manager.cpython-311.pyc differ diff --git a/Objet/main.py b/Objet/main.py index 097fa7429c68a5fb966891edb17aedbd3ec8d343..c740e869ff59a0d63db0166d078e291663f2d16a 100644 --- a/Objet/main.py +++ b/Objet/main.py @@ -68,7 +68,7 @@ class Main: cv2.destroyAllWindows() if __name__ == "__main__": - main = Main("vid4.mp4", "direct") + main = Main("vid3.mp4", "video") main.run() def is_ready(): diff --git a/Objet/video_manager.py b/Objet/video_manager.py index dc367c057b9a9c72352ba98ecb4b0645517bfb88..91aec94570df2d213b8ad77c800b97828187d379 100644 --- a/Objet/video_manager.py +++ b/Objet/video_manager.py @@ -20,6 +20,17 @@ class VideoManager: if self.video_type == "video": self.cap = cv2.VideoCapture(self.video_file) elif self.video_type == "direct": + max_cameras=10 + backend=cv2.CAP_DSHOW + available_cameras = [] + for i in range(max_cameras): + cap = cv2.VideoCapture(i, backend) + if cap.isOpened(): + ret, frame = cap.read() + if ret: + available_cameras.append(i) + cap.release() + print(available_cameras) self.cap = cv2.VideoCapture(0) self.fps = int(self.cap.get(cv2.CAP_PROP_FPS)) self.total_frames = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT)) diff --git "a/__pycache__/chercher_cam\303\251ra.cpython-311.pyc" "b/__pycache__/chercher_cam\303\251ra.cpython-311.pyc" index 184f5a6159bc310caf051e135396901fe985fcee..8ffd2f7914e490cd758c2c24ba0cdcea184b31bd 100644 Binary files "a/__pycache__/chercher_cam\303\251ra.cpython-311.pyc" and "b/__pycache__/chercher_cam\303\251ra.cpython-311.pyc" differ diff --git "a/chercher_cam\303\251ra.py" "b/chercher_cam\303\251ra.py" index a35893138713d40a452a42a552073ef1860b072d..0dbb4d793b333212f10a9662f3f281a07cbe3718 100644 --- "a/chercher_cam\303\251ra.py" +++ "b/chercher_cam\303\251ra.py" @@ -1,47 +1,98 @@ import cv2 import tkinter as tk from tkinter import ttk +from PIL import Image, ImageTk +import threading -def detect_cameras(): - """Détecte les caméras connectées à l'ordinateur.""" - cameras = [] - for i in range(10): # Vérifie les 10 premiers indices de caméra - cap = cv2.VideoCapture(i) - if cap.isOpened(): - cameras.append(i) - cap.release() - return cameras - -def select_camera(): - """Affiche une interface Tkinter pour sélectionner une caméra.""" - cameras = detect_cameras() - if not cameras: - print("Aucune caméra détectée.") - return None - - def on_select(): - nonlocal selected_camera - selected_camera = int(camera_var.get()) - root.destroy() - - root = tk.Tk() - root.title("Sélection de la caméra") - - tk.Label(root, text="Sélectionnez une caméra :").pack(pady=10) - - camera_var = tk.StringVar(value=str(cameras[0])) - for cam in cameras: - ttk.Radiobutton(root, text=f"Caméra {cam}", variable=camera_var, value=str(cam)).pack(anchor=tk.W) - - ttk.Button(root, text="Valider", command=on_select).pack(pady=10) - - selected_camera = None - root.mainloop() - return selected_camera +class CameraSelector: + def __init__(self, root): + self.root = root + self.root.title("Sélection de caméra") + self.cameras = [] + self.current_camera = None + self.video_source = None + + # Détection des caméras disponibles + self.detect_cameras() + + # Interface graphique + self.create_widgets() + + def detect_cameras(self): + """Détecte toutes les caméras disponibles jusqu'à l'index 10""" + self.cameras = [] + for i in range(10): # Vous pouvez augmenter ce nombre si nécessaire + cap = cv2.VideoCapture(i) + if cap.isOpened(): + self.cameras.append(i) + cap.release() + + def create_widgets(self): + """Crée l'interface utilisateur""" + # Cadre principal + main_frame = ttk.Frame(self.root, padding=10) + main_frame.pack() + + # Sélection de caméra + ttk.Label(main_frame, text="Caméras détectées:").pack() + self.camera_var = tk.StringVar() + self.cam_selector = ttk.Combobox(main_frame, textvariable=self.camera_var) + self.cam_selector['values'] = [f"Caméra {i}" for i in self.cameras] + self.cam_selector.pack(pady=5) + + # Bouton de confirmation + ttk.Button(main_frame, text="Ouvrir", command=self.start_camera).pack(pady=5) + + # Zone d'affichage vidéo + self.video_label = ttk.Label(main_frame) + self.video_label.pack() + + def start_camera(self): + """Démarre le flux vidéo de la caméra sélectionnée""" + if self.current_camera is not None: + self.stop_camera() + + selected = self.cam_selector.current() + if selected == -1: + return + + self.video_source = self.cameras[selected] + self.current_camera = cv2.VideoCapture(self.video_source) + + # Démarrer l'affichage vidéo dans un thread séparé + self.thread = threading.Thread(target=self.show_video) + self.thread.daemon = True + self.thread.start() + + def show_video(self): + """Affiche le flux vidéo dans le label""" + while self.current_camera.isOpened(): + ret, frame = self.current_camera.read() + if ret: + # Conversion de l'image pour Tkinter + frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) + img = Image.fromarray(frame) + imgtk = ImageTk.PhotoImage(image=img) + + # Mise à jour de l'interface + self.video_label.configure(image=imgtk) + self.video_label.image = imgtk + else: + break + + def stop_camera(self): + """Arrête le flux vidéo""" + if self.current_camera is not None: + self.current_camera.release() + self.video_label.configure(image='') + self.video_label.image = None + + def on_close(self): + self.stop_camera() + self.root.destroy() if __name__ == "__main__": - camera_index = select_camera() - if camera_index is not None: - print(f"Caméra sélectionnée : {camera_index}") - else: - print("Aucune caméra sélectionnée.") \ No newline at end of file + root = tk.Tk() + app = CameraSelector(root) + root.protocol("WM_DELETE_WINDOW", app.on_close) + root.mainloop() \ No newline at end of file diff --git a/vid3.mp4 b/vid3.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..fdc50934648d989c26de3a8c4ac298b49ac8c3c4 Binary files /dev/null and b/vid3.mp4 differ