Skip to content
Snippets Groups Projects
Commit 4346cce2 authored by Rioux Jeremy's avatar Rioux Jeremy
Browse files

foutu git

parent cb5485e0
Branches jejew
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -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():
......
......@@ -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))
......
No preview for this file type
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
vid3.mp4 0 → 100644
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment