Ask Your Question

HAAR Cascade opencl and Nvidia GPU - Code question

asked 2017-10-10 03:39:54 -0500

Geoff McIver gravatar image

Hi, I've been trying to get a performance lift in detector.detectMultiScale in opencv 3.2.

it appears that opencl HAAR cascade classifiers are only "supported" on AMD or intel opencl devices.

with a nvidia GPU and opencl enabled the code simply does not work. Here is the offending block in cascadedetect.cpp

line 606. It appears that if your device is not intel or AMD then the localSize of the featureEvaluator is set @ Size(0, 0)

if (ocl::haveOpenCL())
    if (ocl::Device::getDefault().isAMD() || ocl::Device::getDefault().isIntel())
        localSize = Size(8, 8);
        lbufSize = Size(origWinSize.width + localSize.width,
                        origWinSize.height + localSize.height);
        if (lbufSize.area() > 1024)
            lbufSize = Size(0, 0);

Why is this?

setting this Size(0, 0) means that the area() call later on returns 0 rendering use_ocl == false

     bool use_ocl = tryOpenCL && ocl::useOpenCL() &&
     OCL_FORCE_CHECK(_image.isUMat()) &&
     featureEvaluator->getLocalSize().area() > 0 &&
     (data.minNodesPerTree == data.maxNodesPerTree) &&
     !isOldFormatCascade() &&
     maskGenerator.empty() &&

I have tested removing the device vendor checks and it appears to function.

My question boils down to... Is there a genuine reason for not supporting OpenCL HAAR Cascades on Nvidia GPU's?

Since the cuda cascade classifier package is out of date and really doesn't function it seems that openCL is a viable candidate for a lift in detection performance.

There appears to be no comments in the code to say why only AMD and INTEL opencl devices are allowed here.

Please advise if I should take this to github.

edit retag flag offensive close merge delete


may be you should update your code before posting an issue

LBerger gravatar imageLBerger ( 2017-10-10 03:44:47 -0500 )edit

Do you mean update to 3.3 or pull master from the repo?

Geoff McIver gravatar imageGeoff McIver ( 2017-10-10 04:12:28 -0500 )edit
LBerger gravatar imageLBerger ( 2017-10-10 04:17:37 -0500 )edit

I've looked at the changes and they don't seem relevant. I'll build master and test.

Geoff McIver gravatar imageGeoff McIver ( 2017-10-10 04:33:13 -0500 )edit

I've pushed a fix and the opencv team have merged it. Anyone who wants this speed up will have to build off master.

Geoff McIver gravatar imageGeoff McIver ( 2017-10-11 12:26:44 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2017-10-11 07:19:36 -0500

What @LBerger is trying to say is that someone beat you to it and got the fix already integrated in latest master, in this commit.

edit flag offensive delete link more


And it seems it was you who provided it ^_^

StevenPuttemans gravatar imageStevenPuttemans ( 2017-10-11 07:20:40 -0500 )edit

Something is really weird in this post

LBerger gravatar imageLBerger ( 2017-10-11 14:51:49 -0500 )edit

I'm too new to answer my own question. :)

It's seems a pull req on github was faster :)

Geoff McIver gravatar imageGeoff McIver ( 2017-10-11 15:17:48 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-10-10 03:39:54 -0500

Seen: 59 times

Last updated: Oct 11