OpenCV 3 Python - Haar Cascade Upper body detector not working on half body (waist) photo?

I tried to spot people in photographs and I had success with pedestrians. However, for my use case, I should be able to detect half body / upper body (waist up) or heads in a photo.

I've tried the upper body hara cascade. 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 that I used. Please note that this is the same image cropped at certain levels.

  • Knee
  • Waist
  • Chest up

Here are the results I got:

  • Knee

Knee Up

  1. Waist

Waist Up

  1. Chest up

Chest up

As you can see, the photos "Knee" and "Chest up" were able to detect the upper body and head region, respectively.

However, the waist photo did not return any results, even if the upper body and head were visible.

Does anyone know how and why this happens, and what can be done to make upper body detection more consistent?

Any help would be appreciated.

+3


source to share





All Articles