2

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).

Community
  • 1
  • 1
Yogevnn
  • 1,430
  • 2
  • 18
  • 37

2 Answers2

1

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));
Yogevnn
  • 1,430
  • 2
  • 18
  • 37
0

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

Community
  • 1
  • 1
zmechanic
  • 1,842
  • 21
  • 27
  • Thank you for the answer, there is no way to train the SVM with my data? As i see it it will recognize with best percentage according to my train data no? so if the DefaultPeopleDetector provided by the openCV can do it good on images similar to the training data, wouldn't it recognize similar images of persons that looks the same as my train data? – Yogevnn May 04 '16 at 13:43
  • Try this answer: http://stackoverflow.com/questions/26607418/improving-accuracy-opencv-hog-people-detector – zmechanic May 04 '16 at 14:19
  • I saw those questions. actually after that i decided to ask a question my self. They didn't explain exactly how to train my SVM. which is my main issue – Yogevnn May 05 '16 at 07:51