@ -60,12 +60,15 @@ static inline cv::Rect scale_rect(const cv::Rect& r, float scale)
return cv : : Rect ( x , y , cvRound ( width ) , cvRound ( height ) ) ;
}
void * workcycleObjectDetectorFunction ( void * p ) ;
namespace cv
{
void * workcycleObjectDetectorFunction ( void * p ) ;
}
class DetectionBasedTracker : : SeparateDetectionWork
class cv : : DetectionBasedTracker : : SeparateDetectionWork
{
public :
SeparateDetectionWork ( DetectionBasedTracker & _detectionBasedTracker , cv : : Ptr < DetectionBasedTracker : : IDetector > _detector ) ;
SeparateDetectionWork ( cv : : DetectionBasedTracker & _detectionBasedTracker , cv : : Ptr < DetectionBasedTracker : : IDetector > _detector ) ;
virtual ~ SeparateDetectionWork ( ) ;
bool communicateWithDetectingThread ( const Mat & imageGray , vector < Rect > & rectsWhereRegions ) ;
bool run ( ) ;
@ -116,7 +119,7 @@ class DetectionBasedTracker::SeparateDetectionWork
long long timeWhenDetectingThreadStartedWork ;
} ;
DetectionBasedTracker : : SeparateDetectionWork : : SeparateDetectionWork ( DetectionBasedTracker & _detectionBasedTracker , cv : : Ptr < DetectionBasedTracker : : IDetector > _detector )
cv : : DetectionBasedTracker : : SeparateDetectionWork : : SeparateDetectionWork ( DetectionBasedTracker & _detectionBasedTracker , cv : : Ptr < DetectionBasedTracker : : IDetector > _detector )
: detectionBasedTracker ( _detectionBasedTracker ) ,
cascadeInThread ( ) ,
isObjectDetectingReady ( false ) ,
@ -149,7 +152,7 @@ DetectionBasedTracker::SeparateDetectionWork::SeparateDetectionWork(DetectionBas
}
}
DetectionBasedTracker : : SeparateDetectionWork : : ~ SeparateDetectionWork ( )
cv : : DetectionBasedTracker : : SeparateDetectionWork : : ~ SeparateDetectionWork ( )
{
if ( stateThread ! = STATE_THREAD_STOPPED ) {
LOGE ( " \n \n \n ATTENTION!!! dangerous algorithm error: destructor DetectionBasedTracker::DetectionBasedTracker::~SeparateDetectionWork is called before stopping the workthread " ) ;
@ -159,7 +162,7 @@ DetectionBasedTracker::SeparateDetectionWork::~SeparateDetectionWork()
pthread_cond_destroy ( & objectDetectorRun ) ;
pthread_mutex_destroy ( & mutex ) ;
}
bool DetectionBasedTracker : : SeparateDetectionWork : : run ( )
bool cv : : DetectionBasedTracker : : SeparateDetectionWork : : run ( )
{
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::run() --- start " ) ;
pthread_mutex_lock ( & mutex ) ;
@ -208,18 +211,18 @@ do {
} while ( 0 )
# endif
void * workcycleObjectDetectorFunction ( void * p )
void * cv : : workcycleObjectDetectorFunction ( void * p )
{
CATCH_ALL_AND_LOG ( { ( ( DetectionBasedTracker : : SeparateDetectionWork * ) p ) - > workcycleObjectDetector ( ) ; } ) ;
CATCH_ALL_AND_LOG ( { ( ( cv : : DetectionBasedTracker : : SeparateDetectionWork * ) p ) - > workcycleObjectDetector ( ) ; } ) ;
try {
( ( DetectionBasedTracker : : SeparateDetectionWork * ) p ) - > stateThread = DetectionBasedTracker : : SeparateDetectionWork : : STATE_THREAD_STOPPED ;
( ( cv : : DetectionBasedTracker : : SeparateDetectionWork * ) p ) - > stateThread = cv : : DetectionBasedTracker : : SeparateDetectionWork : : STATE_THREAD_STOPPED ;
} catch ( . . . ) {
LOGE0 ( " DetectionBasedTracker: workcycleObjectDetectorFunction: ERROR concerning pointer, received as the function parameter " ) ;
}
return NULL ;
}
void DetectionBasedTracker : : SeparateDetectionWork : : workcycleObjectDetector ( )
void cv : : DetectionBasedTracker : : SeparateDetectionWork : : workcycleObjectDetector ( )
{
static double freq = getTickFrequency ( ) ;
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- start " ) ;
@ -343,7 +346,7 @@ void DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector()
LOGI ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector: Returning " ) ;
}
void DetectionBasedTracker : : SeparateDetectionWork : : stop ( )
void cv : : DetectionBasedTracker : : SeparateDetectionWork : : stop ( )
{
//FIXME: TODO: should add quickStop functionality
pthread_mutex_lock ( & mutex ) ;
@ -360,7 +363,7 @@ void DetectionBasedTracker::SeparateDetectionWork::stop()
pthread_mutex_unlock ( & mutex ) ;
}
void DetectionBasedTracker : : SeparateDetectionWork : : resetTracking ( )
void cv : : DetectionBasedTracker : : SeparateDetectionWork : : resetTracking ( )
{
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::resetTracking " ) ;
pthread_mutex_lock ( & mutex ) ;
@ -381,7 +384,7 @@ void DetectionBasedTracker::SeparateDetectionWork::resetTracking()
}
bool DetectionBasedTracker : : SeparateDetectionWork : : communicateWithDetectingThread ( const Mat & imageGray , vector < Rect > & rectsWhereRegions )
bool cv : : DetectionBasedTracker : : SeparateDetectionWork : : communicateWithDetectingThread ( const Mat & imageGray , vector < Rect > & rectsWhereRegions )
{
static double freq = getTickFrequency ( ) ;
@ -431,13 +434,13 @@ bool DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThrea
return shouldHandleResult ;
}
DetectionBasedTracker : : Parameters : : Parameters ( )
cv : : DetectionBasedTracker : : Parameters : : Parameters ( )
{
maxTrackLifetime = 5 ;
minDetectionPeriod = 0 ;
}
DetectionBasedTracker : : InnerParameters : : InnerParameters ( )
cv : : DetectionBasedTracker : : InnerParameters : : InnerParameters ( )
{
numLastPositionsToTrack = 4 ;
numStepsToWaitBeforeFirstShow = 6 ;
@ -450,7 +453,7 @@ DetectionBasedTracker::InnerParameters::InnerParameters()
}
DetectionBasedTracker : : DetectionBasedTracker ( cv : : Ptr < IDetector > mainDetector , cv : : Ptr < IDetector > trackingDetector , const Parameters & params )
cv : : DetectionBasedTracker : : DetectionBasedTracker ( cv : : Ptr < IDetector > mainDetector , cv : : Ptr < IDetector > trackingDetector , const Parameters & params )
: separateDetectionWork ( ) ,
parameters ( params ) ,
innerParameters ( ) ,
@ -471,7 +474,7 @@ DetectionBasedTracker::DetectionBasedTracker(cv::Ptr<IDetector> mainDetector, cv
weightsSizesSmoothing . push_back ( 0.2 ) ;
}
DetectionBasedTracker : : ~ DetectionBasedTracker ( )
cv : : DetectionBasedTracker : : ~ DetectionBasedTracker ( )
{
}
@ -544,7 +547,7 @@ void DetectionBasedTracker::process(const Mat& imageGray)
updateTrackedObjects ( detectedObjectsInRegions ) ;
}
void DetectionBasedTracker : : getObjects ( std : : vector < cv : : Rect > & result ) const
void cv : : DetectionBasedTracker : : getObjects ( std : : vector < cv : : Rect > & result ) const
{
result . clear ( ) ;
@ -558,7 +561,7 @@ void DetectionBasedTracker::getObjects(std::vector<cv::Rect>& result) const
}
}
void DetectionBasedTracker : : getObjects ( std : : vector < Object > & result ) const
void cv : : DetectionBasedTracker : : getObjects ( std : : vector < Object > & result ) const
{
result . clear ( ) ;
@ -571,7 +574,7 @@ void DetectionBasedTracker::getObjects(std::vector<Object>& 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 < ExtObject > & result ) const
void cv : : DetectionBasedTracker : : getObjects ( std : : vector < ExtObject > & result ) const
{
result . clear ( ) ;
@ -583,7 +586,7 @@ void DetectionBasedTracker::getObjects(std::vector<ExtObject>& result) const
}
}
bool DetectionBasedTracker : : run ( )
bool cv : : DetectionBasedTracker : : run ( )
{
if ( ! separateDetectionWork . empty ( ) ) {
return separateDetectionWork - > run ( ) ;
@ -591,14 +594,14 @@ bool DetectionBasedTracker::run()
return false ;
}
void DetectionBasedTracker : : stop ( )
void cv : : DetectionBasedTracker : : stop ( )
{
if ( ! separateDetectionWork . empty ( ) ) {
separateDetectionWork - > stop ( ) ;
}
}
void DetectionBasedTracker : : resetTracking ( )
void cv : : DetectionBasedTracker : : resetTracking ( )
{
if ( ! separateDetectionWork . empty ( ) ) {
separateDetectionWork - > resetTracking ( ) ;
@ -606,7 +609,7 @@ void DetectionBasedTracker::resetTracking()
trackedObjects . clear ( ) ;
}
void DetectionBasedTracker : : updateTrackedObjects ( const vector < Rect > & detectedObjects )
void cv : : DetectionBasedTracker : : updateTrackedObjects ( const vector < Rect > & detectedObjects )
{
enum {
NEW_RECTANGLE = - 1 ,
@ -727,7 +730,7 @@ void DetectionBasedTracker::updateTrackedObjects(const vector<Rect>& detectedObj
}
}
int DetectionBasedTracker : : addObject ( const Rect & location )
int 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 ( TrackedObject ( location ) ) ;
@ -736,12 +739,12 @@ int DetectionBasedTracker::addObject(const Rect& location)
return newId ;
}
Rect DetectionBasedTracker : : calcTrackedObjectPositionToShow ( int i ) const
Rect cv : : DetectionBasedTracker : : calcTrackedObjectPositionToShow ( int i ) const
{
ObjectStatus status ;
return calcTrackedObjectPositionToShow ( i , status ) ;
}
Rect DetectionBasedTracker : : calcTrackedObjectPositionToShow ( int i , ObjectStatus & status ) const
Rect cv : : DetectionBasedTracker : : calcTrackedObjectPositionToShow ( int i , ObjectStatus & status ) const
{
if ( ( i < 0 ) | | ( i > = ( int ) trackedObjects . size ( ) ) ) {
LOGE ( " DetectionBasedTracker::calcTrackedObjectPositionToShow: ERROR: wrong i=%d " , i ) ;
@ -827,7 +830,7 @@ Rect DetectionBasedTracker::calcTrackedObjectPositionToShow(int i, ObjectStatus&
return res ;
}
void DetectionBasedTracker : : detectInRegion ( const Mat & img , const Rect & r , vector < Rect > & detectedObjectsInRegions )
void cv : : DetectionBasedTracker : : detectInRegion ( const Mat & img , const Rect & r , vector < Rect > & detectedObjectsInRegions )
{
Rect r0 ( Point ( ) , img . size ( ) ) ;
Rect r1 = scale_rect ( r , innerParameters . coeffTrackingWindowSize ) ;
@ -864,7 +867,7 @@ void DetectionBasedTracker::detectInRegion(const Mat& img, const Rect& r, vector
}
}
bool DetectionBasedTracker : : setParameters ( const Parameters & params )
bool cv : : DetectionBasedTracker : : setParameters ( const Parameters & params )
{
if ( params . maxTrackLifetime < 0 )
{
@ -882,7 +885,7 @@ bool DetectionBasedTracker::setParameters(const Parameters& params)
return true ;
}
const DetectionBasedTracker : : Parameters & DetectionBasedTracker : : getParameters ( ) const
const cv : : DetectionBasedTracker : : Parameters & DetectionBasedTracker : : getParameters ( ) const
{
return parameters ;
}