Ask Your Question
0

Use hog.detectMultiScale in multiple threads?

asked 2014-09-26 21:46:04 -0600

panan160 gravatar image

updated 2014-09-27 06:35:18 -0600

Siegfried gravatar image

When I do pedestrian detection width Hog + SVM in OpenCV ,I try to using it in two thread to improve the detect speed.But I got OpenCV error: Assertion failed<s >=0> in unknown function,file ..\..\..\opencv\modules\core\src\matrix.cpp,line 116

My code:

DWORD WINAPI DetectFrame1(LPVOID lpPrarmeter){
    HOGDescriptor hog1;
    hog1.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

    while(true){
        WaitForSingleObject(g_hEvent1,INFINITE);        

        int temp;
        hog1.detectMultiScale(detImg1, found1, 0, cv::Size(8,8), cv::Size(0,0), 1.08, 2);  
        //cout<<"得到一帧near :"<<frame<<endl;
        //temp=frame;       // 标志当前处理帧 [9/26/2014 pan]

        if(!detImg1.empty()){
            imshow("det1",detImg1);
        }
        waitKey(10);
        cout<<"1——检测到行人:"<<found1.size()<<endl;
        SetEvent(g_hEvent1);
    }
    return 0;
}
DWORD WINAPI DetectFrame2(LPVOID lpPrarmeter){
    HOGDescriptor hog2;
    hog2.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());         // 该函数不能并发 [9/26/2014 pan]
    while(true){    
        WaitForSingleObject(g_hEvent2,INFINITE);    
        int temp;
        //cout<<"得到一帧far :"<<frame<<endl;
        //temp=frame;           // 标志当前处理帧 [9/26/2014 pan]
        hog2.detectMultiScale(detImg2, found2, 0, cv::Size(8,8), cv::Size(0,0), 1.08, 2);  

        if(!detImg2.empty()){
            imshow("det2",detImg2);
        }
        waitKey(10);
        cout<<"2——检测到行人:"<<found2.size()<<endl;
        SetEvent(g_hEvent2);        // 变为有信号状态 [9/26/2014 pan]
    }
    return 0;
}

Can anyone help me ,thanks.

edit retag flag offensive close merge delete

Comments

2

if(!detImg1.empty()){ // this should go before hog1.detectMultiScale

berak gravatar imageberak ( 2014-09-27 06:49:59 -0600 )edit

thanks,i made a mistake

panan160 gravatar imagepanan160 ( 2014-10-09 02:52:21 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2014-09-29 10:07:35 -0600

R.Saracchini gravatar image

I work with OpenCV functions in a multi-threaded software for decoding/encoding and tracking, and the only issue that I have find so far is with functions from highgui module which deal with windows events such as "cv::imshow" and "cv::waitKey". If such functions are called by one single thread, there is no problem at all, but it crashes or locks up if I try to do it in two or more threads. This with OpenCV compiled with QT and OpenGL support (Linux). Did you tried to remove these function calls and see how it works only with the processing step ? Also, as berak said, make sure that "detImg" and "detImg2" are not empty before call the HOG functions.

edit flag offensive delete link more

Comments

thanks~the problem is reslove

panan160 gravatar imagepanan160 ( 2014-10-09 02:53:25 -0600 )edit

Question Tools

Stats

Asked: 2014-09-26 21:46:04 -0600

Seen: 1,176 times

Last updated: Sep 29 '14