HOG Descriptor using Python + OpenCV
<p>I am trying to implement HOG Descriptor with OpenCV to detect Pedestrians in a <a href="https://www.youtube.com/watch?v=p_GKeQvlFlA" rel="nofollow">video</a>. I am currently using the pre-made dataset by OpenCV <code>hogcascade_pedestrians.xml</code>. Unfortuntley the documentation on this part is very poor on the internet although the HOG Descriptor is very effective for human detection. I have been writing a code for pedestrians detection with Python, and I have stopped at the following code:</p>

<pre><code>import cv2
import numpy as np
import imutils

VidCap = cv2.VideoCapture('pedestrians.mp4')

HOGCascade = cv2.HOGDescriptor('hogcascade_pedestrians.xml')
HOGCascade.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

while True:

    _ , image = VidCap.read()
    image = imutils.resize(image, width=700)

    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    clahe = cv2.createCLAHE(clipLimit=15.0,tileGridSize=(8,8))
    gray = clahe.apply(gray)

    winStride = (8,8)
    padding = (16,16)
    scale = 1.05
    meanshift = -1

    (rects, weights) = HOGCascade.detectMultiScale(gray, winStride=winStride,
                                            padding=padding,
                                            scale=scale,
                                            useMeanshiftGrouping=meanshift)

    for (x, y, w, h) in rects:
        cv2.rectangle(image, (x, y), (x+w, y+h), (0,200,255), 2)

    cv2.imshow('Image', image)

    if cv2.waitKey(5) == 27:
        break

VidCap.release()
cv2.destroyAllWindows()
</code></pre>

<p>I presume that the code scripting would be something like codes written for Haar Cascades. But I have tried that and I got errors. Do anyone have any idea of how to implement the HOG Descriptor on OpenCV with Python.</p>

<p>I have read the following <a href="http://stackoverflow.com/questions/6090399/get-hog-image-features-from-opencv-python">question</a>, but I get nothing from the second answer. </p>

<p>My problem is that I can't find the way to write the code, as the documentation about this part is very poor.</p>

<p><strong>Note:</strong> I am using OpenCV 3.1.0-dev with Python 2.7.11</p>

<pre><code>HOGCascade = cv2.HOGDescriptor()
</code></pre>

<p>If you want to use this <code>.xml</code>, You have lots of preparation work to do. </p>

<p>When u finally get the available descriptor, you should replace the <code>cv2.HOGDescriptor_getDefaultPeopleDetector()</code> in
<code>setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())</code></p>

python python-2.7 opencv image-processing opencv3.1