def _pad_sample(self, image, landmarks): image = pad_image(image, (self.size, self.size))[0] padded_landmarks = [] for l in landmarks: l = pad_image(l, (self.size, self.size))[0] padded_landmarks.append(l) landmarks = np.array(padded_landmarks) return image, landmarks
def __call__(self, sample): """ :param image: numpy image :param annotations: (x1, x2, y1, y2, label) unscaled """ if isinstance(sample, dict): image = sample['image'] image = pad_image(image, (max(image.shape), max(image.shape)))[0] sample['image'] = image else: sample = pad_image(sample, (max(sample.shape), max(sample.shape)))[0] return sample
def pad_heatmaps(heatmaps, size): padded_landmarks = [] for l in heatmaps: l = pad_image(l, size)[0] padded_landmarks.append(l) heatmaps = np.array(padded_landmarks) return heatmaps
def process_image(self, image): image = resize_image_keep_ratio( image, (self.config.image_size, self.config.image_size)) image = pad_image(image, (self.config.image_size, self.config.image_size)) image = image / 255.0 return image
def _pad_sample(self, image, landmarks): image = pad_image(image, (self.size, self.size))[0] heatmaps = pad_heatmaps(landmarks, (self.size, self.size)) return image, heatmaps
def process_image(image, target_size): image = image_processing.resize_image(image, target_size[0]) image = image_processing.pad_image(image, target_size)[0] image = image_processing.normalize_image(image) image = image.transpose([2, 0, 1]) return image
while True: # Grab a single frame of video ret, frame = video_capture.read() # Only process every other frame of video to save time # if process_this_frame: hits = face_identifier.identify(frame) cache = unite_dicts(cache, hits) # Display the results for name, faces in cache.items(): if len(faces) == 5: locs, frames = zip(*faces) frames = np.array([pad_image(resize_image(f, 128), (128, 128))[0] for f in frames], dtype='uint8') result = liveness_detector.predict(frames) color = (0, 255, 0) if result[0] > 0.95 else (0, 0, 255) top, right, bottom, left = locs[-1] # Draw a box around the face cv2.rectangle(frame, (left, top), (right, bottom), color, 2) # Draw a label with a name below the face cv2.rectangle(frame, (left, bottom - 35), (right, bottom), color, cv2.FILLED) font = cv2.FONT_HERSHEY_DUPLEX cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1) cache[name].pop(0) # Display the resulting image cv2.imshow('Video', frame)