testJesorsky.cc

  1 const char *help = "\
  2 progname: testJesorsky.cc\n\
  3 code2html: This program tests jesorskyGTMeasurer class methods.\n\
  4 version: Torch3 vision2.0, 2004-2005\n\
  5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
  6 
  7 #include "FrontalFace19x19.h"
  8 #include "FrontalFace15x20.h"
  9 #include "jesorskyGTMeasurer.h"
 10 
 11 #include "Rectangle2D.h"
 12 
 13 #include "CmdLine.h"
 14 #include "DiskXFile.h"
 15 
 16 using namespace Torch;
 17 
 18 
 19 int main(int argc, char *argv[])
 20 {
 21    	char *posfilename;
 22 	int x_corner, y_corner;
 23 	int width, height;
 24 	int facemodel_id;
 25 	real J;
 26 	bool verbose;
 27 	
 28 	CmdLine cmd;
 29 	cmd.setBOption("write log", false);
 30 	//cmd.info(help);
 31 	
 32 	cmd.addText("\nArguments:");
 33 	cmd.addSCmdArg("posfile", &posfilename, "pos file");
 34 	cmd.addICmdArg("x", &x_corner, "x corner");
 35 	cmd.addICmdArg("y", &y_corner, "y corner");
 36 	cmd.addICmdArg("w", &width, "width");
 37 	cmd.addICmdArg("h", &height, "height");
 38 	cmd.addText("\nArguments:");
 39 	cmd.addICmdOption("-facemodel", &facemodel_id, 2, "facemodel (1=15x20, 2=19x19)");
 40 	cmd.addRCmdOption("-jesorsky", &J, 0.25, "Jesorsky threshold");
 41 	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
 42 	
 43 	cmd.read(argc, argv);
 44 
 45 	Allocator *allocator = new Allocator;
 46 
 47 	//
 48 	DiskXFile *pos_file = new DiskXFile(posfilename, "r");
 49 
 50 	Point2D l_eye;
 51 	Point2D r_eye;
 52 		
 53 	// IDIAP format
 54 	real x, y;
 55 	pos_file->scanf("%f", &x);
 56 	pos_file->scanf("%f", &y);			
 57 	l_eye.x = x; 
 58 	l_eye.y = y;
 59 	pos_file->scanf("%f", &x);
 60 	pos_file->scanf("%f", &y);
 61 	r_eye.x = x; 
 62 	r_eye.y = y;
 63 
 64 	delete pos_file;
 65 
 66 	print(" + Eyes: (%.1f-%.1f) - (%.1f-%.1f)\n", l_eye.x, l_eye.y, r_eye.x, r_eye.y);
 67 
 68 	//
 69 	FaceModel *face_model = NULL;
 70 
 71 	if(facemodel_id == 1)
 72 	{
 73 		message("Using 15x20 face model.");
 74 
 75 		face_model = new(allocator) FrontalFace15x20(1);
 76 	}
 77 	else if(facemodel_id == 2) 
 78 	{
 79 		message("Using 19x19 face model.");
 80 
 81 		face_model = new(allocator) FrontalFace19x19(1);
 82 	}
 83 	else error("face model %d unknown", facemodel_id);
 84 	
 85 	face_model->setBOption("verbose", false);
 86 
 87 	pos_file = new DiskXFile(posfilename, "r");
 88 	face_model->loadXFile(pos_file);
 89 	delete pos_file;
 90 	
 91 	face_model->ldm2bbx();
 92 
 93 	Point2D BBX0(face_model->bbx_points[0]);
 94 	Point2D BBX1(face_model->bbx_points[1]);
 95 	Point2D BBX2(face_model->bbx_points[2]);
 96 	Point2D BBX3(face_model->bbx_points[3]);
 97 	
 98 	print(" + BBX: %s %s %s %s (%dx%d)\n", 
 99 	      				BBX0.sprint(), 
100 	      				BBX1.sprint(), 
101 	      				BBX2.sprint(), 
102 	      				BBX3.sprint(),
103 					face_model->bbx_width, face_model->bbx_height);
104 	
105 	jesorskyGTMeasurer *jesorsky = new(allocator) jesorskyGTMeasurer(face_model, true, J);
106 	jesorsky->setBOption("verbose", verbose);
107 
108 	jesorsky->load(posfilename);
109 
110 	message("Measure with GT");
111 	real the_measure;
112 	
113 	jesorsky->measure(4, face_model->bbx_points, &the_measure);
114 
115 	//
116 	Rectangle2D rect(x_corner, y_corner, width, height);
117 	
118 	sPoint2D bbx[4];
119 
120 	bbx[0] = rect.P0.get();
121 	bbx[1] = rect.P1.get();
122 	bbx[2] = rect.P2.get();
123 	bbx[3] = rect.P3.get();
124 	
125 	print(" + RECT: %s\n", rect.sprint()); 
126 
127 	message("Measure with input:");
128 	jesorsky->measure(4, bbx, &the_measure);
129 
130 	delete allocator;
131 
132 	return(0);
133 }