|
|
|
@ -39,7 +39,8 @@ using namespace std; |
|
|
|
|
static inline cv::Point2f centerRect(const cv::Rect& r) |
|
|
|
|
{ |
|
|
|
|
return cv::Point2f(r.x+((float)r.width)/2, r.y+((float)r.height)/2); |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static inline cv::Rect scale_rect(const cv::Rect& r, float scale) |
|
|
|
|
{ |
|
|
|
|
cv::Point2f m=centerRect(r); |
|
|
|
@ -49,9 +50,10 @@ static inline cv::Rect scale_rect(const cv::Rect& r, float scale) |
|
|
|
|
int y=cvRound(m.y - height/2); |
|
|
|
|
|
|
|
|
|
return cv::Rect(x, y, cvRound(width), cvRound(height)); |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void* workcycleObjectDetectorFunction(void* p); |
|
|
|
|
|
|
|
|
|
class DetectionBasedTracker::SeparateDetectionWork |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
@ -61,6 +63,7 @@ class DetectionBasedTracker::SeparateDetectionWork |
|
|
|
|
bool run(); |
|
|
|
|
void stop(); |
|
|
|
|
void resetTracking(); |
|
|
|
|
|
|
|
|
|
inline bool isWorking() |
|
|
|
|
{ |
|
|
|
|
return (stateThread==STATE_THREAD_WORKING_SLEEPING) || (stateThread==STATE_THREAD_WORKING_WITH_IMAGE); |
|
|
|
@ -430,8 +433,6 @@ DetectionBasedTracker::Parameters::Parameters() |
|
|
|
|
minDetectionPeriod=0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DetectionBasedTracker::InnerParameters::InnerParameters() |
|
|
|
|
{ |
|
|
|
|
numLastPositionsToTrack=4; |
|
|
|
@ -444,6 +445,7 @@ DetectionBasedTracker::InnerParameters::InnerParameters() |
|
|
|
|
coeffObjectSpeedUsingInPrediction=0.8; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DetectionBasedTracker::DetectionBasedTracker(const std::string& cascadeFilename, const Parameters& params) |
|
|
|
|
:separateDetectionWork(), |
|
|
|
|
innerParameters(), |
|
|
|
@ -468,15 +470,13 @@ DetectionBasedTracker::DetectionBasedTracker(const std::string& cascadeFilename, |
|
|
|
|
weightsSizesSmoothing.push_back(0.2); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DetectionBasedTracker::~DetectionBasedTracker() |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DetectionBasedTracker::process(const Mat& imageGray) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
CV_Assert(imageGray.type()==CV_8UC1); |
|
|
|
|
|
|
|
|
|
if (!separateDetectionWork->isWorking()) { |
|
|
|
@ -501,8 +501,6 @@ void DetectionBasedTracker::process(const Mat& imageGray) |
|
|
|
|
vector<Rect> rectsWhereRegions; |
|
|
|
|
bool shouldHandleResult=separateDetectionWork->communicateWithDetectingThread(imageGray, rectsWhereRegions); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (shouldHandleResult) { |
|
|
|
|
LOGD("DetectionBasedTracker::process: get _rectsWhereRegions were got from resultDetect"); |
|
|
|
|
} else { |
|
|
|
@ -560,6 +558,7 @@ void DetectionBasedTracker::getObjects(std::vector<cv::Rect>& result) const |
|
|
|
|
LOGD("DetectionBasedTracker::process: found a object with SIZE %d x %d, rect={%d, %d, %d x %d}", r.width, r.height, r.x, r.y, r.width, r.height); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DetectionBasedTracker::getObjects(std::vector<Object>& result) const |
|
|
|
|
{ |
|
|
|
|
result.clear(); |
|
|
|
@ -574,8 +573,6 @@ void DetectionBasedTracker::getObjects(std::vector<Object>& result) const |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool DetectionBasedTracker::run() |
|
|
|
|
{ |
|
|
|
|
return separateDetectionWork->run(); |
|
|
|
@ -711,6 +708,7 @@ void DetectionBasedTracker::updateTrackedObjects(const vector<Rect>& detectedObj |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Rect DetectionBasedTracker::calcTrackedObjectPositionToShow(int i) const |
|
|
|
|
{ |
|
|
|
|
if ( (i < 0) || (i >= (int)trackedObjects.size()) ) { |
|
|
|
@ -797,6 +795,7 @@ void DetectionBasedTracker::detectInRegion(const Mat& img, const Rect& r, vector |
|
|
|
|
Rect r0(Point(), img.size()); |
|
|
|
|
Rect r1 = scale_rect(r, innerParameters.coeffTrackingWindowSize); |
|
|
|
|
r1 = r1 & r0; |
|
|
|
|
|
|
|
|
|
if ( (r1.width <=0) || (r1.height <= 0) ) { |
|
|
|
|
LOGD("DetectionBasedTracker::detectInRegion: Empty intersection"); |
|
|
|
|
return; |
|
|
|
|