Coverage Report

Created: 2023-06-07 08:11

/work/install-coverage/include/opencv4/opencv2/objdetect/face.hpp
Line
Count
Source (jump to first uncovered line)
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
4
5
#ifndef OPENCV_OBJDETECT_FACE_HPP
6
#define OPENCV_OBJDETECT_FACE_HPP
7
8
#include <opencv2/core.hpp>
9
10
namespace cv
11
{
12
13
//! @addtogroup objdetect_dnn_face
14
//! @{
15
16
/** @brief DNN-based face detector
17
18
model download link: https://github.com/opencv/opencv_zoo/tree/master/models/face_detection_yunet
19
 */
20
class CV_EXPORTS_W FaceDetectorYN
21
{
22
public:
23
0
    virtual ~FaceDetectorYN() {};
24
25
    /** @brief Set the size for the network input, which overwrites the input size of creating model. Call this method when the size of input image does not match the input size when creating model
26
     *
27
     * @param input_size the size of the input image
28
     */
29
    CV_WRAP virtual void setInputSize(const Size& input_size) = 0;
30
31
    CV_WRAP virtual Size getInputSize() = 0;
32
33
    /** @brief Set the score threshold to filter out bounding boxes of score less than the given value
34
     *
35
     * @param score_threshold threshold for filtering out bounding boxes
36
     */
37
    CV_WRAP virtual void setScoreThreshold(float score_threshold) = 0;
38
39
    CV_WRAP virtual float getScoreThreshold() = 0;
40
41
    /** @brief Set the Non-maximum-suppression threshold to suppress bounding boxes that have IoU greater than the given value
42
     *
43
     * @param nms_threshold threshold for NMS operation
44
     */
45
    CV_WRAP virtual void setNMSThreshold(float nms_threshold) = 0;
46
47
    CV_WRAP virtual float getNMSThreshold() = 0;
48
49
    /** @brief Set the number of bounding boxes preserved before NMS
50
     *
51
     * @param top_k the number of bounding boxes to preserve from top rank based on score
52
     */
53
    CV_WRAP virtual void setTopK(int top_k) = 0;
54
55
    CV_WRAP virtual int getTopK() = 0;
56
57
    /** @brief Detects faces in the input image. Following is an example output.
58
59
     * ![image](pics/lena-face-detection.jpg)
60
61
     *  @param image an image to detect
62
     *  @param faces detection results stored in a 2D cv::Mat of shape [num_faces, 15]
63
     *  - 0-1: x, y of bbox top left corner
64
     *  - 2-3: width, height of bbox
65
     *  - 4-5: x, y of right eye (blue point in the example image)
66
     *  - 6-7: x, y of left eye (red point in the example image)
67
     *  - 8-9: x, y of nose tip (green point in the example image)
68
     *  - 10-11: x, y of right corner of mouth (pink point in the example image)
69
     *  - 12-13: x, y of left corner of mouth (yellow point in the example image)
70
     *  - 14: face score
71
     */
72
    CV_WRAP virtual int detect(InputArray image, OutputArray faces) = 0;
73
74
    /** @brief Creates an instance of this class with given parameters
75
     *
76
     *  @param model the path to the requested model
77
     *  @param config the path to the config file for compability, which is not requested for ONNX models
78
     *  @param input_size the size of the input image
79
     *  @param score_threshold the threshold to filter out bounding boxes of score smaller than the given value
80
     *  @param nms_threshold the threshold to suppress bounding boxes of IoU bigger than the given value
81
     *  @param top_k keep top K bboxes before NMS
82
     *  @param backend_id the id of backend
83
     *  @param target_id the id of target device
84
     */
85
    CV_WRAP static Ptr<FaceDetectorYN> create(const String& model,
86
                                              const String& config,
87
                                              const Size& input_size,
88
                                              float score_threshold = 0.9f,
89
                                              float nms_threshold = 0.3f,
90
                                              int top_k = 5000,
91
                                              int backend_id = 0,
92
                                              int target_id = 0);
93
};
94
95
/** @brief DNN-based face recognizer
96
97
model download link: https://github.com/opencv/opencv_zoo/tree/master/models/face_recognition_sface
98
 */
99
class CV_EXPORTS_W FaceRecognizerSF
100
{
101
public:
102
0
    virtual ~FaceRecognizerSF() {};
103
104
    /** @brief Definition of distance used for calculating the distance between two face features
105
     */
106
    enum DisType { FR_COSINE=0, FR_NORM_L2=1 };
107
108
    /** @brief Aligning image to put face on the standard position
109
     *  @param src_img input image
110
     *  @param face_box the detection result used for indicate face in input image
111
     *  @param aligned_img output aligned image
112
     */
113
    CV_WRAP virtual void alignCrop(InputArray src_img, InputArray face_box, OutputArray aligned_img) const = 0;
114
115
    /** @brief Extracting face feature from aligned image
116
     *  @param aligned_img input aligned image
117
     *  @param face_feature output face feature
118
     */
119
    CV_WRAP virtual void feature(InputArray aligned_img, OutputArray face_feature) = 0;
120
121
    /** @brief Calculating the distance between two face features
122
     *  @param face_feature1 the first input feature
123
     *  @param face_feature2 the second input feature of the same size and the same type as face_feature1
124
     *  @param dis_type defining the similarity with optional values "FR_OSINE" or "FR_NORM_L2"
125
     */
126
    CV_WRAP virtual double match(InputArray face_feature1, InputArray face_feature2, int dis_type = FaceRecognizerSF::FR_COSINE) const = 0;
127
128
    /** @brief Creates an instance of this class with given parameters
129
     *  @param model the path of the onnx model used for face recognition
130
     *  @param config the path to the config file for compability, which is not requested for ONNX models
131
     *  @param backend_id the id of backend
132
     *  @param target_id the id of target device
133
     */
134
    CV_WRAP static Ptr<FaceRecognizerSF> create(const String& model, const String& config, int backend_id = 0, int target_id = 0);
135
};
136
137
//! @}
138
} // namespace cv
139
140
#endif