mirror of
https://github.com/opencv/opencv.git
synced 2024-11-27 12:40:05 +08:00
Added buffer-based model loading to FaceRecognizerSF
- Implemented a new `create` method in `FaceRecognizerSF` to allow model and configuration loading from memory buffers (std::vector<uchar>), similar to the existing functionality in `FaceDetectorYN`. - Updated `face_recognize.cpp` with a new constructor in `FaceRecognizerSFImpl` that supports buffer-based loading for both model weights and network configuration. - Ensured compatibility with both file-based and buffer-based model loading by maintaining consistent backend and target settings across both constructors. - This change improves flexibility, allowing FaceRecognizerSF to be instantiated from memory buffers, which is useful for dynamic model loading scenarios such as embedded systems or applications where models are loaded in-memory.
This commit is contained in:
parent
450e741f8d
commit
e1b06371ad
@ -155,6 +155,22 @@ public:
|
||||
* @param target_id the id of target device
|
||||
*/
|
||||
CV_WRAP static Ptr<FaceRecognizerSF> create(CV_WRAP_FILE_PATH const String& model, CV_WRAP_FILE_PATH const String& config, int backend_id = 0, int target_id = 0);
|
||||
|
||||
/**
|
||||
* @brief Creates an instance of this class from a buffer containing the model weights and configuration.
|
||||
* @param framework Name of the framework (ONNX, etc.)
|
||||
* @param bufferModel A buffer containing the binary model weights.
|
||||
* @param bufferConfig A buffer containing the network configuration.
|
||||
* @param backend_id The id of the backend.
|
||||
* @param target_id The id of the target device.
|
||||
*
|
||||
* @return A pointer to the created instance of FaceRecognizerSF.
|
||||
*/
|
||||
CV_WRAP static Ptr<FaceRecognizerSF> create(const String& framework,
|
||||
const std::vector<uchar>& bufferModel,
|
||||
const std::vector<uchar>& bufferConfig,
|
||||
int backend_id = 0,
|
||||
int target_id = 0);
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
@ -26,6 +26,19 @@ public:
|
||||
net.setPreferableBackend(backend_id);
|
||||
net.setPreferableTarget(target_id);
|
||||
}
|
||||
|
||||
FaceRecognizerSFImpl(const String& framework,
|
||||
const std::vector<uchar>& bufferModel,
|
||||
const std::vector<uchar>& bufferConfig,
|
||||
int backend_id, int target_id)
|
||||
{
|
||||
net = dnn::readNet(framework, bufferModel, bufferConfig);
|
||||
CV_Assert(!net.empty());
|
||||
|
||||
net.setPreferableBackend(backend_id);
|
||||
net.setPreferableTarget(target_id);
|
||||
}
|
||||
|
||||
void alignCrop(InputArray _src_img, InputArray _face_mat, OutputArray _aligned_img) const override
|
||||
{
|
||||
Mat face_mat = _face_mat.getMat();
|
||||
@ -189,4 +202,17 @@ Ptr<FaceRecognizerSF> FaceRecognizerSF::create(const String& model, const String
|
||||
#endif
|
||||
}
|
||||
|
||||
Ptr<FaceRecognizerSF> FaceRecognizerSF::create(const String& framework,
|
||||
const std::vector<uchar>& bufferModel,
|
||||
const std::vector<uchar>& bufferConfig,
|
||||
int backend_id, int target_id)
|
||||
{
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
return makePtr<FaceRecognizerSFImpl>(framework, bufferModel, bufferConfig, backend_id, target_id);
|
||||
#else
|
||||
CV_UNUSED(bufferModel); CV_UNUSED(bufferConfig); CV_UNUSED(backend_id); CV_UNUSED(target_id);
|
||||
CV_Error(cv::Error::StsNotImplemented, "cv::FaceRecognizerSF requires enabled 'dnn' module");
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace cv
|
||||
|
Loading…
Reference in New Issue
Block a user