11#include < qglobal.h>
22#include < QDebug>
33#include " GestureAlgos.h"
4+ #include " VirtualTouchScreen.h"
45
56GestureAlgos::GestureAlgos () :
67 screen_(0 , 0 ),
78 image_(0 ,0 ),
89 scaleFactor_(0.0 ), offset_(0 ,0 ),
910 KF_(cv::KalmanFilter(8 , 4 , 0 )),
10- measurement_(cv::Mat_<float >(4 ,1 ))
11+ measurement_(cv::Mat_<float >(4 ,1 )),
12+ mainWnd_(NULL )
1113{
1214}
1315
@@ -124,10 +126,12 @@ void GestureAlgos::initBiquad()
124126 sos_mat_[4 ][0 ] = 1.0 , sos_mat_[4 ][1 ] = 2.0 , sos_mat_[4 ][2 ] = 1.0 , sos_mat_[4 ][3 ] = 1.0 ,
125127 sos_mat_[4 ][4 ] = 0.5304 , sos_mat_[4 ][5 ] = 0.7165 ;
126128 gain_ = 0.0189 ;
127- for (int n = 0 ; n < SosMat::NB_BIQUADS ; ++n) {
128- biquadState[n].index = n;
129- memset (biquadState[n].mem_in , 0 , sizeof (biquadState[n].mem_in ));
130- memset (biquadState[n].mem_out , 0 , sizeof (biquadState[n].mem_out ));
129+ for (int i = 0 ; i < 2 ; ++i) {
130+ for (int n = 0 ; n < SosMat::NB_BIQUADS ; ++n) {
131+ biquadState[i][n].index = n;
132+ memset (biquadState[i][n].mem_in , 0 , sizeof (biquadState[i][n].mem_in ));
133+ memset (biquadState[i][n].mem_out , 0 , sizeof (biquadState[i][n].mem_out ));
134+ }
131135 }
132136}
133137
@@ -148,7 +152,7 @@ double GestureAlgos::biquad(BiquadState *state, double in)
148152 return out;
149153}
150154
151- void GestureAlgos::filterLowPass (qreal &depth )
155+ void GestureAlgos::filterLowPass (qreal &depthThumb, qreal &depthIndex )
152156{
153157 static bool initDone = false ;
154158 if (!initDone) {
@@ -157,15 +161,15 @@ void GestureAlgos::filterLowPass(qreal &depth)
157161 }
158162 // cascade of biquads
159163 for (int n = 0 ; n < SosMat::NB_BIQUADS ; ++n) {
160- depth = biquad (biquadState+n, depth);
164+ depthThumb = biquad (&(biquadState[0 ][n]), depthThumb);
165+ depthIndex = biquad (&(biquadState[1 ][n]), depthIndex);
161166 }
162- depth = gain_*depth;
167+ depthThumb = gain_*depthThumb;
168+ depthIndex = gain_*depthIndex;
163169}
164170
165171GestureAlgos::TouchType GestureAlgos::isTouch (qreal depthThumb, qreal depthIndex)
166172{
167- // constants
168- const static qreal DEPTH_THRESHOLD = 0.45 ;
169173 // permanent variable
170174 static GestureAlgos::TouchType out = GestureAlgos::TouchType::NONE ;
171175
@@ -177,9 +181,11 @@ GestureAlgos::TouchType GestureAlgos::isTouch(qreal depthThumb, qreal depthIndex
177181 }
178182
179183 // process depth information
180- if ((DEPTH_THRESHOLD >= depthThumb) || (DEPTH_THRESHOLD >= depthIndex)) {
184+ if ((mainWnd_->virtualScreenThreshold_ >= depthThumb) ||
185+ (mainWnd_->virtualScreenThreshold_ >= depthIndex)) {
181186 // touch down
182- out = ((DEPTH_THRESHOLD >= depthThumb) && (DEPTH_THRESHOLD >= depthIndex))?
187+ out = ((mainWnd_->virtualScreenThreshold_ >= depthThumb) &&
188+ (mainWnd_->virtualScreenThreshold_ >= depthIndex))?
183189 GestureAlgos::TouchType::DOUBLE_DOWN :GestureAlgos::TouchType::SINGLE_DOWN ;
184190 } else {
185191 // touch up
0 commit comments