mirror of
https://github.com/deepinsight/insightface.git
synced 2025-12-30 08:02:27 +00:00
Update inspireface to 1.2.0
This commit is contained in:
10
cpp-package/inspireface/cpp/sample/api/leak.cpp
Normal file
10
cpp-package/inspireface/cpp/sample/api/leak.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Created by Jingyu Yan
|
||||
* @date 2024-10-01
|
||||
*/
|
||||
|
||||
int main() {
|
||||
char *n = new char[1024];
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Created by Jingyu Yan
|
||||
* @date 2024-10-01
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <inspireface.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
// Check whether the number of parameters is correct
|
||||
if (argc != 4) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Usage: %s <pack_path> <img1_path> <img2_path>", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto packPath = argv[1];
|
||||
auto imgPath1 = argv[2];
|
||||
auto imgPath2 = argv[3];
|
||||
|
||||
HFLogPrint(HF_LOG_INFO, "Pack file Path: %s", packPath);
|
||||
HFLogPrint(HF_LOG_INFO, "Source file Path 1: %s", imgPath1);
|
||||
HFLogPrint(HF_LOG_INFO, "Source file Path 2: %s", imgPath2);
|
||||
|
||||
HResult ret;
|
||||
// The resource file must be loaded before it can be used
|
||||
ret = HFLaunchInspireFace(packPath);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Load Resource error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Create a session for face recognition
|
||||
HOption option = HF_ENABLE_FACE_RECOGNITION;
|
||||
HFSession session;
|
||||
ret = HFCreateInspireFaceSessionOptional(option, HF_DETECT_MODE_ALWAYS_DETECT, 1, -1, -1, &session);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Create session error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<char*> twoImg = {imgPath1, imgPath2};
|
||||
std::vector<std::vector<float>> vec(2, std::vector<float>(512));
|
||||
for (int i = 0; i < twoImg.size(); ++i) {
|
||||
HFImageBitmap imageBitmap = {0};
|
||||
ret = HFCreateImageBitmapFromFilePath(twoImg[i], 3, &imageBitmap);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Create image bitmap error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
// Prepare image data for processing
|
||||
|
||||
HFImageStream stream;
|
||||
ret = HFCreateImageStreamFromImageBitmap(imageBitmap, HF_CAMERA_ROTATION_0, &stream); // Create an image stream for processing
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Create stream error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Execute face tracking on the image
|
||||
HFMultipleFaceData multipleFaceData = {0};
|
||||
ret = HFExecuteFaceTrack(session, stream, &multipleFaceData); // Track faces in the image
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Run face track error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
if (multipleFaceData.detectedNum == 0) { // Check if any faces were detected
|
||||
HFLogPrint(HF_LOG_ERROR, "No face was detected: %s", twoImg[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Extract facial features from the first detected face, an interface that uses copy features in a comparison scenario
|
||||
ret = HFFaceFeatureExtractCpy(session, stream, multipleFaceData.tokens[0], vec[i].data()); // Extract features
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Extract feature error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = HFReleaseImageStream(stream);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Release image stream error: %d", ret);
|
||||
}
|
||||
ret = HFReleaseImageBitmap(imageBitmap);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Release image bitmap error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
// Make feature1
|
||||
HFFaceFeature feature1 = {0};
|
||||
feature1.data = vec[0].data();
|
||||
feature1.size = vec[0].size();
|
||||
|
||||
// Make feature2
|
||||
HFFaceFeature feature2 = {0};
|
||||
feature2.data = vec[1].data();
|
||||
feature2.size = vec[1].size();
|
||||
|
||||
// Run comparison
|
||||
HFloat similarity;
|
||||
ret = HFFaceComparison(feature1, feature2, &similarity);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Feature comparison error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
HFloat recommended_cosine_threshold;
|
||||
ret = HFGetRecommendedCosineThreshold(&recommended_cosine_threshold);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Get recommended cosine threshold error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (similarity > recommended_cosine_threshold) {
|
||||
HFLogPrint(HF_LOG_INFO, "%.3f > %.3f ✓ Same face", similarity, recommended_cosine_threshold);
|
||||
} else {
|
||||
HFLogPrint(HF_LOG_WARN, "%.3f < %.3f ✗ Different face", similarity, recommended_cosine_threshold);
|
||||
}
|
||||
HFLogPrint(HF_LOG_INFO, "Similarity score: %.3f", similarity);
|
||||
|
||||
// Convert cosine similarity to percentage similarity.
|
||||
// Note: conversion parameters are not optimal and should be adjusted based on your specific use case.
|
||||
HFloat percentage;
|
||||
ret = HFCosineSimilarityConvertToPercentage(similarity, &percentage);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Convert similarity to percentage error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
HFLogPrint(HF_LOG_INFO, "Percentage similarity: %f", percentage);
|
||||
|
||||
// The memory must be freed at the end of the program
|
||||
ret = HFReleaseInspireFaceSession(session);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Release session error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
228
cpp-package/inspireface/cpp/sample/api/sample_face_track.cpp
Normal file
228
cpp-package/inspireface/cpp/sample/api/sample_face_track.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
/**
|
||||
* Created by Jingyu Yan
|
||||
* @date 2024-10-01
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <inspireface.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
// Check whether the number of parameters is correct
|
||||
if (argc < 3 || argc > 4) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Usage: %s <pack_path> <source_path> [rotation]", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto packPath = argv[1];
|
||||
auto sourcePath = argv[2];
|
||||
int rotation = 0;
|
||||
|
||||
// If rotation is provided, check and set the value
|
||||
if (argc == 4) {
|
||||
rotation = std::atoi(argv[3]);
|
||||
if (rotation != 0 && rotation != 90 && rotation != 180 && rotation != 270) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Invalid rotation value. Allowed values are 0, 90, 180, 270.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
HFRotation rotation_enum;
|
||||
// Set rotation based on input parameter
|
||||
switch (rotation) {
|
||||
case 90:
|
||||
rotation_enum = HF_CAMERA_ROTATION_90;
|
||||
break;
|
||||
case 180:
|
||||
rotation_enum = HF_CAMERA_ROTATION_180;
|
||||
break;
|
||||
case 270:
|
||||
rotation_enum = HF_CAMERA_ROTATION_270;
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
rotation_enum = HF_CAMERA_ROTATION_0;
|
||||
break;
|
||||
}
|
||||
|
||||
HFLogPrint(HF_LOG_INFO, "Pack file Path: %s", packPath);
|
||||
HFLogPrint(HF_LOG_INFO, "Source file Path: %s", sourcePath);
|
||||
HFLogPrint(HF_LOG_INFO, "Rotation: %d", rotation);
|
||||
|
||||
HFSetLogLevel(HF_LOG_INFO);
|
||||
|
||||
HResult ret;
|
||||
// The resource file must be loaded before it can be used
|
||||
ret = HFLaunchInspireFace(packPath);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Load Resource error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Enable the functions in the pipeline: mask detection, live detection, and face quality
|
||||
// detection
|
||||
HOption option = HF_ENABLE_QUALITY | HF_ENABLE_MASK_DETECT | HF_ENABLE_LIVENESS | HF_ENABLE_DETECT_MODE_LANDMARK;
|
||||
// Non-video or frame sequence mode uses IMAGE-MODE, which is always face detection without
|
||||
// tracking
|
||||
HFDetectMode detMode = HF_DETECT_MODE_ALWAYS_DETECT;
|
||||
// Maximum number of faces detected
|
||||
HInt32 maxDetectNum = 20;
|
||||
// Face detection image input level
|
||||
HInt32 detectPixelLevel = 160;
|
||||
// Handle of the current face SDK algorithm context
|
||||
HFSession session = {0};
|
||||
ret = HFCreateInspireFaceSessionOptional(option, detMode, maxDetectNum, detectPixelLevel, -1, &session);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Create FaceContext error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
HFSessionSetTrackPreviewSize(session, detectPixelLevel);
|
||||
HFSessionSetFilterMinimumFacePixelSize(session, 4);
|
||||
|
||||
// Load a image
|
||||
HFImageBitmap image;
|
||||
ret = HFCreateImageBitmapFromFilePath(sourcePath, 3, &image);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "The source entered is not a picture or read error.");
|
||||
return ret;
|
||||
}
|
||||
// Prepare an image parameter structure for configuration
|
||||
HFImageStream imageHandle = {0};
|
||||
ret = HFCreateImageStreamFromImageBitmap(image, rotation_enum, &imageHandle);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Create ImageStream error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Execute HF_FaceContextRunFaceTrack captures face information in an image
|
||||
HFMultipleFaceData multipleFaceData = {0};
|
||||
ret = HFExecuteFaceTrack(session, imageHandle, &multipleFaceData);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Execute HFExecuteFaceTrack error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Print the number of faces detected
|
||||
auto faceNum = multipleFaceData.detectedNum;
|
||||
HFLogPrint(HF_LOG_INFO, "Num of face: %d", faceNum);
|
||||
|
||||
// Copy a new image to draw
|
||||
HFImageBitmap drawImage = {0};
|
||||
ret = HFImageBitmapCopy(image, &drawImage);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Copy ImageBitmap error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
HFImageBitmapData data;
|
||||
ret = HFImageBitmapGetData(drawImage, &data);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Get ImageBitmap data error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
for (int index = 0; index < faceNum; ++index) {
|
||||
HFLogPrint(HF_LOG_INFO, "========================================");
|
||||
HFLogPrint(HF_LOG_INFO, "Token size: %d", multipleFaceData.tokens[index].size);
|
||||
HFLogPrint(HF_LOG_INFO, "Process face index: %d", index);
|
||||
HFLogPrint(HF_LOG_INFO, "DetConfidence: %f", multipleFaceData.detConfidence[index]);
|
||||
HFImageBitmapDrawRect(drawImage, multipleFaceData.rects[index], {0, 100, 255}, 4);
|
||||
|
||||
// Print FaceID, In IMAGE-MODE it is changing, in VIDEO-MODE it is fixed, but it may be lost
|
||||
HFLogPrint(HF_LOG_INFO, "FaceID: %d", multipleFaceData.trackIds[index]);
|
||||
|
||||
// Print Head euler angle, It can often be used to judge the quality of a face by the Angle
|
||||
// of the head
|
||||
HFLogPrint(HF_LOG_INFO, "Roll: %f, Yaw: %f, Pitch: %f", multipleFaceData.angles.roll[index], multipleFaceData.angles.yaw[index],
|
||||
multipleFaceData.angles.pitch[index]);
|
||||
|
||||
HInt32 numOfLmk;
|
||||
HFGetNumOfFaceDenseLandmark(&numOfLmk);
|
||||
HPoint2f denseLandmarkPoints[numOfLmk];
|
||||
ret = HFGetFaceDenseLandmarkFromFaceToken(multipleFaceData.tokens[index], denseLandmarkPoints, numOfLmk);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "HFGetFaceDenseLandmarkFromFaceToken error!!");
|
||||
return -1;
|
||||
}
|
||||
for (size_t i = 0; i < numOfLmk; i++) {
|
||||
HFImageBitmapDrawCircleF(drawImage, {denseLandmarkPoints[i].x, denseLandmarkPoints[i].y}, 0, {100, 100, 0}, 2);
|
||||
}
|
||||
auto& rt = multipleFaceData.rects[index];
|
||||
float area = ((float)(rt.height * rt.width)) / (data.width * data.height);
|
||||
HFLogPrint(HF_LOG_INFO, "area: %f", area);
|
||||
|
||||
HPoint2f fiveKeyPoints[5];
|
||||
ret = HFGetFaceFiveKeyPointsFromFaceToken(multipleFaceData.tokens[index], fiveKeyPoints, 5);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "HFGetFaceFiveKeyPointsFromFaceToken error!!");
|
||||
return -1;
|
||||
}
|
||||
for (size_t i = 0; i < 5; i++) {
|
||||
HFImageBitmapDrawCircleF(drawImage, {fiveKeyPoints[i].x, fiveKeyPoints[i].y}, 0, {0, 0, 232}, 2);
|
||||
}
|
||||
}
|
||||
HFImageBitmapWriteToFile(drawImage, "draw_detected.jpg");
|
||||
HFLogPrint(HF_LOG_WARN, "Write to file success: %s", "draw_detected.jpg");
|
||||
|
||||
// Run pipeline function
|
||||
// Select the pipeline function that you want to execute, provided that it is already enabled
|
||||
// when FaceContext is created!
|
||||
auto pipelineOption = HF_ENABLE_QUALITY | HF_ENABLE_MASK_DETECT | HF_ENABLE_LIVENESS;
|
||||
// In this loop, all faces are processed
|
||||
ret = HFMultipleFacePipelineProcessOptional(session, imageHandle, &multipleFaceData, pipelineOption);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Execute Pipeline error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Get mask detection results from the pipeline cache
|
||||
HFFaceMaskConfidence maskConfidence = {0};
|
||||
ret = HFGetFaceMaskConfidence(session, &maskConfidence);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Get mask detect result error: %d", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get face quality results from the pipeline cache
|
||||
HFFaceQualityConfidence qualityConfidence = {0};
|
||||
ret = HFGetFaceQualityConfidence(session, &qualityConfidence);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Get face quality result error: %d", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int index = 0; index < faceNum; ++index) {
|
||||
HFLogPrint(HF_LOG_INFO, "========================================");
|
||||
HFLogPrint(HF_LOG_INFO, "Process face index from pipeline: %d", index);
|
||||
HFLogPrint(HF_LOG_INFO, "Mask detect result: %f", maskConfidence.confidence[index]);
|
||||
HFLogPrint(HF_LOG_INFO, "Quality predict result: %f", qualityConfidence.confidence[index]);
|
||||
// We set the threshold of wearing a mask as 0.85. If it exceeds the threshold, it will be
|
||||
// judged as wearing a mask. The threshold can be adjusted according to the scene
|
||||
if (maskConfidence.confidence[index] > 0.85) {
|
||||
HFLogPrint(HF_LOG_INFO, "Mask");
|
||||
} else {
|
||||
HFLogPrint(HF_LOG_INFO, "Non Mask");
|
||||
}
|
||||
}
|
||||
|
||||
ret = HFReleaseImageStream(imageHandle);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Release image stream error: %d", ret);
|
||||
}
|
||||
// The memory must be freed at the end of the program
|
||||
ret = HFReleaseInspireFaceSession(session);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Release session error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = HFReleaseImageBitmap(image);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Release image bitmap error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = HFReleaseImageBitmap(drawImage);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Release draw image bitmap error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/**
|
||||
* Created by Jingyu Yan
|
||||
* @date 2024-10-01
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <inspireface.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
// Check whether the number of parameters is correct
|
||||
if (argc < 3 || argc > 4) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Usage: %s <pack_path> <source_path> [rotation]", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto packPath = argv[1];
|
||||
auto sourcePath = argv[2];
|
||||
int rotation = 0;
|
||||
|
||||
// If rotation is provided, check and set the value
|
||||
if (argc == 4) {
|
||||
rotation = std::atoi(argv[3]);
|
||||
if (rotation != 0 && rotation != 90 && rotation != 180 && rotation != 270) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Invalid rotation value. Allowed values are 0, 90, 180, 270.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
HFRotation rotation_enum;
|
||||
// Set rotation based on input parameter
|
||||
switch (rotation) {
|
||||
case 90:
|
||||
rotation_enum = HF_CAMERA_ROTATION_90;
|
||||
break;
|
||||
case 180:
|
||||
rotation_enum = HF_CAMERA_ROTATION_180;
|
||||
break;
|
||||
case 270:
|
||||
rotation_enum = HF_CAMERA_ROTATION_270;
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
rotation_enum = HF_CAMERA_ROTATION_0;
|
||||
break;
|
||||
}
|
||||
|
||||
HFLogPrint(HF_LOG_INFO, "Pack file Path: %s", packPath);
|
||||
HFLogPrint(HF_LOG_INFO, "Source file Path: %s", sourcePath);
|
||||
HFLogPrint(HF_LOG_INFO, "Rotation: %d", rotation);
|
||||
|
||||
HFSetLogLevel(HF_LOG_INFO);
|
||||
|
||||
HResult ret;
|
||||
// The resource file must be loaded before it can be used
|
||||
ret = HFLaunchInspireFace(packPath);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Load Resource error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Enable the functions in the pipeline: mask detection, live detection, and face quality
|
||||
// detection
|
||||
HOption option = HF_ENABLE_QUALITY | HF_ENABLE_MASK_DETECT | HF_ENABLE_LIVENESS | HF_ENABLE_DETECT_MODE_LANDMARK;
|
||||
// Non-video or frame sequence mode uses IMAGE-MODE, which is always face detection without
|
||||
// tracking
|
||||
HFDetectMode detMode = HF_DETECT_MODE_ALWAYS_DETECT;
|
||||
// Maximum number of faces detected
|
||||
HInt32 maxDetectNum = 20;
|
||||
// Face detection image input level
|
||||
HInt32 detectPixelLevel = 160;
|
||||
// Handle of the current face SDK algorithm context
|
||||
HFSession session = {0};
|
||||
ret = HFCreateInspireFaceSessionOptional(option, detMode, maxDetectNum, detectPixelLevel, -1, &session);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Create FaceContext error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
HFSessionSetTrackPreviewSize(session, detectPixelLevel);
|
||||
HFSessionSetFilterMinimumFacePixelSize(session, 4);
|
||||
|
||||
// Load a image
|
||||
HFImageBitmap image;
|
||||
ret = HFCreateImageBitmapFromFilePath(sourcePath, 3, &image);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "The source entered is not a picture or read error.");
|
||||
return ret;
|
||||
}
|
||||
// Prepare an image parameter structure for configuration
|
||||
HFImageStream imageHandle = {0};
|
||||
ret = HFCreateImageStreamFromImageBitmap(image, rotation_enum, &imageHandle);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Create ImageStream error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int loop = 100;
|
||||
|
||||
// Enable the cost spend
|
||||
HFSessionSetEnableTrackCostSpend(session, 1);
|
||||
|
||||
// Execute HF_FaceContextRunFaceTrack captures face information in an image
|
||||
HFMultipleFaceData multipleFaceData = {0};
|
||||
for (int i = 0; i < loop; i++) {
|
||||
ret = HFExecuteFaceTrack(session, imageHandle, &multipleFaceData);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Execute HFExecuteFaceTrack error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
HFLogPrint(HF_LOG_INFO, "Number of Detection: %d", multipleFaceData.detectedNum);
|
||||
HFSessionPrintTrackCostSpend(session);
|
||||
|
||||
ret = HFReleaseImageStream(imageHandle);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Release image stream error: %d", ret);
|
||||
}
|
||||
// The memory must be freed at the end of the program
|
||||
ret = HFReleaseInspireFaceSession(session);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Release session error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = HFReleaseImageBitmap(image);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Release image bitmap error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
104
cpp-package/inspireface/cpp/sample/api/sample_feature_hub.cpp
Normal file
104
cpp-package/inspireface/cpp/sample/api/sample_feature_hub.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#include <iostream>
|
||||
#include <inspireface.h>
|
||||
#include <vector>
|
||||
|
||||
static std::vector<float> FT = {
|
||||
0.0706566, 0.00640248, 0.0418103, -0.00597861, 0.0269879, 0.0187478, 0.0486305, 0.0349162, -0.0080779, -0.0550556, 0.0229963,
|
||||
-0.00683422, -0.0338589, 0.0533989, -0.0371725, 0.000972469, 0.0612415, 0.0389846, -0.00126743, -0.0128782, 0.0935529, 0.0588179,
|
||||
0.0164787, -0.00732871, -0.0458209, -0.0100137, -0.0372892, 0.000871123, 0.0245121, -0.0811471, -0.00481095, 0.0266868, 0.0712961,
|
||||
-0.0675362, -0.0117453, 0.0658745, -0.0694139, -0.00704822, -0.0237313, 0.0209365, 0.0131902, 0.00192449, -0.0593105, 0.0191942,
|
||||
-0.00625798, 0.00748682, 0.0533557, 0.0314002, -0.0627113, 0.0827862, 0.00336722, -0.0191575, -0.0180252, 0.0150318, -0.0686462,
|
||||
0.0465634, 0.0627244, 0.0449248, -0.037054, -0.0486668, 0.040752, 0.0143315, -0.0763842, -0.0161973, 0.0319588, 0.0112792,
|
||||
-0.102007, 0.0649219, 0.0630833, 0.0421069, 0.0519043, -0.084082, 0.0249516, 0.023046, 0.071994, -0.0272229, 0.0167103,
|
||||
-0.00694243, 0.0366775, 0.0672882, 0.0122419, -0.0233413, -0.0144258, -0.012853, -0.0202025, 0.000983093, -0.00776073, -0.0268638,
|
||||
0.00682446, 0.0262906, -0.0407654, -0.0144264, -0.0310807, 0.0596711, 0.0238081, -0.0138019, 0.000502882, 0.0496892, 0.0126823,
|
||||
0.0511028, -0.0310699, -0.0322141, 0.00996936, 0.0675392, -0.0164277, 0.0930009, -0.037467, 0.0419618, -0.00358901, -0.0309569,
|
||||
-0.0225608, -0.0332198, 0.00102291, 0.108814, -0.0831313, 0.048208, -0.0277542, -0.061584, 0.0721224, -0.0795082, 0.0340047,
|
||||
0.056139, -0.0166783, -0.0803042, -0.014245, -0.0476374, 0.048495, 0.0378856, 0.0706566, 0.00640248, 0.0418103, -0.00597861,
|
||||
0.0269879, 0.0187478, 0.0486305, 0.0349162, -0.0080779, -0.0550556, 0.0229963, -0.00683422, -0.0338589, 0.0533989, -0.0371725,
|
||||
0.000972469, 0.0612415, 0.0389846, -0.00126743, -0.0128782, 0.0935529, 0.0588179, 0.0164787, -0.00732871, -0.0458209, -0.0100137,
|
||||
-0.0372892, 0.000871123, 0.0245121, -0.0811471, -0.00481095, 0.0266868, 0.0712961, -0.0675362, -0.0117453, 0.0658745, -0.0694139,
|
||||
-0.00704822, -0.0237313, 0.0209365, 0.0131902, 0.00192449, -0.0593105, 0.0191942, -0.00625798, 0.00748682, 0.0533557, 0.0314002,
|
||||
-0.0627113, 0.0827862, 0.00336722, -0.0191575, -0.0180252, 0.0150318, -0.0686462, 0.0465634, 0.0627244, 0.0449248, -0.037054,
|
||||
-0.0486668, 0.040752, 0.0143315, -0.0763842, -0.0161973, 0.0319588, 0.0112792, -0.102007, 0.0649219, 0.0630833, 0.0421069,
|
||||
0.0519043, -0.084082, 0.0249516, 0.023046, 0.071994, -0.0272229, 0.0167103, -0.00694243, 0.0366775, 0.0672882, 0.0122419,
|
||||
-0.0233413, -0.0144258, -0.012853, -0.0202025, 0.000983093, -0.00776073, -0.0268638, 0.00682446, 0.0262906, -0.0407654, -0.0144264,
|
||||
-0.0310807, 0.0596711, 0.0238081, -0.0138019, 0.000502882, 0.0496892, 0.0126823, 0.0511028, -0.0310699, -0.0322141, 0.00996936,
|
||||
0.0675392, -0.0164277, 0.0930009, -0.037467, 0.0419618, -0.00358901, -0.0309569, -0.0225608, -0.0332198, 0.00102291, 0.108814,
|
||||
-0.0831313, 0.048208, -0.0277542, -0.061584, 0.0721224, -0.0795082, 0.0340047, 0.056139, -0.0166783, -0.0803042, -0.014245,
|
||||
-0.0476374, 0.048495, 0.0378856, 0.0706566, 0.00640248, 0.0418103, -0.00597861, 0.0269879, 0.0187478, 0.0486305, 0.0349162,
|
||||
-0.0080779, -0.0550556, 0.0229963, -0.00683422, -0.0338589, 0.0533989, -0.0371725, 0.000972469, 0.0612415, 0.0389846, -0.00126743,
|
||||
-0.0128782, 0.0935529, 0.0588179, 0.0164787, -0.00732871, -0.0458209, -0.0100137, -0.0372892, 0.000871123, 0.0245121, -0.0811471,
|
||||
-0.00481095, 0.0266868, 0.0712961, -0.0675362, -0.0117453, 0.0658745, -0.0694139, -0.00704822, -0.0237313, 0.0209365, 0.0131902,
|
||||
0.00192449, -0.0593105, 0.0191942, -0.00625798, 0.00748682, 0.0533557, 0.0314002, -0.0627113, 0.0827862, 0.00336722, -0.0191575,
|
||||
-0.0180252, 0.0150318, -0.0686462, 0.0465634, 0.0627244, 0.0449248, -0.037054, -0.0486668, 0.040752, 0.0143315, -0.0763842,
|
||||
-0.0161973, 0.0319588, 0.0112792, -0.102007, 0.0649219, 0.0630833, 0.0421069, 0.0519043, -0.084082, 0.0249516, 0.023046,
|
||||
0.071994, -0.0272229, 0.0167103, -0.00694243, 0.0366775, 0.0672882, 0.0122419, -0.0233413, -0.0144258, -0.012853, -0.0202025,
|
||||
0.000983093, -0.00776073, -0.0268638, 0.00682446, 0.0262906, -0.0407654, -0.0144264, -0.0310807, 0.0596711, 0.0238081, -0.0138019,
|
||||
0.000502882, 0.0496892, 0.0126823, 0.0511028, -0.0310699, -0.0322141, 0.00996936, 0.0675392, -0.0164277, 0.0930009, -0.037467,
|
||||
0.0419618, -0.00358901, -0.0309569, -0.0225608, -0.0332198, 0.00102291, 0.108814, -0.0831313, 0.048208, -0.0277542, -0.061584,
|
||||
0.0721224, -0.0795082, 0.0340047, 0.056139, -0.0166783, -0.0803042, -0.014245, -0.0476374, 0.048495, 0.0378856, 0.0706566,
|
||||
0.00640248, 0.0418103, -0.00597861, 0.0269879, 0.0187478, 0.0486305, 0.0349162, -0.0080779, -0.0550556, 0.0229963, -0.00683422,
|
||||
-0.0338589, 0.0533989, -0.0371725, 0.000972469, 0.0612415, 0.0389846, -0.00126743, -0.0128782, 0.0935529, 0.0588179, 0.0164787,
|
||||
-0.00732871, -0.0458209, -0.0100137, -0.0372892, 0.000871123, 0.0245121, -0.0811471, -0.00481095, 0.0266868, 0.0712961, -0.0675362,
|
||||
-0.0117453, 0.0658745, -0.0694139, -0.00704822, -0.0237313, 0.0209365, 0.0131902, 0.00192449, -0.0593105, 0.0191942, -0.00625798,
|
||||
0.00748682, 0.0533557, 0.0314002, -0.0627113, 0.0827862, 0.00336722, -0.0191575, -0.0180252, 0.0150318, -0.0686462, 0.0465634,
|
||||
0.0627244, 0.0449248, -0.037054, -0.0486668, 0.040752, 0.0143315, -0.0763842, -0.0161973, 0.0319588, 0.0112792, -0.102007,
|
||||
0.0649219, 0.0630833, 0.0421069, 0.0519043, -0.084082, 0.0249516, 0.023046, 0.071994, -0.0272229, 0.0167103, -0.00694243,
|
||||
0.0366775, 0.0672882, 0.0122419, -0.0233413, -0.0144258, -0.012853, -0.0202025, 0.000983093, -0.00776073, -0.0268638, 0.00682446,
|
||||
0.0262906, -0.0407654, -0.0144264, -0.0310807, 0.0596711, 0.0238081, -0.0138019, 0.000502882, 0.0496892, 0.0126823, 0.0511028,
|
||||
-0.0310699, -0.0322141, 0.00996936, 0.0675392, -0.0164277, 0.0930009, -0.037467, 0.0419618, -0.00358901, -0.0309569, -0.0225608,
|
||||
-0.0332198, 0.00102291, 0.108814, -0.0831313, 0.048208, -0.0277542, -0.061584, 0.0721224, -0.0795082, 0.0340047, 0.056139,
|
||||
-0.0166783, -0.0803042, -0.014245, -0.0476374, 0.048495, 0.0378856,
|
||||
};
|
||||
|
||||
int main() {
|
||||
HResult ret;
|
||||
// The resource file must be loaded before it can be used
|
||||
ret = HFLaunchInspireFace("test_res/pack/Pikachu");
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Load Resource error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
HFFeatureHubConfiguration configuration;
|
||||
configuration.primaryKeyMode = HF_PK_AUTO_INCREMENT;
|
||||
configuration.enablePersistence = 1;
|
||||
configuration.persistenceDbPath = "test.db";
|
||||
configuration.searchMode = HF_SEARCH_MODE_EXHAUSTIVE;
|
||||
configuration.searchThreshold = 0.48f;
|
||||
ret = HFFeatureHubDataEnable(configuration);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Enable feature hub error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// std::vector<float> feature(512, 0.0f);
|
||||
|
||||
int64_t result_id = 0;
|
||||
HFFaceFeature feature = {0};
|
||||
feature.data = FT.data();
|
||||
feature.size = FT.size();
|
||||
HFFaceFeatureIdentity identity = {0};
|
||||
identity.feature = &feature;
|
||||
ret = HFFeatureHubInsertFeature(identity, &result_id);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Insert feature error: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// std::vector<float> query_feature(512, 20.0f);
|
||||
HFFaceFeature query_feature = {0};
|
||||
query_feature.data = FT.data();
|
||||
query_feature.size = FT.size();
|
||||
HFloat confidence;
|
||||
HFFaceFeatureIdentity search_result = {0};
|
||||
ret = HFFeatureHubFaceSearch(query_feature, &confidence, &search_result);
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Search feature error: %d", ret);
|
||||
} else {
|
||||
HFLogPrint(HF_LOG_INFO, "Search face feature success, result_id: %d", search_result.id);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
#include <inspireface.h>
|
||||
|
||||
int main() {
|
||||
std::string resourcePath = "test_res/pack/Pikachu";
|
||||
HResult ret = HFReloadInspireFace(resourcePath.c_str());
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Failed to launch InspireFace: %d", ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Switch to another resource
|
||||
ret = HFReloadInspireFace("test_res/pack/Megatron");
|
||||
if (ret != HSUCCEED) {
|
||||
HFLogPrint(HF_LOG_ERROR, "Failed to reload InspireFace: %d", ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user