Ask Your Question

Is CascadeClassifier_GPU really thread-unsafe?

asked 2013-08-02 14:50:43 -0500

xaffeine gravatar image

In my multithreaded C++ program, I get malfunctions unless I keep CascadeClassifier_GPU::detectMultiScale inside a critical section. This is true even though each of my calling threads has a separate instance of CascadeClassifier_GPU.

Why is this? Is it a bug?

In the code below, all I have to do to make it break is to remove the scoped lock. This seems to prove the thread-unsafety.

void OcvGpuFaceFinder::detectMultiScale( const cv::Mat & img, std::vector< cv::Rect> & faceRects
            , double scaleFactor
            , int minNeighbors, int flagsIgnored
            , cv::Size minFaceSize
            , cv::Size maxFaceSizeIgnored

    static MJCCritSect critter;

    cv::gpu::GpuMat d_img;
    d_img.upload( img );

    int numFound= 0;
    cv::Mat rectMat;
    cv::gpu::GpuMat d_objBuf;

        MJCCritSect::ScopedLocker locker( critter );
        numFound = m_impl.detectMultiScale( d_img, d_objBuf
            , scaleFactor
            , minNeighbors
            , minFaceSize

    // download the part of the gpu dest Mat that contains found face rectangles
    d_objBuf.colRange(0, numFound).download( rectMat );
    cv::Rect* faces = rectMat.ptr<cv::Rect>();

    // copy face rects to final destination
    for( int ii=0; ii < numFound; ++ii )
        faceRects.push_back( faces[ ii ] );

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-08-03 09:48:15 -0500

Vladislav Vinogradov gravatar image

Yes, it is not thread-safe even for different objects. Implementation uses some global objects (textures).

edit flag offensive delete link more


very sad -- I hope this bug can be fixed!

xaffeine gravatar imagexaffeine ( 2013-08-05 12:39:41 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2013-08-02 14:50:43 -0500

Seen: 335 times

Last updated: Aug 03 '13