Site icon Machine Learning Projects

Pedestrian Detection using HOGs in Python – simplest way – easy project – 2023

Machine Learning Projects

In today’s blog, we will perform pedestrian detection using HOG short for Histogram for Gradients. HOGs are great feature detectors and can also be used for object detection with SVM but due to many other State of the Art object detection algorithms like YOLO, and SSD, present out there, we don’t use HOGs much for object detection.

This is going to be a very short and crisp blog so without any further due, Let’s do it…

Checkout the video here –

Code for pedestrian detection using HOGs…

import cv2
from imutils.object_detection import non_max_suppression
from imutils import resize
import numpy as np

hog = cv2.HOGDescriptor()

img = cv2.imread('f.jpg')
img = resize(img,height=500)

rects,weights = hog.detectMultiScale(img,winStride=(4,4),padding=(8,8),scale=1.05)

copy = img.copy()
for x,y,w,h in rects:

cv2.imshow('before suppression',copy)

r = np.array([[x,y,x+w,y+h] for x,y,w,h in rects])
pick = non_max_suppression(r,probs=None,overlapThresh=0.65)    

for xa,ya,xb,yb in pick:

cv2.imshow('after suppression',img)

before suppression
after suppression

NOTE – You can see that majority of the boxes in the before suppression image (in the right bottom portion) are suppressed in the after suppression image.

NOTE – You can see that as we performed Pedestrian Detection using HOG, we are not getting unbelievable results. It is picking some noise also. That’s why we use YOLO or SSDs for Object Detection nowadays where accuracy is our main requirement.

Download the Source Code…

Do let me know if there’s any query regarding this topic by contacting me by email or LinkedIn.

So this is all for this blog folks, thanks for reading it and I hope you are taking something with you after reading this and till the next time ?…


Check out my other machine learning projectsdeep learning projectscomputer vision projectsNLP projectsFlask projects at

Exit mobile version