Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Body detection using haarcascade

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.