예제 #1
0
 def recognize(self):
     classifier = HaarcascadeDetective().get_face_classifier()
     while self.playing:
         try:
             if len(self.frames) == 0:
                 time.sleep(0.05)
                 continue
             if self.flag_recognize:
                 frame = self.frames.pop()
                 faces = classifier.get_faces_position(frame)
                 self.recognized_faces.clear()
                 for (x, y, w, h) in faces:
                     face = frame[y:y + h, x:x + w]
                     if self.model is not None:
                         gray = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
                         params = self.model.predict(gray)
                         user = self.find_user_by_id(params[0])
                         if user is not None:
                             self.recognized_faces[user[1]] = ((x, y, w, h), user[2], user[3], int(params[1]))
                         else:
                             self.recognized_faces['-1'] = ((x, y, w, h), 'No this user', '255,0,0', 0)
                     else:
                         self.recognized_faces['-2'] = ((x, y, w, h), 'No model', '255,0,0', 0)
         except Exception as e:
             print(e)
예제 #2
0
 def recognize(self):
     while self.flag_recognize:
         try:
             if self.recognizing_frame is None:
                 time.sleep(0.05)
                 continue
             self.recognized_faces.clear()
             faces = HaarcascadeDetective.get_faces_position(
                 self.recognizing_frame)
             for (x, y, w, h) in faces:
                 recognized_face = {'position': (x, y, w, h)}
                 face = self.recognizing_frame[y:y + h, x:x + w]
                 if self.model is not None:
                     gray = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
                     params = self.model.predict(gray)
                     if params[1] <= Config.threshold:
                         recognized_face['name'] = self.users[params[0]]
                         recognized_face['degree'] = int(params[1])
                 self.recognized_faces.append(recognized_face)
             self.recognizing_frame = None
         except Exception as e:
             print(e)
예제 #3
0
 def recognize(self):
     classifier = HaarcascadeDetective().get_face_classifier()
     while self.playing:
         if len(self.frames) == 0:
             continue
         frame = self.frames.pop()
         if self.flag_recognize:
             faces = classifier.get_faces_position(frame)
             self.recognized_faces.clear()
             for (x, y, w, h) in faces:
                 face = frame[y:y + h, x:x + w]
                 if self.model is not None:
                     gray = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
                     params = self.model.predict(gray)
                     if params[1] <= Tool.config.getint(
                             'recognize', 'threshold', fallback=50):
                         self.recognized_faces[self.face_names[
                             params[0]]] = (x, y, w, h)
                     else:
                         self.recognized_faces['Unknown'] = (x, y, w, h)
                 else:
                     self.recognized_faces['Unknown'] = (x, y, w, h)