/* * 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 "mp_alignEyes.h" #include #include #include "rimage.h" #include "rimage_matlab.h" #include "mp_rotateFace.h" #include "mptVersion.h" #include "certVersion.h" #ifdef MPTDEBUG #warning Debug code is turned on #endif const char *usage(); /** A C++ replacement for the Matlab align_eyes function. * This function takes five arguments: * -# mxArray: A Matlab image * -# int: The patch size of the returned image * -# int: The x coordinate of the subject's left eye * -# int: The x coordinate of the subject's right eye * -# int: The y coordinate of the subject's left eye * -# int: The y coordinate of the subject's right eye * This function returns an mxArray containing the rotated image, with width and height of the patch size * * It uses a class defined in interpolate.h (the smiledetector project of FeatureLearning) to do the actual rotation. */ void mexFunction(int nlhs,mxArray*plhs[],int nrhs, const mxArray*prhs[]) { // check number of input/output variables if (nlhs != 1 ) mexErrMsgTxt("mp_alignEyes: normal use requires one output. Call mp_alignEyes( 'help' ) for more details."); // if prhs[0] is a string, and it equals 'version', then return the version string // Otherwise return more detailed help messages if( (nrhs >= 1) && (mxCHAR_CLASS == mxGetClassID( prhs[0] )) ) { char *str = mxArrayToString( prhs[0] ); if( 0 == strcmp( "version", str ) ) { std::string version( getMPTRevisionString() ); version += "::"; version += getCertRevisionString(); plhs[0] = mxCreateString( version.c_str() ); } else if( 0 == strcmp( "help", str ) ) { plhs[0] = mxCreateString( usage() ); } else { mexErrMsgTxt( usage() ); } return; } if (nrhs < 6) mexErrMsgTxt("mp_alignEyes: normal use requires six inputs. Call mp_alignEyes( 'help' ) for more details."); int patchSize = static_cast(mxGetScalar(prhs[1])); int xl = static_cast(mxGetScalar(prhs[2])); int xr = static_cast(mxGetScalar(prhs[3])); int yl = static_cast(mxGetScalar(prhs[4])); int yr = static_cast(mxGetScalar(prhs[5])); RImage *pixels = rimageFromMatlabArray( prhs[0] ); #ifdef MPTDEBUG writeImageMat( prhs[0], "input.mat" ); #endif // create our new object which will do all the setup/takedown stuff, and call CIntegralInterpolate // arguments: RImage pixels, int patchSize, int xl, int xr, int yl, int yr MP_RotateFace rotator( pixels, patchSize, xl, xr, yl, yr ); if( nrhs > 6 ) { float topRate = static_cast(mxGetScalar(prhs[6])); rotator.setEyeTopRate( topRate ); if( nrhs > 7 ) { float lenRate = static_cast(mxGetScalar(prhs[7])); rotator.setEyeLenRate( lenRate ); } } RImage *result = rotator.rotatedImage(); // Write results into the first return value, as a matlab matrix plhs[0] = matlabArrayFromRimage( result ); #ifdef MPTDEBUG writeImageMat( plhs[0], "output.mat" ); // write the result out #endif delete pixels; delete result; } const char *usage() { return "mp_alignEyes examples:\n [rotatedImage]=mp_alignEyes( image, (int)patch size, (ints, eye positions)xl,xr,yl,yr );\n [versStr]=mp_alignEyes('version');\n [helpStr]=mp_alignEyes('help');"; } /* * 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. */