From 2f20ab2a29dc628eabad0adb74a77094a2392e54 Mon Sep 17 00:00:00 2001 From: Guido Diepen Date: Mon, 27 Feb 2017 09:17:23 +0100 Subject: [PATCH] Perform a double-check: if the centerpoint of the detect face is within a tracker rectangle AND the centerpoint of the tracker rectangle is within the bounds of the detected face, only then we consider it a match --- .../demo - track multiple faces.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/track multiple faces/demo - track multiple faces.py b/track multiple faces/demo - track multiple faces.py index 63e608f..1f15b0b 100644 --- a/track multiple faces/demo - track multiple faces.py +++ b/track multiple faces/demo - track multiple faces.py @@ -165,11 +165,20 @@ def detectAndTrackMultipleFaces(): t_w = int(tracked_position.width()) t_h = int(tracked_position.height()) + + #calculate the centerpoint + t_x_bar = t_x + 0.5 * t_w + t_y_bar = t_y + 0.5 * t_h + #check if the centerpoint of the face is within the - #rectangleof a tracker region. If it is, we have - #a match - if ( ( t_x <= x_bar <= (t_x + t_w) ) and - ( t_y <= y_bar <= (t_y + t_h))): + #rectangleof a tracker region. Also, the centerpoint + #of the tracker region must be within the region + #detected as a face. If both of these conditions hold + #we have a match + if ( ( t_x <= x_bar <= (t_x + t_w)) and + ( t_y <= y_bar <= (t_y + t_h)) and + ( x <= t_x_bar <= (x + w )) and + ( y <= t_y_bar <= (y + h ))): matchedFid = fid