Skip to content

Commit

Permalink
Merge pull request #153 from HyperInspire/feature/update_image_stream
Browse files Browse the repository at this point in the history
Add track cost time
  • Loading branch information
tunmx authored Jan 22, 2025
2 parents 8ef4bb9 + b75e705 commit 78d20d8
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 71 deletions.
24 changes: 24 additions & 0 deletions cpp/inspireface/c_api/inspireface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,30 @@ HResult HFGetFaceFiveKeyPointsFromFaceToken(HFFaceBasicToken singleFace, HPoint2
return HSUCCEED;
}

HResult HFSessionSetEnableTrackCostSpend(HFSession session, bool value) {
if (session == nullptr) {
return HERR_INVALID_CONTEXT_HANDLE;
}
HF_FaceAlgorithmSession *ctx = (HF_FaceAlgorithmSession *)session;
if (ctx == nullptr) {
return HERR_INVALID_CONTEXT_HANDLE;
}
ctx->impl.SetEnableTrackCostSpend(value);
return HSUCCEED;
}

HResult HFSessionPrintTrackCostSpend(HFSession session) {
if (session == nullptr) {
return HERR_INVALID_CONTEXT_HANDLE;
}
HF_FaceAlgorithmSession *ctx = (HF_FaceAlgorithmSession *)session;
if (ctx == nullptr) {
return HERR_INVALID_CONTEXT_HANDLE;
}
ctx->impl.PrintTrackCostSpend();
return HSUCCEED;
}

HResult HFFeatureHubFaceSearchThresholdSetting(float threshold) {
FEATURE_HUB_DB->SetRecognitionThreshold(threshold);
return HSUCCEED;
Expand Down
14 changes: 14 additions & 0 deletions cpp/inspireface/c_api/inspireface.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,20 @@ HYPER_CAPI_EXPORT extern HResult HFGetFaceDenseLandmarkFromFaceToken(HFFaceBasic
*/
HYPER_CAPI_EXPORT extern HResult HFGetFaceFiveKeyPointsFromFaceToken(HFFaceBasicToken singleFace, HPoint2f *landmarks, HInt32 num);

/**
* @brief Set the enable cost spend
* @param value The enable cost spend value
* @return int32_t Status code of the operation.
* */
HYPER_CAPI_EXPORT extern HResult HFSessionSetEnableTrackCostSpend(HFSession session, bool value);

/**
* @brief Print the cost spend
* @param session The session handle
* @return int32_t Status code of the operation.
* */
HYPER_CAPI_EXPORT extern HResult HFSessionPrintTrackCostSpend(HFSession session);

/************************************************************************
* Face Recognition
************************************************************************/
Expand Down
22 changes: 20 additions & 2 deletions cpp/inspireface/face_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ int32_t FaceSession::Configuration(DetectModuleMode detect_mode, int32_t max_det

m_face_pipeline_ = std::make_shared<FacePipelineModule>(INSPIRE_LAUNCH->getMArchive(), param.enable_liveness, param.enable_mask_detect,
param.enable_face_attribute, param.enable_interaction_liveness);
m_face_track_cost_ = std::make_shared<inspirecv::TimeSpend>("FaceTrack");

return HSUCCEED;
}

int32_t FaceSession::FaceDetectAndTrack(inspirecv::InspireImageProcess& process) {
std::lock_guard<std::mutex> lock(m_mtx_);
if (m_enable_track_cost_spend_) {
m_face_track_cost_->Start();
}
m_detect_cache_.clear();
m_face_basic_data_cache_.clear();
m_face_rects_cache_.clear();
Expand Down Expand Up @@ -107,7 +111,9 @@ int32_t FaceSession::FaceDetectAndTrack(inspirecv::InspireImageProcess& process)
basic.dataSize = m_detect_cache_[i].size();
basic.data = m_detect_cache_[i].data();
}

if (m_enable_track_cost_spend_) {
m_face_track_cost_->Stop();
}
// LOGD("Track COST: %f", m_face_track_->GetTrackTotalUseTime());
return HSUCCEED;
}
Expand Down Expand Up @@ -410,4 +416,16 @@ int32_t FaceSession::SetTrackModeDetectInterval(int value) {
return HSUCCEED;
}

} // namespace inspire
int32_t FaceSession::SetEnableTrackCostSpend(bool value) {
m_enable_track_cost_spend_ = value;
m_face_track_cost_->Reset();
return HSUCCEED;
}

void FaceSession::PrintTrackCostSpend() {
if (m_enable_track_cost_spend_) {
INSPIRE_LOGI("%s", m_face_track_cost_->Report().c_str());
}
}

} // namespace inspire
18 changes: 18 additions & 0 deletions cpp/inspireface/face_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define INSPIRE_FACE_CONTEXT_H

#include <memory>
#include <inspirecv/inspirecv.h>
#include "data_type.h"
#include "track_module/face_track_module.h"
#include "pipeline_module/face_pipeline_module.h"
Expand Down Expand Up @@ -334,6 +335,18 @@ class INSPIRE_API FaceSession {
* */
int32_t SetTrackModeDetectInterval(int value);

/**
* @brief Set the enable cost spend
* @param value The enable cost spend value
* @return int32_t Status code of the operation.
* */
int32_t SetEnableTrackCostSpend(bool value);

/**
* @brief Print the cost spend
* */
void PrintTrackCostSpend();

private:
// Private member variables
CustomPipelineParameter m_parameter_; ///< Stores custom parameters for the pipeline
Expand Down Expand Up @@ -375,6 +388,11 @@ class INSPIRE_API FaceSession {
float m_face_feature_norm_; ///< Cache for face feature norm

std::mutex m_mtx_; ///< Mutex for thread safety.

// cost spend
std::shared_ptr<inspirecv::TimeSpend> m_face_track_cost_;

bool m_enable_track_cost_spend_ = false;
};

} // namespace inspire
Expand Down
Loading

0 comments on commit 78d20d8

Please sign in to comment.