OpenCV 3.0 parallel_for_

asked 2015-08-26 14:20:04 -0600

Alin Popescu gravatar image

updated 2015-08-26 14:38:07 -0600

Hello,

I've implemented a parallel image descriptor extractor using opencv 3.0 parallel_for_ and BRISK descriptor extractor.

What I do is to split the image into horizontal stripes and compute the image descriptors in parallel. This is the outer call:

_extractor.init(img, featureCount);
cv::parallel_for_(cv::Range(0, _processorCount), _extractor); // _processorCount == 4 _extractor.buildFinal(keyPoints, features);

Then, for each thread I call _featureExtractor->detectAndCompute(_image, mask, keyPoints, features); with a proper initialized horizontal mask stripe.

However, this implementation doesn't run faster than the serial implementation. It runs 2x slower (23 ms for serial and 40+ ms for parallel). I did some debugging and saw opencv uses Microsoft concurrency framework. Moreover, when printing out the called range and getThreadNum() I get this:

range[0,1] thread [2]
range[3,4] thread [2]
range[2,3] thread [2]
range[1,2] thread [2]

That means that my inner code runs on a single thread, 4 times like a serial implementation. Do you know what's wrong with my approach?

Thank you, Alin

edit retag flag offensive close merge delete

Comments

I think you have four thread. About speed now If you have four thread it can be slower than one thread if time computing is very short. Memory manamgement to prepare threading is time consumming so take a big image and try to test.

LBerger gravatar imageLBerger ( 2015-08-26 14:58:42 -0600 )edit

I have tested with microsoft concurrency windows 10 and vs 2013 and I have got thread number. May be it depends of concurrency version

I have deleted following previous answer because I'm not sure :

*If you are using getThreadNumber It could be a problem. In TBB getThreadNum give always 0 with TBB version 4.3 And for Microsoft convurency it is:

      #elif defined HAVE_CONCURRENCY
        return std::max(0, (int)Concurrency::Context::VirtualProcessorId()); // zero for master thread, unique number for others but not necessary 1,2,3,...
      #else

I think that could be origin for your problem.*

LBerger gravatar imageLBerger ( 2015-08-28 04:30:00 -0600 )edit