How to improve the accuracy of human detection with HOG?

asked 2014-01-13 08:45:59 -0500

updated 2014-01-14 01:30:18 -0500

Siegfried gravatar image

Hello, everyone.

I have a code for human detection. But it works not good enough as my expectation. How can I improve the accuracy by modifying the code? Thanks for helping.

Here are my code:

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>     
#include <opencv2\opencv.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv\cxcore.h>

using namespace std;    
using namespace cv;

int main (int argc, const char * argv[])
{
    CvCapture *capture = cvCaptureFromFile("D:video3.mp4");     

    if(!capture)    
    {
            printf("!!! cvCaptureFromFile failed (file not found?)\n");
            return -1; 
    }

    IplImage *frame = NULL; 

    Mat img;    

    HOGDescriptor hog;  

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

    namedWindow("video capture", CV_WINDOW_AUTOSIZE);   

    int a = 3;
    while (true)    
    {
        frame = cvQueryFrame(capture);  

        if (!frame)     
            {
                printf("!!! cvQueryFrame failed: no frame\n");
                break;
        }
        a++;

        img = frame;    

        if(a == 4)
        {
            a = 0;

                if (!img.data)  
            {
                continue;
            }


                vector<Rect> found, found_filtered; 

            hog.detectMultiScale(img, found, 0, Size(8,8), Size(0,0), 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);
                    }

                }


            cout<< "numbers of rectangle:" <<found.size()<<endl;

            cout<< "numbers of rectangle after filtered:" <<found_filtered.size()<<endl;  

                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