warp_to_png.cc

Go to the documentation of this file.
00001 /*
00002 
00003     This file is part of the FAST-ER machine learning system.
00004     Copyright (C) 2008  Edward Rosten and Los Alamos National Laboratory
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License along
00017     with this program; if not, write to the Free Software Foundation, Inc.,
00018     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00019 */
00020 /**
00021 \file warp_to_png.cc Main file for the warp_to_png executable.
00022 
00023 \section wpUsage Usage
00024 
00025 <code> warp_to_png [--size "x y"] < </code>\e infile.warp \c > \e outfile.png
00026 
00027 \section Description
00028 
00029 Converts a \ref camDataset "text warp file" in to a \ref canPNG "PNG warp file". The size is used to specify the image shape to convert to
00030 and defaults to 768 by 576.
00031 
00032 */
00033 
00034 
00035 #include <iostream>
00036 #include <iterator>
00037 #include <vector>
00038 #include <cstdlib>
00039 
00040 #include <cvd/image_io.h>
00041 
00042 #include <gvars3/instances.h>
00043 
00044 #include "warp_to_png.h"
00045 
00046 ///\cond never
00047 using namespace std;
00048 using namespace CVD;
00049 using namespace GVars3;
00050 using namespace TooN;
00051 ///\endcond
00052 
00053 
00054 ///Driving function
00055 ///@param argc Number of command line arguments
00056 ///@param argv Commandline argument list
00057 int main(int argc, char** argv)
00058 {
00059     try
00060     {
00061         GUI.parseArguments(argc, argv);
00062 
00063         ImageRef size = GV3::get<ImageRef>("size", ImageRef(768,576), 1);
00064 
00065         
00066         Image<Rgb<unsigned short> > si(size);
00067 
00068         for(int y=0; y < size.y; y++)
00069             for(int x=0; x < size.x; x++)
00070             {
00071                 float f1, f2;
00072                 cin >> f1 >> f2;
00073 
00074                 if(!cin.good())
00075                 {
00076                     cerr << "EOF!\n";
00077                     exit(1);
00078                 }
00079 
00080                 if(f1 < -5 || f1 > 1000)
00081                 {
00082                     cerr << "Bad value at " << x << ", " << y << ": " << f1;
00083                     exit(2);
00084                 }
00085 
00086                 if(f2 < -5 || f2 > 1000)
00087                 {
00088                     cerr << "Bad value at " << x << ", " << y << ": " << f2;
00089                     exit(2);
00090                 }
00091 
00092                 Rgb<unsigned short> o;
00093 
00094                 o.red = (unsigned short) ((SHIFT + f1)*MULTIPLIER + .5);
00095                 o.green = (unsigned short) ((SHIFT + f2)*MULTIPLIER + .5);
00096                 o.blue = 0;
00097 
00098                 si[y][x] = o;
00099             }
00100 
00101         img_save(si, cout, ImageType::PNG);
00102     }
00103     catch(Exceptions::All e)
00104     {
00105         cerr << "Error: " << e.what << endl;
00106         return 1;
00107     }   
00108 }

Generated on Mon Mar 2 12:47:12 2009 for FAST-ER by  doxygen 1.5.3