The `mtcnn` library provides a Python implementation of the Multi-task Cascaded Convolutional Networks (MTCNN) for robust face detection and alignment. It is currently at version 1.0.0, supporting Python >= 3.10 and TensorFlow >= 2.12. Releases are infrequent, indicating a mature and stable codebase.
pip install mtcnnVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load an image (using OpenCV, converting to RGB), initialize the MTCNN detector, and use `detect_faces` to find faces and their keypoints. The output `faces` is a list of dictionaries, where each dictionary contains the bounding box, confidence score, and facial keypoints.
Ensure your Python environment is version 3.10 or later. Consider using `pyenv` or `conda` to manage Python versions.
Upgrade `mtcnn` to version 1.0.0 or later to ensure compatibility with TensorFlow 2.x (specifically >=2.12 as per PyPI).
After loading with OpenCV, convert the image using `img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)`.
Ensure internet connectivity during the first initialization. Subsequent runs will use the cached models.
Install TensorFlow with GPU support if your hardware allows. Otherwise, be aware that CPU-only inference will be considerably slower.