/* * mp_alignEyes.cc * * Matlab interface for calling a C++ face rotator which uses CIntegralInterpolate (in FeatureLearning/Runtime/Libraries/smiledetector/src/interpolate.h) * Input: image, patch size, and eye cooridinates * Output: a patch sized image rotated around the center of the eyes * * Created by Andrew Salamon on Wed Mar 29 2006. * * Copyright (c) 2006 Machine Perception Laboratory * University of California San Diego. * Please read the license information at the end of this file. */ #include #include // For auto_ptr extern "C" { #include "mex.h" } #include "rimage.h" #include "rimage_matlab.h" #include "mp_CERT.h" #ifdef MPTDEBUG #warning Debug code is turned on #endif /** A C++ replacement for the Matlab Gabor code in CERT * This function takes three arguments: * -# mxArray: A Matlab image * -# int: The patch width of the image * -# int: The patch height of the image * -# string: Optional flag saying which step we should stop at, probably only useful for debugging * Eventually it will take an additional four arguments for looping through kernels and the SVM weights * This function will eventually return an mxArray containing values for each AU * Currently all it does is the equivalent of the Matlab function mat2gray */ void mexFunction(int nlhs,mxArray*plhs[],int nrhs, const mxArray*prhs[]) { static MP_CERT *cert = NULL; // check number of input/output variables if (nlhs != 2 ) mexErrMsgTxt("mp_gabor: requires two outputs: AU values (Yout), and eye positions"); if( nrhs != 1 ) mexErrMsgTxt("mp_CERTMex: requires one input: an image."); RImage *pixels = rimageFromMatlabArray( prhs[0] ); std::auto_ptr > pixelDeleter(pixels); if( !cert ) cert = new MP_CERT(); std::vector res = cert->calcAUs( *pixels ); plhs[0] = mxCreateDoubleMatrix( 1, 8, mxREAL ); double *plx = mxGetPr( plhs[0] ); for( unsigned int i=0; i < res.size(); ++i) { plx[i] = res[i]; } std::vector eyes = cert->eyes(); plhs[1] = mxCreateDoubleMatrix( 1, 4, mxREAL ); double *eyeOut = mxGetPr( plhs[1] ); for( unsigned int i=0; i < eyes.size(); ++i) { eyeOut[i] = eyes[i]; } } /* * Copyright (c) 2006 Machine Perception Laboratory * University of California San Diego. * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */