def pad(self, video, length): pad_length = max(length - video.length, 0) video_length = min(length, video.length) mouth_padding = np.zeros((pad_length, video.mouth.shape[1], video.mouth.shape[2], video.mouth.shape[3]), dtype=np.uint8) new_video = Video(video.face_predictor_path) new_video.mouth = np.concatenate( (video.mouth[0:video_length], mouth_padding), 0) new_video.set_data(new_video.mouth) return new_video
def retain_keyframes(self, video): first = video.mouth[0] threshold = 300 res = None org_index = 0 new_mouth = [] new_mouth.append(first) for index in range(len(video.mouth) - 1): second = video.mouth[index + 1] filename = index + 1 res = self.find_diff(first, second) diff = np.count_nonzero(res) if diff > threshold: new_mouth.append(second) org_index += 1 first = second new_mouth = np.array(new_mouth) new_video = Video(video.face_predictor_path) new_video.mouth = new_mouth new_video.set_data(new_video.mouth) return new_video