HenryChen
HenryChen

Reputation: 153

Human Detection Using HOG Descriptor

I'm new for using HOG detector to detect humans on the road, and I've already write the code and try to run it, but it always have the error on the this line: "hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());" this line, can any one tell me what's wrong with my code?

    #include < stdio.h>
    #include < iostream>
    #include < opencv2\opencv.hpp>
    #include < opencv2/core/core.hpp>
    #include < opencv2/highgui/highgui.hpp>
    #include < opencv2/video/background_segm.hpp>
    #include <opencv2/imgproc.hpp>
    #include <opencv2/objdetect.hpp>
    #include <peopledetect.cpp>

    using namespace cv;
    using namespace std;

    int main(int argc, const char * argv[])
    {
        VideoCapture cap(0);
        cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
        cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);

        if (!cap.isOpened())
            return -1;

        Mat img;
        namedWindow("opencv", CV_WINDOW_AUTOSIZE);
        HOGDescriptor hog;
        hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

        while (true)
        {
            cap >> img;
            if (img.empty())
                continue;

            vector<Rect> found, found_filtered;
            hog.detectMultiScale(img, found, 0, Size(8, 8), Size(32, 32), 1.05, 2);
            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];
                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(), Scalar(0, 255, 0), 3);
            }

            imshow("opencv", img);
            waitKey(1);
        }
        return 0;
    }

Upvotes: 0

Views: 1064

Answers (1)

Sunreef
Sunreef

Reputation: 4542

In general, you should never include .cpp files in a C++ program. There are .h and .hpp headers for that.

Now, for your particular problem, if we're talking about the same peopledetect.cpp, the function you want is not defined there but in a header included there... You probably already have the right header (objdetect.hpp) so just remove the #include <peopledetect.cpp> line

Upvotes: 1

Related Questions