def test__given_img__when_read__then_returns_correct_numpy_array( extension, expected_array): img_path = IMG_DIR / f'einstein.{extension}' actual_array = read_img(img_path) assert actual_array.shape == expected_array.shape assert numpy.allclose(actual_array, expected_array, atol=20, rtol=20)
def test__given_rgba_img__when_read__then_returns_rgb_img(mocker): array = np.ones(shape=(10, 10, 4)) imageio = mocker.patch(IMAGEIO) imageio.imread.return_value = array actual_img = read_img(MOCK) expected_img = np.ones(shape=(10, 10, 3)) assert (actual_img == expected_img).all()
def find_faces_post(): detector = managers.plugin_manager.detector face_plugins = managers.plugin_manager.filter_face_plugins( _get_face_plugin_names()) faces = detector(img=read_img(request.files['file']), det_prob_threshold=_get_det_prob_threshold(), face_plugins=face_plugins) plugins_versions = {p.slug: str(p) for p in [detector] + face_plugins} faces = _limit(faces, request.values.get(ARG.LIMIT)) return jsonify(plugins_versions=plugins_versions, result=faces)
def scan_faces_post(): from flask import request img = read_img(request.files['file']) limit_faces = _get_limit_faces_fun(request.values.get(ARG.LIMIT)) scanner: FaceScanner = get_scanner() det_prob_threshold = _get_det_prob_threshold(request) scanned_faces = scanner.scan(img, det_prob_threshold) return jsonify(calculator_version=get_scanner().ID, result=limit_faces(_at_least_one_face(scanned_faces)))
def test__given_truncated_img__when_read__then_does_not_crash(): img_path = IMG_DIR / 'truncated.jpg' actual_array = read_img(img_path) assert actual_array.shape == (225, 225, 3)
def act(): read_img(IMG_DIR / file)
def act(): read_img(MOCK)
def _scan_faces_local(img_name): img = read_img(IMG_DIR / img_name) return scanner.scan(img)
else: logger.info( f"Found all {len(noses)} face{s(len(noses))} in correct places for '{img_name}'" ) else: logging.warning(f"Image '{img_name}' is not annotated, skipping") return error_count if __name__ == '__main__': init_runtime(logging_level=LOGGING_LEVEL) logger.info(ENV.to_json() if ENV_MAIN.IS_DEV_ENV else ENV.to_str()) total_error_count = 0 for img_name in ENV.IMG_NAMES: boxes = [face.box for face in _scan_faces(img_name)] noses = name_2_annotation.get(img_name) error_count = _calculate_errors(boxes, noses, img_name) total_error_count += error_count if SAVE_IMG or SAVE_IMG_ON_ERROR and error_count: img = read_img(IMG_DIR / img_name) save_img(img, boxes, noses, img_name) if total_error_count: logger.error( f"Found a total of {total_error_count} error{s(total_error_count)}" ) exit(1)
def _scan_faces_local(scanner_id, img_name): img = read_img(IMG_DIR / img_name) scanner: FaceScanner = id_2_face_scanner_cls[scanner_id]() return scanner.scan(img)
def _get_image(img_name): image_path = TMP_DIR / 'originalPics' / Path(f'{img_name}.jpg') return read_img(image_path) if not ENV.DRY_RUN else np.zeros((1, 1, 3))
def scan_faces_post(): faces = scanner.scan(img=read_img(request.files['file']), det_prob_threshold=_get_det_prob_threshold()) faces = _limit(faces, request.values.get(ARG.LIMIT)) return jsonify(calculator_version=scanner.ID, result=faces)
def scan(img_path, *args, **kwargs): img = read_img(img_path) return scanner.scan_(img, *args, **kwargs)