2
votes

I searched the web a lot and couldn't find any simple solution.

I'm trying to create a people detector, for this project i chose the Emgu library.

For now i'm able to detect persons but with no good percentage of success.

I'm trying to train my SVM, i saw on this post: SVM classifier based on HOG features for “object detection” in OpenCV the process i need for training:

Step 1) Prepare some training images of the objects you want to detect (positive samples). Also you will need to prepare some images with no objects of interest (negative samples).

Step 2) Detect HOG features of the training sample and use this features to train an SVM classifier (also provided in OpenCV).

Step 3) Use the coefficients of the trained SVM classifier in HOGDescriptor::setSVMDetector() method.

I have some training images and i'm using this lines of code to extract HOG features:

public static Image<Bgr, Byte> Resize(Image<Bgr, Byte> im)
    {
        return im.Resize(64, 128,   Inter.Linear);
    }
    public static float[] GetVector(Image<Bgr, Byte> im)
    {
        HOGDescriptor hog = new HOGDescriptor();    // with defaults values
        Image<Bgr, Byte> imageOfInterest = Resize(im);
        Point[] p = new Point[imageOfInterest.Width * imageOfInterest.Height];
        int k = 0;
        for (int i = 0; i < imageOfInterest.Width; i++)
        {
            for (int j = 0; j < imageOfInterest.Height; j++)
            {
                Point p1 = new Point(i, j);
                p[k++] = p1;
            }
        }

        return hog.Compute(imageOfInterest, new Size(8, 8), new Size(0, 0), p);
    }

But i couldn't find how could i train my SVM (step 2 on the steps above).

2

2 Answers

1
votes

I've been able to do that. Note: it has some problems i haven't yet solved with too much HoG features.

The code is:

//GetVector - function from people detection file 
float[] hog = GetVector(new Image<Bgr, byte>(image));

 svm.TrainAuto(new TrainData(training_mat, Emgu.CV.ML.MlEnum.DataLayoutType.RowSample, lables));
0
votes

People detection is not simple with OpenCV (EmguCV is just C# wrapper for it). People can take different poses: front, side, hands up/down, etc. It's even more complex task than detecting faces with HAAR Cascade (http://docs.opencv.org/3.1.0/d7/d8b/tutorial_py_face_detection.html#gsc.tab=0).

You need to reconsider your approach, as you have far better chances with XBox Kinect. Kinect SDK has necessary functions to detect people. Check out this answer: https://stackoverflow.com/a/10584231/1786034