Getting Vector subscript error in people detector sample code

asked 2018-04-08 23:26:27 -0500

PrabhakarM gravatar image

updated 2018-04-09 02:08:02 -0500

LBerger gravatar image

Hi,

I am using below code

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
// static void help()
// {
//     printf(
//             "\nDemonstrate the use of the HoG descriptor using\n"
//             "  HOGDescriptor::hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());\n"
//             "Usage:\n"
//             "./peopledetect (<image_filename> | <image_list>.txt)\n\n");
// }
int main(int argc, char** argv)
{

VideoCapture cap(0); // open the default camera
if (!cap.isOpened())  // check if we succeeded
    return -1;
HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
namedWindow("people detector", 1);
for (;;)
{

    Mat img;
    cap >> img;
    resize(img, img, Size(360,280));
    vector<Rect> found, found_filtered;
    double t = (double)getTickCount();
    // run the detector with default parameters. to get a higher hit-rate
    // (and more false alarms, respectively), decrease the hitThreshold and
    // groupThreshold (set groupThreshold to 0 to turn off the grouping completely).
    hog.detectMultiScale(img, found, 0, Size(8, 8), Size(32, 32), 1.05, 2);
    t = (double)getTickCount() - t;
    printf("tdetection time = %gms\n", t*1000. / cv::getTickFrequency());
    size_t i, j;
    for (i = 0; i < found.size(); i++)
    {
        Rect r = found[i];
        for (j = 0; j < found.size(); j++)
            if (j != i && (r & found[j]) == r)
                break;
        if (j == found.size())
            found_filtered.push_back(r);
    }
    for (i = 0; i < found_filtered.size(); i++)
    {
        Rect r = found_filtered[i];
        // the HOG detector returns slightly larger rectangles than the real objects.
        // so we slightly shrink the rectangles to get a nicer output.
        r.x += cvRound(r.width*0.1);
        r.width = cvRound(r.width*0.8);
        r.y += cvRound(r.height*0.07);
        r.height = cvRound(r.height*0.8);
        rectangle(img, r.tl(), r.br(), cv::Scalar(0, 255, 0), 3);
    }
    imshow("people detector", img);
    int c = waitKey(10);
    if (c == 'q' || c == 'Q')
        break;
}
return 0;}

This code working well in my PC but same code giving Vector subscript error when running in my laptop.

Please help me to solve this problem.

Regards, Prabhakar M

edit retag flag offensive close merge delete

Comments

Give full error message. OS? opencv version ? Windows : Are you trying to mix release and debug dll on the new machine ?

LBerger gravatar imageLBerger ( 2018-04-09 02:13:56 -0500 )edit

debug it, please, and give us more information. (else you leave us guessing)

where exactly does it happen ?

berak gravatar imageberak ( 2018-04-09 02:55:39 -0500 )edit

@LBerger

I am using Win 10 OS.

Opencv 3.3. IO didnt mix release and debug dll.

When I try to debug when reaching this line

hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

It is showing below error

Debug Assertion failed.

Expression: Vector subscript out of range.

Please help me to sort it out.

PrabhakarM gravatar imagePrabhakarM ( 2018-05-09 08:17:20 -0500 )edit

@LBerger Still I am didn't find any solution. Please help me.

PrabhakarM gravatar imagePrabhakarM ( 2018-06-05 05:38:13 -0500 )edit

please try to run it in a debugger

berak gravatar imageberak ( 2018-06-05 05:41:56 -0500 )edit