bonjour a tous
voici mon script:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
 
from imutils.video import VideoStream
import face_recognition
import imutils
import pickle
import cv2
import tkinter as tk
import tkinter.ttk as ttk
from PIL import Image, ImageTk
import threading
 
Encodings = "/home/pi/bot/aramis/source/cam/encodings.pickle"
cascade = "/home/pi/bot/aramis/source/cam/haarcascade_frontalface_default.xml"
data = pickle.loads(open(Encodings, "rb").read())
detector = cv2.CascadeClassifier(cascade)
vs = VideoStream(src=0).start()
 
def showCam():
    imageFrame.grid(row=0, column=0, padx=10, pady=2)
    camButton.grid_forget()
    hideButton.grid(row=0,column=0)
def hideCam():
    imageFrame.grid_forget()
    hideButton.grid_forget()
    camButton.grid(row=0,column=0)
 
def faceReco():
    while True:
        frame = vs.read()
        frame = cv2.flip(frame, 0)
        frame = imutils.resize(frame, width=500)
 
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        rects = detector.detectMultiScale(gray, scaleFactor=1.1, 
            minNeighbors=5, minSize=(30, 30),
            flags=cv2.CASCADE_SCALE_IMAGE)
 
        boxes = [(y, x + w, y + h, x) for (x, y, w, h) in rects]
 
        encodings = face_recognition.face_encodings(rgb, boxes)
        names = []
 
        for encoding in encodings:
            matches = face_recognition.compare_faces(data["encodings"],
                encoding)
            name = "Unknown"
 
            if True in matches:
 
                matchedIdxs = [i for (i, b) in enumerate(matches) if b]
                counts = {}
 
 
                for i in matchedIdxs:
                    name = data["names"][i]
                    counts[name] = counts.get(name, 0) + 1
 
                name = max(counts, key=counts.get)
 
            names.append(name)
 
 
        for ((top, right, bottom, left), name) in zip(boxes, names):
 
            cv2.rectangle(frame, (left, top), (right, bottom),
                (0, 255, 0), 2)
            y = top - 15 if top - 15 > 15 else top + 15
            cv2.putText(frame, name, (left, y), cv2.FONT_HERSHEY_SIMPLEX,
                0.75, (0, 255, 0), 2)
 
 
        cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
        img = Image.fromarray(cv2image)
        imgtk = ImageTk.PhotoImage(image=img)
        lmain.configure(image=imgtk)
        lmain.imgtk = imgtk 
 
fenetre=tk.Tk()
style = ttk.Style()
fenetre.title("Aramis")
fenetre.bind("<Escape>", exit)
fenetre.withdraw()
fenetre.update_idletasks()
x = (fenetre.winfo_screenwidth() - fenetre.winfo_reqwidth()) / 2
y = (fenetre.winfo_screenheight() - fenetre.winfo_reqheight()) / 2
fenetre.geometry("+%d+%d" % (x, y))
 
#Graphics window
imageFrame = tk.Frame(fenetre, width=100, height=100)
#imageFrame.grid(row=0, column=0, padx=10, pady=2)
#Capture video frames
lmain = tk.Label(imageFrame)
lmain.grid(row=1, column=0)
sliderFrame = tk.Frame(fenetre, width=600, height=100)
sliderFrame.grid(row = 2, column=0, padx=10, pady=2)
camButton = tk.Button(sliderFrame, text="cam",command=showCam)
camButton.grid(row=0,column=0)
camLab = tk.Label(sliderFrame, text="")
camLab.grid(row=0,column=1)
hideButton= tk.Button(sliderFrame, text="hide",command= hideCam)
 
B=threading.Thread(target=faceReco)
B.setDaemon(True)
B.start()
fenetre.deiconify()
fenetre.mainloop()
Dans les grosses lignes mon script ouvre un fenetre tkinter la fonction face_reco : accede a la camera + detection faciale ensuite la retransmet dans la frame lmain.

J ai appris a creer ma bibliotheque . je souhaiterai ajouter ma fonction face_reco a ma bibliotheque mais je n arrive a importer la video dans lmain?
auriez vous une marche a suivre ou un tutoriel pour m expliquer comment faire svp?
merci d avance