#ifndef TRACKINGTRIGGER_H #define TRACKINGTRIGGER_H #include #include #include #include using namespace std; struct ScoredRect { ScoredRect() : id(-1) ,isMask(false){} bool isMask; float score; cv::Rect rect; long id; map properties; }; class TrackingTrigger { public: TrackingTrigger(float threshold) : threshold(threshold), faceTrackingId(0) {} bool triggerOnce(ScoredRect &rect) { bool found = false; for (auto lastRect: lastScoreRects) { if (lastRect.id >= 0 && (rect.rect & lastRect.rect).area() > lastRect.rect.area() * 0.4) { found = true; rect.id = lastRect.id; rect.properties = lastRect.properties; tempScoreRects.push_back(rect); break; } } if (!found) { if (rect.score < threshold) { // tempScoreRects.push_back(rect); return false; } else { rect.id = faceTrackingId++; tempScoreRects.push_back(rect); return true; } } return false; } void triggerLine() { lastScoreRects = tempScoreRects; tempScoreRects.clear(); } ScoredRect &getLastRect() { return tempScoreRects[tempScoreRects.size() - 1]; } std::vector getLastScoreRects() const { return lastScoreRects; } private: float threshold; std::vector lastScoreRects; std::vector tempScoreRects; std::atomic faceTrackingId; }; #endif // TRACKINGTRIGGER_H