rotateppm.cc

 1 const char *help = "\
 2 progname: rotateppm.cc\n\
 3 code2html: This program reads a ppm image and rotate it.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageRgb.h"
 8 #include "ipRotate.h"
 9 #include "DiskXFile.h"
10 #include "CmdLine.h"
11 
12 using namespace Torch;
13 
14 int main(int argc, char **argv)
15 {
16 	char *image_filename;
17 	bool verbose;
18 	real angle;
19 	int xc;
20 	int yc;
21   
22 	
23   	CmdLine cmd;
24 	cmd.setBOption("write log", false);
25   	cmd.info(help);
26   	cmd.addText("\nArguments:");
27   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
28   	cmd.addText("\nOptions:");
29   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
30   	cmd.addRCmdOption("-angle", &angle, 0.0, "ccw angle in degree");
31   	cmd.addICmdOption("-xc", &xc, -1, "center X of rotation (if -1 center of the image)");
32   	cmd.addICmdOption("-yc", &yc, -1, "center Y of rotation (if -1 center of the image)");
33 
34 	cmd.read(argc, argv);
35 
36 
37 	Image *image_in = NULL;
38 	Image *image_out = NULL;
39 
40 	image_in = new ImageRgb();
41 	image_in->setBOption("verbose", verbose);
42 	
43 	image_in->load(image_filename);
44 
45 	if(verbose)
46 	{
47 		print("Image info:\n");
48 		print("   width = %d\n", image_in->width);
49 		print("   height = %d\n", image_in->height);
50 		print("   format = %s (%d)\n", image_in->coding, image_in->n_planes);
51 	}
52 
53 	if(xc == -1) xc = FixI(image_in->width/2.0);
54 	if(yc == -1) yc = FixI(image_in->height/2.0);
55 
56 	ipRotate *imachine = NULL;
57 	imachine = new ipRotate(angle, image_in->width, image_in->height, "rgb");
58 	imachine->setBOption("verbose", verbose);
59 	imachine->setCenter(xc, yc);
60 	imachine->process(image_in);
61 	
62 	image_out = new ImageRgb();
63 	image_out->setBOption("verbose", verbose);
64 
65 	image_out->copyFrom(imachine->getWidthOut(), imachine->getHeightOut(), imachine->seq_out->frames[0], "rgb");
66 	image_out->save("rotate.ppm");
67 	
68 	delete imachine;
69 	delete image_out;
70 	delete image_in;
71 
72 	return(0);
73 }