/* * mp_rotateFace * * Author: Andrew Salamon * Date: Wed Mar 29 2006 * * This class is an adaptor between the mp_alignEyesMex and the interpolator that does the image * rotation. Primarily it does some setup, calls the interpolator, then does some teardown. * Arguments: * pixels: input image (full size) * patchSize: size (width and height) for the rotated face image * xl, xr, yl, yr: eye coordinates * Return value: * The rotated and cropped face. It was allocated with new, so needs to be deleted when the caller is done with it. * * 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. * */ #ifndef __MP_ROTATEFACE_H__ #define __MP_ROTATEFACE_H__ #include "rimage.h" #include "featureDetector.hpp" #include "interpolate.h" /** Rotate and crop a face out of a larger image. * Given an image, a patch size (which needs to be 96 for CERT), and eye locations, we rotate the face * so the eyes are horizontal then crop out a face. A new image with the face is either returned, or * a passed in RImage is used to store the face. */ class MP_RotateFace { public: typedef std::vector< ObjectWithFeatures > OWFList; public: MP_RotateFace( int _patchSize ); MP_RotateFace( const RImage *pixels, int patchSize, int xl, int xr, int yl, int yr ); virtual ~MP_RotateFace(); void setImage( const RImage *_pixels, int _xl, int _xr, int _yl, int _yr ); RImage *rotatedImage(); ///< Creates a new RImage with the rotated and cropped face. The caller will need to delete the returned image. bool rotateIntoPatch( RImage &patch, RIntegral *integral = NULL ); ///< Rotate and crop into an existing RImage. bool rotateImageIntoPatch( const RImage *pixels, int xl, int xr, int yl, int yr, RImage &patch, RIntegral *integral = NULL ); ///< Set a new image and rotate into the supplied patch image. /// This method may throw an exception. The only exception type is currently a char *, so catch( const char *msg ) will catch all current exceptions. bool rotateImageUsingFeatures( FeatureDetector *fd, const RImage *pixels, OWFList &allFaces, RImage &patch, FeatureAlignment::alignment_method method=FeatureAlignment::eyes_only, RIntegral *integral = NULL ); void setEyeTopRate( float newRate ); float getEyeTopRate(); void setEyeLenRate( float newRate ); float getEyeLenRate(); CFourCoordinates getFaceBox() { return faceBox; } private: const RImage *pixels; int patchSize; int xl; int xr; int yl; int yr; // These can be used to override values in the interpolator. float eye_top_rate; bool override_top; float eye_len_rate; bool override_len; RIntegral pfIntegral; CFourCoordinates faceBox; /// Returns the integral pointer (pointer to pfIntegral if passed in pointer is null, otherwise just the passed in one). inline RIntegral *setupIntegral( RIntegral *integral, const RImage *pixels ); inline void setupPatch( RImage &patch ); }; #endif