source: QMUL/trunk/DistanceCheck/src/distanceCheck.cpp @ 25

Revision 25, 3.8 KB checked in by ginevra, 11 years ago (diff)
Line 
1/*
2AUTHOR: Ginevra Castellano
3Queen Mary University of London
4DATE: 03/2009
5VERSION: 1.0
6*/
7
8// This class includes functions that allow one to predict whether the user is staying still, approaching the camera or
9// withdrawing by comparing the area of the face bounding box in the current frame with the values of the area in
10// a temporal window of size N preceding it
11
12#include "distanceCheck.h"
13
14
15DistanceCheck::DistanceCheck(int windowSize)
16{
17        this->windowSize = windowSize;
18        if (this->windowSize < 0) this->windowSize = 1;
19}
20
21DistanceCheck::~DistanceCheck()
22{
23        this->faceAreaVals.clear();
24
25}
26
27double DistanceCheck::getAverageVal(int startValIndex, int endValIndex)
28{
29        int valsSize = this->faceAreaVals.size();    // Calculate the size of faceAreaVals (the vector that stores the areas)
30        double average = 0.0;
31        int sumArea = 0;
32
33        int j= 0;
34        for (j = startValIndex; j < endValIndex+1; j++) 
35        {
36                sumArea += this->faceAreaVals[j];     // Sum of the areas
37        }
38        int num = (endValIndex - startValIndex) + 1;
39        average = (double)((double)sumArea/(double)num);  // Calculate the average area
40        return average;
41}
42
43double DistanceCheck::getAverageValInWindow(void)
44{
45        int valsSize = this->faceAreaVals.size();
46        if (valsSize <= this->windowSize) return 0.0; 
47        int currentIndex = valsSize - 1;
48        double average = 0.0;
49        average = this->getAverageVal(currentIndex - this->windowSize, currentIndex - 1); // Calculate the average area over a temporal window of size "windowSize" preceding the current frame
50        printf("\nAverage is %lf", average);
51        return average;
52}
53
54void DistanceCheck::addFaceVal(int val)
55{
56        this->faceAreaVals.push_back(val);  // Store the values of the area in a vector
57}
58
59void DistanceCheck::setFaceVal(int index, int val)
60{
61        if ((index > this->faceAreaVals.size() -1) || (index < 0)) return; 
62        this->faceAreaVals[index] = val;
63}
64
65int DistanceCheck::getNumElements(void) 
66{
67        return this->faceAreaVals.size();
68}
69
70
71// Compare the area of the face bounding box in the current frame with the average value of the area over a set
72// temporal window preceding it
73
74int DistanceCheck::getMovementType(void)
75{
76
77    int valsSize = this->faceAreaVals.size();
78        int currentIndex = valsSize - 1;
79        double average = this->getAverageValInWindow();
80
81        if (valsSize <= this->windowSize) return UNDEFINED;
82
83        double percent = 0.1;  // Percentage of increase/decrease of the area of the face bounding box
84    double extra = faceAreaVals[currentIndex - this->windowSize] * percent;  // Increase/decrease of the area of the face bounding box in the first frame of the window
85    double newBiggerArea = faceAreaVals[currentIndex - this->windowSize] + extra; // Area in the first frame of the window increased of a certain percentage
86    double newSmallerArea = faceAreaVals[currentIndex - this->windowSize] - extra;  // Area in the first frame of the window decreased of a certain percentage
87
88        // If the area of the face bounding box in the current frame is not bigger than the area of the starting frame of the window
89        // increased of a certain percentage and is not smaller than the area at the starting frame of the window decreased of a
90        // of a certain percentage the user is staying still
91
92        if (faceAreaVals[this->faceAreaVals.size() - 1] <= newBiggerArea &&
93                faceAreaVals[this->faceAreaVals.size() - 1]   >= newSmallerArea)
94        {
95                return STAYING_STILL;
96        }
97   
98        // If the area of the face bounding box in the current frame is bigger than the average area over the preceding temporal window
99        // the user is approaching the camera
100       
101        else if (this->faceAreaVals[this->faceAreaVals.size() - 1] > average)
102        {
103                return APPROACHING;
104        }
105       
106        // If the area of the face bounding box in the current frame is smaller than the average area over the preceding temporal window
107        // the user is withdrawing
108       
109        else
110        {
111                return WITHDRAWING;
112        }
113}
114
Note: See TracBrowser for help on using the repository browser.