From 16a82b17475fad26a45b76e8e18a886a6c50aa9e Mon Sep 17 00:00:00 2001 From: Joan Puigcerver Date: Wed, 23 Jul 2014 22:47:51 +0200 Subject: [PATCH] Added an option to traincascade program to select the maximum number of threads to use during training --- apps/traincascade/traincascade.cpp | 7 +++++++ doc/user_guide/ug_traincascade.rst | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/apps/traincascade/traincascade.cpp b/apps/traincascade/traincascade.cpp index e6e16ba89..52bacc808 100644 --- a/apps/traincascade/traincascade.cpp +++ b/apps/traincascade/traincascade.cpp @@ -13,6 +13,7 @@ int main( int argc, char* argv[] ) int numPos = 2000; int numNeg = 1000; int numStages = 20; + int numThreads = getNumThreads(); int precalcValBufSize = 256, precalcIdxBufSize = 256; bool baseFormatSave = false; @@ -36,6 +37,7 @@ int main( int argc, char* argv[] ) cout << " [-precalcValBufSize ]" << endl; cout << " [-precalcIdxBufSize ]" << endl; cout << " [-baseFormatSave]" << endl; + cout << " [-numThreads ]" << endl; cascadeParams.printDefaults(); stageParams.printDefaults(); for( int fi = 0; fi < fc; fi++ ) @@ -82,6 +84,10 @@ int main( int argc, char* argv[] ) { baseFormatSave = true; } + else if( !strcmp( argv[i], "-numThreads" ) ) + { + numThreads = atoi(argv[++i]); + } else if ( cascadeParams.scanAttr( argv[i], argv[i+1] ) ) { i++; } else if ( stageParams.scanAttr( argv[i], argv[i+1] ) ) { i++; } else if ( !set ) @@ -98,6 +104,7 @@ int main( int argc, char* argv[] ) } } + setNumThreads( numThreads ); classifier.train( cascadeDirName, vecName, bgName, diff --git a/doc/user_guide/ug_traincascade.rst b/doc/user_guide/ug_traincascade.rst index 601f50438..20c1b1683 100644 --- a/doc/user_guide/ug_traincascade.rst +++ b/doc/user_guide/ug_traincascade.rst @@ -200,6 +200,12 @@ Command line arguments of ``opencv_traincascade`` application grouped by purpose This argument is actual in case of Haar-like features. If it is specified, the cascade will be saved in the old format. + * ``-numThreads `` + + Maximum number of threads to use during training. Notice that + the actual number of used threads may be lower, depending on + your machine and compilation options. + #. Cascade parameters: