# Head detection using HOG and SVM

I am currently trying to detect heads in a sequence of real-footage images and am using HOG feature descriptor and SVM as classifier.

Currently I am using Dalal's HOG implementation code in MATLAB found in this link: http://www.mathworks.com/matlabcentral/fileexchange/46408-histogram-of-oriented-gradients--hog--code-using-matlab

Currently I am using libSVM MATLAB version found in this link: http://www.csie.ntu.edu.tw/~cjlin/libsvm/

I prepared 350 positive training images and 1243 negative training images.

The hog feature vectors extracted from the training images are converted to libsvmFormat and inputted in the libsvm training method, to obtain a model. The hog vector length is that of 1764.

Regarding the libSVM I chose these as parameters:

• -s 0 (i.e. C-SVC)
• -c 1 (i.e. cost = 1)
• -t 2 (i.e. kernel = RBF)
• -g 3 (i.e. gamma = 3 (this is for kernel))

Regarding the HOG version, I left the cell, bin & block parameters as they were in the implementation shown in the link above.

I am using a scanning window of size 128x128 and 256x256 to scan through the whole image to detect possible heads. At each window, the hog feature vector is extracted for each image and is inputted in libsvm predict, to test whether it should be classified as a head or not.

However, after doing all the above, I have a numerous amount of false negatives and can't figure out what I am doing wrong.

Can someone experience please offer some advice on what is possibly wrong? I really need to figure this out please. Much appreciated!

The thing to keep in mind here is that HOG is not invariant to in-plane rotation. A change in orientation of more than 10-15 degrees will probably throw it off. So if your head can have different orientations in the image, you would either need to train multiple detectors or use something other than HOG.

By the way, there is a function extractHOGFeatures in the Computer Vision System Toolbox, and SVM is available in the Statistics Toolbox. See this example.

Edit: from your sample images it looks like in most cases you need to detect profile faces. vision.CascadeObjectDetector in the Computer Vision System Toolbox can do that for you. For greater robustness, I would run two detectors in succession: one for profile faces and one for frontal faces. And also, HOG may not be your best choice here. For face detection Haar or LBP features generally work better.

No matter what you do, you will have some false negatives. So, if you are using a video camera, I would also recommend tracking the faces. See this example. This will give you an opportunity to correct mistakes made on individual frames.

Edit2: You can also train your own detector with trainCascadeObjectDetector, and you can use trainingImageLabeler app to label the positive samples.

• The CCTV camera is static, so the heads are from the same angle, but obviously the heads can rotate. So you mean in my case I shouldn't use HOG descriptor? – Sambas23 Nov 17 '14 at 15:28
• Are you looking at the heads from above? – Dima Nov 17 '14 at 15:29
• Could this be a problem with insufficient contrast? If so, you may want to try doing histogram equalization, before running the detector. – Dima Nov 17 '14 at 15:30
• Actually, it would really help if you could post an image showing some detections and some of the flase negatives. Otherwise I am just guessing here. – Dima Nov 17 '14 at 15:34
• Hi, @Dima this is how it was...postimg.org/image/3vw961ruh However, after re-reading Dalal's paper I tried to use the hard-examples method he uses, i.e. I included the negative detected windows in the negative training folder and re-trained my model. And it gave me this result..postimg.org/image/vjexq58rn which is much better...any more advice? – Sambas23 Nov 17 '14 at 17:38

There are a lot of possible problems.

Firstly, you should do a quick check and see how your false alarms look like, especially how reasonable they are. If there are some false alarms quite similar to heads visually, then donot worry about them for now.

Secondly, often time you need to perform cross validations to determine the parameter set used in your classifier, instead of picking one set of default parameters. It is also common that one set of good parameters in one problem is inappropriate for another. Thus, you should verify whether or not your SVM params are optimal for your problem.

Thirdly, it is well known that object detection also need post-processing to prune detection results and to handle possible overlapping results. Sometimes, even simple heuristics will work well.

Finally, try to use boost + cascade to retrain false classified samples.

• Thank you very much for your feedback! That is what I was actually dealing about. Thanks. – Sambas23 Nov 18 '14 at 17:52