DNN Model Documentation
Documentation for the Deep Neural Network (DNN) models.
For more information on the DNN module in OpenCV, visit OpenCV DNN documentation.
See also the following pages for more information about the models
- Caffe Models
- TensorFlow Models
detect_face_dnn(img, net, framework='caffe', conf_threshold=0.7, detect_multiple_faces=False)
Function that detects faces in an image using a Deep Neural Network (DNN) model. The function supports models trained with either the Caffe or TensorFlow framework.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img |
ndarray
|
The input image in which faces are to be detected. The image should be in a format
acceptable by OpenCV, typically a numpy ndarray obtained from |
required |
net |
dnn_Net
|
The pre-trained DNN model loaded using |
required |
framework |
str
|
Specifies the framework of the pre-trained model. Can be 'caffe' or 'tensorflow'. Defaults to 'caffe'. |
'caffe'
|
conf_threshold |
float
|
The minimum confidence threshold for a detection to be considered valid. Ranges between 0 and 1, with a higher threshold reducing false positives. Defaults to 0.7. |
0.7
|
detect_multiple_faces |
bool
|
If True, detects and returns bounding boxes for all detected faces. If False, returns a bounding box for the most prominent face or None if no faces are detected. |
False
|
Returns:
Type | Description |
---|---|
list | tuple | None
|
If True, returns a list of tuples (x, y, width, height) for each detected face. If False, returns a single tuple (x, y, width, height) for the most prominent face, or None if no faces are detected. Each tuple contains the coordinates of the top-left corner and the dimensions of the bounding box. |
Note
This function requires that the appropriate DNN model files are accessible and properly configured before use. The OpenCV Server code has this setup by default.
Source code in src/models/code/dnn.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|