Example to deploy libfacedetection with the OpenCV DNN module and ONNX in both Python and C++.
NOTE: The OpenCV DNN module now supports ONNX models with dynamic input sizes since version 4.5.1. Please install OpenCV >= 4.5.1 to run this example!
Envrionment tested:
- System: Ubuntu 18.04 LTS / 20.04 LTS
- OpenCV >= 4.5.1
- Python >= 3.6
Download the ported onnx
model from https://github.com/ShiqiYu/libfacedetection.train/tree/master/tasks/task1/onnx and place it in this directory.
You can view the network architecture here[netron].
- Install
numpy
andopencv-python
.pip install numpy pip install opencv-python
- Run the detection demo. For more options, run
python python/detect.py --help
.python python/detect.py --image=/path/to/example/image --model=/path/to/onnx/model
- Build the example with
cmake
:cd cpp mkdir build && cd build cmake .. # NOTE: if cmake failed find OpenCV, add the option `-DCMAKE_PREFIX_PATH=/path/to/opencv/install` make
- Run the example:
./detect-image /path/to/image /path/to/YuFaceDetectNet.onnx ./detect-camera 0 /path/to/YuFaceDetectNet.onnx # '0' is your camera index.