- Recognizer: adafacerecognizer.onnx (AdaFace, new default) with automatic fallback to ansfacerecognizer.onnx (ArcFace) for pre-v1.4 zips. AdaFace consumes BGR: new AdaFace handler in ONNXEngine skips the BGR2RGB swap, and the TensorRT paths gate their cvtColor on m_swapRB. - New C API: SetANSRFRecognizerModel (0=AdaFace, 1=ArcFace), GetANSRFRecognizerModel, GetANSRFModelInfo. A live switch reloads the recognizer and regenerates all stored embeddings from the enrolled face crops; the generating model is persisted in a new SETTINGS table (EMBEDDING_MODEL) so upgrading an ArcFace database to the AdaFace default migrates automatically on LoadEngine. - Attributes: prefer agegender.onnx (ViT: gender_logits [male,female] + age_pred in years; also handles the single-tensor research export) and emotionsrecognition.onnx (YOLOv11-cls, classes from .names) behind new IAgeGenderEstimator/IEmotionsClassifier interfaces, falling back to the legacy OpenVINO IRs. EP follows hardware: NVIDIA uses TensorRT EP with disk-cached engines, AMD DirectML, Intel OpenVINO. - Emotion JSON mapping: handle the new Fear class and the never-matched surprise label (both map to Attentive). - ANSFR-UnitTest: TestModelSwitchV14 covers default model selection, ONNX attribute backends, enrollment, and adaface<->arcface switching. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
62 lines
2.8 KiB
C++
62 lines
2.8 KiB
C++
#ifndef FACEDATABASE_H
|
|
#define FACEDATABASE_H
|
|
#pragma once
|
|
#include <iostream>
|
|
#include <map>
|
|
//#include "ARCFaceRT.h"
|
|
#include "sqlite3.h"
|
|
#include <vector>
|
|
#include "ANSFRCommon.h"
|
|
|
|
namespace ANSCENTER {
|
|
// Structured embedding record for double-buffer reload
|
|
struct FaceEmbeddingRecord {
|
|
int faceId; // FACE.ID (unique per face)
|
|
std::string userId; // FACE.USER (= USER.ID, as string)
|
|
std::vector<float> embedding;
|
|
};
|
|
|
|
class FaceDatabase {
|
|
public:
|
|
FaceDatabase();
|
|
~FaceDatabase();
|
|
bool Destroy();
|
|
bool Initialize(std::string path, int embeddingDim, std::string dataFolder);
|
|
int InsertUser(std::string code, std::string userName);
|
|
int UpdateUser(int UserId, std::string newUserCode, std::string newUserName);
|
|
int InsertFace(int userId, std::string imgPath, float embedding[]);
|
|
int DeleteFace(int id);
|
|
int DeleteUser(int UserId);
|
|
int GetFaceIdsByUser(int userId, std::vector<int>& faceIds);
|
|
int GetUserId(std::string code);
|
|
int GetUser(int userId, std::string& code, std::string& userName);
|
|
int GetUsers(std::vector<int>& ids, std::vector<std::string>& codes, std::vector<std::string>& userNames);
|
|
// Fix #12: Batch query — returns users with their face IDs in a single query
|
|
int GetUsersWithFaceIds(std::vector<int>& ids, std::vector<std::string>& codes,
|
|
std::vector<std::string>& userNames, std::vector<std::vector<int>>& faceIdsByUser);
|
|
int GetFaceById(int faceId, int& userId, std::string& imagePath);
|
|
// All enrolled faces (ID, USER, IMG_PATH) — used to regenerate
|
|
// embeddings after a recognizer model switch.
|
|
int GetAllFaces(std::vector<FaceRecord>& faces);
|
|
// Replaces the stored embedding of one face (same dim as Initialize).
|
|
int UpdateFaceEmbedding(int faceId, const float embedding[]);
|
|
// Simple key/value store (SETTINGS table, created on demand) — used
|
|
// to persist which recognizer model generated the stored embeddings.
|
|
bool SetSetting(const std::string& key, const std::string& value);
|
|
std::string GetSetting(const std::string& key);
|
|
std::map<std::string, std::string> GetUserDict();
|
|
int GetEmbeddings(ANSFRBase& recognizer);
|
|
int GetEmbeddings(std::unique_ptr<ANSFRBase>& recognizer);
|
|
// Returns all face embedding records (FACE.ID + USER.ID + embedding) for double-buffer reload
|
|
int GetAllEmbeddingRecords(std::vector<FaceEmbeddingRecord>& records);
|
|
private:
|
|
sqlite3* m_db;
|
|
int m_embedding_dim;
|
|
std::string _dataFolder;
|
|
std::mutex _mutex;
|
|
// Fix #10: Logger for database operations
|
|
ANSCENTER::SPDLogger& _logger = ANSCENTER::SPDLogger::GetInstance("FaceDB");
|
|
int GetNumEmbeddings();
|
|
};
|
|
}
|
|
#endif |