提交 3337c1e0 编写于 作者: O osthafen 提交者: Adam Geitgey

Make --upsample a parameter for command line face_recognition

Otherwise smaller faces can't be located via command line
上级 d34c622b
......@@ -14,9 +14,9 @@ def print_result(filename, location):
print("{},{},{},{},{}".format(filename, top, right, bottom, left))
def test_image(image_to_check, model):
def test_image(image_to_check, model, upsample):
unknown_image = face_recognition.load_image_file(image_to_check)
face_locations = face_recognition.face_locations(unknown_image, number_of_times_to_upsample=0, model=model)
face_locations = face_recognition.face_locations(unknown_image, number_of_times_to_upsample=upsample, model=model)
for face_location in face_locations:
print_result(image_to_check, face_location)
......@@ -26,7 +26,7 @@ def image_files_in_folder(folder):
return [os.path.join(folder, f) for f in os.listdir(folder) if re.match(r'.*\.(jpg|jpeg|png)', f, flags=re.I)]
def process_images_in_process_pool(images_to_check, number_of_cpus, model):
def process_images_in_process_pool(images_to_check, number_of_cpus, model, upsample):
if number_of_cpus == -1:
processes = None
else:
......@@ -42,6 +42,7 @@ def process_images_in_process_pool(images_to_check, number_of_cpus, model):
function_parameters = zip(
images_to_check,
itertools.repeat(model),
itertools.repeat(upsample),
)
pool.starmap(test_image, function_parameters)
......@@ -51,7 +52,8 @@ def process_images_in_process_pool(images_to_check, number_of_cpus, model):
@click.argument('image_to_check')
@click.option('--cpus', default=1, help='number of CPU cores to use in parallel. -1 means "use all in system"')
@click.option('--model', default="hog", help='Which face detection model to use. Options are "hog" or "cnn".')
def main(image_to_check, cpus, model):
@click.option('--upsample', default=0, help='How many times to upsample the image looking for faces. Higher numbers find smaller faces.')
def main(image_to_check, cpus, model, upsample):
# Multi-core processing only supported on Python 3.4 or greater
if (sys.version_info < (3, 4)) and cpus != 1:
click.echo("WARNING: Multi-processing support requires Python 3.4 or greater. Falling back to single-threaded processing!")
......@@ -59,11 +61,11 @@ def main(image_to_check, cpus, model):
if os.path.isdir(image_to_check):
if cpus == 1:
[test_image(image_file, model) for image_file in image_files_in_folder(image_to_check)]
[test_image(image_file, model, upsample) for image_file in image_files_in_folder(image_to_check)]
else:
process_images_in_process_pool(image_files_in_folder(image_to_check), cpus, model)
process_images_in_process_pool(image_files_in_folder(image_to_check), cpus, model, upsample)
else:
test_image(image_to_check, model)
test_image(image_to_check, model, upsample)
if __name__ == "__main__":
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册