Ask Your Question

Revision history [back]

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;
}