I've been trying to detect people in photos and I've had some success with pedestrians. However, for my use case scenario, I need to be able to detect half body/upper body (waist up) or heads in photo.
I tried the haar cascade for the upper body. Here is the code I used:
import numpy as np
import cv2
img = cv2.imread('/path/to/img.jpg',0)
upperBody_cascade = cv2.CascadeClassifier('path/to/haarcascade_upperbody.xml')
arrUpperBody = upperBody_cascade.detectMultiScale(img)
if arrUpperBody != ():
for (x,y,w,h) in arrUpperBody:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
print 'body found'
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
And I had 3 test images I used. Kindly note that it's the same image, cropped at certain levels.
- Knee Up
- Waist Up
- Chest Up
Here were the results I got:
- Knee Up
- Waist Up
- Chest Up
As you can see, the Knee Up and Chest Up photos were able to detect the upper body and head area respectively.
However, the waist up photo didn't return any results, even if the upper body and the head are visible.
Does anyone know how or why this happens and what can be done to make the upper body detection much more consistent?