#include // for cout and cerr #include #define USE_IMAGEMAGICK #ifdef USE_IMAGEMAGICK #include #endif #include "rimage.h" #include "rimage_ser.h" #include "mp_CERT.h" void printResults( std::vector &results ) { std::cout.precision(8); for( unsigned int i=0; i < results.size(); ++i ) { std::cout << results[i]; if( i < (results.size() - 1) ) std::cout << ", "; } std::cout << std::endl; } int main (int argc, char *argv[]) { if (argc < 2) { std::cerr << "Usage: " << argv[0] << " [-f] " << std::endl; std::cerr << " -f: Assume a face in the image has already been cropped and rotated." << std::endl; exit(1); } MP_CERT cert; bool isFace = false; std::string path( argv[1] ); if( (3 == argc) && ("-f" == path) ) { isFace = true; path = argv[2]; } RImage pixels; if( !restoreRImageFromFile( pixels, path ) ) { #ifdef USE_IMAGEMAGICK Magick::Image image( argv[1] ); /* Or we could create an image from in memory data (e.g. video frame capture) Magick::Blob blob( inMemoryImageDataPtr, inMemoryImageDataLength ); Magick::Image image( blob ); */ if (image.columns() == 0 && image.rows() == 0) { std::cerr << "Image contains 0 rows and 0 columns! Exiting..." << std::endl; exit(1); } image.quantizeColors(256); // convert to 256 colors image.quantize(); // convert to grayscale pixels.setSize( image.columns(), image.rows() ); image.write( 0, 0, image.columns(), image.rows(), "I", Magick::FloatPixel, pixels.array ); #else std::cerr << "Unable to read image file. Exiting..." << std::endl; exit(1); #endif } #ifdef DEBUG std::cout << "First Ten Pixel values: "; for( int i = 0; i < 10; ++i ) std::cout << pixels.array[i] << ", "; std::cout << std::endl; #endif std::vector aus; cert.setDoEmotions( true ); if( isFace ) aus = cert.calcAUsFromFace( pixels ); else aus = cert.calcAUs( pixels ); std::cout << "Au's 1, 2, 4, 5, 10, 12, 14, 20: " << std::endl; printResults( aus ); std::vector emotions = cert.getEmotions(); std::cout << std::endl << "Emotion Detectors 'Upper Face Fear', 'Distress', 'Contempt', 'Lower Face Fear' and 'Fear + Distress': " << std::endl; printResults( emotions ); }