Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update track mode #149

Merged
merged 12 commits into from
Jan 21, 2025
Merged

Feature/update track mode #149

merged 12 commits into from
Jan 21, 2025

Conversation

tunmx
Copy link
Member

@tunmx tunmx commented Jan 21, 2025

No description provided.

Copy link

devloai bot commented Jan 21, 2025

Automatic code review is enabled for this repository. Reviewing this PR now.

Copy link

@devloai devloai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the track mode updates and found several areas for improvement while maintaining the core functionality. The changes include good enhancements to the tracking system, particularly the configurable parameters for smoothing and detection. The main suggestions focus on API consistency, documentation accuracy, and code maintainability. Please address the method name typo and documentation issues as they affect the public API. The code organization suggestions will help with long-term maintenance.

@@ -159,6 +159,21 @@ class INSPIRE_API FaceTrackModule {
*/
bool IsDetectModeLandmark() const;

/**
* @brief Fix detect threshold
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation comments for these methods incorrectly state "Fix detect threshold". Please update them to accurately describe their purpose. For example:

For SetTrackModeSmoothRatio:

    /**
     * @brief Sets the smoothing ratio for landmark tracking
     * @param value Smoothing ratio between 0 and 1, smaller values mean stronger smoothing
     */

For SetTrackModeNumSmoothCacheFrame:

    /**
     * @brief Sets the number of frames to use for landmark smoothing
     * @param value Number of previous frames to consider for smoothing
     */

/**
* @brief Fix detect interval
* */
void SetTrackModelDetectInterval(int value);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name has a typo - "Model" should be "Mode":

Suggested change
void SetTrackModelDetectInterval(int value);
void SetTrackModeDetectInterval(int value);

@@ -186,8 +186,22 @@ bool FaceTrackModule::TrackFace(inspirecv::InspireImageProcess &image, FaceObjec
// INSPIRE_LOGD("Extensive Affine Cost %f", extensive_cost_time.GetCostTimeUpdate());
}
}
// Replace the landmark with the high-quality landmark
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting the landmark mapping into a separate method to improve readability and maintainability. The same mapping is done twice (once for setting and once for getting smoothed landmarks). Something like:

void UpdateHighQualityLandmarks(FaceObjectInternal& face, const std::vector<inspirecv::Point2f>& landmarks) {
    landmarks[FaceLandmarkAdapt::LEFT_EYE_CENTER] = face.high_result.lmk[0];
    landmarks[FaceLandmarkAdapt::RIGHT_EYE_CENTER] = face.high_result.lmk[1];
    landmarks[FaceLandmarkAdapt::NOSE_CORNER] = face.high_result.lmk[2];
    landmarks[FaceLandmarkAdapt::MOUTH_LEFT_CORNER] = face.high_result.lmk[3];
    landmarks[FaceLandmarkAdapt::MOUTH_RIGHT_CORNER] = face.high_result.lmk[4];
}

@@ -28,13 +28,14 @@ class INSPIRE_API FaceObjectInternal {
face_action_ = std::make_shared<FaceActionPredictor>(10);
}

void SetLandmark(const std::vector<inspirecv::Point2f> &lmk, bool update_rect = true, bool update_matrix = true) {
void SetLandmark(const std::vector<inspirecv::Point2f> &lmk, bool update_rect = true, bool update_matrix = true, float h = 0.06f, int n = 5) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default values for h and n parameters in SetLandmark method are different from the class member defaults in FaceTrackModule (0.06 vs 0.025 and 5 vs 15). Consider:

  1. Using consistent defaults across the codebase
  2. Adding validation for these parameters (e.g. h should be between 0 and 1, n should be positive)
  3. Adding documentation for what these parameters mean and their valid ranges

@@ -205,7 +219,8 @@ void FaceTrackModule::UpdateStream(inspirecv::InspireImageProcess &image) {
detection_index_ += 1;
if (m_mode_ == DETECT_MODE_ALWAYS_DETECT || m_mode_ == DETECT_MODE_TRACK_BY_DETECT)
trackingFace.clear();
if (detection_index_ % detection_interval_ == 0 || m_mode_ == DETECT_MODE_ALWAYS_DETECT || m_mode_ == DETECT_MODE_TRACK_BY_DETECT) {
if (trackingFace.empty() || detection_index_ % detection_interval_ == 0 || m_mode_ == DETECT_MODE_ALWAYS_DETECT ||
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition for detection has become quite long and complex. Consider extracting it to a method with a descriptive name for better readability:

bool shouldPerformDetection() const {
    return trackingFace.empty() || 
           detection_index_ % detection_interval_ == 0 || 
           m_mode_ == DETECT_MODE_ALWAYS_DETECT ||
           m_mode_ == DETECT_MODE_TRACK_BY_DETECT;
}

@tunmx tunmx merged commit b0e8c6f into master Jan 21, 2025
13 checks passed
@tunmx tunmx deleted the feature/update_track_mode branch January 21, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant