thearn / webcam-pulse-detector

A python application that detects and highlights the heart-rate of an individual (using only their own webcam) in real-time.
Other
3.16k stars 596 forks source link

Suggested code change for more robust head detection. #10

Closed maym86 closed 11 years ago

maym86 commented 11 years ago

Try replacing the two lines at ~84 in detectors.py

if self.return_one:            
    self.detected[0] = detected[0]

with

if self.return_one:            
    width = detected[0][2]
    height = detected[0][3]
    for i in range(1,len(detected)):
        if detected[i][2] > width and detected[i][3] > height: 
            detected[0] = detected[i]
            width = detected[i][2]
            height = detected[i][3]
    self.detected[0] = detected[0]

This provides much more robust head tracking by always returning the single largest head in the image rather than the first head returned in the detector array. Makes the head detection more stable and may allow you to not have to use the 'S' key.

Thanks for releasing this.

Mike

thearn commented 11 years ago

Sounds good, I'll give this a shot.

Thanks for the feedback!

maym86 commented 11 years ago

Made a change. Had left a line out. Mike