mirror of
https://github.com/deepinsight/insightface.git
synced 2026-03-23 20:30:17 +00:00
Update inspireface to 1.2.3
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <inspirecv/inspirecv.h>
|
||||
#include <inspireface/inspireface.hpp>
|
||||
|
||||
int main() {
|
||||
INSPIREFACE_CONTEXT->Reload("test_res/pack/Pikachu");
|
||||
// Create session
|
||||
inspire::CustomPipelineParameter param;
|
||||
param.enable_recognition = true;
|
||||
param.enable_liveness = true;
|
||||
param.enable_mask_detect = true;
|
||||
param.enable_face_attribute = true;
|
||||
param.enable_face_quality = true;
|
||||
std::shared_ptr<inspire::Session> session(inspire::Session::CreatePtr(inspire::DETECT_MODE_ALWAYS_DETECT, 1, param, 320));
|
||||
// Prepare image
|
||||
inspirecv::Image img = inspirecv::Image::Create("data.jpg", 3);
|
||||
inspirecv::Image gray_img = img.ToGray();
|
||||
|
||||
// Create image and frame process
|
||||
inspirecv::FrameProcess process =
|
||||
inspirecv::FrameProcess::Create(gray_img.Data(), gray_img.Height(), gray_img.Width(), inspirecv::GRAY, inspirecv::ROTATION_0);
|
||||
auto decode = process.ExecutePreviewImageProcessing(true);
|
||||
decode.Write("decode.jpg");
|
||||
|
||||
// Detect
|
||||
std::vector<inspire::FaceTrackWrap> results;
|
||||
int32_t ret;
|
||||
ret = session->FaceDetectAndTrack(process, results);
|
||||
std::cout << "Face size: " << results.size() << std::endl;
|
||||
for (const auto& result : results) {
|
||||
// Draw face
|
||||
inspirecv::Rect2i rect = inspirecv::Rect2i::Create(result.rect.x, result.rect.y, result.rect.width, result.rect.height);
|
||||
img.DrawRect(rect, inspirecv::Color::Red);
|
||||
}
|
||||
img.Write("result.jpg");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
#include <inspirecv/inspirecv.h>
|
||||
#include <inspireface/inspireface.hpp>
|
||||
#include <inspireface/image_process/nexus_processor/image_processor.h>
|
||||
|
||||
void test_resize(std::unique_ptr<inspire::nexus::ImageProcessor>& processor, int aligned_width) {
|
||||
processor->SetAlignedWidth(aligned_width);
|
||||
// Create image
|
||||
inspirecv::Image img = inspirecv::Image::Create("kun.jpg", 3);
|
||||
// Resize image
|
||||
uint8_t* dst_data = nullptr;
|
||||
int dst_width = 112;
|
||||
int dst_height = 112;
|
||||
processor->Resize(img.Data(), img.Width(), img.Height(), 3, &dst_data, dst_width, dst_height);
|
||||
inspirecv::Image dst_img(dst_width, dst_height, 3, dst_data, false);
|
||||
dst_img.Write("dst_w" + std::to_string(aligned_width) + ".jpg");
|
||||
std::cout << "Save dst image to dst_w" << aligned_width << ".jpg" << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Create image processor
|
||||
auto processor = inspire::nexus::ImageProcessor::Create(inspire::Launch::IMAGE_PROCESSING_RGA);
|
||||
test_resize(processor, 4);
|
||||
test_resize(processor, 16);
|
||||
// wrong aligned width
|
||||
test_resize(processor, 7);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -19,7 +19,8 @@ int main() {
|
||||
db_config.search_mode = inspire::SEARCH_MODE_EXHAUSTIVE;
|
||||
db_config.recognition_threshold = 0.48f;
|
||||
db_config.primary_key_mode = inspire::AUTO_INCREMENT;
|
||||
INSPIREFACE_FEATURE_HUB->EnableHub(db_config);
|
||||
auto ret = INSPIREFACE_FEATURE_HUB->EnableHub(db_config);
|
||||
INSPIREFACE_CHECK_MSG(ret == HSUCCEED, "EnableHub failed");
|
||||
|
||||
// Create a session
|
||||
auto param = inspire::CustomPipelineParameter();
|
||||
@@ -43,6 +44,9 @@ int main() {
|
||||
// Insert face feature into the hub, because the id is INSPIRE_INVALID_ID, so input id is ignored
|
||||
int64_t result_id;
|
||||
INSPIREFACE_FEATURE_HUB->FaceFeatureInsert(feature.embedding, INSPIRE_INVALID_ID, result_id);
|
||||
|
||||
inspire::FaceEmbedding face_feature;
|
||||
INSPIREFACE_FEATURE_HUB->GetFaceFeature(result_id, face_feature);
|
||||
|
||||
// Prepare a photo of the same person for the query
|
||||
auto query_image = inspirecv::Image::Create("test_res/data/bulk/jntm.jpg");
|
||||
@@ -65,9 +69,13 @@ int main() {
|
||||
|
||||
INSPIREFACE_CHECK_MSG(search_result.id == result_id, "Search face feature result id is not equal to the inserted id");
|
||||
|
||||
// Update the face feature
|
||||
INSPIREFACE_FEATURE_HUB->FaceFeatureUpdate(query_feature.embedding, result_id);
|
||||
|
||||
// Remove the face feature
|
||||
INSPIREFACE_FEATURE_HUB->FaceFeatureRemove(result_id);
|
||||
INSPIREFACE_CHECK_MSG(INSPIREFACE_FEATURE_HUB->GetFaceFeatureCount() == 0, "Face feature is not removed");
|
||||
|
||||
|
||||
std::cout << "Remove face feature successfully" << std::endl;
|
||||
|
||||
@@ -76,5 +84,11 @@ int main() {
|
||||
INSPIREFACE_CHECK_MSG(search_result.id == INSPIRE_INVALID_ID, "Search face feature result id is not equal to the inserted id");
|
||||
std::cout << "Query again, search face feature result: " << search_result.id << std::endl;
|
||||
|
||||
|
||||
// Top-k query
|
||||
std::vector<inspire::FaceSearchResult> top_k_results;
|
||||
INSPIREFACE_FEATURE_HUB->SearchFaceFeatureTopK(query_feature.embedding, top_k_results, 10, true);
|
||||
std::cout << "Top-k query result: " << top_k_results.size() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -40,6 +40,10 @@ int main(int argc, char** argv) {
|
||||
ret = session->FaceDetectAndTrack(process, results);
|
||||
INSPIREFACE_CHECK_MSG(ret == 0, "FaceDetectAndTrack failed");
|
||||
|
||||
// Run pipeline for each face
|
||||
ret = session->MultipleFacePipelineProcess(process, param, results);
|
||||
INSPIREFACE_CHECK_MSG(ret == 0, "MultipleFacePipelineProcess failed");
|
||||
|
||||
for (auto& result : results) {
|
||||
std::cout << "result: " << result.trackId << std::endl;
|
||||
std::cout << "quality: " << result.quality[0] << ", " << result.quality[1] << ", " << result.quality[2] << ", " << result.quality[3] << ", "
|
||||
@@ -49,6 +53,11 @@ int main(int argc, char** argv) {
|
||||
image.DrawRect(rect, inspirecv::Color::Red);
|
||||
inspirecv::TransformMatrix trans = inspirecv::TransformMatrix::Create(result.trans.m00, result.trans.m01, result.trans.tx, result.trans.m10, result.trans.m11, result.trans.ty);
|
||||
std::cout << "trans: " << trans.GetInverse() << std::endl;
|
||||
|
||||
std::vector<inspirecv::Point2f> landmark = session->GetFaceDenseLandmark(result);
|
||||
for (auto& point : landmark) {
|
||||
image.DrawCircle(point.As<int>(), 2, inspirecv::Color::Green);
|
||||
}
|
||||
}
|
||||
image.Write("result.jpg");
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <inspirecv/inspirecv.h>
|
||||
#include <inspireface/inspireface.hpp>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 3) {
|
||||
std::cout << "Usage: " << argv[0] << " <model_path> <image_path>" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string model_path = argv[1];
|
||||
std::string image_path = argv[2];
|
||||
|
||||
// Global init(only once)
|
||||
INSPIREFACE_CONTEXT->Reload(model_path);
|
||||
|
||||
// Create image and frame process
|
||||
inspirecv::Image image = inspirecv::Image::Create(image_path);
|
||||
inspirecv::FrameProcess process =
|
||||
inspirecv::FrameProcess::Create(image.Data(), image.Height(), image.Width(), inspirecv::BGR, inspirecv::ROTATION_0);
|
||||
|
||||
// Create session
|
||||
inspire::CustomPipelineParameter param;
|
||||
param.enable_recognition = true;
|
||||
param.enable_liveness = true;
|
||||
param.enable_mask_detect = true;
|
||||
param.enable_face_attribute = true;
|
||||
param.enable_face_quality = true;
|
||||
std::shared_ptr<inspire::Session> session(inspire::Session::CreatePtr(inspire::DETECT_MODE_LIGHT_TRACK, 100, param, 640));
|
||||
session->SetTrackPreviewSize(640);
|
||||
session->SetTrackModeDetectInterval(10);
|
||||
|
||||
INSPIREFACE_CHECK_MSG(session != nullptr, "Session is not valid");
|
||||
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
||||
// Detect and track
|
||||
std::vector<inspire::FaceTrackWrap> results;
|
||||
int32_t ret;
|
||||
// Start time
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
ret = session->FaceDetectAndTrack(process, results);
|
||||
INSPIREFACE_CHECK_MSG(ret == 0, "FaceDetectAndTrack failed");
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
// End time
|
||||
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
||||
std::cout << i << " MultipleFacePipelineProcess: " << duration.count() / 1000.0 << " ms" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user