Ask Your Question
0

human detection with HOG. How to improve it?

asked 2013-10-14 07:38:21 -0600

rokasma gravatar image

Hello,

I have a code for human detection, but it works not as good as I want. I read some articles that is possible to train this detector. I was searching for hour to find some good tutorials for training. Maybe you can help me.

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

using namespace std;
using namespace cv;

int main (int argc, const char * argv[])
{
    VideoCapture cap(CV_CAP_ANY);
    cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);    
    if (!cap.isOpened())
        return -1;

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

    namedWindow("video capture", CV_WINDOW_AUTOSIZE);
    while (true)
    {
        cap >> img;
        if (!img.data)
            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.06);
        r.height = cvRound(r.height*0.9);
        rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 2);
    }
        imshow("video capture", img);
        if (waitKey(20) >= 0)
            break;
    }
    return 0;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-10-15 06:54:56 -0600

Siegfried gravatar image

Hi, there is very few information on how to train your own HOGDetector (SVM model). One entry point could be this thread. But the link to a tutorial in this thread is broken :-(. Perhaps you can take a look at the referenced git repository.

edit flag offensive delete link more

Comments

Hi I am using the same code to detect people in videos. But it is not detecting the people constantly and the boundaries surrounding people are flickering .

also the videos are playing at a slower rate as compared to the original video. so is there any limitation on the video format or the resolution ?

thanks

ads gravatar imageads ( 2016-12-29 04:48:19 -0600 )edit

Hi. The "flickering" is a normal behavior. Since the HoGDetector (and all other algorithms for pedestrian detection) does not detect every person in each image of a video. In this video someone runs the opencv_gpu_hog example on the example video from opencv. As you can see, even in the opencv example you can some "flickering".

The reason why the videos are played at slower rate is that HoG needs a lot of computational power. If you want more fps you can tune the parameters of the detectMultiScale(...) method. Reduce the resolution of the video (the opencv example video has only a resolution of 768x576 pixel). Or use the CUDA HoGDetector.

Siegfried gravatar imageSiegfried ( 2016-12-30 05:02:42 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-10-14 07:38:21 -0600

Seen: 3,531 times

Last updated: Oct 15 '13