2011-11-16 18:29:10 +01:00
# if defined(__linux__) || defined(LINUX) || defined(__APPLE__) || defined(ANDROID)
# include "opencv2/contrib/detection_based_tracker.hpp"
# define DEBUGLOGS 1
2012-06-07 19:21:29 +02:00
# ifdef ANDROID
2011-11-16 18:29:10 +01:00
# include <android/log.h>
# define LOG_TAG "OBJECT_DETECTOR"
# define LOGD0(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
# define LOGI0(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
# define LOGW0(...) ((void)__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
# define LOGE0(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
# else
# include <stdio.h>
# define LOGD0(_str, ...) do{printf(_str , ## __VA_ARGS__); printf("\n");fflush(stdout);} while(0)
# define LOGI0(_str, ...) do{printf(_str , ## __VA_ARGS__); printf("\n");fflush(stdout);} while(0)
# define LOGW0(_str, ...) do{printf(_str , ## __VA_ARGS__); printf("\n");fflush(stdout);} while(0)
# define LOGE0(_str, ...) do{printf(_str , ## __VA_ARGS__); printf("\n");fflush(stdout);} while(0)
# endif
# if DEBUGLOGS
# define LOGD(_str, ...) LOGD0(_str , ## __VA_ARGS__)
# define LOGI(_str, ...) LOGI0(_str , ## __VA_ARGS__)
# define LOGW(_str, ...) LOGW0(_str , ## __VA_ARGS__)
# define LOGE(_str, ...) LOGE0(_str , ## __VA_ARGS__)
2012-06-07 19:21:29 +02:00
# else
2011-11-16 18:29:10 +01:00
# define LOGD(...) do{} while(0)
# define LOGI(...) do{} while(0)
# define LOGW(...) do{} while(0)
# define LOGE(...) do{} while(0)
# endif
using namespace cv ;
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 ) ;
2012-08-23 12:39:10 +02:00
}
2012-06-25 19:01:55 +02:00
2011-11-16 18:29:10 +01:00
static inline cv : : Rect scale_rect ( const cv : : Rect & r , float scale )
{
cv : : Point2f m = centerRect ( r ) ;
float width = r . width * scale ;
float height = r . height * scale ;
int x = cvRound ( m . x - width / 2 ) ;
int y = cvRound ( m . y - height / 2 ) ;
return cv : : Rect ( x , y , cvRound ( width ) , cvRound ( height ) ) ;
2012-08-23 12:39:10 +02:00
}
2011-11-16 18:29:10 +01:00
2012-06-25 19:01:55 +02:00
namespace cv
{
void * workcycleObjectDetectorFunction ( void * p ) ;
}
class cv : : DetectionBasedTracker : : SeparateDetectionWork
2011-11-16 18:29:10 +01:00
{
2011-11-17 16:17:02 +01:00
public :
2012-06-25 19:01:55 +02:00
SeparateDetectionWork ( cv : : DetectionBasedTracker & _detectionBasedTracker , cv : : Ptr < DetectionBasedTracker : : IDetector > _detector ) ;
2011-11-17 16:17:02 +01:00
virtual ~ SeparateDetectionWork ( ) ;
bool communicateWithDetectingThread ( const Mat & imageGray , vector < Rect > & rectsWhereRegions ) ;
bool run ( ) ;
void stop ( ) ;
void resetTracking ( ) ;
2012-08-23 12:39:10 +02:00
2011-11-17 16:17:02 +01:00
inline bool isWorking ( )
{
2011-11-17 17:16:09 +01:00
return ( stateThread = = STATE_THREAD_WORKING_SLEEPING ) | | ( stateThread = = STATE_THREAD_WORKING_WITH_IMAGE ) ;
2011-11-17 16:17:02 +01:00
}
inline void lock ( )
{
pthread_mutex_lock ( & mutex ) ;
}
inline void unlock ( )
{
pthread_mutex_unlock ( & mutex ) ;
}
2011-11-16 18:29:10 +01:00
2011-11-17 16:17:02 +01:00
protected :
2011-11-16 18:29:10 +01:00
2011-11-17 16:17:02 +01:00
DetectionBasedTracker & detectionBasedTracker ;
2012-06-25 19:01:55 +02:00
cv : : Ptr < DetectionBasedTracker : : IDetector > cascadeInThread ;
2011-11-16 18:29:10 +01:00
2011-11-17 16:17:02 +01:00
pthread_t second_workthread ;
pthread_mutex_t mutex ;
pthread_cond_t objectDetectorRun ;
pthread_cond_t objectDetectorThreadStartStop ;
2011-11-16 18:29:10 +01:00
2011-11-17 16:17:02 +01:00
std : : vector < cv : : Rect > resultDetect ;
volatile bool isObjectDetectingReady ;
volatile bool shouldObjectDetectingResultsBeForgot ;
2011-11-16 18:29:10 +01:00
2011-11-17 16:17:02 +01:00
enum StateSeparatedThread {
STATE_THREAD_STOPPED = 0 ,
2011-11-17 17:16:09 +01:00
STATE_THREAD_WORKING_SLEEPING ,
STATE_THREAD_WORKING_WITH_IMAGE ,
2011-11-17 16:17:02 +01:00
STATE_THREAD_WORKING ,
STATE_THREAD_STOPPING
} ;
volatile StateSeparatedThread stateThread ;
cv : : Mat imageSeparateDetecting ;
void workcycleObjectDetector ( ) ;
friend void * workcycleObjectDetectorFunction ( void * p ) ;
long long timeWhenDetectingThreadStartedWork ;
} ;
2012-06-25 19:01:55 +02:00
cv : : DetectionBasedTracker : : SeparateDetectionWork : : SeparateDetectionWork ( DetectionBasedTracker & _detectionBasedTracker , cv : : Ptr < DetectionBasedTracker : : IDetector > _detector )
2011-11-17 16:17:02 +01:00
: detectionBasedTracker ( _detectionBasedTracker ) ,
2012-05-21 15:54:42 +02:00
cascadeInThread ( ) ,
2011-11-16 18:29:10 +01:00
isObjectDetectingReady ( false ) ,
shouldObjectDetectingResultsBeForgot ( false ) ,
stateThread ( STATE_THREAD_STOPPED ) ,
2011-11-17 16:17:02 +01:00
timeWhenDetectingThreadStartedWork ( - 1 )
2011-11-16 18:29:10 +01:00
{
2012-06-25 19:01:55 +02:00
CV_Assert ( ! _detector . empty ( ) ) ;
cascadeInThread = _detector ;
2011-11-16 18:29:10 +01:00
int res = 0 ;
res = pthread_mutex_init ( & mutex , NULL ) ; //TODO: should be attributes?
if ( res ) {
2011-11-17 16:17:02 +01:00
LOGE ( " ERROR in DetectionBasedTracker::SeparateDetectionWork::SeparateDetectionWork in pthread_mutex_init(&mutex, NULL) is %d " , res ) ;
2011-11-16 18:29:10 +01:00
throw ( std : : exception ( ) ) ;
}
res = pthread_cond_init ( & objectDetectorRun , NULL ) ;
if ( res ) {
2011-11-17 16:17:02 +01:00
LOGE ( " ERROR in DetectionBasedTracker::SeparateDetectionWork::SeparateDetectionWork in pthread_cond_init(&objectDetectorRun,, NULL) is %d " , res ) ;
2011-11-16 18:29:10 +01:00
pthread_mutex_destroy ( & mutex ) ;
throw ( std : : exception ( ) ) ;
}
res = pthread_cond_init ( & objectDetectorThreadStartStop , NULL ) ;
if ( res ) {
2011-11-17 16:17:02 +01:00
LOGE ( " ERROR in DetectionBasedTracker::SeparateDetectionWork::SeparateDetectionWork in pthread_cond_init(&objectDetectorThreadStartStop,, NULL) is %d " , res ) ;
2011-11-16 18:29:10 +01:00
pthread_cond_destroy ( & objectDetectorRun ) ;
pthread_mutex_destroy ( & mutex ) ;
throw ( std : : exception ( ) ) ;
}
}
2011-11-17 16:17:02 +01:00
2012-06-25 19:01:55 +02:00
cv : : DetectionBasedTracker : : SeparateDetectionWork : : ~ SeparateDetectionWork ( )
2011-11-16 18:29:10 +01:00
{
if ( stateThread ! = STATE_THREAD_STOPPED ) {
2011-11-17 16:17:02 +01:00
LOGE ( " \n \n \n ATTENTION!!! dangerous algorithm error: destructor DetectionBasedTracker::DetectionBasedTracker::~SeparateDetectionWork is called before stopping the workthread " ) ;
2011-11-16 18:29:10 +01:00
}
pthread_cond_destroy ( & objectDetectorThreadStartStop ) ;
pthread_cond_destroy ( & objectDetectorRun ) ;
pthread_mutex_destroy ( & mutex ) ;
}
2012-06-25 19:01:55 +02:00
bool cv : : DetectionBasedTracker : : SeparateDetectionWork : : run ( )
2011-11-16 18:29:10 +01:00
{
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::run() --- start " ) ;
pthread_mutex_lock ( & mutex ) ;
if ( stateThread ! = STATE_THREAD_STOPPED ) {
LOGE ( " DetectionBasedTracker::SeparateDetectionWork::run is called while the previous run is not stopped " ) ;
2011-11-16 18:29:10 +01:00
pthread_mutex_unlock ( & mutex ) ;
2011-11-17 16:17:02 +01:00
return false ;
2011-11-16 18:29:10 +01:00
}
2011-11-17 17:16:09 +01:00
stateThread = STATE_THREAD_WORKING_SLEEPING ;
2011-11-17 16:17:02 +01:00
pthread_create ( & second_workthread , NULL , workcycleObjectDetectorFunction , ( void * ) this ) ; //TODO: add attributes?
pthread_cond_wait ( & objectDetectorThreadStartStop , & mutex ) ;
pthread_mutex_unlock ( & mutex ) ;
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::run --- end " ) ;
return true ;
2011-11-16 18:29:10 +01:00
}
# ifdef __GNUC__
2012-08-23 12:39:10 +02:00
# define CATCH_ALL_AND_LOG(_block) \
do { \
2011-11-16 18:29:10 +01:00
try { \
_block ; \
break ; \
} \
catch ( cv : : Exception & e ) { \
2012-08-23 12:39:10 +02:00
LOGE0 ( " \n %s: ERROR: OpenCV Exception caught: \n '%s' \n \n " , __func__ , e . what ( ) ) ; \
2011-11-16 18:29:10 +01:00
} catch ( std : : exception & e ) { \
2012-08-23 12:39:10 +02:00
LOGE0 ( " \n %s: ERROR: Exception caught: \n '%s' \n \n " , __func__ , e . what ( ) ) ; \
2011-11-16 18:29:10 +01:00
} catch ( . . . ) { \
2012-08-23 12:39:10 +02:00
LOGE0 ( " \n %s: ERROR: UNKNOWN Exception caught \n \n " , __func__ ) ; \
2011-11-16 18:29:10 +01:00
} \
2011-11-17 16:17:02 +01:00
} while ( 0 )
2011-11-16 18:29:10 +01:00
# else
2012-08-23 12:39:10 +02:00
# define CATCH_ALL_AND_LOG(_block) \
do { \
2011-11-16 18:29:10 +01:00
try { \
_block ; \
break ; \
} \
catch ( cv : : Exception & e ) { \
2012-08-23 12:39:10 +02:00
LOGE0 ( " \n ERROR: OpenCV Exception caught: \n '%s' \n \n " , e . what ( ) ) ; \
2011-11-16 18:29:10 +01:00
} catch ( std : : exception & e ) { \
2012-08-23 12:39:10 +02:00
LOGE0 ( " \n ERROR: Exception caught: \n '%s' \n \n " , e . what ( ) ) ; \
2011-11-16 18:29:10 +01:00
} catch ( . . . ) { \
2012-08-23 12:39:10 +02:00
LOGE0 ( " \n ERROR: UNKNOWN Exception caught \n \n " ) ; \
2011-11-16 18:29:10 +01:00
} \
2012-06-07 19:21:29 +02:00
} while ( 0 )
2011-11-16 18:29:10 +01:00
# endif
2012-06-25 19:01:55 +02:00
void * cv : : workcycleObjectDetectorFunction ( void * p )
2011-11-16 18:29:10 +01:00
{
2012-06-25 19:01:55 +02:00
CATCH_ALL_AND_LOG ( { ( ( cv : : DetectionBasedTracker : : SeparateDetectionWork * ) p ) - > workcycleObjectDetector ( ) ; } ) ;
2011-11-17 17:16:09 +01:00
try {
2012-06-25 19:01:55 +02:00
( ( cv : : DetectionBasedTracker : : SeparateDetectionWork * ) p ) - > stateThread = cv : : DetectionBasedTracker : : SeparateDetectionWork : : STATE_THREAD_STOPPED ;
2011-11-17 17:16:09 +01:00
} catch ( . . . ) {
LOGE0 ( " DetectionBasedTracker: workcycleObjectDetectorFunction: ERROR concerning pointer, received as the function parameter " ) ;
}
2011-11-16 18:29:10 +01:00
return NULL ;
}
2012-06-25 19:01:55 +02:00
void cv : : DetectionBasedTracker : : SeparateDetectionWork : : workcycleObjectDetector ( )
2011-11-16 18:29:10 +01:00
{
static double freq = getTickFrequency ( ) ;
2011-11-17 16:17:02 +01:00
LOGD0 ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- start " ) ;
2011-11-16 18:29:10 +01:00
vector < Rect > objects ;
2011-11-17 17:16:09 +01:00
CV_Assert ( stateThread = = STATE_THREAD_WORKING_SLEEPING ) ;
2012-06-07 19:21:29 +02:00
pthread_mutex_lock ( & mutex ) ;
2011-11-16 18:29:10 +01:00
{
pthread_cond_signal ( & objectDetectorThreadStartStop ) ;
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- before waiting " ) ;
2011-11-17 17:16:09 +01:00
CV_Assert ( stateThread = = STATE_THREAD_WORKING_SLEEPING ) ;
2011-11-16 18:29:10 +01:00
pthread_cond_wait ( & objectDetectorRun , & mutex ) ;
2011-11-17 17:16:09 +01:00
if ( isWorking ( ) ) {
stateThread = STATE_THREAD_WORKING_WITH_IMAGE ;
}
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- after waiting " ) ;
2011-11-16 18:29:10 +01:00
}
pthread_mutex_unlock ( & mutex ) ;
bool isFirstStep = true ;
isObjectDetectingReady = false ;
2011-11-17 17:16:09 +01:00
while ( isWorking ( ) )
2011-11-16 18:29:10 +01:00
{
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- next step " ) ;
2011-11-16 18:29:10 +01:00
if ( ! isFirstStep ) {
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- before waiting " ) ;
2011-11-17 17:16:09 +01:00
CV_Assert ( stateThread = = STATE_THREAD_WORKING_SLEEPING ) ;
2011-11-16 18:29:10 +01:00
pthread_mutex_lock ( & mutex ) ;
2012-05-22 15:24:37 +02:00
if ( ! isWorking ( ) ) { //it is a rare case, but may cause a crash
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- go out from the workcycle from inner part of lock just before waiting " ) ;
pthread_mutex_unlock ( & mutex ) ;
break ;
}
2011-11-17 17:16:09 +01:00
CV_Assert ( stateThread = = STATE_THREAD_WORKING_SLEEPING ) ;
2011-11-16 18:29:10 +01:00
pthread_cond_wait ( & objectDetectorRun , & mutex ) ;
2011-11-17 17:16:09 +01:00
if ( isWorking ( ) ) {
stateThread = STATE_THREAD_WORKING_WITH_IMAGE ;
}
2011-11-16 18:29:10 +01:00
pthread_mutex_unlock ( & mutex ) ;
2011-11-17 17:16:09 +01:00
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- after waiting " ) ;
2011-11-16 18:29:10 +01:00
} else {
isFirstStep = false ;
}
2011-11-17 17:16:09 +01:00
if ( ! isWorking ( ) ) {
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- go out from the workcycle just after waiting " ) ;
2011-11-16 18:29:10 +01:00
break ;
}
if ( imageSeparateDetecting . empty ( ) ) {
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- imageSeparateDetecting is empty, continue " ) ;
2011-11-16 18:29:10 +01:00
continue ;
}
2012-06-07 19:21:29 +02:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- start handling imageSeparateDetecting, img.size=%dx%d, img.data=0x%p " ,
2011-11-16 18:29:10 +01:00
imageSeparateDetecting . size ( ) . width , imageSeparateDetecting . size ( ) . height , ( void * ) imageSeparateDetecting . data ) ;
int64 t1_detect = getTickCount ( ) ;
2012-06-25 19:01:55 +02:00
cascadeInThread - > detect ( imageSeparateDetecting , objects ) ;
2012-06-19 10:10:05 +02:00
2012-06-25 19:01:55 +02:00
/*cascadeInThread.detectMultiScale( imageSeparateDetecting, objects,
2011-11-17 16:17:02 +01:00
detectionBasedTracker . parameters . scaleFactor , detectionBasedTracker . parameters . minNeighbors , 0
2011-11-16 18:29:10 +01:00
| CV_HAAR_SCALE_IMAGE
,
min_objectSize ,
max_objectSize
) ;
2012-06-25 19:01:55 +02:00
*/
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- end handling imageSeparateDetecting " ) ;
2011-11-16 18:29:10 +01:00
2011-11-17 17:16:09 +01:00
if ( ! isWorking ( ) ) {
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- go out from the workcycle just after detecting " ) ;
2011-11-16 18:29:10 +01:00
break ;
}
2012-08-23 12:39:10 +02:00
int64 t2_detect = getTickCount ( ) ;
int64 dt_detect = t2_detect - t1_detect ;
2011-11-16 18:29:10 +01:00
double dt_detect_ms = ( ( double ) dt_detect ) / freq * 1000.0 ;
2011-11-17 16:17:02 +01:00
LOGI ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- objects num==%d, t_ms=%.4f " , ( int ) objects . size ( ) , dt_detect_ms ) ;
2011-11-16 18:29:10 +01:00
pthread_mutex_lock ( & mutex ) ;
if ( ! shouldObjectDetectingResultsBeForgot ) {
resultDetect = objects ;
isObjectDetectingReady = true ;
} else { //shouldObjectDetectingResultsBeForgot==true
resultDetect . clear ( ) ;
isObjectDetectingReady = false ;
shouldObjectDetectingResultsBeForgot = false ;
}
2011-11-17 17:16:09 +01:00
if ( isWorking ( ) ) {
stateThread = STATE_THREAD_WORKING_SLEEPING ;
}
2011-11-16 18:29:10 +01:00
pthread_mutex_unlock ( & mutex ) ;
objects . clear ( ) ;
2011-11-17 17:16:09 +01:00
} // while(isWorking())
2011-11-16 18:29:10 +01:00
pthread_mutex_lock ( & mutex ) ;
2011-11-17 17:16:09 +01:00
stateThread = STATE_THREAD_STOPPED ;
2011-11-16 18:29:10 +01:00
isObjectDetectingReady = false ;
shouldObjectDetectingResultsBeForgot = false ;
pthread_cond_signal ( & objectDetectorThreadStartStop ) ;
pthread_mutex_unlock ( & mutex ) ;
2011-11-17 16:17:02 +01:00
LOGI ( " DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector: Returning " ) ;
2011-11-16 18:29:10 +01:00
}
2011-11-17 16:17:02 +01:00
2012-06-25 19:01:55 +02:00
void cv : : DetectionBasedTracker : : SeparateDetectionWork : : stop ( )
2011-11-16 18:29:10 +01:00
{
//FIXME: TODO: should add quickStop functionality
pthread_mutex_lock ( & mutex ) ;
2011-11-17 17:16:09 +01:00
if ( ! isWorking ( ) ) {
2011-11-16 18:29:10 +01:00
pthread_mutex_unlock ( & mutex ) ;
LOGE ( " SimpleHighguiDemoCore::stop is called but the SimpleHighguiDemoCore pthread is not active " ) ;
return ;
}
stateThread = STATE_THREAD_STOPPING ;
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::stop: before going to sleep to wait for the signal from the workthread " ) ;
2011-11-16 18:29:10 +01:00
pthread_cond_signal ( & objectDetectorRun ) ;
pthread_cond_wait ( & objectDetectorThreadStartStop , & mutex ) ;
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::stop: after receiving the signal from the workthread, stateThread=%d " , ( int ) stateThread ) ;
2011-11-16 18:29:10 +01:00
pthread_mutex_unlock ( & mutex ) ;
}
2012-06-25 19:01:55 +02:00
void cv : : DetectionBasedTracker : : SeparateDetectionWork : : resetTracking ( )
2011-11-16 18:29:10 +01:00
{
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::resetTracking " ) ;
2011-11-16 18:29:10 +01:00
pthread_mutex_lock ( & mutex ) ;
2011-11-17 17:16:09 +01:00
if ( stateThread = = STATE_THREAD_WORKING_WITH_IMAGE ) {
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::resetTracking: since workthread is detecting objects at the moment, we should make cascadeInThread stop detecting and forget the detecting results " ) ;
2011-11-16 18:29:10 +01:00
shouldObjectDetectingResultsBeForgot = true ;
//cascadeInThread.setStopFlag();//FIXME: TODO: this feature also should be contributed to OpenCV
} else {
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::resetTracking: since workthread is NOT detecting objects at the moment, we should NOT make any additional actions " ) ;
2011-11-16 18:29:10 +01:00
}
resultDetect . clear ( ) ;
isObjectDetectingReady = false ;
pthread_mutex_unlock ( & mutex ) ;
2012-06-07 19:21:29 +02:00
2011-11-16 18:29:10 +01:00
}
2012-06-25 19:01:55 +02:00
bool cv : : DetectionBasedTracker : : SeparateDetectionWork : : communicateWithDetectingThread ( const Mat & imageGray , vector < Rect > & rectsWhereRegions )
2011-11-17 16:17:02 +01:00
{
static double freq = getTickFrequency ( ) ;
2012-08-23 12:39:10 +02:00
bool shouldCommunicateWithDetectingThread = ( stateThread = = STATE_THREAD_WORKING_SLEEPING ) ;
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread: shouldCommunicateWithDetectingThread=%d " , ( shouldCommunicateWithDetectingThread ? 1 : 0 ) ) ;
if ( ! shouldCommunicateWithDetectingThread ) {
return false ;
}
2012-08-23 12:39:10 +02:00
bool shouldHandleResult = false ;
2011-11-17 16:17:02 +01:00
pthread_mutex_lock ( & mutex ) ;
if ( isObjectDetectingReady ) {
shouldHandleResult = true ;
2012-08-23 12:39:10 +02:00
rectsWhereRegions = resultDetect ;
2011-11-17 16:17:02 +01:00
isObjectDetectingReady = false ;
2012-08-23 12:39:10 +02:00
double lastBigDetectionDuration = 1000.0 * ( ( ( double ) ( getTickCount ( ) - timeWhenDetectingThreadStartedWork ) ) / freq ) ;
2011-11-17 16:17:02 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread: lastBigDetectionDuration=%f ms " , ( double ) lastBigDetectionDuration ) ;
}
2012-08-23 12:39:10 +02:00
bool shouldSendNewDataToWorkThread = true ;
2011-11-17 16:17:02 +01:00
if ( timeWhenDetectingThreadStartedWork > 0 ) {
double time_from_previous_launch_in_ms = 1000.0 * ( ( ( double ) ( getTickCount ( ) - timeWhenDetectingThreadStartedWork ) ) / freq ) ; //the same formula as for lastBigDetectionDuration
shouldSendNewDataToWorkThread = ( time_from_previous_launch_in_ms > = detectionBasedTracker . parameters . minDetectionPeriod ) ;
2012-06-07 19:21:29 +02:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread: shouldSendNewDataToWorkThread was 1, now it is %d, since time_from_previous_launch_in_ms=%.2f, minDetectionPeriod=%d " ,
2011-11-17 16:17:02 +01:00
( shouldSendNewDataToWorkThread ? 1 : 0 ) , time_from_previous_launch_in_ms , detectionBasedTracker . parameters . minDetectionPeriod ) ;
}
if ( shouldSendNewDataToWorkThread ) {
imageSeparateDetecting . create ( imageGray . size ( ) , CV_8UC1 ) ;
imageGray . copyTo ( imageSeparateDetecting ) ; //may change imageSeparateDetecting ptr. But should not.
timeWhenDetectingThreadStartedWork = getTickCount ( ) ;
pthread_cond_signal ( & objectDetectorRun ) ;
}
pthread_mutex_unlock ( & mutex ) ;
2011-11-17 17:16:09 +01:00
LOGD ( " DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread: result: shouldHandleResult=%d " , ( shouldHandleResult ? 1 : 0 ) ) ;
2011-11-17 16:17:02 +01:00
return shouldHandleResult ;
}
2012-06-25 19:01:55 +02:00
cv : : DetectionBasedTracker : : Parameters : : Parameters ( )
2011-11-17 16:17:02 +01:00
{
maxTrackLifetime = 5 ;
minDetectionPeriod = 0 ;
}
2012-06-25 19:01:55 +02:00
cv : : DetectionBasedTracker : : InnerParameters : : InnerParameters ( )
2011-11-17 16:17:02 +01:00
{
numLastPositionsToTrack = 4 ;
numStepsToWaitBeforeFirstShow = 6 ;
numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown = 3 ;
numStepsToShowWithoutDetecting = 3 ;
coeffTrackingWindowSize = 2.0 ;
coeffObjectSizeToTrack = 0.85 ;
coeffObjectSpeedUsingInPrediction = 0.8 ;
}
2012-06-25 19:01:55 +02:00
2012-06-28 18:07:10 +02:00
cv : : DetectionBasedTracker : : DetectionBasedTracker ( cv : : Ptr < IDetector > mainDetector , cv : : Ptr < IDetector > trackingDetector , const Parameters & params )
2011-11-17 16:17:02 +01:00
: separateDetectionWork ( ) ,
2012-06-25 19:01:55 +02:00
parameters ( params ) ,
2011-11-17 16:17:02 +01:00
innerParameters ( ) ,
2012-06-25 19:01:55 +02:00
numTrackedSteps ( 0 ) ,
2012-06-28 18:07:10 +02:00
cascadeForTracking ( trackingDetector )
2011-11-17 16:17:02 +01:00
{
2012-06-25 19:01:55 +02:00
CV_Assert ( ( params . maxTrackLifetime > = 0 )
2012-06-28 18:07:10 +02:00
// && (!mainDetector.empty())
& & ( ! trackingDetector . empty ( ) ) ) ;
2012-06-19 10:10:05 +02:00
2012-06-28 18:07:10 +02:00
if ( ! mainDetector . empty ( ) ) {
separateDetectionWork = new SeparateDetectionWork ( * this , mainDetector ) ;
}
2011-11-17 16:17:02 +01:00
weightsPositionsSmoothing . push_back ( 1 ) ;
weightsSizesSmoothing . push_back ( 0.5 ) ;
weightsSizesSmoothing . push_back ( 0.3 ) ;
weightsSizesSmoothing . push_back ( 0.2 ) ;
2012-06-24 10:50:03 +02:00
}
2012-06-25 19:01:55 +02:00
cv : : DetectionBasedTracker : : ~ DetectionBasedTracker ( )
2011-11-17 16:17:02 +01:00
{
}
void DetectionBasedTracker : : process ( const Mat & imageGray )
{
CV_Assert ( imageGray . type ( ) = = CV_8UC1 ) ;
2012-06-28 18:07:10 +02:00
if ( ( ! separateDetectionWork . empty ( ) ) & & ( ! separateDetectionWork - > isWorking ( ) ) ) {
2011-11-17 16:17:02 +01:00
separateDetectionWork - > run ( ) ;
}
static double freq = getTickFrequency ( ) ;
static long long time_when_last_call_started = getTickCount ( ) ;
{
double delta_time_from_prev_call = 1000.0 * ( ( ( double ) ( getTickCount ( ) - time_when_last_call_started ) ) / freq ) ;
LOGD ( " DetectionBasedTracker::process: time from the previous call is %f ms " , ( double ) delta_time_from_prev_call ) ;
time_when_last_call_started = getTickCount ( ) ;
}
Mat imageDetect = imageGray ;
vector < Rect > rectsWhereRegions ;
2012-06-28 18:07:10 +02:00
bool shouldHandleResult = false ;
if ( ! separateDetectionWork . empty ( ) ) {
shouldHandleResult = separateDetectionWork - > communicateWithDetectingThread ( imageGray , rectsWhereRegions ) ;
}
2011-11-17 16:17:02 +01:00
if ( shouldHandleResult ) {
LOGD ( " DetectionBasedTracker::process: get _rectsWhereRegions were got from resultDetect " ) ;
} else {
LOGD ( " DetectionBasedTracker::process: get _rectsWhereRegions from previous positions " ) ;
2012-08-23 12:39:10 +02:00
for ( size_t i = 0 ; i < trackedObjects . size ( ) ; i + + ) {
int n = trackedObjects [ i ] . lastPositions . size ( ) ;
2011-11-17 16:17:02 +01:00
CV_Assert ( n > 0 ) ;
2012-08-23 12:39:10 +02:00
Rect r = trackedObjects [ i ] . lastPositions [ n - 1 ] ;
if ( r . area ( ) = = 0 ) {
2011-11-17 16:17:02 +01:00
LOGE ( " DetectionBasedTracker::process: ERROR: ATTENTION: strange algorithm's behavior: trackedObjects[i].rect() is empty " ) ;
continue ;
}
//correction by speed of rectangle
if ( n > 1 ) {
2012-08-23 12:39:10 +02:00
Point2f center = centerRect ( r ) ;
Point2f center_prev = centerRect ( trackedObjects [ i ] . lastPositions [ n - 2 ] ) ;
Point2f shift = ( center - center_prev ) * innerParameters . coeffObjectSpeedUsingInPrediction ;
2011-11-17 16:17:02 +01:00
2012-08-23 12:39:10 +02:00
r . x + = cvRound ( shift . x ) ;
r . y + = cvRound ( shift . y ) ;
2011-11-17 16:17:02 +01:00
}
rectsWhereRegions . push_back ( r ) ;
}
}
LOGI ( " DetectionBasedTracker::process: tracked objects num==%d " , ( int ) trackedObjects . size ( ) ) ;
vector < Rect > detectedObjectsInRegions ;
LOGD ( " DetectionBasedTracker::process: rectsWhereRegions.size()=%d " , ( int ) rectsWhereRegions . size ( ) ) ;
for ( size_t i = 0 ; i < rectsWhereRegions . size ( ) ; i + + ) {
2012-08-23 12:39:10 +02:00
Rect r = rectsWhereRegions [ i ] ;
2011-11-17 16:17:02 +01:00
detectInRegion ( imageDetect , r , detectedObjectsInRegions ) ;
}
LOGD ( " DetectionBasedTracker::process: detectedObjectsInRegions.size()=%d " , ( int ) detectedObjectsInRegions . size ( ) ) ;
updateTrackedObjects ( detectedObjectsInRegions ) ;
}
2012-06-25 19:01:55 +02:00
void cv : : DetectionBasedTracker : : getObjects ( std : : vector < cv : : Rect > & result ) const
2011-11-17 16:17:02 +01:00
{
result . clear ( ) ;
for ( size_t i = 0 ; i < trackedObjects . size ( ) ; i + + ) {
Rect r = calcTrackedObjectPositionToShow ( i ) ;
if ( r . area ( ) = = 0 ) {
continue ;
}
result . push_back ( r ) ;
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 ) ;
}
}
2012-06-25 19:01:55 +02:00
void cv : : DetectionBasedTracker : : getObjects ( std : : vector < Object > & result ) const
2011-11-17 16:17:02 +01:00
{
result . clear ( ) ;
for ( size_t i = 0 ; i < trackedObjects . size ( ) ; i + + ) {
Rect r = calcTrackedObjectPositionToShow ( i ) ;
if ( r . area ( ) = = 0 ) {
continue ;
}
result . push_back ( Object ( r , trackedObjects [ i ] . id ) ) ;
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 ) ;
}
}
2012-06-25 19:01:55 +02:00
bool cv : : DetectionBasedTracker : : run ( )
2011-11-17 16:17:02 +01:00
{
2012-06-28 18:07:10 +02:00
if ( ! separateDetectionWork . empty ( ) ) {
return separateDetectionWork - > run ( ) ;
}
return false ;
2011-11-17 16:17:02 +01:00
}
2012-06-25 19:01:55 +02:00
void cv : : DetectionBasedTracker : : stop ( )
2011-11-17 16:17:02 +01:00
{
2012-06-28 18:07:10 +02:00
if ( ! separateDetectionWork . empty ( ) ) {
separateDetectionWork - > stop ( ) ;
}
2011-11-17 16:17:02 +01:00
}
2012-06-25 19:01:55 +02:00
void cv : : DetectionBasedTracker : : resetTracking ( )
2011-11-17 16:17:02 +01:00
{
2012-06-28 18:07:10 +02:00
if ( ! separateDetectionWork . empty ( ) ) {
separateDetectionWork - > resetTracking ( ) ;
}
2011-11-17 16:17:02 +01:00
trackedObjects . clear ( ) ;
}
2012-06-25 19:01:55 +02:00
void cv : : DetectionBasedTracker : : updateTrackedObjects ( const vector < Rect > & detectedObjects )
2011-11-16 18:29:10 +01:00
{
enum {
NEW_RECTANGLE = - 1 ,
INTERSECTED_RECTANGLE = - 2
} ;
int N1 = trackedObjects . size ( ) ;
int N2 = detectedObjects . size ( ) ;
LOGD ( " DetectionBasedTracker::updateTrackedObjects: N1=%d, N2=%d " , N1 , N2 ) ;
for ( int i = 0 ; i < N1 ; i + + ) {
trackedObjects [ i ] . numDetectedFrames + + ;
}
vector < int > correspondence ( detectedObjects . size ( ) , NEW_RECTANGLE ) ;
correspondence . clear ( ) ;
correspondence . resize ( detectedObjects . size ( ) , NEW_RECTANGLE ) ;
for ( int i = 0 ; i < N1 ; i + + ) {
LOGD ( " DetectionBasedTracker::updateTrackedObjects: i=%d " , i ) ;
TrackedObject & curObject = trackedObjects [ i ] ;
int bestIndex = - 1 ;
int bestArea = - 1 ;
int numpositions = curObject . lastPositions . size ( ) ;
CV_Assert ( numpositions > 0 ) ;
Rect prevRect = curObject . lastPositions [ numpositions - 1 ] ;
LOGD ( " DetectionBasedTracker::updateTrackedObjects: prevRect[%d]={%d, %d, %d x %d} " , i , prevRect . x , prevRect . y , prevRect . width , prevRect . height ) ;
for ( int j = 0 ; j < N2 ; j + + ) {
LOGD ( " DetectionBasedTracker::updateTrackedObjects: j=%d " , j ) ;
if ( correspondence [ j ] > = 0 ) {
LOGD ( " DetectionBasedTracker::updateTrackedObjects: j=%d is rejected, because it has correspondence=%d " , j , correspondence [ j ] ) ;
continue ;
}
if ( correspondence [ j ] ! = NEW_RECTANGLE ) {
LOGD ( " DetectionBasedTracker::updateTrackedObjects: j=%d is rejected, because it is intersected with another rectangle " , j ) ;
continue ;
}
2012-06-07 19:21:29 +02:00
LOGD ( " DetectionBasedTracker::updateTrackedObjects: detectedObjects[%d]={%d, %d, %d x %d} " ,
2011-11-16 18:29:10 +01:00
j , detectedObjects [ j ] . x , detectedObjects [ j ] . y , detectedObjects [ j ] . width , detectedObjects [ j ] . height ) ;
Rect r = prevRect & detectedObjects [ j ] ;
if ( ( r . width > 0 ) & & ( r . height > 0 ) ) {
LOGD ( " DetectionBasedTracker::updateTrackedObjects: There is intersection between prevRect and detectedRect, r={%d, %d, %d x %d} " ,
r . x , r . y , r . width , r . height ) ;
correspondence [ j ] = INTERSECTED_RECTANGLE ;
if ( r . area ( ) > bestArea ) {
LOGD ( " DetectionBasedTracker::updateTrackedObjects: The area of intersection is %d, it is better than bestArea=%d " , r . area ( ) , bestArea ) ;
bestIndex = j ;
bestArea = r . area ( ) ;
}
}
}
if ( bestIndex > = 0 ) {
LOGD ( " DetectionBasedTracker::updateTrackedObjects: The best correspondence for i=%d is j=%d " , i , bestIndex ) ;
correspondence [ bestIndex ] = i ;
for ( int j = 0 ; j < N2 ; j + + ) {
if ( correspondence [ j ] > = 0 )
continue ;
Rect r = detectedObjects [ j ] & detectedObjects [ bestIndex ] ;
if ( ( r . width > 0 ) & & ( r . height > 0 ) ) {
LOGD ( " DetectionBasedTracker::updateTrackedObjects: Found intersection between "
" rectangles j=%d and bestIndex=%d, rectangle j=%d is marked as intersected " , j , bestIndex , j ) ;
correspondence [ j ] = INTERSECTED_RECTANGLE ;
}
}
} else {
LOGD ( " DetectionBasedTracker::updateTrackedObjects: There is no correspondence for i=%d " , i ) ;
curObject . numFramesNotDetected + + ;
}
}
LOGD ( " DetectionBasedTracker::updateTrackedObjects: start second cycle " ) ;
for ( int j = 0 ; j < N2 ; j + + ) {
LOGD ( " DetectionBasedTracker::updateTrackedObjects: j=%d " , j ) ;
int i = correspondence [ j ] ;
if ( i > = 0 ) { //add position
LOGD ( " DetectionBasedTracker::updateTrackedObjects: add position " ) ;
trackedObjects [ i ] . lastPositions . push_back ( detectedObjects [ j ] ) ;
while ( ( int ) trackedObjects [ i ] . lastPositions . size ( ) > ( int ) innerParameters . numLastPositionsToTrack ) {
trackedObjects [ i ] . lastPositions . erase ( trackedObjects [ i ] . lastPositions . begin ( ) ) ;
}
trackedObjects [ i ] . numFramesNotDetected = 0 ;
} else if ( i = = NEW_RECTANGLE ) { //new object
LOGD ( " DetectionBasedTracker::updateTrackedObjects: new object " ) ;
trackedObjects . push_back ( detectedObjects [ j ] ) ;
} else {
LOGD ( " DetectionBasedTracker::updateTrackedObjects: was auxiliary intersection " ) ;
}
}
std : : vector < TrackedObject > : : iterator it = trackedObjects . begin ( ) ;
while ( it ! = trackedObjects . end ( ) ) {
2012-06-07 19:21:29 +02:00
if ( ( it - > numFramesNotDetected > parameters . maxTrackLifetime )
2011-11-16 18:29:10 +01:00
| |
2012-06-07 19:21:29 +02:00
(
2011-11-16 18:29:10 +01:00
( it - > numDetectedFrames < = innerParameters . numStepsToWaitBeforeFirstShow )
& &
( it - > numFramesNotDetected > innerParameters . numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown )
)
)
{
int numpos = it - > lastPositions . size ( ) ;
CV_Assert ( numpos > 0 ) ;
Rect r = it - > lastPositions [ numpos - 1 ] ;
LOGD ( " DetectionBasedTracker::updateTrackedObjects: deleted object {%d, %d, %d x %d} " ,
r . x , r . y , r . width , r . height ) ;
it = trackedObjects . erase ( it ) ;
} else {
it + + ;
}
}
}
2012-06-25 19:01:55 +02:00
2012-07-09 16:37:12 +02:00
int cv : : DetectionBasedTracker : : addObject ( const Rect & location )
2012-06-28 18:07:10 +02:00
{
LOGD ( " DetectionBasedTracker::addObject: new object {%d, %d %dx%d} " , location . x , location . y , location . width , location . height ) ;
2012-07-09 16:37:12 +02:00
trackedObjects . push_back ( TrackedObject ( location ) ) ;
int newId = trackedObjects . back ( ) . id ;
LOGD ( " DetectionBasedTracker::addObject: newId = %d " , newId ) ;
return newId ;
2012-06-28 18:07:10 +02:00
}
2012-06-25 19:01:55 +02:00
Rect cv : : DetectionBasedTracker : : calcTrackedObjectPositionToShow ( int i ) const
2011-11-16 18:29:10 +01:00
{
if ( ( i < 0 ) | | ( i > = ( int ) trackedObjects . size ( ) ) ) {
LOGE ( " DetectionBasedTracker::calcTrackedObjectPositionToShow: ERROR: wrong i=%d " , i ) ;
return Rect ( ) ;
}
if ( trackedObjects [ i ] . numDetectedFrames < = innerParameters . numStepsToWaitBeforeFirstShow ) {
2012-06-07 19:21:29 +02:00
LOGI ( " DetectionBasedTracker::calcTrackedObjectPositionToShow: trackedObjects[%d].numDetectedFrames=%d <= numStepsToWaitBeforeFirstShow=%d --- return empty Rect() " ,
2011-11-16 18:29:10 +01:00
i , trackedObjects [ i ] . numDetectedFrames , innerParameters . numStepsToWaitBeforeFirstShow ) ;
return Rect ( ) ;
}
if ( trackedObjects [ i ] . numFramesNotDetected > innerParameters . numStepsToShowWithoutDetecting ) {
return Rect ( ) ;
}
const TrackedObject : : PositionsVector & lastPositions = trackedObjects [ i ] . lastPositions ;
int N = lastPositions . size ( ) ;
if ( N < = 0 ) {
LOGE ( " DetectionBasedTracker::calcTrackedObjectPositionToShow: ERROR: no positions for i=%d " , i ) ;
return Rect ( ) ;
}
int Nsize = std : : min ( N , ( int ) weightsSizesSmoothing . size ( ) ) ;
int Ncenter = std : : min ( N , ( int ) weightsPositionsSmoothing . size ( ) ) ;
Point2f center ;
double w = 0 , h = 0 ;
if ( Nsize > 0 ) {
double sum = 0 ;
for ( int j = 0 ; j < Nsize ; j + + ) {
int k = N - j - 1 ;
2012-06-25 19:01:55 +02:00
w + = lastPositions [ k ] . width * weightsSizesSmoothing [ j ] ;
h + = lastPositions [ k ] . height * weightsSizesSmoothing [ j ] ;
2011-11-16 18:29:10 +01:00
sum + = weightsSizesSmoothing [ j ] ;
}
w / = sum ;
h / = sum ;
} else {
w = lastPositions [ N - 1 ] . width ;
h = lastPositions [ N - 1 ] . height ;
}
if ( Ncenter > 0 ) {
double sum = 0 ;
for ( int j = 0 ; j < Ncenter ; j + + ) {
int k = N - j - 1 ;
Point tl ( lastPositions [ k ] . tl ( ) ) ;
Point br ( lastPositions [ k ] . br ( ) ) ;
Point2f c1 ;
c1 = tl ;
2012-06-25 19:01:55 +02:00
c1 = c1 * 0.5f ;
2011-11-16 18:29:10 +01:00
Point2f c2 ;
c2 = br ;
c2 = c2 * 0.5f ;
c1 = c1 + c2 ;
center = center + ( c1 * weightsPositionsSmoothing [ j ] ) ;
sum + = weightsPositionsSmoothing [ j ] ;
}
center * = ( float ) ( 1 / sum ) ;
} else {
int k = N - 1 ;
Point tl ( lastPositions [ k ] . tl ( ) ) ;
Point br ( lastPositions [ k ] . br ( ) ) ;
Point2f c1 ;
c1 = tl ;
c1 = c1 * 0.5f ;
Point2f c2 ;
c2 = br ;
c2 = c2 * 0.5f ;
center = c1 + c2 ;
}
Point2f tl = center - ( Point2f ( w , h ) * 0.5 ) ;
Rect res ( cvRound ( tl . x ) , cvRound ( tl . y ) , cvRound ( w ) , cvRound ( h ) ) ;
LOGD ( " DetectionBasedTracker::calcTrackedObjectPositionToShow: Result for i=%d: {%d, %d, %d x %d} " , i , res . x , res . y , res . width , res . height ) ;
return res ;
}
2012-06-25 19:01:55 +02:00
void cv : : DetectionBasedTracker : : detectInRegion ( const Mat & img , const Rect & r , vector < Rect > & detectedObjectsInRegions )
2011-11-16 18:29:10 +01:00
{
Rect r0 ( Point ( ) , img . size ( ) ) ;
2012-08-23 12:39:10 +02:00
Rect r1 = scale_rect ( r , innerParameters . coeffTrackingWindowSize ) ;
r1 = r1 & r0 ;
2011-11-16 18:29:10 +01:00
if ( ( r1 . width < = 0 ) | | ( r1 . height < = 0 ) ) {
LOGD ( " DetectionBasedTracker::detectInRegion: Empty intersection " ) ;
return ;
}
2012-06-25 19:01:55 +02:00
int d = cvRound ( std : : min ( r . width , r . height ) * innerParameters . coeffObjectSizeToTrack ) ;
2011-11-16 18:29:10 +01:00
vector < Rect > tmpobjects ;
Mat img1 ( img , r1 ) ; //subimage for rectangle -- without data copying
LOGD ( " DetectionBasedTracker::detectInRegion: img1.size()=%d x %d, d=%d " ,
img1 . size ( ) . width , img1 . size ( ) . height , d ) ;
2012-06-25 19:01:55 +02:00
cascadeForTracking - > setMinObjectSize ( Size ( d , d ) ) ;
cascadeForTracking - > detect ( img1 , tmpobjects ) ;
/*
detectMultiScale ( img1 , tmpobjects ,
2011-11-16 18:29:10 +01:00
parameters . scaleFactor , parameters . minNeighbors , 0
| CV_HAAR_FIND_BIGGEST_OBJECT
| CV_HAAR_SCALE_IMAGE
,
Size ( d , d ) ,
max_objectSize
2012-06-25 19:01:55 +02:00
) ; */
2011-11-16 18:29:10 +01:00
for ( size_t i = 0 ; i < tmpobjects . size ( ) ; i + + ) {
Rect curres ( tmpobjects [ i ] . tl ( ) + r1 . tl ( ) , tmpobjects [ i ] . size ( ) ) ;
detectedObjectsInRegions . push_back ( curres ) ;
}
}
2012-06-25 19:01:55 +02:00
bool cv : : DetectionBasedTracker : : setParameters ( const Parameters & params )
2011-11-16 18:29:10 +01:00
{
2012-06-25 19:01:55 +02:00
if ( params . maxTrackLifetime < 0 )
2011-11-16 18:29:10 +01:00
{
LOGE ( " DetectionBasedTracker::setParameters: ERROR: wrong parameters value " ) ;
return false ;
}
2012-06-28 18:07:10 +02:00
if ( ! separateDetectionWork . empty ( ) ) {
separateDetectionWork - > lock ( ) ;
}
2011-11-16 18:29:10 +01:00
parameters = params ;
2012-06-28 18:07:10 +02:00
if ( ! separateDetectionWork . empty ( ) ) {
separateDetectionWork - > unlock ( ) ;
}
2011-11-16 18:29:10 +01:00
return true ;
}
2012-07-09 16:37:12 +02:00
const cv : : DetectionBasedTracker : : Parameters & DetectionBasedTracker : : getParameters ( ) const
2011-11-16 18:29:10 +01:00
{
return parameters ;
}
# endif