diff --git a/modules/contrib/include/opencv2/contrib/detection_based_tracker.hpp b/modules/contrib/include/opencv2/contrib/detection_based_tracker.hpp index 239011d22..18129cea2 100644 --- a/modules/contrib/include/opencv2/contrib/detection_based_tracker.hpp +++ b/modules/contrib/include/opencv2/contrib/detection_based_tracker.hpp @@ -30,7 +30,7 @@ class DetectionBasedTracker scaleFactor(1.1f) {} - virtual void detect(const cv::Mat& Image, std::vector& objects) = 0; + virtual void detect(const cv::Mat& image, std::vector& objects) = 0; void setMinObjectSize(const cv::Size& min) { @@ -73,7 +73,7 @@ class DetectionBasedTracker float scaleFactor; }; - DetectionBasedTracker(cv::Ptr MainDetector, cv::Ptr TrackingDetector, const Parameters& params); + DetectionBasedTracker(cv::Ptr mainDetector, cv::Ptr trackingDetector, const Parameters& params); virtual ~DetectionBasedTracker(); virtual bool run(); @@ -90,6 +90,8 @@ class DetectionBasedTracker virtual void getObjects(std::vector& result) const; virtual void getObjects(std::vector& result) const; + virtual void addObject(const cv::Rect& location); + protected: class SeparateDetectionWork; cv::Ptr separateDetectionWork; diff --git a/modules/contrib/src/detection_based_tracker.cpp b/modules/contrib/src/detection_based_tracker.cpp index 9edec6df0..c4e6e4067 100644 --- a/modules/contrib/src/detection_based_tracker.cpp +++ b/modules/contrib/src/detection_based_tracker.cpp @@ -442,18 +442,20 @@ cv::DetectionBasedTracker::InnerParameters::InnerParameters() } -cv::DetectionBasedTracker::DetectionBasedTracker(cv::Ptr MainDetector, cv::Ptr TrackingDetector, const Parameters& params) +cv::DetectionBasedTracker::DetectionBasedTracker(cv::Ptr mainDetector, cv::Ptr trackingDetector, const Parameters& params) :separateDetectionWork(), parameters(params), innerParameters(), numTrackedSteps(0), - cascadeForTracking(TrackingDetector) + cascadeForTracking(trackingDetector) { CV_Assert( (params.maxTrackLifetime >= 0) - && (!MainDetector.empty()) - && (!TrackingDetector.empty()) ); +// && (!mainDetector.empty()) + && (!trackingDetector.empty()) ); - separateDetectionWork = new SeparateDetectionWork(*this, MainDetector); + if (!mainDetector.empty()) { + separateDetectionWork = new SeparateDetectionWork(*this, mainDetector); + } weightsPositionsSmoothing.push_back(1); weightsSizesSmoothing.push_back(0.5); @@ -469,7 +471,7 @@ void DetectionBasedTracker::process(const Mat& imageGray) { CV_Assert(imageGray.type()==CV_8UC1); - if (!separateDetectionWork->isWorking()) { + if ( (!separateDetectionWork.empty()) && (!separateDetectionWork->isWorking()) ) { separateDetectionWork->run(); } @@ -485,7 +487,10 @@ void DetectionBasedTracker::process(const Mat& imageGray) Mat imageDetect=imageGray; vector rectsWhereRegions; - bool shouldHandleResult=separateDetectionWork->communicateWithDetectingThread(imageGray, rectsWhereRegions); + bool shouldHandleResult=false; + if (!separateDetectionWork.empty()) { + shouldHandleResult = separateDetectionWork->communicateWithDetectingThread(imageGray, rectsWhereRegions); + } if (shouldHandleResult) { LOGD("DetectionBasedTracker::process: get _rectsWhereRegions were got from resultDetect"); @@ -560,17 +565,24 @@ void cv::DetectionBasedTracker::getObjects(std::vector& result) const bool cv::DetectionBasedTracker::run() { - return separateDetectionWork->run(); + if (!separateDetectionWork.empty()) { + return separateDetectionWork->run(); + } + return false; } void cv::DetectionBasedTracker::stop() { - separateDetectionWork->stop(); + if (!separateDetectionWork.empty()) { + separateDetectionWork->stop(); + } } void cv::DetectionBasedTracker::resetTracking() { - separateDetectionWork->resetTracking(); + if (!separateDetectionWork.empty()) { + separateDetectionWork->resetTracking(); + } trackedObjects.clear(); } @@ -694,6 +706,12 @@ void cv::DetectionBasedTracker::updateTrackedObjects(const vector& detecte } } +void cv::DetectionBasedTracker::addObject(const Rect& location) +{ + LOGD("DetectionBasedTracker::addObject: new object {%d, %d %dx%d}",location.x, location.y, location.width, location.height); + trackedObjects.push_back(location); +} + Rect cv::DetectionBasedTracker::calcTrackedObjectPositionToShow(int i) const { if ( (i < 0) || (i >= (int)trackedObjects.size()) ) { @@ -819,9 +837,13 @@ bool cv::DetectionBasedTracker::setParameters(const Parameters& params) return false; } - separateDetectionWork->lock(); + if (!separateDetectionWork.empty()) { + separateDetectionWork->lock(); + } parameters=params; - separateDetectionWork->unlock(); + if (!separateDetectionWork.empty()) { + separateDetectionWork->unlock(); + } return true; }