Skip to content Skip to sidebar Skip to footer

Hog Training And Detection In Python Using Opencv

I'm having an issue with useful detection using Python, OpenCV 3.1 and HOG. While I have working code that executes without error, the trained HOG/SVM combination fails to detect o

Solution 1:

I think that you need all support vectors you have. So the problem is not your training code, it is your test.

svm.train(training_data, cv2.ml.ROW_SAMPLE, classifications)

You do your training with all data you have but when comes to testing, you only use a small part of your resulting classifier.

svmvec = svm.getSupportVectors()[0]

Change this line and you'll have one less problem.


Solution 2:

The reason why single rectangle is created at the center is because the detector classified almost all region as "human". By default, detectMultiScale suppress the overlap of the rectangles. So you can only see the single rectangle at the center. You can turn off this suppression with finalThreshold option of detectMultiScale.

hogParams = { 'finalThreshold': 0}
found, w = hog.detectMultiScale(test_img, **hogParams)

By default, this parameter is set to 2. You can see almost all regions are filled by the rectangle color.

My answer to this "misclassification" is simple change of the order of the labels.

classifications = np.array([0] * 600 + [1] * 600)

Post a Comment for "Hog Training And Detection In Python Using Opencv"