How do I build OpenCV with TBB?
Asked Answered
G

7

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?

Gall answered 3/11, 2011 at 11:40 Comment(0)
B
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 
Blok answered 26/5, 2014 at 17:8 Comment(2)
The op is obviously on Windows.Gilead
@Gilead - The answers are not just for the OP. You can actually land on this page by googling build Open CV Mac like I did.Blok
P
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!

Polky answered 8/1, 2013 at 18:46 Comment(0)
D
2

For linux, do:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON BUILD_TBB=ON ..
Deodar answered 21/12, 2015 at 19:48 Comment(0)
B
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

Babara answered 3/11, 2011 at 12:6 Comment(3)
Where do I set this? Do I need to run something to install TBB? All I've done is extract the .zip file.Gall
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.Babara
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 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.Gall
G
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.

Grieve answered 12/6, 2014 at 19:31 Comment(0)
S
0

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

$ sudo apt-get install libtbb-dev
Schlosser answered 3/6, 2017 at 18:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.