Yes, you can do like this:
// A very raw example of using tbb's thread
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/video/video.hpp>
#include <opencv2/highgui.hpp>
#include <tbb/tbb.h>
#include <iostream>
using namespace std;
using namespace cv;
using namespace tbb;
int main(int argc, char* argv[])
{
Mat im1 = imread(argv[1]);
Mat imGray;
if (im1.data == nullptr)
{
cout << "Error while reading file " << argv[1];
return 1;
}
imshow("Input image", im1);
cvtColor(im1, imGray, CV_RGB2GRAY);
Mat im3, im4;
tbb_thread th1([&imGray, &im3]() // in fact, you can do this with C++ thread
{
int windowSize = 5; // starting threshold value
int constant = 5; // starting constant value
adaptiveThreshold(imGray, im3, 255,
CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY,
windowSize, constant);
});
tbb_thread th2([&imGray, &im4]()
{
cv::GaussianBlur(imGray, im4, cv::Size(3, 3), 5.0f);
});
th1.join();
th2.join();
imshow("Grayscale image", imGray);
imshow("Adaptive thresholding", im3);
imshow("Gaussian blur", im4);
cvWaitKey(0);
return 0;
}
Parallel processing is used very offen in OpenCV particulary in filter processing. If you want to use TBB for filtering it's always used in different way. Image is divided in strip and multi-core is used for each strip.
I think If you want to use TBB for each image you have to disable TBB in Opencv and activate TBB in your program.
There is no example for TBB because TBB is encapsulated like OpenMP COncurrency cstripes and GCD.
(what is GCD and CStripes?)
There is an interesting article "The Foundations for Scalable Multi-core Software in Intel® Threading Building Blocks" http://citeseerx.ist.psu.edu/viewdoc/... with fibonacci number example similar as is in example code within TBB package. See page 54. It's long article but contains precious examples, explaining, diagrams and benchmarks. Link to LBerger's note: http://answers.opencv.org/question/15...