MCPcopy Create free account
hub / github.com/HyperInspire/InspireFace / main

Function main

cpp/sample/cpp_api/cpp_sample_face_crud.cpp:4–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <inspireface/inspireface.hpp>
3
4int main() {
5 // Launch InspireFace
6 std::string model_path = "test_res/pack/Pikachu";
7 INSPIREFACE_CONTEXT->Reload(model_path);
8 INSPIREFACE_CHECK_MSG(INSPIREFACE_CONTEXT->isMLoad(), "InspireFace is not loaded");
9
10 // Enable feature hub
11 std::string db_path = "case_crud.db";
12 // Remove the database file if it exists
13 if (std::remove(db_path.c_str()) != 0) {
14 std::cerr << "Error removing database file: " << db_path << std::endl;
15 }
16 inspire::DatabaseConfiguration db_config;
17 db_config.enable_persistence = true;
18 db_config.persistence_db_path = db_path;
19 db_config.search_mode = inspire::SEARCH_MODE_EXHAUSTIVE;
20 db_config.recognition_threshold = 0.48f;
21 db_config.primary_key_mode = inspire::AUTO_INCREMENT;
22 auto ret = INSPIREFACE_FEATURE_HUB->EnableHub(db_config);
23 INSPIREFACE_CHECK_MSG(ret == HSUCCEED, "EnableHub failed");
24
25 // Create a session
26 auto param = inspire::CustomPipelineParameter();
27 param.enable_recognition = true;
28 auto session = inspire::Session::CreatePtr(inspire::DETECT_MODE_ALWAYS_DETECT, 1, param, 320);
29 INSPIREFACE_CHECK_MSG(session != nullptr, "Session is not created");
30
31 // Prepare an image for insertion into the hub
32 auto image = inspirecv::Image::Create("test_res/data/bulk/kun.jpg");
33 auto image_process = inspirecv::FrameProcess::Create(image.Data(), image.Height(), image.Width(), inspirecv::BGR, inspirecv::ROTATION_0);
34
35 // Detect and track
36 std::vector<inspire::FaceTrackWrap> results;
37 session->FaceDetectAndTrack(image_process, results);
38 INSPIREFACE_CHECK_MSG(results.size() > 0, "No face detected");
39
40 // Extract face feature
41 inspire::FaceEmbedding feature;
42 session->FaceFeatureExtract(image_process, results[0], feature);
43
44 // Insert face feature into the hub, because the id is INSPIRE_INVALID_ID, so input id is ignored
45 int64_t result_id;
46 INSPIREFACE_FEATURE_HUB->FaceFeatureInsert(feature.embedding, INSPIRE_INVALID_ID, result_id);
47
48 inspire::FaceEmbedding face_feature;
49 INSPIREFACE_FEATURE_HUB->GetFaceFeature(result_id, face_feature);
50
51 // Prepare a photo of the same person for the query
52 auto query_image = inspirecv::Image::Create("test_res/data/bulk/jntm.jpg");
53 auto query_image_process = inspirecv::FrameProcess::Create(query_image.Data(), query_image.Height(), query_image.Width(), inspirecv::BGR, inspirecv::ROTATION_0);
54
55 // Detect and track
56 std::vector<inspire::FaceTrackWrap> query_results;
57 session->FaceDetectAndTrack(query_image_process, query_results);
58 INSPIREFACE_CHECK_MSG(query_results.size() > 0, "No face detected");
59
60 // Extract face feature
61 inspire::FaceEmbedding query_feature;

Callers

nothing calls this directly

Calls 15

CreatePtrFunction · 0.85
ReloadMethod · 0.80
isMLoadMethod · 0.80
EnableHubMethod · 0.80
sizeMethod · 0.80
FaceFeatureInsertMethod · 0.80
SearchFaceFeatureMethod · 0.80
FaceFeatureUpdateMethod · 0.80
FaceFeatureRemoveMethod · 0.80
GetFaceFeatureCountMethod · 0.80
SearchFaceFeatureTopKMethod · 0.80

Tested by

no test coverage detected