Ask Your Question
1

Body detection using haarcascade

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

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:
   cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
   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

Comments

2

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

berak gravatar imageberak ( 2014-09-15 10:06:48 -0600 )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 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

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

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


cam=cv2.VideoCapture(0)

while True:

ret, frame = cam.read()
frame=imutils.resize(frame, width=min(100, frame.shape[1]))
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
upper=fc.detectMultiScale(gray,1.1,1)
#print lips
for (a,b,c,d) in upper:
    cv2.rectangle(frame,(a,b),(a+c,b+d),(0,0,255),2)
print len(upper)
cv2.imshow('detect',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

cam.release() cv2.destroyAllWindows()

edit flag offensive delete link more
0

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

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

Comments

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 -0600 )edit

Question Tools

Stats

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

Seen: 12,577 times

Last updated: Jul 26 '16