| 6 | #include <inspireface/inspireface.hpp> |
| 7 | |
| 8 | int main(int argc, char** argv) { |
| 9 | if (argc != 4) { |
| 10 | std::cout << "Usage: " << argv[0] << " <model_path> <image_path1> <image_path2>" << std::endl; |
| 11 | return -1; |
| 12 | } |
| 13 | |
| 14 | std::string model_path = argv[1]; |
| 15 | std::string image_path1 = argv[2]; |
| 16 | std::string image_path2 = argv[3]; |
| 17 | |
| 18 | // Global init(only once) |
| 19 | INSPIREFACE_CONTEXT->Reload(model_path); |
| 20 | |
| 21 | // Create image and frame process |
| 22 | inspirecv::Image image1 = inspirecv::Image::Create(image_path1); |
| 23 | inspirecv::Image image2 = inspirecv::Image::Create(image_path2); |
| 24 | inspirecv::FrameProcess process1 = inspirecv::FrameProcess::Create(image1.Data(), image1.Height(), image1.Width(), inspirecv::BGR, inspirecv::ROTATION_0); |
| 25 | inspirecv::FrameProcess process2 = inspirecv::FrameProcess::Create(image2.Data(), image2.Height(), image2.Width(), inspirecv::BGR, inspirecv::ROTATION_0); |
| 26 | |
| 27 | // Create session |
| 28 | inspire::CustomPipelineParameter param; |
| 29 | param.enable_recognition = true; |
| 30 | |
| 31 | // Create session |
| 32 | std::shared_ptr<inspire::Session> session( |
| 33 | inspire::Session::CreatePtr(inspire::DETECT_MODE_ALWAYS_DETECT, 1, param, 320)); |
| 34 | |
| 35 | INSPIREFACE_CHECK_MSG(session != nullptr, "Session is not valid"); |
| 36 | |
| 37 | // Detect and track |
| 38 | std::vector<inspire::FaceTrackWrap> results1; |
| 39 | std::vector<inspire::FaceTrackWrap> results2; |
| 40 | |
| 41 | // Detect and track |
| 42 | session->FaceDetectAndTrack(process1, results1); |
| 43 | session->FaceDetectAndTrack(process2, results2); |
| 44 | |
| 45 | INSPIREFACE_CHECK_MSG(!results1.empty() && !results2.empty(), "No face detected"); |
| 46 | |
| 47 | // Get feature |
| 48 | inspire::FaceEmbedding feature1; |
| 49 | inspire::FaceEmbedding feature2; |
| 50 | session->FaceFeatureExtract(process1, results1[0], feature1); |
| 51 | session->FaceFeatureExtract(process2, results2[0], feature2); |
| 52 | |
| 53 | // Compare |
| 54 | float similarity; |
| 55 | INSPIREFACE_FEATURE_HUB->CosineSimilarity(feature1.embedding, feature2.embedding, similarity); |
| 56 | std::cout << "cosine of similarity: " << similarity << std::endl; |
| 57 | std::cout << "percentage of similarity: " << SIMILARITY_CONVERTER_RUN(similarity) << std::endl; |
| 58 | |
| 59 | std::cout << "== using alignment image ==" << std::endl; |
| 60 | |
| 61 | // Get face alignment image |
| 62 | inspirecv::Image wrapped1; |
| 63 | inspirecv::Image wrapped2; |
| 64 | session->GetFaceAlignmentImage(process1, results1[0], wrapped1); |
| 65 | session->GetFaceAlignmentImage(process2, results2[0], wrapped2); |
nothing calls this directly
no test coverage detected