def augmentation_pair(params): """ Augmenting pair of images """ source_image_path, target_image_path, size, source_out_path, target_out_path, augment, verbose = params source_image = extract_image(source_image_path) target_image = extract_image(target_image_path) filename = os.path.basename(os.path.normpath(source_image_path)) if verbose: print("Augmenting image %r ..." % filename) augmentImagePairPhantom(source_image, target_image, size, source_out_path, target_out_path, augment) if verbose: print("Augmented image %r ..." % filename)
def image_teach(): image = utils.extract_image(request) name, id = utils.extract_name_or_id(request) face = dlib_api.teach_person(np.array(image), name=name, id=id, weight=request.json.get('weight', 1.0)) return jsonify(utils.face_to_dict(face))
def main(data_dir): """ Extracts faces from FaceForensics++ dataset. Args: data_dir: Base directory of the FaceForensics++ dataset. """ extract_count = 0 try: # Validate argument. Exit if invalid. if not os.path.isdir(data_dir): print('"{}" is not a directory'.format(data_dir), file=stderr) exit(1) # Create directory for output images, if it does not already exist. output_dir = '{}/original_sequences_images/{}/images'.format( data_dir, COMPRESSION_LEVEL) if not os.path.exists(output_dir): os.makedirs(output_dir) print("Extracting images...") seqs = get_orig_sequences(data_dir, COMPRESSION_LEVEL) for s in seqs: output_fn = '{}/{}.png'.format(output_dir, s.seq_id) if os.path.exists(output_fn): # Do not recreate an image if it already exists. # If the user wants to recreated an image, # the old image must be deleted first. continue print('Extracting image for sequence {}...'.format(s.seq_id)) img, _ = extract_image(s) if img is None: print(" No frame with a face found") else: # Write image to disk. try: cv2.imwrite(output_fn, img) extract_count += 1 except KeyboardInterrupt as e: # Safely handle premature termination. # Remove unfinished file. if os.exists(output_fn): os.remove(output_fn) raise e except KeyboardInterrupt: print('Program terminated prematurely') finally: if extract_count == 0: print('No images extracted') else: print('{} images extracted'.format(extract_count))
def hack(img_name): """ HACK Recognize a CAPTCHA image :param img_name: filename of image :return: digits: 1x5 matrix, 5 digits in the input CAPTCHA image. """ data = sio.loadmat('hack_data.mat') X = data['X'] y = data['y'] digits = extract_image(img_name) show_image(digits) digits = knn(digits, X, y, 20).reshape(-1) print('The digits in this CAPTCHA is %d %d %d %d %d' % (digits[0], digits[1], digits[2], digits[3], digits[4]))
def extract_face(seq): """ Extracts a single face image from a video sequence. Args: seq: FFVideoSeq representing video sequence. Returns: An image of a face on success. None on failure. """ img, locations = extract_image(seq) if img is None: # No frame with a face was found. return None else: # We found a frame with a face. # If there are multiple faces, choose the largest. loc = get_largest_face(locations) cropped = crop_face(img, loc, ZOOMOUT_FACTOR) return cropped
def image_identify(): image = utils.extract_image(request) faces = dlib_api.detect_and_identify_faces(np.array(image)) return jsonify(utils.faces_to_list(faces))