Ask Your Question

Body detection using haarcascade

asked 2014-09-15 09:33:18 -0500

Christosh gravatar image

I am trying to detect body from images using haar cascades. I am using python code in order to do so, my code is the following:

import numpy as np
import sys
import cv2

body_cascade = cv2.CascadeClassifier('cascades/haarcascade_upperbody.xml')
img = cv2.imread('body/body4.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = body_cascade .detectMultiScale(gray, 1.1, 8)

for (x,y,w,h) in faces:
   roi_gray = gray[y:y+h, x:x+w]
   roi_color = img[y:y+h, x:x+w]

I ve tested several images, the three cascades for body several scalefactors. However, it seems not finding the body in any image. Am I doing something wrong in the parameters of detection? When I tried frontface cascades everything worked fine.

edit retag flag offensive close merge delete



you could try to reduce the minneighbour param in detectMultiScale. 3 instead of 8 maybe.

berak gravatar imageberak ( 2014-09-15 10:06:48 -0500 )edit

Also increasing the scale step to 1.05 (more finer stages) can increase detection chance!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-26 08:15:55 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2017-09-20 13:12:14 -0500

Try this for me its working after resizing and decreasing the neighbour


while True:

ret, frame =
frame=imutils.resize(frame, width=min(100, frame.shape[1]))
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#print lips
for (a,b,c,d) in upper:
print len(upper)
if cv2.waitKey(1) & 0xFF == ord('q'):

cam.release() cv2.destroyAllWindows()

edit flag offensive delete link more

answered 2016-07-26 07:44:04 -0500

the solution is.

i read a description in haarcascade_fullbody.xml in line 132 says : hese detectors will also work at very low image resolutions

may be you must try to resize image first. see in description in the first line of xml file says : 14x28 fullbody detector (see the detailed description below).

hope it help.

edit flag offensive delete link more


Wow wait, if the guys is not providing the Size properties, then the function is multiscale on the scaled image pyramid, so your point would be useless ...

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-26 08:22:08 -0500 )edit

Question Tools


Asked: 2014-09-15 09:33:18 -0500

Seen: 11,262 times

Last updated: Jul 26 '16