From ff8f551148db779a3fdd1f91b8b1ac2cc7120b6d Mon Sep 17 00:00:00 2001 From: Paul Chevalier <paul.guillaume.chevalier@gmail.com> Date: Wed, 26 Mar 2025 14:59:19 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20du=20test=20pour=20v=C3=A9rifier=20la?= =?UTF-8?q?=20cam=C3=A9ra?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chercher_cam\303\251ra.cpython-311.pyc" | Bin 0 -> 2835 bytes chargement.py | 51 ++++++++++++++++++ "chercher_cam\303\251ra.py" | 47 ++++++++++++++++ test_cherchercamera.py | 32 +++++++++++ 4 files changed, 130 insertions(+) create mode 100644 "__pycache__/chercher_cam\303\251ra.cpython-311.pyc" create mode 100644 chargement.py create mode 100644 "chercher_cam\303\251ra.py" create mode 100644 test_cherchercamera.py diff --git "a/__pycache__/chercher_cam\303\251ra.cpython-311.pyc" "b/__pycache__/chercher_cam\303\251ra.cpython-311.pyc" new file mode 100644 index 0000000000000000000000000000000000000000..ecfb16a20188bdd4eba6725239fc7089a480ac92 GIT binary patch literal 2835 zcmaJ?-*4MQ96!hB#BI~0U8jwOwHSCn*&r2TTiI5+!8#2JZ3iubR%4MDU)waU9WM5? zO|6tom6lXN18Ha#2vH;`tJVh|c|__zU{6MiELEBWd*Cfng*5TR_nbP5OU32#z5CvM z?|a|-{`mOk_V!i;?Zfb&(_aV({lOT&;qA#*1t#~9f)q|gll76C3;`cfxjBB4=a9lL zqDib^paKaiLN3J4(qsq`VHIW%80)pk2#MV6fOSy`lgPK|yU;2J`|z(f(8Y}*Z$Glz z4%<zNe=*^aB<J#mk;`l!^#*1%5C1I-$UQWT7Ld_UjzD=(=^*-SY=JY_iS0J)na-H` z9kL6d`Or#}q<;dT;1g+b9<BJ!dnUAtMh<~SaQlB-P$P#b<MRj}9x{)B?BK?lK{5uB zR8o*K^4!K6m0_Z58mw-t!Q#e>q`sn4C9BB>F=^^A7Ug8v6{xID6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8siAR@FEwpq{$=OMqIK4npe9kgRTfaAsUfX9H_ z!ro1>-HIKu#lwzx*b)y{<6R}AhIwIs4gDYayA?%am1E_;N?&oXipASQw}z~E(#D4z ze8|Fwp5XA}yQOjKxnmYSZsX$)KK=-wdWcW`w#UM!Y&_`TK?@H)>Fm0D@Tar)BfoI# ztv`(ZIBInswL6bGokxp9)%d;|;slke(-OZawpHTG*n0Vm`xzk6f1UmP!k9JwiGATy z=fbC!IAMzujyUm1y!=qS{QK05Gc{|8mu)fUh&jvaPjF;$sAMcB?@w5`&&GWY?t6s$ zAL9PsUb1k%jn6swoQ2Ol-j^tjvUd&N8ooKYI0{T#!omqJKV31MW<g4)O%?|~lbXN+ zAV4}PnLV((10#Y$sbmXfVDCnZI_%Jwf%EdiOD->l>^cp;*Xgty-7eRxrjTp&C6HZ1 zo=IK;{3G_y>58e60eTF!7^)N)iqv?H<Ep5&=>4i_ujThD+HVDW4U1e?4K>K#1Kjg9 z)F8(Zj+Smb<PTW<fohlZ<y&8!zI(d(K{e84MP8_i?IppAy?OstAkb~`gd?7?{QkJU VowCJVN9?uyUTZ@*0qVSW{0rzfl`;ST literal 0 HcmV?d00001 diff --git a/chargement.py b/chargement.py new file mode 100644 index 0000000..36a2f01 --- /dev/null +++ b/chargement.py @@ -0,0 +1,51 @@ +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) + + diff --git "a/chercher_cam\303\251ra.py" "b/chercher_cam\303\251ra.py" new file mode 100644 index 0000000..a358931 --- /dev/null +++ "b/chercher_cam\303\251ra.py" @@ -0,0 +1,47 @@ +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 diff --git a/test_cherchercamera.py b/test_cherchercamera.py new file mode 100644 index 0000000..6ae040f --- /dev/null +++ b/test_cherchercamera.py @@ -0,0 +1,32 @@ +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 -- GitLab