void SmilesApp::detectSmiles(const RImage<float> &pixels) { mFaces.clear(); // Find Smiles if( mMPSmile->findSmiles( pixels, mFaces, 1.00, wt_avg ) ){ //console() << " findSmiles error " << endl; return; } mSmileResponse = 0; // The result is in faces(VisualObject). if(!mFaces.empty()) { for(list<VisualObject *>::iterator it = mFaces.begin(); it != mFaces.end(); ++it) { mFace = static_cast<FaceObject*>(*it); mSmileResponse = mFace->activation; mSmileResponse = max( 0.0f, min( mSmileResponse, mSmileLimit ) ) / mSmileLimit; } //console() << mFaces.size() << " faces detected!" << endl; }else{ //console() << " no faces detected " << endl; } mSmileAverage[mSmileAverageIndex] = mSmileResponse; mSmileAverageIndex++; if(mSmileAverageIndex>=mSmileAverageNumOfFrames)mSmileAverageIndex=0; float smileSum = 0; for(int i=0;i<mSmileAverageNumOfFrames;i++){ smileSum += mSmileAverage[i]; } mSmileThreshold = smileSum/mSmileAverageNumOfFrames; }
void SmilesApp::draw() { gl::enableAlphaBlending(); gl::clear( Color::black() ); gl::color(1.0f, 1.0f, 1.0f); // draw webcam capture if( !mCapture || !mSurface ) return; gl::draw( gl::Texture(mSurface) ); if(mGreyChannel){ gl::pushMatrices();{ gl::translate(mSmileRect.getUpperLeft()); gl::draw( gl::Texture(mGreyChannel) ); }gl::popMatrices(); } // draw rect that actually gets analysed: gl::color(ColorA(0.0f, 1.0f, 0.0f, 1.0f)); gl::drawStrokedRect(mSmileRect); gl::drawStrokedCircle(mSmileRect.getUpperLeft(), 10); gl::drawStrokedCircle(mSmileRect.getUpperRight(), 10); gl::drawStrokedCircle(mSmileRect.getLowerLeft(), 10); gl::drawStrokedCircle(mSmileRect.getLowerRight(), 10); //draw mSmileThreshold gl::pushMatrices();{ gl::color(ColorA(1.0f, 0.0f, 0.0f, 0.3f)); gl::drawSolidRect(Rectf( 0, (1-mSmileThreshold)*getWindowHeight(), getWindowWidth(), getWindowHeight() ) ); gl::drawStrokedRect( Rectf(0, 0, getWindowWidth(), getWindowHeight() ) ); }gl::popMatrices(); //draw faces if(!mFaces.empty()){ gl::pushMatrices();{ gl::translate(mSmileRect.getUpperLeft()); gl::color(1.0f, 1.0f, 1.0f); for(list<VisualObject *>::iterator it = mFaces.begin(); it != mFaces.end(); ++it) { mFace = static_cast<FaceObject*>(*it); gl::drawStrokedRect(Rectf(mFace->x, mFace->y, mFace->x+mFace->xSize, mFace->y+mFace->ySize )); } }gl::popMatrices(); } mParams.draw(); }
void MPBlink::get_eyes(const RImage<float> &pixels, VisualObject &faces){ list<VisualObject *>::iterator it = faces.begin(); FaceBoxList face; double act[10]; for (; it != faces.end(); ++it) { FaceObject * f = static_cast<FaceObject*>(*it); if (f->eyes.rightEye && f->eyes.leftEye){ if( debug ){ printf("eyes.xLeft[%f] yLeft[%f]\n", f->eyes.xLeft, f->eyes.yLeft); printf("eyes.xRight[%f] yRight[%f]\n", f->eyes.xRight, f->eyes.yRight); } double xd = f->eyes.xLeft - f->eyes.xRight; double yd = f->eyes.yLeft - f->eyes.yRight; float eye_dist = sqrt((xd*xd +yd*yd)); float sin_d = -yd/xd; float cos_d = eye_dist/xd; float h_eye_zero = max(0.0,f->eyes.xRight-eye_dist*(h_eye_factor+h_off_pct)); float v_eye_zero = max(0.0,f->eyes.yRight-eye_dist*(v_eye_factor+v_off_pct)); float xwidth = eye_dist*(1 + 2*h_eye_factor); float ywidth = eye_dist*(2*v_eye_factor); int xedges; int yedges; float xfrac; float yfrac; float yoff[eye_dest_width]; double xstep = xwidth/static_cast<double>(eye_dest_width-1); double ystep = ywidth/static_cast<double>(eye_dest_height-1); float j; int i; for(i = 0, j = 0; i < eye_dest_width; ++i, j+=xstep){ yoff[i] = -sin_d * j; } float tempx, tempy; float *p = eyes.array; float f00, f01, f11, f10, fx0, fx1; for(int y=0; y < eye_dest_height; ++y){ float xinit = (sin_d * ystep*y)+h_eye_zero; float yinit = v_eye_zero + ystep*y; for(int x=0; x < eye_dest_width; ++x){ tempx = xinit + xstep*x; tempy = yinit + yoff[x]; xedges = static_cast<int>(tempx); yedges = static_cast<int>(tempy); xfrac = tempx - xedges; yfrac = tempy - yedges; f00 = pixels.getPixel(xedges,yedges); f01 = pixels.getPixel(xedges,yedges + 1); f10 = pixels.getPixel(xedges + 1,yedges); f11 = pixels.getPixel(xedges + 1,yedges + 1); // xfrac and y frac are the remainders fx0 = f00 + xfrac*(f10-f00); fx1 = f01 + xfrac*(f11-f01); *(p++) = (fx0 + yfrac*(fx1-fx0)); // eyes.setPixel(x,y,(fx0 + yfrac*(fx1-fx0))); } } //eyes.print(); debug = false; int num_blink_windows = search(eyes, face, 0, 1.0, 0, act,0); (*it)->activation = act[0]; if( debug ){ printf("num_blink_windows: %d, activation: %f\n", num_blink_windows, act[0]); } //f->activation = cluster.UpdateCluster(f->activation) - f->activation; } else f->activation = 0.0f; } }