diff --git a/bob/pad/face/preprocessor/VideoFaceCrop.py b/bob/pad/face/preprocessor/VideoFaceCrop.py index 7689fed94073c15cece1e6c8f7614c12ba86117f..a335fc1cbff908a815dd311f95f557a2655ed7a9 100644 --- a/bob/pad/face/preprocessor/VideoFaceCrop.py +++ b/bob/pad/face/preprocessor/VideoFaceCrop.py @@ -85,8 +85,10 @@ class VideoFaceCrop(Preprocessor, object): Default: ``False``. ``face_detection_method`` : :py:class:`str` - A package to be used for face detection. Available options: "dlib" and - "mtcnn". + A package to be used for face detection. Options supported by this + package: "dlib" (dlib is a dependency of this package). If bob.ip.mtcnn + is installed in your system you can use it as-well (bob.ip.mtcnn is NOT + a dependency of this package). ``kwargs`` Remaining keyword parameters passed to the Base constructor, such as ``color_channel`` or ``dtype``. diff --git a/bob/pad/face/utils/face_detection_utils.py b/bob/pad/face/utils/face_detection_utils.py index 4ce2f22c1ca1e7dff88a3b1e2a980560d3376dce..66b16de7dbdf996f5b26a6addb3da08667894f44 100644 --- a/bob/pad/face/utils/face_detection_utils.py +++ b/bob/pad/face/utils/face_detection_utils.py @@ -7,9 +7,8 @@ This file contains face detection utils. #============================================================================== # Import here: -import bob.ip.dlib # for face detection functionality +import importlib -import bob.ip.mtcnn #============================================================================== def detect_face_in_image(image, method = "dlib"): @@ -22,8 +21,10 @@ def detect_face_in_image(image, method = "dlib"): A color image to detect the face in. ``method`` : :py:class:`str` - A package to be used for face detection. Available options: "dlib" and - "mtcnn". + A package to be used for face detection. Options supported by this + package: "dlib" (dlib is a dependency of this package). If bob.ip.mtcnn + is installed in your system you can use it as-well (bob.ip.mtcnn is NOT + a dependency of this package). **Returns:** @@ -33,13 +34,15 @@ def detect_face_in_image(image, method = "dlib"): If no annotations found an empty dictionary is returned. """ - if method == "dlib": + try: + face_detection_module = importlib.import_module("bob.ip." + method) + except ImportError: + raise ImportError("No module named bob.ip." + method) - data = bob.ip.dlib.FaceDetector().detect_single_face(image) + if not hasattr(face_detection_module, 'FaceDetector'): + raise AttributeError("bob.ip." + method + " module has no attribute FaceDetector") - if method == "mtcnn": - - data = bob.ip.mtcnn.FaceDetector().detect_single_face(image) + data = face_detection_module.FaceDetector().detect_single_face(image) annotations = {} @@ -65,8 +68,10 @@ def detect_faces_in_video(frame_container, method = "dlib"): FrameContainer containing the frames data. ``method`` : :py:class:`str` - A package to be used for face detection. Available options: "dlib" and - "mtcnn". + A package to be used for face detection. Options supported by this + package: "dlib" (dlib is a dependency of this package). If bob.ip.mtcnn + is installed in your system you can use it as-well (bob.ip.mtcnn is NOT + a dependency of this package). **Returns:**