mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Migrate Android Face Detection sample to DNN.
This commit is contained in:
@@ -62,7 +62,9 @@ Net readNet(const String& _framework, const std::vector<uchar>& bufferModel,
|
||||
const std::vector<uchar>& bufferConfig)
|
||||
{
|
||||
String framework = toLowerCase(_framework);
|
||||
if (framework == "caffe")
|
||||
if (framework == "onnx")
|
||||
return readNetFromONNX(bufferModel);
|
||||
else if (framework == "caffe")
|
||||
return readNetFromCaffe(bufferConfig, bufferModel);
|
||||
else if (framework == "tensorflow")
|
||||
return readNetFromTensorflow(bufferModel, bufferConfig);
|
||||
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
*/
|
||||
CV_WRAP virtual int detect(InputArray image, OutputArray faces) = 0;
|
||||
|
||||
/** @brief Creates an instance of this class with given parameters
|
||||
/** @brief Creates an instance of face detector class with given parameters
|
||||
*
|
||||
* @param model the path to the requested model
|
||||
* @param config the path to the config file for compability, which is not requested for ONNX models
|
||||
@@ -90,6 +90,29 @@ public:
|
||||
int top_k = 5000,
|
||||
int backend_id = 0,
|
||||
int target_id = 0);
|
||||
|
||||
/** @overload
|
||||
*
|
||||
* @param framework Name of origin framework
|
||||
* @param bufferModel A buffer with a content of binary file with weights
|
||||
* @param bufferConfig A buffer with a content of text file contains network configuration
|
||||
* @param input_size the size of the input image
|
||||
* @param score_threshold the threshold to filter out bounding boxes of score smaller than the given value
|
||||
* @param nms_threshold the threshold to suppress bounding boxes of IoU bigger than the given value
|
||||
* @param top_k keep top K bboxes before NMS
|
||||
* @param backend_id the id of backend
|
||||
* @param target_id the id of target device
|
||||
*/
|
||||
CV_WRAP static Ptr<FaceDetectorYN> create(const String& framework,
|
||||
const std::vector<uchar>& bufferModel,
|
||||
const std::vector<uchar>& bufferConfig,
|
||||
const Size& input_size,
|
||||
float score_threshold = 0.9f,
|
||||
float nms_threshold = 0.3f,
|
||||
int top_k = 5000,
|
||||
int backend_id = 0,
|
||||
int target_id = 0);
|
||||
|
||||
};
|
||||
|
||||
/** @brief DNN-based face recognizer
|
||||
|
||||
@@ -48,6 +48,35 @@ public:
|
||||
topK = top_k;
|
||||
}
|
||||
|
||||
FaceDetectorYNImpl(const String& framework,
|
||||
const std::vector<uchar>& bufferModel,
|
||||
const std::vector<uchar>& bufferConfig,
|
||||
const Size& input_size,
|
||||
float score_threshold,
|
||||
float nms_threshold,
|
||||
int top_k,
|
||||
int backend_id,
|
||||
int target_id)
|
||||
:divisor(32),
|
||||
strides({8, 16, 32})
|
||||
{
|
||||
net = dnn::readNet(framework, bufferModel, bufferConfig);
|
||||
CV_Assert(!net.empty());
|
||||
|
||||
net.setPreferableBackend(backend_id);
|
||||
net.setPreferableTarget(target_id);
|
||||
|
||||
inputW = input_size.width;
|
||||
inputH = input_size.height;
|
||||
|
||||
padW = (int((inputW - 1) / divisor) + 1) * divisor;
|
||||
padH = (int((inputH - 1) / divisor) + 1) * divisor;
|
||||
|
||||
scoreThreshold = score_threshold;
|
||||
nmsThreshold = nms_threshold;
|
||||
topK = top_k;
|
||||
}
|
||||
|
||||
void setInputSize(const Size& input_size) override
|
||||
{
|
||||
inputW = input_size.width;
|
||||
@@ -264,4 +293,22 @@ Ptr<FaceDetectorYN> FaceDetectorYN::create(const String& model,
|
||||
#endif
|
||||
}
|
||||
|
||||
Ptr<FaceDetectorYN> FaceDetectorYN::create(const String& framework,
|
||||
const std::vector<uchar>& bufferModel,
|
||||
const std::vector<uchar>& bufferConfig,
|
||||
const Size& input_size,
|
||||
const float score_threshold,
|
||||
const float nms_threshold,
|
||||
const int top_k,
|
||||
const int backend_id,
|
||||
const int target_id)
|
||||
{
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
return makePtr<FaceDetectorYNImpl>(framework, bufferModel, bufferConfig, input_size, score_threshold, nms_threshold, top_k, backend_id, target_id);
|
||||
#else
|
||||
CV_UNUSED(model); CV_UNUSED(config); CV_UNUSED(input_size); CV_UNUSED(score_threshold); CV_UNUSED(nms_threshold); CV_UNUSED(top_k); CV_UNUSED(backend_id); CV_UNUSED(target_id);
|
||||
CV_Error(cv::Error::StsNotImplemented, "cv::FaceDetectorYN requires enabled 'dnn' module.");
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace cv
|
||||
|
||||
Reference in New Issue
Block a user