FaceRecog/include/face_sdk.h

68 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <vector>
#include <string>
// 避免在头文件中暴露完整的 OpenCV 头,使用前向声明
namespace cv {
class Mat;
}
// SDK 状态码
enum class SDKStatus {
SUCCESS = 0,
MODEL_LOAD_ERROR = -1,
EXTRACTION_ERROR = -2,
NO_FACE_DETECTED = -3,
POOR_QUALITY = -4,
INVALID_INPUT = -5
};
// 特征提取结果
struct FeatureResult {
SDKStatus status;
std::vector<float> feature; // 512维特征
std::string error_message;
};
// 【宏观架构核心】
// FaceSDK 类,提供给 C++ 调用
class FaceSDK {
public:
/**
* @brief 构造函数初始化SDK加载模型
* @param model_dir 存放7个onnx文件的目录路径
*/
FaceSDK(const std::string& model_dir);
/**
* @brief 析构函数:释放资源
*/
~FaceSDK();
/**
* @brief 接口1提取图片特征值
* @param image 输入图像 (OpenCV Mat, BGR 格式)
* @return FeatureResult 结构体,包含状态和特征向量
*/
FeatureResult extractFeature(const cv::Mat& image);
/**
* @brief 接口2比较两个特征值 (静态函数)
* @param feature1 特征向量1
* @param feature2 特征向量2
* @return 相似度 (0.0 ~ 1.0),余弦相似度
*/
static float compareFeatures(const std::vector<float>& feature1,
const std::vector<float>& feature2);
private:
// PImpl 模式 (Pointer to Implementation)
// 这是一个高级 C++ 技巧,用于隐藏所有内部实现细节
// (如 FacePipeline, ONNX Runtime, OpenCV 的成员变量)
// 使得这个头文件非常干净,并且编译速度更快。
class Impl;
Impl* p_impl;
};