Skip to content
Snippets Groups Projects
Commit ff8f5511 authored by Paul Chevalier's avatar Paul Chevalier
Browse files

ajout du test pour vérifier la caméra

parent 429fc6de
No related branches found
No related tags found
No related merge requests found
File added
import inspect
import time
def count_function_lines(func):
"""Counts the number of lines in a function."""
source_lines = inspect.getsourcelines(func)[0]
return len(source_lines)
def progress_percentage(func, lines_done):
"""Calculates the percentage of lines completed in a function."""
total_lines = count_function_lines(func)
if total_lines == 0:
return 0
return (lines_done / total_lines) * 100
def current_line():
"""Returns the current line number being executed in a function."""
return inspect.currentframe().f_back.f_lineno
def fonction_longue():
# Simulate a long function
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
time.sleep(2)
if __name__ == '__main__':
while progress_percentage(fonction_longue, current_line) < 100:
print(f"Line {current_line}: {progress_percentage(fonction_longue, current_line):.2f}%")
time.sleep(0.5)
import cv2
import tkinter as tk
from tkinter import ttk
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
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
import chercher_caméra as cc
import cv2
import tkinter as tk
def select_camera_lanceemnt():
camera_index = cc.select_camera()
if camera_index is not None:
cap = cv2.VideoCapture(camera_index)
if not cap.isOpened():
print("Erreur : Impossible d'ouvrir la caméra.")
return
while True:
ret, frame = cap.read()
if not ret:
print("Erreur : Impossible de lire le flux vidéo.")
break
cv2.imshow("Flux vidéo", frame)
if cv2.waitKey(1) & 0xFF == ord('q'): # Appuyez sur 'q' pour quitter
break
cap.release()
cv2.destroyAllWindows()
if camera_index is not None:
print(f"Caméra sélectionnée : {camera_index}")
else:
print("Aucune caméra sélectionnée.")
if __name__ == "__main__":
select_camera_lanceemnt()
\ No newline at end of file
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