qa_rectlut.cpp

00001
00002 /***************************************************************************
00003  *  qa_rectlut.h - QA for rectification LUT
00004  *
00005  *  Generated: Wed Oct 32 18:03:48 2007
00006  *  Copyright  2007  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 /// @cond QA
00025 
00026 #include <fvutils/rectification/rectfile.h>
00027 #include <fvutils/rectification/rectinfo_lut_block.h>
00028
00029 #include <list>
00030 #include <cstdlib>
00031 #include <iostream>
00032
00033 using namespace std;
00034
00035 #define WIDTH  640
00036 #define HEIGHT 480
00037 
00038 int
00039 main(int argc, char **argv)
00040 {
00041   srand(23423);
00042
00043   const char *s = "qatest.rif";
00044   if ( argc > 1 ) {
00045     s = argv[1];
00046   }
00047
00048   RectificationInfoFile *rif = new RectificationInfoFile(0xDEADBEEF, "No real camera");
00049
00050   RectificationLutInfoBlock *rlib = new RectificationLutInfoBlock(WIDTH, HEIGHT,
00051                                                                   FIREVISION_RECTINFO_CAMERA_MAIN);
00052
00053   RectificationLutInfoBlock *rlib2 = new RectificationLutInfoBlock(WIDTH, HEIGHT,
00054                                                                    FIREVISION_RECTINFO_CAMERA_LEFT);
00055
00056   /* Random alternative, harder to read though
00057   for ( int i = 0; i < 10; ++i ) {
00058     uint16_t x, y, to_x, to_y;
00059     x=1+(uint16_t)(1.f * WIDTH * rand() / (RAND_MAX + 1.f));
00060     y=1+(uint16_t)(1.f * HEIGHT * rand() / (RAND_MAX + 1.f));
00061     to_x=1+(uint16_t)(1.f * WIDTH * rand() / (RAND_MAX + 1.f));
00062     to_y=1+(uint16_t)(1.f * HEIGHT * rand() / (RAND_MAX + 1.f));
00063 
00064     printf("Mapping (%u, %u) to (%u, %u)\n", x, y, to_x, to_y);
00065     rlib->set_mapping(x, y, to_x, to_y);
00066   }
00067   */
00068
00069   for ( int i = 0; i < 10; ++i ) {
00070     uint16_t x = i, y = i, to_x = i * 2, to_y = i * 2;
00071     printf("Mapping (%u, %u) to (%u, %u)\n", x, y, to_x, to_y);
00072     rlib->set_mapping(x, y, to_x, to_y);
00073   }
00074
00075   for ( int i = 10; i < 20; ++i ) {
00076     uint16_t x = i, y = i, to_x = i * 2, to_y = i * 2;
00077     printf("Mapping2 (%u, %u) to (%u, %u)\n", x, y, to_x, to_y);
00078     rlib2->set_mapping(x, y, to_x, to_y);
00079   }
00080
00081   rif->add_rectinfo_block(rlib);
00082   rif->add_rectinfo_block(rlib2);
00083
00084   RectificationInfoFile::RectInfoBlockVector *blocks = rif->rectinfo_blocks();
00085
00086   for (RectificationInfoFile::RectInfoBlockVector::iterator i = blocks->begin(); i != blocks->end(); ++i) {
00087     RectificationLutInfoBlock *rlib = dynamic_cast<RectificationLutInfoBlock *>(*i);
00088     if ( rlib == NULL ) {
00089       printf("Got rectification info block of unknown type");
00090       continue;
00091     }
00092
00093     printf("LUT:  type: %u  camera: %u  size: %zu\n",
00094            rlib->type(), rlib->camera(), rlib->block_size());
00095
00096     cout << "Looking for non-zero mappings" << endl;
00097     uint16_t x, y, to_x, to_y;
00098     for ( y = 0; y < HEIGHT; ++y) {
00099       for ( x = 0; x < WIDTH; ++x) {
00100         // Use evil (slow) method here, it's just for the QA...
00101         rlib->mapping(x, y, &to_x, &to_y);
00102         if ( (to_x != 0) || (to_y != 0) ) {
00103           printf("(%u, %u) maps to (%u, %u)\n", x, y, to_x, to_y);
00104         }
00105       }
00106     }
00107   }
00108
00109   delete blocks;
00110
00111   cout << "Writing to " << s << endl;
00112   rif->write(s);
00113
00114   rif->clear();
00115
00116   cout << "Reading from " << s << endl;
00117   rif->read(s);
00118
00119   blocks = rif->rectinfo_blocks();
00120
00121   for (RectificationInfoFile::RectInfoBlockVector::iterator i = blocks->begin(); i != blocks->end(); ++i) {
00122     RectificationLutInfoBlock *rlib = dynamic_cast<RectificationLutInfoBlock *>(*i);
00123     if ( rlib == NULL ) {
00124       printf("Got rectification info block of unknown type");
00125       continue;
00126
00127     }
00128
00129     printf("LUT:  type: %u  camera: %u  size: %zu\n",
00130            rlib->type(), rlib->camera(), rlib->block_size());
00131
00132     cout << "Looking for non-zero mappings" << endl;
00133     uint16_t x, y, to_x, to_y;
00134     for ( y = 0; y < HEIGHT; ++y) {
00135       for ( x = 0; x < WIDTH; ++x) {
00136         // Use evil (slow) method here, it's just for the QA...
00137         rlib->mapping(x, y, &to_x, &to_y);
00138         if ( (to_x != 0) || (to_y != 0) ) {
00139           printf("(%u, %u) maps to (%u, %u)\n", x, y, to_x, to_y);
00140         }
00141       }
00142     }
00143   }
00144
00145   delete blocks;
00146
00147   delete rif;
00148   return 0;
00149 }
00150
00151
00152 
00153 /// @endcond