Update inspireface to 1.2.0

This commit is contained in:
Jingyu
2025-03-25 00:51:26 +08:00
parent 977ea6795b
commit ca64996b84
388 changed files with 28584 additions and 13036 deletions

View File

@@ -1,11 +1,12 @@
//
// Created by tunm on 2023/9/23.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include "opencv2/opencv.hpp"
#include "inspireface/middleware/costman.h"
#include "middleware/inference_helper/customized/rknn_adapter.h"
#include "middleware/inference_wrapper/customized/rknn_adapter.h"
#include "inspireface/feature_hub/simd.h"
#include <memory>
#include "inspireface/recognition_module/extract/extract.h"
@@ -15,16 +16,16 @@ using namespace inspire;
int main() {
std::vector<std::string> names = {
"test_res/images/test_data/0.jpg",
"test_res/images/test_data/1.jpg",
"test_res/images/test_data/2.jpg",
"test_res/images/test_data/0.jpg",
"test_res/images/test_data/1.jpg",
"test_res/images/test_data/2.jpg",
};
InspireArchive loader("test_res/pack/test_zip_rec");
{
InspireModel model;
loader.LoadModel("feature", model);
auto net = std::make_shared<RKNNAdapter>();
net->Initialize((unsigned char* )model.buffer, model.bufferSize);
net->Initialize((unsigned char *)model.buffer, model.bufferSize);
net->setOutputsWantFloat(1);
EmbeddedList list;
@@ -37,27 +38,26 @@ int main() {
auto out = net->GetOutputData(0);
auto dims = net->GetOutputTensorSize(0);
// for (int i = 0; i < dims.size(); ++i) {
// LOGD("%lu", dims[i]);
// }
//
for (int i = 0; i < 512; ++i) {
std::cout << out[i] << ", ";
}
std::cout << std::endl;
// for (int i = 0; i < dims.size(); ++i) {
// LOGD("%lu", dims[i]);
// }
//
for (int i = 0; i < 512; ++i) {
std::cout << out[i] << ", ";
}
std::cout << std::endl;
Embedded emb;
for (int j = 0; j < 512; ++j) {
emb.push_back(out[j]);
}
list.push_back(emb);
}
for (int i = 0; i < list.size(); ++i) {
auto &embedded = list[i];
float mse = 0.0f;
for (const auto &one: embedded) {
for (const auto &one : embedded) {
mse += one * one;
}
mse = sqrt(mse);
@@ -76,24 +76,26 @@ int main() {
Configurable param;
param.set<int>("model_index", 0);
param.set<std::string>("input_layer", "input");
param.set<std::vector<std::string>>("outputs_layers", {"267", });
param.set<std::vector<std::string>>("outputs_layers", {
"267",
});
param.set<std::vector<int>>("input_size", {112, 112});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
param.set<bool>("swap_color", true); // RK requires rgb input
param.set<bool>("swap_color", true); // RK requires rgb input
m_extract_ = std::make_shared<Extract>();
InspireModel model;
loader.LoadModel("feature", model);
m_extract_->loadData(model, InferenceHelper::kRknn);
m_extract_->loadData(model, InferenceWrapper::INFER_RKNN);
cv::Mat image = cv::imread(names[0]);
// cv::Mat rgb;
// cv::cvtColor(image, rgb, cv::COLOR_BGR2RGB);
// cv::Mat rgb;
// cv::cvtColor(image, rgb, cv::COLOR_BGR2RGB);
auto feat = m_extract_->GetFaceFeature(image);
for (int i = 0; i < 512; ++i) {
std::cout << feat[i] << ", ";
@@ -101,7 +103,6 @@ int main() {
std::cout << std::endl;
}
LOGD("End");
return 0;

View File

@@ -1,8 +1,9 @@
//
// Created by Tunm-Air13 on 2023/9/20.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include "opencv2/opencv.hpp"
//#include "inspireface/middleware/model_loader/model_loader.h"
// #include "inspireface/middleware/model_loader/model_loader.h"
#include "inspireface/track_module/face_detect/all.h"
#include "inspireface/middleware/costman.h"
@@ -30,8 +31,7 @@ int main() {
std::shared_ptr<FaceDetect> m_face_detector_;
m_face_detector_ = std::make_shared<FaceDetect>(320);
m_face_detector_->loadData(model, InferenceHelper::kRknn);
m_face_detector_->loadData(model, InferenceWrapper::INFER_RKNN);
// Load a image
cv::Mat image = cv::imread("test_res/images/face_sample.png");
@@ -42,11 +42,10 @@ int main() {
LOGD("Faces: %ld", locs.size());
for (auto &loc: locs) {
for (auto &loc : locs) {
cv::rectangle(image, cv::Point2f(loc.x1, loc.y1), cv::Point2f(loc.x2, loc.y2), cv::Scalar(0, 0, 255), 3);
}
cv::imwrite("det.jpg", image);
return 0;
}

View File

@@ -1,7 +1,7 @@
//
// Created by tunm on 2023/9/21.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include "opencv2/opencv.hpp"
@@ -15,40 +15,41 @@ using namespace inspire;
std::shared_ptr<InspireArchive> loader;
void rec_function() {
std::shared_ptr<Extract> m_extract_;
Configurable param;
// param.set<int>("model_index", ModelIndex::_03_extract);
// param.set<int>("model_index", ModelIndex::_03_extract);
param.set<std::string>("input_layer", "input");
param.set<std::vector<std::string>>("outputs_layers", {"267", });
param.set<std::vector<std::string>>("outputs_layers", {
"267",
});
param.set<std::vector<int>>("input_size", {112, 112});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
param.set<bool>("swap_color", true); // RK requires rgb input
param.set<bool>("swap_color", true); // RK requires rgb input
m_extract_ = std::make_shared<Extract>();
InspireModel model;
loader->LoadModel("feature", model);
m_extract_->loadData(model, InferenceHelper::kRknn);
m_extract_->loadData(model, InferenceWrapper::INFER_RKNN);
loader.reset();
std::vector<std::string> files = {
"test_res/images/test_data/0.jpg",
"test_res/images/test_data/1.jpg",
"test_res/images/test_data/2.jpg",
"test_res/images/test_data/0.jpg",
"test_res/images/test_data/1.jpg",
"test_res/images/test_data/2.jpg",
};
EmbeddedList embedded_list;
for (int i = 0; i < files.size(); ++i) {
auto warped = cv::imread(files[i]);
Timer timer;
auto emb = (*m_extract_)(warped);
LOGD("耗时: %f", timer.GetCostTimeUpdate());
LOGD("cost: %f", timer.GetCostTimeUpdate());
embedded_list.push_back(emb);
LOGD("%lu", emb.size());
}
@@ -63,26 +64,21 @@ void rec_function() {
LOGD("0 vs 2 : %f", _0v2);
LOGD("1 vs 2 : %f", _1v2);
// LOGD("size: %lu", embedded_list.size());
// LOGD("num of vector: %lu", embedded_list[2].size());
//
// float _0v1 = simd_dot(embedded_list[0].data(), embedded_list[1].data(), 512);
// float _0v2 = simd_dot(embedded_list[0].data(), embedded_list[2].data(), 512);
// float _1v2 = simd_dot(embedded_list[1].data(), embedded_list[2].data(), 512);
// LOGD("0 vs 1 : %f", _0v1);
// LOGD("0 vs 2 : %f", _0v2);
// LOGD("1 vs 2 : %f", _1v2);
// LOGD("size: %lu", embedded_list.size());
// LOGD("num of vector: %lu", embedded_list[2].size());
//
// float _0v1 = simd_dot(embedded_list[0].data(), embedded_list[1].data(), 512);
// float _0v2 = simd_dot(embedded_list[0].data(), embedded_list[2].data(), 512);
// float _1v2 = simd_dot(embedded_list[1].data(), embedded_list[2].data(), 512);
// LOGD("0 vs 1 : %f", _0v1);
// LOGD("0 vs 2 : %f", _0v2);
// LOGD("1 vs 2 : %f", _1v2);
}
int main() {
loader = std::make_shared<InspireArchive>();
loader->ReLoad("test_res/pack/Gundam_RV1109");
rec_function();
return 0;

View File

@@ -1,6 +1,7 @@
//
// Created by Tunm-Air13 on 2023/9/21.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include "opencv2/opencv.hpp"
#include "inspireface/track_module/face_detect/all.h"
@@ -16,26 +17,25 @@ using namespace inspire;
InspireArchive loader;
void test_rnet() {
std::shared_ptr<RNet> m_rnet_;
Configurable param;
// param.set<int>("model_index", ModelIndex::_04_refine_net);
// param.set<int>("model_index", ModelIndex::_04_refine_net);
param.set<std::string>("input_layer", "input_1");
param.set<std::vector<std::string>>("outputs_layers", {"conv5-1/Softmax", "conv5-2/BiasAdd"});
param.set<std::vector<int>>("input_size", {24, 24});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<bool>("swap_color", true); // RGB mode
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<bool>("swap_color", true); // RGB mode
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
InspireModel model;
loader.LoadModel("refine_net", model);
m_rnet_ = std::make_shared<RNet>();
m_rnet_->loadData(model, InferenceHelper::kRknn);
m_rnet_->loadData(model, InferenceWrapper::INFER_RKNN);
{
// Load a image
@@ -56,28 +56,29 @@ void test_rnet() {
LOGD("cost: %f", timer.GetCostTimeUpdate());
LOGD("non face: %f", score);
}
}
void test_mask() {
Configurable param;
// param.set<int>("model_index", ModelIndex::_05_mask);
// param.set<int>("model_index", ModelIndex::_05_mask);
param.set<std::string>("input_layer", "input_1");
param.set<std::vector<std::string>>("outputs_layers", {"activation_1/Softmax",});
param.set<std::vector<std::string>>("outputs_layers", {
"activation_1/Softmax",
});
param.set<std::vector<int>>("input_size", {96, 96});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<bool>("swap_color", true); // RGB mode
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<bool>("swap_color", true); // RGB mode
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
std::shared_ptr<MaskPredict> m_mask_predict_;
m_mask_predict_ = std::make_shared<MaskPredict>();
InspireModel model;
loader.LoadModel("mask_detect", model);
m_mask_predict_->loadData(model, InferenceHelper::kRknn);
m_mask_predict_->loadData(model, InferenceWrapper::INFER_RKNN);
{
// Load a image
@@ -98,32 +99,33 @@ void test_mask() {
LOGD("cost: %f", timer.GetCostTimeUpdate());
LOGD("maskless: %f", score);
}
}
void test_quality() {
Configurable param;
// param.set<int>("model_index", ModelIndex::_07_pose_q_fp16);
// param.set<int>("model_index", ModelIndex::_07_pose_q_fp16);
param.set<std::string>("input_layer", "data");
param.set<std::vector<std::string>>("outputs_layers", {"fc1", });
param.set<std::vector<std::string>>("outputs_layers", {
"fc1",
});
param.set<std::vector<int>>("input_size", {96, 96});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<bool>("swap_color", true); // RGB mode
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<bool>("swap_color", true); // RGB mode
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
std::shared_ptr<FacePoseQuality> m_face_quality_;
m_face_quality_ = std::make_shared<FacePoseQuality>();
InspireModel model;
loader.LoadModel("pose_quality", model);
m_face_quality_->loadData(model, InferenceHelper::kRknn);
m_face_quality_->loadData(model, InferenceWrapper::INFER_RKNN);
{
std::vector<std::string> names = {
"test_res/images/test_data/p3.jpg",
// "test_res/images/test_data/p1.jpg",
"test_res/images/test_data/p3.jpg",
// "test_res/images/test_data/p1.jpg",
};
for (int i = 0; i < names.size(); ++i) {
LOGD("Image: %s", names[i].c_str());
@@ -131,9 +133,9 @@ void test_quality() {
Timer timer;
auto pose_res = (*m_face_quality_)(image);
LOGD("质量cost: %f", timer.GetCostTimeUpdate());
LOGD("quality cost: %f", timer.GetCostTimeUpdate());
for (auto &p: pose_res.lmk) {
for (auto &p : pose_res.lmk) {
cv::circle(image, p, 0, cv::Scalar(0, 0, 255), 2);
}
cv::imwrite("pose.jpg", image);
@@ -141,22 +143,21 @@ void test_quality() {
LOGD("yam: %f", pose_res.yaw);
LOGD("roll: %f", pose_res.roll);
for (auto q: pose_res.lmk_quality) {
for (auto q : pose_res.lmk_quality) {
std::cout << q << ", ";
}
std::cout << std::endl;
}
}
}
void test_landmark_mnn() {
Configurable param;
// param.set<int>("model_index", ModelIndex::_01_lmk);
// param.set<int>("model_index", ModelIndex::_01_lmk);
param.set<std::string>("input_layer", "input_1");
param.set<std::vector<std::string>>("outputs_layers", {"prelu1/add", });
param.set<std::vector<std::string>>("outputs_layers", {
"prelu1/add",
});
param.set<std::vector<int>>("input_size", {112, 112});
param.set<std::vector<float>>("mean", {127.5f, 127.5f, 127.5f});
param.set<std::vector<float>>("norm", {0.0078125f, 0.0078125f, 0.0078125f});
@@ -184,30 +185,28 @@ void test_landmark_mnn() {
}
cv::imwrite("lmk.jpg", image);
}
void test_landmark() {
Configurable param;
// param.set<int>("model_index", ModelIndex::_01_lmk);
// param.set<int>("model_index", ModelIndex::_01_lmk);
param.set<std::string>("input_layer", "input_1");
param.set<std::vector<std::string>>("outputs_layers", {"prelu1/add", });
param.set<std::vector<std::string>>("outputs_layers", {
"prelu1/add",
});
param.set<std::vector<int>>("input_size", {112, 112});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
std::shared_ptr<FaceLandmark> m_landmark_predictor_;
m_landmark_predictor_ = std::make_shared<FaceLandmark>(112);
InspireModel model;
loader.LoadModel("landmark", model);
m_landmark_predictor_->loadData(model, InferenceHelper::kRknn);
m_landmark_predictor_->loadData(model, InferenceWrapper::INFER_RKNN);
cv::Mat image = cv::imread("test_res/images/test_data/0.jpg");
cv::resize(image, image, cv::Size(112, 112));
@@ -226,24 +225,22 @@ void test_landmark() {
}
cv::imwrite("lmk.jpg", image);
}
void test_liveness() {
Configurable param;
// param.set<int>("model_index", ModelIndex::_06_msafa27);
// param.set<int>("model_index", ModelIndex::_06_msafa27);
param.set<std::string>("input_layer", "data");
param.set<std::vector<std::string>>("outputs_layers", {"556",});
param.set<std::vector<std::string>>("outputs_layers", {
"556",
});
param.set<std::vector<int>>("input_size", {80, 80});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<bool>("swap_color", false); // RGB mode
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<bool>("swap_color", false); // RGB mode
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
std::shared_ptr<RBGAntiSpoofing> m_rgb_anti_spoofing_;
@@ -251,15 +248,11 @@ void test_liveness() {
InspireModel model;
loader.LoadModel("rgb_anti_spoofing", model);
m_rgb_anti_spoofing_ = std::make_shared<RBGAntiSpoofing>(80, true);
m_rgb_anti_spoofing_->loadData(model, InferenceHelper::kRknn);
m_rgb_anti_spoofing_->loadData(model, InferenceWrapper::INFER_RKNN);
std::vector<std::string> names = {
"test_res/images/test_data/real.jpg",
"test_res/images/test_data/fake.jpg",
"test_res/images/test_data/live.jpg",
"test_res/images/test_data/ttt.jpg",
"test_res/images/test_data/w.jpg",
"test_res/images/test_data/w2.jpg",
"test_res/images/test_data/real.jpg", "test_res/images/test_data/fake.jpg", "test_res/images/test_data/live.jpg",
"test_res/images/test_data/ttt.jpg", "test_res/images/test_data/w.jpg", "test_res/images/test_data/w2.jpg",
};
for (int i = 0; i < names.size(); ++i) {
@@ -269,7 +262,6 @@ void test_liveness() {
LOGD("cost: %f", timer.GetCostTimeUpdate());
LOGD("%s : %f", names[i].c_str(), score);
}
}
int test_liveness_ctx() {
@@ -278,13 +270,9 @@ int test_liveness_ctx() {
FaceContext ctx;
ctx.Configuration("test_res/pack/Gundam_RV1109", inspire::DETECT_MODE_IMAGE, 3, parameter);
std::vector<std::string> names = {
"test_res/images/test_data/real.jpg",
"test_res/images/test_data/fake.jpg",
"test_res/images/test_data/live.jpg",
"test_res/images/test_data/ttt.jpg",
"test_res/images/test_data/w.jpg",
"test_res/images/test_data/w2.jpg",
"test_res/images/test_data/bb.png",
"test_res/images/test_data/real.jpg", "test_res/images/test_data/fake.jpg", "test_res/images/test_data/live.jpg",
"test_res/images/test_data/ttt.jpg", "test_res/images/test_data/w.jpg", "test_res/images/test_data/w2.jpg",
"test_res/images/test_data/bb.png",
};
for (int i = 0; i < names.size(); ++i) {
@@ -293,22 +281,21 @@ int test_liveness_ctx() {
LOGD("%s : %f", names[i].c_str(), score);
}
return 0;
}
int main() {
loader.ReLoad("test_res/pack/Gundam_RV1109");
// test_rnet();
// test_rnet();
// test_mask();
// test_mask();
// test_quality();
// test_quality();
// test_landmark_mnn();
// test_landmark_mnn();
// test_landmark();
// test_landmark();
test_liveness();
test_liveness_ctx();

View File

@@ -1,6 +1,7 @@
//
// Created by Tunm-Air13 on 2023/9/22.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include "opencv2/opencv.hpp"
@@ -12,18 +13,14 @@ using namespace inspire;
int main() {
FaceContext ctx;
CustomPipelineParameter param;
int32_t ret = ctx.Configuration(
"test_res/pack/Gundam_RV1109",
DetectMode::DETECT_MODE_VIDEO,
3,
param);
int32_t ret = ctx.Configuration("test_res/pack/Gundam_RV1109", DetectMode::DETECT_MODE_VIDEO, 3, param);
if (ret != HSUCCEED) {
LOGE("Initiate error");
}
cv::Mat frame;
std::string imageFolder = "test_res/video_frames/";
// auto video_frame_num = 10;
// auto video_frame_num = 10;
auto video_frame_num = 288;
for (int i = 0; i < video_frame_num; ++i) {
auto index = i + 1;
@@ -45,7 +42,7 @@ int main() {
LOGD("track id: %d", ctx.GetTrackingFaceList()[0].GetTrackingId());
auto &face = ctx.GetTrackingFaceList()[0];
for (auto &p: face.landmark_) {
for (auto &p : face.landmark_) {
cv::circle(frame, p, 0, cv::Scalar(0, 0, 255), 3);
}
@@ -55,7 +52,8 @@ int main() {
cv::rectangle(frame, rect, cv::Scalar(0, 0, 255), 2, 1);
std::string text = "ID: " + std::to_string(track_id) + " Count: " + std::to_string(track_count) + " Cf: " + std::to_string(face.GetConfidence());
std::string text =
"ID: " + std::to_string(track_id) + " Count: " + std::to_string(track_count) + " Cf: " + std::to_string(face.GetConfidence());
cv::Point text_position(rect.x, rect.y - 10);
int font_face = cv::FONT_HERSHEY_SIMPLEX;
@@ -70,7 +68,5 @@ int main() {
cv::imwrite(saveFile.str(), frame);
}
return 0;
}

View File

@@ -1,6 +1,7 @@
//
// Created by tunm on 2024/4/6.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include <iostream>
#include "track_module/face_track.h"
#include "inspireface/feature_hub/face_recognition.h"
@@ -8,7 +9,7 @@
#include "track_module/face_track.h"
#include "pipeline_module/face_pipeline.h"
#include "inspireface/feature_hub/face_recognition.h"
#include "middleware/inference_helper/customized/rknn_adapter.h"
#include "middleware/inference_wrapper/customized/rknn_adapter.h"
using namespace inspire;
@@ -16,9 +17,9 @@ int main() {
InspireArchive archive;
auto ret = archive.ReLoad("test_res/pack/Gundam_RV1109");
LOGD("ReLoad %d", ret);
// InspireModel model;
// ret = archive.LoadModel("mask_detect", model);
// LOGD("LoadModel %d", ret);
// InspireModel model;
// ret = archive.LoadModel("mask_detect", model);
// LOGD("LoadModel %d", ret);
FaceTrack track;
ret = track.Configuration(archive);
@@ -28,11 +29,10 @@ int main() {
FaceRecognition recognition(archive, true);
// std::shared_ptr<RKNNAdapter> rknet = std::make_shared<RKNNAdapter>();
// ret = rknet->Initialize((unsigned char* )model.buffer, model.bufferSize);
//
// LOGD("LoadModel %d", ret);
// std::shared_ptr<RKNNAdapter> rknet = std::make_shared<RKNNAdapter>();
// ret = rknet->Initialize((unsigned char* )model.buffer, model.bufferSize);
//
// LOGD("LoadModel %d", ret);
return 0;
}

View File

@@ -1,6 +1,7 @@
//
// Created by tunm on 2024/4/6.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include <iostream>
#include "track_module/face_track.h"
#include "inspireface/recognition_module/face_feature_extraction.h"
@@ -13,7 +14,7 @@ int main() {
archive.ReLoad("test_res/pack/Gundam_RV1109");
FaceTrack track;
// FaceRecognition recognition(archive, true);
// FaceRecognition recognition(archive, true);
auto ret = track.Configuration(archive);
INSPIRE_LOGD("ret=%d", ret);
@@ -29,13 +30,13 @@ int main() {
track.UpdateStream(stream, true);
// if (!track.trackingFace.empty()) {
// auto const &face = track.trackingFace[0];
// cv::rectangle(image, face.GetRectSquare(), cv::Scalar(200, 0, 20), 2);
// }
//
// cv::imshow("w", image);
// cv::waitKey(0);
// if (!track.trackingFace.empty()) {
// auto const &face = track.trackingFace[0];
// cv::rectangle(image, face.GetRectSquare(), cv::Scalar(200, 0, 20), 2);
// }
//
// cv::imshow("w", image);
// cv::waitKey(0);
InspireModel model;
ret = archive.LoadModel("mask_detect", model);

View File

@@ -1,19 +1,19 @@
//
// Created by Tunm-Air13 on 2023/9/11.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include <iostream>
#include "opencv2/opencv.hpp"
#include "log.h"
#include "inspireface/feature_hub/simd.h"
//#include <Eigen/Dense>
// #include <Eigen/Dense>
using namespace inspire;
int main() {
int N = 512;
int vectorSize = 512; // Vector length
int vectorSize = 512; // Vector length
{
// Create an Nx512 matrix of type CV_32F and fill it with random numbers
cv::Mat mat(N, vectorSize, CV_32F);
@@ -26,14 +26,13 @@ int main() {
std::cout << mat.size << std::endl;
std::cout << one.size << std::endl;
auto timeStart = (double) cv::getTickCount();
auto timeStart = (double)cv::getTickCount();
cv::Mat cosineSimilarities;
cv::gemm(mat, one, 1, cv::Mat(), 0, cosineSimilarities);
double cost = ((double) cv::getTickCount() - timeStart) / cv::getTickFrequency() * 1000;
double cost = ((double)cv::getTickCount() - timeStart) / cv::getTickFrequency() * 1000;
INSPIRE_LOGD("Matrix COST: %f", cost);
}
{
@@ -51,33 +50,33 @@ int main() {
vectorOne[i] = static_cast<float>(std::rand()) / RAND_MAX;
}
auto timeStart = (double) cv::getTickCount();
auto timeStart = (double)cv::getTickCount();
// dot
for (const auto &v: matrix) {
for (const auto &v : matrix) {
simd_dot(v.data(), vectorOne.data(), vectorSize);
}
double cost = ((double) cv::getTickCount() - timeStart) / cv::getTickFrequency() * 1000;
double cost = ((double)cv::getTickCount() - timeStart) / cv::getTickFrequency() * 1000;
INSPIRE_LOGD("Vector COST: %f", cost);
}
// {
// Eigen::initParallel();
// Eigen::MatrixXf mat(N, vectorSize);
// mat = Eigen::MatrixXf::Random(N, vectorSize);
//
// std::cout << mat.rows() << " x " << mat.cols() << std::endl;
//
//
// Eigen::VectorXf one(vectorSize);
// one = Eigen::VectorXf::Random(vectorSize);
//
// auto timeStart = (double) cv::getTickCount();
// Eigen::VectorXf result = mat * one;
//
// double cost = ((double) cv::getTickCount() - timeStart) / cv::getTickFrequency() * 1000;
// LOGD("Eigen COST: %f", cost);
// }
// {
// Eigen::initParallel();
// Eigen::MatrixXf mat(N, vectorSize);
// mat = Eigen::MatrixXf::Random(N, vectorSize);
//
// std::cout << mat.rows() << " x " << mat.cols() << std::endl;
//
//
// Eigen::VectorXf one(vectorSize);
// one = Eigen::VectorXf::Random(vectorSize);
//
// auto timeStart = (double) cv::getTickCount();
// Eigen::VectorXf result = mat * one;
//
// double cost = ((double) cv::getTickCount() - timeStart) / cv::getTickFrequency() * 1000;
// LOGD("Eigen COST: %f", cost);
// }
return 0;
}

View File

@@ -1,6 +1,7 @@
//
// Created by tunm on 2023/10/3.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include <iostream>
#include "inspireface/c_api/inspireface.h"
#include "opencv2/opencv.hpp"
@@ -8,7 +9,7 @@
using namespace inspire;
std::string basename(const std::string& path) {
std::string basename(const std::string &path) {
size_t lastSlash = path.find_last_of("/\\"); // Take into account the cross-platform separator
if (lastSlash == std::string::npos) {
return path; // Without the slash, the entire path is the base name
@@ -30,7 +31,7 @@ int compare() {
parameter.enable_mask_detect = 1;
parameter.enable_recognition = 1;
parameter.enable_face_quality = 1;
HF_DetectMode detMode = HF_DETECT_MODE_IMAGE; // Selecting the image mode is always detection
HF_DetectMode detMode = HF_DETECT_MODE_IMAGE; // Selecting the image mode is always detection
HContextHandle session;
ret = HF_CreateFaceContextFromResourceFile(path, parameter, detMode, 3, &session);
if (ret != HSUCCEED) {
@@ -38,13 +39,13 @@ int compare() {
}
std::vector<std::string> names = {
"/Users/tunm/datasets/lfw_funneled/Abel_Pacheco/Abel_Pacheco_0001.jpg",
"/Users/tunm/datasets/lfw_funneled/Abel_Pacheco/Abel_Pacheco_0004.jpg",
"/Users/tunm/datasets/lfw_funneled/Abel_Pacheco/Abel_Pacheco_0001.jpg",
"/Users/tunm/datasets/lfw_funneled/Abel_Pacheco/Abel_Pacheco_0004.jpg",
};
HInt32 featureNum;
HF_GetFeatureLength(&featureNum);
INSPIRE_LOGD("Feature length: %d", featureNum);
HFloat featuresCache[names.size()][featureNum]; // Store the cached vector
HFloat featuresCache[names.size()][featureNum]; // Store the cached vector
for (int i = 0; i < names.size(); ++i) {
auto &name = names[i];
@@ -63,7 +64,7 @@ int compare() {
HImageHandle imageSteamHandle;
ret = HF_CreateImageStream(&imageData, &imageSteamHandle);
if (ret == HSUCCEED) {
INSPIRE_LOGD("image handle: %ld", (long )imageSteamHandle);
INSPIRE_LOGD("image handle: %ld", (long)imageSteamHandle);
}
HF_MultipleFaceData multipleFaceData = {0};
@@ -71,9 +72,11 @@ int compare() {
INSPIRE_LOGD("Number of faces detected: %d", multipleFaceData.detectedNum);
for (int i = 0; i < multipleFaceData.detectedNum; ++i) {
cv::Rect rect = cv::Rect(multipleFaceData.rects[i].x, multipleFaceData.rects[i].y, multipleFaceData.rects[i].width, multipleFaceData.rects[i].height);
cv::Rect rect =
cv::Rect(multipleFaceData.rects[i].x, multipleFaceData.rects[i].y, multipleFaceData.rects[i].width, multipleFaceData.rects[i].height);
cv::rectangle(image, rect, cv::Scalar(0, 255, 200), 2);
INSPIRE_LOGD("%d, track_id: %d, pitch: %f, yaw: %f, roll: %f", i, multipleFaceData.trackIds[i], multipleFaceData.angles.pitch[i], multipleFaceData.angles.yaw[i], multipleFaceData.angles.roll[i]);
INSPIRE_LOGD("%d, track_id: %d, pitch: %f, yaw: %f, roll: %f", i, multipleFaceData.trackIds[i], multipleFaceData.angles.pitch[i],
multipleFaceData.angles.yaw[i], multipleFaceData.angles.roll[i]);
INSPIRE_LOGD("token size: %d", multipleFaceData.tokens->size);
}
#ifndef DISABLE_GUI
@@ -89,16 +92,16 @@ int compare() {
return -1;
}
// for (int j = 0; j < 512; ++j) {
// std::cout << featuresCache[0][j] << ", ";
// }
// std::cout << std::endl;
// for (int j = 0; j < 512; ++j) {
// std::cout << featuresCache[0][j] << ", ";
// }
// std::cout << std::endl;
// HSize size;
// HF_GetFaceBasicTokenSize(&size);
// LOGD("in size: %ld", size);
//
// LOGD("o size %d", multipleFaceData.tokens[0].size);
// HSize size;
// HF_GetFaceBasicTokenSize(&size);
// LOGD("in size: %ld", size);
//
// LOGD("o size %d", multipleFaceData.tokens[0].size);
HBuffer buffer[multipleFaceData.tokens[0].size];
HF_CopyFaceBasicToken(multipleFaceData.tokens[0], buffer, multipleFaceData.tokens[0].size);
@@ -108,7 +111,7 @@ int compare() {
token.data = buffer;
HFloat quality;
// ret = HF_FaceQualityDetect(session, multipleFaceData.tokens[0], &quality);
// ret = HF_FaceQualityDetect(session, multipleFaceData.tokens[0], &quality);
ret = HF_FaceQualityDetect(session, token, &quality);
INSPIRE_LOGD("RET : %d", ret);
INSPIRE_LOGD("Q: %f", quality);
@@ -120,7 +123,6 @@ int compare() {
} else {
INSPIRE_LOGE("image release error: %ld", ret);
}
}
HFloat compResult;
@@ -147,7 +149,6 @@ int compare() {
int search() {
HResult ret;
// 初始化context
HString path = "test_res/pack/Pikachu";
HF_ContextCustomParameter parameter = {0};
parameter.enable_liveness = 1;
@@ -185,7 +186,7 @@ int search() {
HImageHandle imageSteamHandle;
ret = HF_CreateImageStream(&imageData, &imageSteamHandle);
if (ret != HSUCCEED) {
INSPIRE_LOGE("image handle error: %ld", (long )imageSteamHandle);
INSPIRE_LOGE("image handle error: %ld", (long)imageSteamHandle);
return -1;
}
@@ -214,16 +215,15 @@ int search() {
ret = HF_FeatureHubInsertFeature(identity);
if (ret != HSUCCEED) {
INSPIRE_LOGE("插入失败: %ld", ret);
INSPIRE_LOGE("Insert failed: %ld", ret);
return -1;
}
// // 在插入一次测试一下重复操作问题
// ret = HF_FeaturesGroupInsertFeature(session, identity);
// if (ret != HSUCCEED) {
// LOGE("不能重复id插入: %ld", ret);
// }
// // Test duplicate insertion operation
// ret = HF_FeaturesGroupInsertFeature(session, identity);
// if (ret != HSUCCEED) {
// INSPIRE_LOGE("Cannot insert duplicate ID: %ld", ret);
// }
delete[] tagName;
@@ -247,7 +247,7 @@ int search() {
HImageHandle imageSteamHandle;
ret = HF_CreateImageStream(&imageData, &imageSteamHandle);
if (ret != HSUCCEED) {
INSPIRE_LOGE("image handle error: %ld", (long )imageSteamHandle);
INSPIRE_LOGE("image handle error: %ld", (long)imageSteamHandle);
return -1;
}
HF_MultipleFaceData multipleFaceData = {0};
@@ -265,10 +265,10 @@ int search() {
return -1;
}
// ret = HF_FaceContextFeatureRemove(session, 3);
// if (ret != HSUCCEED) {
// LOGE("delete failed: %ld", ret);
// }
// ret = HF_FaceContextFeatureRemove(session, 3);
// if (ret != HSUCCEED) {
// LOGE("delete failed: %ld", ret);
// }
std::string newName = "Six";
char *newTagName = new char[newName.size() + 1];
@@ -283,10 +283,9 @@ int search() {
}
delete[] newTagName;
HF_FaceFeatureIdentity searchIdentity = {0};
// HF_FaceFeature featureSearched = {0};
// searchIdentity.feature = &featureSearched;
// HF_FaceFeature featureSearched = {0};
// searchIdentity.feature = &featureSearched;
HFloat confidence;
ret = HF_FeatureHubFaceSearch(feature, &confidence, &searchIdentity);
if (ret != HSUCCEED) {
@@ -298,7 +297,6 @@ int search() {
INSPIRE_LOGD("The matched tag: %s", searchIdentity.tag);
INSPIRE_LOGD("The matched customId: %d", searchIdentity.customId);
// Face Pipeline
ret = HF_MultipleFacePipelineProcess(session, imageSteamHandle, &multipleFaceData, parameter);
if (ret != HSUCCEED) {
@@ -331,7 +329,6 @@ int search() {
HF_FeatureHubViewDBTable();
HF_FaceFeatureIdentity identity;
ret = HF_FeatureHubGetFaceIdentity(100, &identity);
if (ret != HSUCCEED) {
@@ -350,47 +347,44 @@ int search() {
}
int opiton() {
// HInt32 mask = HF_ENABLE_FACE_RECOGNITION | HF_ENABLE_LIVENESS;
// HInt32 mask = HF_ENABLE_FACE_RECOGNITION | HF_ENABLE_LIVENESS;
return 0;
}
int main() {
HResult ret;
// {
// // 测试ImageStream
// cv::Mat image = cv::imread("test_res/images/kun.jpg");
// HF_ImageData imageData = {0};
// imageData.data = image.data;
// imageData.height = image.rows;
// imageData.width = image.cols;
// imageData.rotation = CAMERA_ROTATION_0;
// imageData.format = STREAM_BGR;
//
// HImageHandle imageSteamHandle;
// ret = HF_CreateImageStream(&imageData, &imageSteamHandle);
// if (ret == HSUCCEED) {
// LOGD("image handle: %ld", (long )imageSteamHandle);
// }
// HF_DeBugImageStreamImShow(imageSteamHandle);
//
// ret = HF_ReleaseImageStream(imageSteamHandle);
// if (ret == HSUCCEED) {
// imageSteamHandle = nullptr;
// LOGD("image released");
// } else {
// LOGE("image release error: %ld", ret);
// }
//
// }
// {
// // TestImageStream
// cv::Mat image = cv::imread("test_res/images/kun.jpg");
// HF_ImageData imageData = {0};
// imageData.data = image.data;
// imageData.height = image.rows;
// imageData.width = image.cols;
// imageData.rotation = CAMERA_ROTATION_0;
// imageData.format = STREAM_BGR;
//
// HImageHandle imageSteamHandle;
// ret = HF_CreateImageStream(&imageData, &imageSteamHandle);
// if (ret == HSUCCEED) {
// LOGD("image handle: %ld", (long )imageSteamHandle);
// }
// HF_DeBugImageStreamImShow(imageSteamHandle);
//
// ret = HF_ReleaseImageStream(imageSteamHandle);
// if (ret == HSUCCEED) {
// imageSteamHandle = nullptr;
// LOGD("image released");
// } else {
// LOGE("image release error: %ld", ret);
// }
//
// }
// compare();
// compare();
search();
opiton();
}

View File

@@ -1,7 +1,7 @@
//
// Created by tunm on 2023/9/15.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include <iostream>
#include "face_context.h"
@@ -46,10 +46,10 @@ int main() {
ctx.FaceDetectAndTrack(stream);
// LOGD("Track Cost: %f", ctx.GetTrackTotalUseTime());
// LOGD("Track Cost: %f", ctx.GetTrackTotalUseTime());
auto &faces = ctx.GetTrackingFaceList();
for (auto &face: faces) {
for (auto &face : faces) {
auto rect = face.GetRect();
int track_id = face.GetTrackingId();
int track_count = face.GetTrackingCount();
@@ -60,19 +60,18 @@ int main() {
cv::Point text_position(rect.x, rect.y - 10);
const auto& pose_and_quality = face.high_result;
const auto &pose_and_quality = face.high_result;
float mean_quality = 0.0f;
for (int i = 0; i < pose_and_quality.lmk_quality.size(); ++i) {
mean_quality += pose_and_quality.lmk_quality[i];
}
mean_quality /= pose_and_quality.lmk_quality.size();
mean_quality = 1 - mean_quality;
std::string pose_text = "pitch: " + std::to_string(pose_and_quality.pitch) + ",Yaw: " + std::to_string(pose_and_quality.yaw) + ",roll:" +std::to_string(pose_and_quality.roll) + ", q: " +
std::to_string(mean_quality);
std::string pose_text = "pitch: " + std::to_string(pose_and_quality.pitch) + ",Yaw: " + std::to_string(pose_and_quality.yaw) +
",roll:" + std::to_string(pose_and_quality.roll) + ", q: " + std::to_string(mean_quality);
cv::Point pose_position(rect.x, rect.y + rect.height + 20);
int font_face = cv::FONT_HERSHEY_SIMPLEX;
double font_scale = 0.5;
int font_thickness = 1;
@@ -82,7 +81,6 @@ int main() {
cv::putText(frame, pose_text, pose_position, font_face, font_scale, font_color, font_thickness);
}
cv::imshow("Webcam", frame);
if (cv::waitKey(1) == 27) {

View File

@@ -1,15 +1,15 @@
//
// Created by Tunm-Air13 on 2024/4/10.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include <iostream>
#include "inspireface/c_api/inspireface.h"
#include "inspireface/middleware/camera_stream/camera_stream.h"
void non_file_test() {
HResult ret;
HPath path = "test_res/pack/abc"; // Use error path
HPath path = "test_res/pack/abc"; // Use error path
HF_ContextCustomParameter parameter = {0};
HF_DetectMode detMode = HF_DETECT_MODE_IMAGE;
HContextHandle session;
@@ -28,7 +28,6 @@ void camera_test() {
stream.SetDataFormat(inspire::NV12);
stream.SetDataBuffer(image.data, image.rows, image.cols);
auto decode = stream.GetScaledImage(1.0f, true);
}
int main() {

View File

@@ -1,6 +1,7 @@
//
// Created by tunm on 2024/4/6.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include <iostream>
#include "track_module/face_track.h"
#include "inspireface/recognition_module/face_feature_extraction.h"
@@ -12,7 +13,7 @@ int main() {
InspireArchive archive("test_res/pack/Pikachu");
FaceTrack track;
// FaceRecognition recognition(archive, true);
// FaceRecognition recognition(archive, true);
auto ret = track.Configuration(archive);
INSPIRE_LOGD("ret=%d", ret);
@@ -27,12 +28,11 @@ int main() {
track.UpdateStream(stream, true);
}
// InspireModel model;
// ret = archive.LoadModel("mask_detect", model);
// std::cout << ret << std::endl;
//
// archive.PublicPrintSubFiles();
// InspireModel model;
// ret = archive.LoadModel("mask_detect", model);
// std::cout << ret << std::endl;
//
// archive.PublicPrintSubFiles();
return 0;
}

View File

@@ -1,6 +1,7 @@
//
// Created by tunm on 2023/9/8.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include <iostream>
#include "track_module/face_detect/face_pose.h"
@@ -14,12 +15,14 @@ int main(int argc, char** argv) {
Configurable param;
param.set<std::string>("input_layer", "data");
param.set<std::vector<std::string>>("outputs_layers", {"ip3_pose", });
param.set<std::vector<std::string>>("outputs_layers", {
"ip3_pose",
});
param.set<std::vector<int>>("input_size", {112, 112});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<int>("input_channel", 1); // Input Gray
param.set<int>("input_image_channel", 1); // BGR 2 Gray
param.set<int>("input_image_channel", 1); // BGR 2 Gray
auto m_pose_net_ = std::make_shared<FacePose>();
InspireModel model;

View File

@@ -1,6 +1,7 @@
//
// Created by tunm on 2023/9/10.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include <iostream>
#include "face_context.h"
@@ -11,7 +12,7 @@
using namespace inspire;
std::string GetFileNameWithoutExtension(const std::string& filePath) {
std::string GetFileNameWithoutExtension(const std::string &filePath) {
size_t slashPos = filePath.find_last_of("/\\");
if (slashPos != std::string::npos) {
std::string fileName = filePath.substr(slashPos + 1);
@@ -52,7 +53,6 @@ int comparison1v1(FaceContext &ctx) {
return -1;
}
ctx.FaceRecognitionModule()->FaceExtract(stream, faces[0], feature_1);
}
{
@@ -68,7 +68,6 @@ int comparison1v1(FaceContext &ctx) {
return -1;
}
ctx.FaceRecognitionModule()->FaceExtract(stream, faces[0], feature_2);
}
float rec;
@@ -78,14 +77,11 @@ int comparison1v1(FaceContext &ctx) {
return 0;
}
int search(FaceContext &ctx) {
// std::shared_ptr<FeatureBlock> block;
// block.reset(FeatureBlock::Create(hyper::MC_OPENCV));
// std::shared_ptr<FeatureBlock> block;
// block.reset(FeatureBlock::Create(hyper::MC_OPENCV));
std::vector<String> files_list = {
};
std::vector<String> files_list = {};
for (int i = 0; i < files_list.size(); ++i) {
auto image = cv::imread(files_list[i]);
CameraStream stream;
@@ -103,11 +99,11 @@ int search(FaceContext &ctx) {
FEATURE_HUB->RegisterFaceFeature(feature, i, GetFileNameWithoutExtension(files_list[i]), 1000 + i);
}
// ctx.FaceRecognitionModule()->PrintMatrix();
// ctx.FaceRecognitionModule()->PrintMatrix();
// auto ret = block->DeleteFeature(3);
// LOGD("DEL: %d", ret);
// block->PrintMatrix();
// auto ret = block->DeleteFeature(3);
// LOGD("DEL: %d", ret);
// block->PrintMatrix();
FEATURE_HUB->DeleteFaceFeature(2);
@@ -129,8 +125,8 @@ int search(FaceContext &ctx) {
}
ctx.FaceRecognitionModule()->FaceExtract(stream, faces[0], feature);
// block->UpdateFeature(4, feature);
// block->AddFeature(feature);
// block->UpdateFeature(4, feature);
// block->AddFeature(feature);
}
// Prepare an image to search
@@ -150,18 +146,17 @@ int search(FaceContext &ctx) {
ctx.FaceRecognitionModule()->FaceExtract(stream, faces[0], feature);
SearchResult result;
auto timeStart = (double) cv::getTickCount();
auto timeStart = (double)cv::getTickCount();
FEATURE_HUB->SearchFaceFeature(feature, result);
double cost = ((double) cv::getTickCount() - timeStart) / cv::getTickFrequency() * 1000;
double cost = ((double)cv::getTickCount() - timeStart) / cv::getTickFrequency() * 1000;
INSPIRE_LOGD("Search time: %f", cost);
INSPIRE_LOGD("Top1: %d, %f, %s %d", result.index, result.score, result.tag.c_str(), result.customId);
}
return 0;
}
int main(int argc, char** argv) {
int main(int argc, char **argv) {
FaceContext ctx;
CustomPipelineParameter param;
param.enable_recognition = true;
@@ -170,11 +165,10 @@ int main(int argc, char** argv) {
INSPIRE_LOGE("Initialization error");
return -1;
}
comparison1v1(ctx);
// search(ctx);
// search(ctx);
return 0;
}

View File

@@ -1,6 +1,7 @@
//
// Created by tunm on 2023/9/7.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include <iostream>
#include "face_context.h"
@@ -31,12 +32,12 @@ int main(int argc, char** argv) {
std::vector<HyperFaceData> faces;
for (int i = 0; i < ctx.GetNumberOfFacesCurrentlyDetected(); ++i) {
// const ByteArray &byteArray = ctx.GetDetectCache()[i];
// const ByteArray &byteArray = ctx.GetDetectCache()[i];
HyperFaceData face = {0};
// ret = DeserializeHyperFaceData(byteArray, face);
// ret = DeserializeHyperFaceData(byteArray, face);
const FaceBasicData &faceBasic = ctx.GetFaceBasicDataCache()[i];
ret = DeserializeHyperFaceData((char* )faceBasic.data, faceBasic.dataSize, face);
const FaceBasicData& faceBasic = ctx.GetFaceBasicDataCache()[i];
ret = DeserializeHyperFaceData((char*)faceBasic.data, faceBasic.dataSize, face);
INSPIRE_LOGD("OK!");
if (ret != HSUCCEED) {
@@ -48,17 +49,16 @@ int main(int argc, char** argv) {
std::cout << rect << std::endl;
cv::rectangle(rot90, rect, cv::Scalar(0, 0, 233), 2);
for (auto &p: face.keyPoints) {
for (auto& p : face.keyPoints) {
cv::Point2f point(p.x, p.y);
cv::circle(rot90, point, 0, cv::Scalar(0, 0, 255), 5);
}
}
// cv::imshow("wq", rot90);
// cv::waitKey(0);
// cv::imshow("wq", rot90);
// cv::waitKey(0);
cv::imwrite("wq.png", rot90);
ret = ctx.FacesProcess(stream, faces, param);
if (ret != HSUCCEED) {
return -1;

View File

@@ -1,6 +1,7 @@
//
// Created by Tunm-Air13 on 2023/10/11.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include <iostream>
#include "inspireface/feature_hub/persistence/sqlite_faces_manage.h"

View File

@@ -1,13 +1,14 @@
//
// Created by tunm on 2023/8/29.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include <iostream>
#include "inspireface/track_module/face_track.h"
#include "opencv2/opencv.hpp"
using namespace inspire;
int video_test(FaceTrack &ctx, int cam_id) {
int video_test(FaceTrack& ctx, int cam_id) {
#ifndef ISF_USE_MOBILE_OPENCV_IN_LOCAL
cv::VideoCapture cap(cam_id);
@@ -37,8 +38,8 @@ int video_test(FaceTrack &ctx, int cam_id) {
INSPIRE_LOGD("Track Cost: %f", ctx.GetTrackTotalUseTime());
auto const &faces = ctx.trackingFace;
for (auto const &face: faces) {
auto const& faces = ctx.trackingFace;
for (auto const& face : faces) {
auto rect = face.GetRect();
int track_id = face.GetTrackingId();
int track_count = face.GetTrackingCount();
@@ -51,7 +52,7 @@ int video_test(FaceTrack &ctx, int cam_id) {
const auto& pose_and_quality = face.high_result;
std::vector<float> euler = {pose_and_quality.yaw, pose_and_quality.roll, pose_and_quality.pitch};
std::string pose_text = "P: " + std::to_string(euler[0]) + ",Yaw: " + std::to_string(euler[1]) + ",roll:" +std::to_string(euler[2]);
std::string pose_text = "P: " + std::to_string(euler[0]) + ",Yaw: " + std::to_string(euler[1]) + ",roll:" + std::to_string(euler[2]);
cv::Point pose_position(rect.x, rect.y + rect.height + 20);
@@ -64,7 +65,6 @@ int video_test(FaceTrack &ctx, int cam_id) {
cv::putText(frame, pose_text, pose_position, font_face, font_scale, font_color, font_thickness);
}
cv::imshow("Webcam", frame);
if (cv::waitKey(1) == 27) {
@@ -107,8 +107,8 @@ void video_file_test(FaceTrack& ctx, const std::string& video_filename) {
ctx.UpdateStream(stream, false);
INSPIRE_LOGD("Track Cost: %f", ctx.GetTrackTotalUseTime());
auto const &faces = ctx.trackingFace;
for (auto const &face: faces) {
auto const& faces = ctx.trackingFace;
for (auto const& face : faces) {
auto rect = face.GetRect();
int track_id = face.GetTrackingId();
int track_count = face.GetTrackingCount();
@@ -116,7 +116,7 @@ void video_file_test(FaceTrack& ctx, const std::string& video_filename) {
cv::rectangle(frame, rect, cv::Scalar(0, 0, 255), 2, 1);
auto lmk = face.GetLanmdark();
for (auto & p : lmk) {
for (auto& p : lmk) {
cv::circle(frame, p, 0, cv::Scalar(0, 0, 242), 2);
}
@@ -125,7 +125,8 @@ void video_file_test(FaceTrack& ctx, const std::string& video_filename) {
cv::Point text_position(rect.x, rect.y - 10);
const auto& euler = face.high_result;
std::string pose_text = "pitch: " + std::to_string(euler.pitch) + ",Yaw: " + std::to_string(euler.yaw) + ",roll:" +std::to_string(euler.roll);
std::string pose_text =
"pitch: " + std::to_string(euler.pitch) + ",Yaw: " + std::to_string(euler.yaw) + ",roll:" + std::to_string(euler.roll);
cv::Point pose_position(rect.x, rect.y + rect.height + 20);
@@ -163,8 +164,8 @@ int main(int argc, char** argv) {
const std::string folder = "test_res/pack/Pikachu";
INSPIRE_LOGD("%s", folder.c_str());
// ModelLoader loader;
// loader.Reset(folder);
// ModelLoader loader;
// loader.Reset(folder);
InspireArchive archive;
archive.ReLoad(folder);
@@ -183,7 +184,7 @@ int main(int argc, char** argv) {
} else if (source == "image") {
cv::Mat image = cv::imread(input);
if (!image.empty()) {
// image_test(ctx, image);
// image_test(ctx, image);
} else {
std::cerr << "Unable to open the image file." << std::endl;
}