Ask Your Question
0

Tuning OpenCV HOG method for reliable pedestrian detection using Thermographic camera

asked 2015-09-14 05:02:14 -0600

funk gravatar image

updated 2015-09-14 05:55:29 -0600

I'm using the following example (opencv-2.4.11/samples/python2/peopledetect.py) from OpenCV to detect pedestrians.

#!/usr/bin/env python

import numpy as np
import cv2

help_message = '''
USAGE: peopledetect.py <image_names> ...

Press any key to continue, ESC to stop.
'''

def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh

def draw_detections(img, rects, thickness = 1):
    for x, y, w, h in rects:
        # the HOG detector returns slightly larger rectangles than the real objects.
        # so we slightly shrink the rectangles to get a nicer output.
        pad_w, pad_h = int(0.15*w), int(0.05*h)
        cv2.rectangle(img, (x+pad_w, y+pad_h), (x+w-pad_w, y+h-pad_h), (0, 255, 0), thickness)


if __name__ == '__main__':
    import sys
    from glob import glob
    import itertools as it

    print help_message

    hog = cv2.HOGDescriptor()
    hog.setSVMDetector( cv2.HOGDescriptor_getDefaultPeopleDetector() )

    for fn in it.chain(*map(glob, sys.argv[1:])):
        print fn, ' - ',
        try:
            img = cv2.imread(fn)
        except:
            print 'loading error'
            continue

        found, w = hog.detectMultiScale(img, winStride=(8,8), padding=(32,32), scale=1.05)
        found_filtered = []
        for ri, r in enumerate(found):
            for qi, q in enumerate(found):
                if ri != qi and inside(r, q):
                    break
            else:
                found_filtered.append(r)
        draw_detections(img, found)
        draw_detections(img, found_filtered, 3)
        print '%d (%d) found' % (len(found_filtered), len(found))
        cv2.imshow('img', img)
        ch = 0xFF & cv2.waitKey()
        if ch == 27:
            break
    cv2.destroyAllWindows()

Unfortunately, the detection results seem to be unstable since the pedestrian is detected on some frames and is not detected to others that are quite similar to the first ones as you can see below.

enter image description here

enter image description here

My questions

  1. Can I use the OpenCV's HOG implementation for detecting pedestrians on frames captured from a thermal camera?
  2. If yes, how to tune the OpenCV's peopledetect.py example in order to get better resutls?
  3. Else if no, please give me your suggestions for pre-processing methods or other directions on pedestrian detection methods using OpenCV.

Thank you guys!

PS. First publication: http://stackoverflow.com/questions/32...

edit retag flag offensive close merge delete

Comments

3

since your image is inverted wrt. illumination, you might try to use (255 - img)

(but, like Steven said below, your missing detections are most likely due to varition in pose)

berak gravatar imageberak ( 2015-09-14 06:07:14 -0600 )edit
2

I don't think that you have to invert the image. Since the HoG implementation in OpenCV 2.4.11 doesn't consider the sign of the gradient. The reason is that in a typical pedestrian detection scenario the color of the clothing of the pedestrian is unknown (e.g. bright clothing on dark background or dark clothing on bright background). In your scenario the person typically will be brighter than the background. Dalal wrote in his paper (section 6.3) that using signed gradients does help significantly. In OpenCV 3.0 C++ HoG implementation you can set an flag if the descriptor use signed or unsigned gradients. But then, you can not use the default descriptor anymore and you have to train your own descriptor.

Siegfried gravatar imageSiegfried ( 2015-09-15 02:25:07 -0600 )edit
1

^^ oh, right (i was plain guessing), thanks for highlighting this !

berak gravatar imageberak ( 2015-09-15 02:36:36 -0600 )edit

@Siegfried, thanks for the tip!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-09-15 03:07:31 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-09-14 05:54:22 -0600

Actually, in both cases the false negative and the true positive result are quite different, especially for computer based systems

  • In the first case, you have a backwards view as true positive but a side view for the false positive.
  • In the second case, you have an open leg situation versus a closed leg situation.

So my first guess might be that your training database is not sufficiently large and variate enough for cooping with all these situations, let alone assume that you can model different views in a single model.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-09-14 05:02:14 -0600

Seen: 3,292 times

Last updated: Sep 14 '15