def main( input_path, image_output_path, weights_path, image_extensions, face_threshold, plate_threshold, write_json, keep_exif, obfuscation_parameters ): download_weights(download_directory=weights_path) kernel_size, sigma, box_kernel_size = obfuscation_parameters.split(',') obfuscator = Obfuscator(kernel_size=int(kernel_size), sigma=float(sigma), box_kernel_size=int(box_kernel_size)) detectors = { 'face': Detector(kind='face', weights_path=get_weights_path(weights_path, kind='face')), 'plate': Detector(kind='plate', weights_path=get_weights_path(weights_path, kind='plate')) } detection_thresholds = { 'face': face_threshold, 'plate': plate_threshold } anonymizer = Anonymizer(obfuscator=obfuscator, detectors=detectors) anonymizer.anonymize_images( input_path=input_path, output_path=image_output_path, detection_thresholds=detection_thresholds, file_types=image_extensions.split(','), write_json=write_json, keep_exif=keep_exif )
def test_it_downloads_weights(tmp_path): weights_directory = tmp_path / 'weights' assert len(list(weights_directory.glob('**/*.pb'))) == 0 download_weights(download_directory=weights_directory, version='1.0.0') assert len(list(weights_directory.glob('**/*.pb'))) == 2 assert (weights_directory / 'weights_face_v1.0.0.pb').is_file() assert (weights_directory / 'weights_plate_v1.0.0.pb').is_file() assert not (weights_directory / 'nonexistent_path.pb').is_file()
def test_it_detects_obvious_faces(tmp_path): weights_directory = tmp_path / 'weights' face_weights_path = get_weights_path(weights_directory, kind='face') download_weights(weights_directory) detector = Detector(kind='face', weights_path=face_weights_path) np_image = load_np_image('./test/detection/face_test_image.jpg') left_face = Box(x_min=267, y_min=64, x_max=311, y_max=184, score=0.0, kind='face') right_face = Box(x_min=369, y_min=68, x_max=420, y_max=152, score=0.0, kind='face') boxes = detector.detect(np_image, detection_threshold=0.2) assert len(boxes) >= 2 for box in boxes: assert box.score >= 0.2 assert boxes[0].score >= 0.5 and boxes[1].score >= 0.5 assert ((box_covers_box(boxes[0], left_face) and box_covers_box(boxes[1], right_face)) or (box_covers_box(boxes[1], left_face) and box_covers_box(boxes[0], right_face)))