def init(self, location, frame): """ Initial tracker """ left, top, width, height = location self._tracker.init(frame, location) label_object(frame, left, top, left + width, top + height, self._name)
def init(self, location, frame): """ Initial tracker """ left, top, width, height = location rect = dlib.rectangle(left, top, left + width, top + height) self._tracker.start_track(frame, rect) label_object(frame, left, top, left + width, top + height, self._name)
def update(self, frame): """ Update tracker """ ret_val, pos = self._tracker.update(frame) if ret_val: left = int(pos[0]) top = int(pos[1]) right = int(pos[0] + pos[2]) bottom = int(pos[1] + pos[3]) label_object(frame, left, top, right, bottom, self._name)
def update(self, frame): """ Update tracker """ confidence = self._tracker.update(frame) pos = self._tracker.get_position() if confidence > self.threshold: left = int(pos.left()) top = int(pos.top()) right = int(pos.right()) bottom = int(pos.bottom()) label_object(frame, left, top, right, bottom, self._name)
def recognize_face(self, frame, tolerance=0.5, shrink=0.25): """ Recognize face """ face_locations, face_encodings = self.detect_face(frame, shrink) for location, face_encoding in zip(face_locations, face_encodings): left, top, right, bottom = [int(i / shrink) for i in location] distances = np.linalg.norm(self.encodings - face_encoding, axis=1) if min(distances) < tolerance: name = self.names[distances.argmin()] else: name = "Unknown" label_object(frame, left, top, right, bottom, name)
def recognize_face(self, frame, tolerance=1, shrink=1): """ Recognize face """ faces = self.detect_face(frame, shrink) for location in faces: left, top, width, height = [int(i / shrink) for i in location] right = left + width bottom = top + height img = cv2.cvtColor(frame[top:bottom, left:right], cv2.COLOR_BGR2GRAY) aligned_face = align_face(img) if aligned_face is not None: img = cv2.resize(aligned_face, (self.image_size, self.image_size)) label, confidence = self.face_recognizer.predict(aligned_face) confidence = confidence / 100 name = self.face_recognizer.getLabelInfo(label) if confidence > tolerance: name = "Unknown" label_object(frame, left, top, right, bottom, name)
def recognize_track_face(frame, tolerance, tracking, shrink=0.25): """ Recognize and track faces """ face_locations, face_encodings = detect_face(frame, shrink) tracks = [] for location, face_encoding in zip(face_locations, face_encodings): top, right, bottom, left = [int(i / shrink) for i in location] distances = face_recognition.face_distance(ENCODINGS, face_encoding) if min(distances) < tolerance: name = NAMES[distances.argmin()] else: name = "Unknown" if not tracking: label_object(frame, left, top, right, bottom, name) return None if tracking == "dlib": track = DlibCorrelationTracker(name, 5) else: track = OpencvTracker(name, tracking) track.init((left, top, right - left, bottom - top), frame) tracks.append(track) return tracks