face.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #ifndef OPENCV_OBJDETECT_FACE_HPP
  5. #define OPENCV_OBJDETECT_FACE_HPP
  6. #include <opencv2/core.hpp>
  7. namespace cv
  8. {
  9. //! @addtogroup objdetect_dnn_face
  10. //! @{
  11. /** @brief DNN-based face detector
  12. model download link: https://github.com/opencv/opencv_zoo/tree/master/models/face_detection_yunet
  13. */
  14. class CV_EXPORTS_W FaceDetectorYN
  15. {
  16. public:
  17. virtual ~FaceDetectorYN() {};
  18. /** @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
  19. *
  20. * @param input_size the size of the input image
  21. */
  22. CV_WRAP virtual void setInputSize(const Size& input_size) = 0;
  23. CV_WRAP virtual Size getInputSize() = 0;
  24. /** @brief Set the score threshold to filter out bounding boxes of score less than the given value
  25. *
  26. * @param score_threshold threshold for filtering out bounding boxes
  27. */
  28. CV_WRAP virtual void setScoreThreshold(float score_threshold) = 0;
  29. CV_WRAP virtual float getScoreThreshold() = 0;
  30. /** @brief Set the Non-maximum-suppression threshold to suppress bounding boxes that have IoU greater than the given value
  31. *
  32. * @param nms_threshold threshold for NMS operation
  33. */
  34. CV_WRAP virtual void setNMSThreshold(float nms_threshold) = 0;
  35. CV_WRAP virtual float getNMSThreshold() = 0;
  36. /** @brief Set the number of bounding boxes preserved before NMS
  37. *
  38. * @param top_k the number of bounding boxes to preserve from top rank based on score
  39. */
  40. CV_WRAP virtual void setTopK(int top_k) = 0;
  41. CV_WRAP virtual int getTopK() = 0;
  42. /** @brief A simple interface to detect face from given image
  43. *
  44. * @param image an image to detect
  45. * @param faces detection results stored in a cv::Mat
  46. */
  47. CV_WRAP virtual int detect(InputArray image, OutputArray faces) = 0;
  48. /** @brief Creates an instance of this class with given parameters
  49. *
  50. * @param model the path to the requested model
  51. * @param config the path to the config file for compability, which is not requested for ONNX models
  52. * @param input_size the size of the input image
  53. * @param score_threshold the threshold to filter out bounding boxes of score smaller than the given value
  54. * @param nms_threshold the threshold to suppress bounding boxes of IoU bigger than the given value
  55. * @param top_k keep top K bboxes before NMS
  56. * @param backend_id the id of backend
  57. * @param target_id the id of target device
  58. */
  59. CV_WRAP static Ptr<FaceDetectorYN> create(const String& model,
  60. const String& config,
  61. const Size& input_size,
  62. float score_threshold = 0.9f,
  63. float nms_threshold = 0.3f,
  64. int top_k = 5000,
  65. int backend_id = 0,
  66. int target_id = 0);
  67. };
  68. /** @brief DNN-based face recognizer
  69. model download link: https://github.com/opencv/opencv_zoo/tree/master/models/face_recognition_sface
  70. */
  71. class CV_EXPORTS_W FaceRecognizerSF
  72. {
  73. public:
  74. virtual ~FaceRecognizerSF() {};
  75. /** @brief Definition of distance used for calculating the distance between two face features
  76. */
  77. enum DisType { FR_COSINE=0, FR_NORM_L2=1 };
  78. /** @brief Aligning image to put face on the standard position
  79. * @param src_img input image
  80. * @param face_box the detection result used for indicate face in input image
  81. * @param aligned_img output aligned image
  82. */
  83. CV_WRAP virtual void alignCrop(InputArray src_img, InputArray face_box, OutputArray aligned_img) const = 0;
  84. /** @brief Extracting face feature from aligned image
  85. * @param aligned_img input aligned image
  86. * @param face_feature output face feature
  87. */
  88. CV_WRAP virtual void feature(InputArray aligned_img, OutputArray face_feature) = 0;
  89. /** @brief Calculating the distance between two face features
  90. * @param face_feature1 the first input feature
  91. * @param face_feature2 the second input feature of the same size and the same type as face_feature1
  92. * @param dis_type defining the similarity with optional values "FR_OSINE" or "FR_NORM_L2"
  93. */
  94. CV_WRAP virtual double match(InputArray face_feature1, InputArray face_feature2, int dis_type = FaceRecognizerSF::FR_COSINE) const = 0;
  95. /** @brief Creates an instance of this class with given parameters
  96. * @param model the path of the onnx model used for face recognition
  97. * @param config the path to the config file for compability, which is not requested for ONNX models
  98. * @param backend_id the id of backend
  99. * @param target_id the id of target device
  100. */
  101. CV_WRAP static Ptr<FaceRecognizerSF> create(const String& model, const String& config, int backend_id = 0, int target_id = 0);
  102. };
  103. //! @}
  104. } // namespace cv
  105. #endif