11

I'm trying and failing to make opencv_traincascade use multiple threads. The only documentation I can find says to "build OpenCV with TBB". I'm not sure if I'm failing to successfully build OpenCV with TBB, or whether there's some flag I need to set for opencv_traincascade.

I've downloaded the OpenCV version 2.3.1 windows superpack and tbb40_20111003oss_win.zip, which I extracted to C:\tbb40_20111003oss. I then generated VC8 .sln and .proj files using CMake, setting

WITH_TBB: ON

TBB_INCLUDE_DIR:PATH=C:\tbb40_20111003oss\include

TBB_LIB_DIR:PATH=C:/tbb40_20111003oss/lib/intel64/vc8

OpenCV then builds without errors, but when I run opencv_traincascade it's singlethreaded. Does anyone know what I'm doing wrong?

Community
  • 1
  • 1
theotherphil
  • 667
  • 2
  • 10
  • 16

7 Answers7

5

If you are on Mac you can do this with homebrew:

brew tap homebrew/science
brew install opencv --with-tbb

Or if you have already installed with homebrew:

brew uninstall opencv
brew install opencv --with-tbb

Also, the info command tells you about other flags you might be interested in, e.g. --with-java

brew info opencv 
Robert
  • 37,670
  • 37
  • 171
  • 213
2

I know this is an old thread but I think the problem is that you are using Traincascade with Haart feature insdead of using with the LBP features which uses integer instead of floating point and are working 3 times faster.

See the comment in this question for more information from the author about this. Quick summary: Haart training is difficult to paralelize but LBP is much easier and take advantage of a lot of processors.

Hope it help!

Jean-François Côté
  • 4,200
  • 11
  • 52
  • 88
2

For linux, do:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON BUILD_TBB=ON ..
ozgeneral
  • 6,079
  • 2
  • 30
  • 45
1

Try setNumThreads(), with the number of your processor cores as parameters. There is a helper function to find the optimum number of threads (equals the number of cores), but I cannot remember it.

And make sure you also rebuild the train_cascade exe

Sam
  • 19,708
  • 4
  • 59
  • 82
  • Where do I set this? Do I need to run something to install TBB? All I've done is extract the .zip file. – theotherphil Nov 03 '11 at 12:15
  • call the function in your code... if you have your own project. But.. hmm, did you add the TBB in the system PATH? if not, please do it, log out and log in again and try it. – Sam Nov 03 '11 at 12:17
  • The .vcproj files generated by CMake list the TBB directories as additional include directories. I've added TBB to the system path and rebuilt, but with no luck. The documentation here http://opencv.itseez.com/trunk/doc/user_guide/ug_traincascade.html states that "Note opencv_traincascade application is TBB-parallelized. To use it in multicore mode OpenCV must be built with TBB." It doesn't mention a multicore flag as input, so it appears to suggest that opencv_traincascade should automatically run multithreaded. But it doesn't. – theotherphil Nov 03 '11 at 12:38
0

Instructions here: http://devel-open.blogspot.com.ar/2012/06/instalando-opencv-240-en-ubuntu.html

gal007
  • 6,911
  • 8
  • 47
  • 70
0

After building the tbb binaries, make sure your path is correctly directing your executable to the tbb dlls. It is possible that you are loading the non-tbb dlls (this happened to me) and these will provide no multithreading.

Ade
  • 1
0

Also, one touch point is the installation of Intel TBB on the system:

$ sudo apt-get install libtbb-dev
user1756541
  • 89
  • 1
  • 4