OpenCV 3.3 setNumThreads(0) bug

asked 2017-09-22 09:45:15 -0600

I can produce this, only in OpenCV 3.3, only when using the pthreads parallel framework.

First If I setNumThreads (3) then, I change this value to setNumThreads (0), then I change the value again to setNumThreads (3), then the last action has no effect, and application using one thread. In general, after I set the value of setNumThreads (0), all future changes to setNumThreads() do not give an effet.

test code for produce:

#include <opencv2/opencv.hpp>
#include <chrono>
#include <iostream>

using namespace std;
using namespace std::chrono;

cv::CascadeClassifier* cascadeFrontalFace;
cv::Mat image;

std::vector<cv::Rect> detectFace(){
    std::vector<cv::Rect> dets;
    cascadeFrontalFace->detectMultiScale(image,dets, 1.2, 6,0,cv::Size(20,20));
    return dets;
}

int main(int argc, char *argv[])
{
    std::cout<< cv::getBuildInformation()<<endl;
    image = cv::imread("/home/nick64/testgstreamer/3/video12z8.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    cascadeFrontalFace=new cv::CascadeClassifier("/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml");
    int tcnt[]={3,0,3};
    for(int i=0; i<3; ++i){        
        milliseconds startTime = duration_cast< milliseconds >(
            system_clock::now().time_since_epoch()
        );

        for(int n=0; n<10; ++n){
            cv::setNumThreads(tcnt[i]);
            std::vector<cv::Rect> dets;
            cascadeFrontalFace->detectMultiScale(image,dets, 1.2, 6,0,cv::Size(20,20));
            std::cout << "face detected:" << dets.size()<<endl;
        }

        milliseconds endTime = duration_cast< milliseconds >(
            system_clock::now().time_since_epoch()
        );
        std::cout<< "between time: " << (endTime-startTime).count() << "num threads: " << cv::getNumThreads() <<endl;
    }
    delete cascadeFrontalFace;
}

Output for OpenCV 3.3:

General configuration for OpenCV 3.3.0 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /media/nick64/1c6afc58-05d2-4957-802e-352b30bdedf0/dernel_ubuntu1610/OpenCv3.3/332/opencv-3.3.0/contrib/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2017-09-22T11:06:39Z
    Host:                        Linux 4.4.0.intel.r5.0 x86_64
    CMake:                       3.5.2
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      requested:                 AVX2
    Dispatched code generation:
      requested:                 AVX AVX2

  C/C++:
    Built as dynamic libs?:      YES
    C++11:                       YES
    C++ Compiler:                /usr/bin/x86_64-linux-gnu-g++  (ver 6.2.0)
    C++ flags (Release):         -g -O2 -fdebug-prefix-map=/media/nick64/1c6afc58-05d2-4957-802e-352b30bdedf0/dernel_ubuntu1610/OpenCv3.3/332/opencv-3.3.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mf16c -mfma -mavx -mavx2 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -g -O2 -fdebug-prefix-map=/media/nick64/1c6afc58-05d2-4957-802e-352b30bdedf0/dernel_ubuntu1610/OpenCv3.3/332/opencv-3.3.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mf16c -mfma -mavx -mavx2 -fvisibility=hidden -fvisibility-inlines-hidden -g  -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/x86_64-linux-gnu-gcc
    C flags (Release):           -Wdate-time -D_FORTIFY_SOURCE=2    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror ...
(more)
edit retag flag offensive close merge delete

Comments

Why do you post an issue ? Are you sure that detectMultiscale use thread?

LBerger gravatar imageLBerger ( 2017-09-22 10:12:32 -0600 )edit

I also pust bugreport now. I think all function work in one thread after this. But i test it only for CascadeClassifier::detectMultiScale

Lubagov gravatar imageLubagov ( 2017-09-22 10:44:54 -0600 )edit