From 9d1c4cec973ed6395e25a8c0fe5a8a551f30e146 Mon Sep 17 00:00:00 2001 From: pansen <pansen626@sina.com> Date: 星期三, 26 十二月 2018 13:59:35 +0800 Subject: [PATCH] save code --- QiaoJiaSystem/StructureApp/TrackingTrigger.h | 63 ++++++++++++++++++++++++------- 1 files changed, 48 insertions(+), 15 deletions(-) diff --git a/QiaoJiaSystem/StructureApp/TrackingTrigger.h b/QiaoJiaSystem/StructureApp/TrackingTrigger.h index 8fe9509..544dd77 100644 --- a/QiaoJiaSystem/StructureApp/TrackingTrigger.h +++ b/QiaoJiaSystem/StructureApp/TrackingTrigger.h @@ -9,7 +9,8 @@ using namespace std; struct ScoredRect { - ScoredRect() : id(-1) ,isMask(false){} + ScoredRect() : id(-1), isMask(false) {} + bool isMask; float score; cv::Rect rect; @@ -22,7 +23,50 @@ TrackingTrigger(float threshold) : threshold(threshold), faceTrackingId(0) {} - bool triggerOnce(ScoredRect &rect) { + + bool triggerOnce(ScoredRect &rect, long faceId = -1) { + if (faceId < 0) { + return triggerOnce(rect, false); + } else { + bool found = false; + for (auto lastRect: lastScoreRects) { + if (lastRect.id >= 0 && lastRect.id == faceId) { + found = true; + rect.id = faceId; + rect.properties = lastRect.properties; + tempScoreRects.push_back(rect); + break; + } + } + if (!found) { + if (rect.score < threshold) { +// tempScoreRects.push_back(rect); + return false; + } else { + rect.id = faceId; + tempScoreRects.push_back(rect); + return true; + } + } + return false; + } + } + + void triggerLine() { + lastScoreRects.swap(tempScoreRects);// = tempScoreRects; + tempScoreRects.clear(); + } + + ScoredRect &getLastRect() { + return tempScoreRects[tempScoreRects.size() - 1]; + } + + std::vector<ScoredRect> getLastScoreRects() const { + return lastScoreRects; + } + +private: + bool triggerOnce(ScoredRect &rect, bool) { bool found = false; for (auto lastRect: lastScoreRects) { if (lastRect.id >= 0 && (rect.rect & lastRect.rect).area() > lastRect.rect.area() * 0.4) { @@ -46,23 +90,12 @@ return false; } - void triggerLine() { - lastScoreRects = tempScoreRects; - tempScoreRects.clear(); - } - - ScoredRect &getLastRect() { - return tempScoreRects[tempScoreRects.size() - 1]; - } - - std::vector<ScoredRect> getLastScoreRects() const { - return lastScoreRects; - } - private: float threshold; std::vector<ScoredRect> lastScoreRects; std::vector<ScoredRect> tempScoreRects; + std::vector<int> lastScoreInts; + std::vector<int> tempScoreInts; std::atomic<long> faceTrackingId; }; -- Gitblit v1.8.0