void SmilesApp::setup() { mSmileLimit = 4.0f; mSmileAverageNumOfFrames = 10; mCamIndex = 0; mFps = getAverageFps(); try { mCapture = Capture( CAMWIDTH, CAMHEIGHT ); mCapture.start(); } catch( ... ) { console() << "Failed to initialize capture" << std::endl; } mSmileRect = Rectf(300,100,600,400); setupSmileDetector(mSmileRect.getInteriorArea().getWidth(), mSmileRect.getInteriorArea().getHeight()); console()<< mSmileRect.getInteriorArea().getWidth() << mSmileRect.getInteriorArea().getHeight() << endl; mSmileThreshold = 0; mSmileAverageIndex = 0; mParams = params::InterfaceGl( "Parameters", Vec2i( 220, 170 ) ); mParams.addParam( "FPS", &mFps,"", true ); mParams.addSeparator(); mParams.addParam( "SmileResponse", &mSmileResponse, "", true ); mParams.addParam( "SmileThreshold", &mSmileThreshold, "", true ); mParams.addParam( "mSmileLimit", &mSmileLimit ); mParams.addParam( "mSmileAverageNumOfFrames", &mSmileAverageNumOfFrames ); }
void SmilesApp::update() { mFps = getAverageFps(); if(mCapture && mCapture.checkNewFrame() ){ mSurface = mCapture.getSurface(); } if (mSurface){ mGreyChannel = Channel( mSurface.clone(mSmileRect.getInteriorArea()) ); int totalDetectionPixels = mGreyChannel.getWidth()*mGreyChannel.getHeight(); unsigned char * detectionPixels = mGreyChannel.getData(); for (int i = 0; i < totalDetectionPixels; i++){ mRImage_pixels->array[i] = detectionPixels[i]; } detectSmiles(*mRImage_pixels); //console() << smileThreshold << endl; } }
// This routine assumes that srcRect maps into dstArea // and trims both the dst and the src proportionally to accommodate any clipping void getClippedScaledRects( const Area &srcSurfaceBounds, const Rectf &srcRect, const Area &dstSurfaceBounds, const Area &dstArea, Rectf *resultSrcRect, Area *resultDstArea ) { // clip the destination, create newSrcRect from mapping Area clippedDst = dstArea.getClipBy( dstSurfaceBounds ); Rectf newSrcRect = RectMapping( Rectf( dstArea ), srcRect ).map( Rectf( clippedDst ) ); // clip the src, create newDstRect from mapping newSrcRect.clipBy( Rectf( srcSurfaceBounds ) ); Rectf newDstRect = RectMapping( srcRect, Rectf( dstArea ) ).map( Rectf( newSrcRect ) ); // discretize and clip the destinaton // the discretization is done to minimize the area *resultDstArea = newDstRect.getInteriorArea(); resultDstArea->clipBy( dstSurfaceBounds ); // now map the discretized, clipped destination back once more to get the final source *resultSrcRect = RectMapping( Rectf( dstArea ), srcRect ).map( Rectf( *resultDstArea ) ); // this is not kosher, but sometimes we need to fudge things on the src to keep it in bounds resultSrcRect->clipBy( Rectf( srcSurfaceBounds ) ); }
void SmilesApp::mouseUp( MouseEvent event ){ mSmileRectDraggingCorner = -1; setupSmileDetector(mSmileRect.getInteriorArea().getWidth(), mSmileRect.getInteriorArea().getHeight()); }