Fawkes API
Fawkes Development Version
|
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 #include <cstdio> 00033 00034 using namespace std; 00035 using namespace firevision; 00036 00037 #define WIDTH 640 00038 #define HEIGHT 480 00039 00040 int 00041 main(int argc, char **argv) 00042 { 00043 srand(23423); 00044 00045 const char *s = "qatest.rif"; 00046 if ( argc > 1 ) { 00047 s = argv[1]; 00048 } 00049 00050 RectificationInfoFile *rif = new RectificationInfoFile(0xDEADBEEF, "No real camera"); 00051 00052 RectificationLutInfoBlock *rlib = new RectificationLutInfoBlock(WIDTH, HEIGHT, 00053 FIREVISION_RECTINFO_CAMERA_MAIN); 00054 00055 RectificationLutInfoBlock *rlib2 = new RectificationLutInfoBlock(WIDTH, HEIGHT, 00056 FIREVISION_RECTINFO_CAMERA_LEFT); 00057 00058 /* Random alternative, harder to read though 00059 for ( int i = 0; i < 10; ++i ) { 00060 uint16_t x, y, to_x, to_y; 00061 x=1+(uint16_t)(1.f * WIDTH * rand() / (RAND_MAX + 1.f)); 00062 y=1+(uint16_t)(1.f * HEIGHT * rand() / (RAND_MAX + 1.f)); 00063 to_x=1+(uint16_t)(1.f * WIDTH * rand() / (RAND_MAX + 1.f)); 00064 to_y=1+(uint16_t)(1.f * HEIGHT * rand() / (RAND_MAX + 1.f)); 00065 00066 printf("Mapping (%u, %u) to (%u, %u)\n", x, y, to_x, to_y); 00067 rlib->set_mapping(x, y, to_x, to_y); 00068 } 00069 */ 00070 00071 for ( int i = 0; i < 10; ++i ) { 00072 uint16_t x = i, y = i, to_x = i * 2, to_y = i * 2; 00073 printf("Mapping (%u, %u) to (%u, %u)\n", x, y, to_x, to_y); 00074 rlib->set_mapping(x, y, to_x, to_y); 00075 } 00076 00077 for ( int i = 10; i < 20; ++i ) { 00078 uint16_t x = i, y = i, to_x = i * 2, to_y = i * 2; 00079 printf("Mapping2 (%u, %u) to (%u, %u)\n", x, y, to_x, to_y); 00080 rlib2->set_mapping(x, y, to_x, to_y); 00081 } 00082 00083 rif->add_rectinfo_block(rlib); 00084 rif->add_rectinfo_block(rlib2); 00085 00086 RectificationInfoFile::RectInfoBlockVector *blocks = rif->rectinfo_blocks(); 00087 00088 for (RectificationInfoFile::RectInfoBlockVector::iterator i = blocks->begin(); i != blocks->end(); ++i) { 00089 RectificationLutInfoBlock *rlib = dynamic_cast<RectificationLutInfoBlock *>(*i); 00090 if ( rlib == NULL ) { 00091 printf("Got rectification info block of unknown type"); 00092 continue; 00093 } 00094 00095 printf("LUT: type: %u camera: %u size: %zu\n", 00096 rlib->type(), rlib->camera(), rlib->block_size()); 00097 00098 cout << "Looking for non-zero mappings" << endl; 00099 uint16_t x, y, to_x, to_y; 00100 for ( y = 0; y < HEIGHT; ++y) { 00101 for ( x = 0; x < WIDTH; ++x) { 00102 // Use evil (slow) method here, it's just for the QA... 00103 rlib->mapping(x, y, &to_x, &to_y); 00104 if ( (to_x != 0) || (to_y != 0) ) { 00105 printf("(%u, %u) maps to (%u, %u)\n", x, y, to_x, to_y); 00106 } 00107 } 00108 } 00109 } 00110 00111 delete blocks; 00112 00113 cout << "Writing to " << s << endl; 00114 rif->write(s); 00115 00116 rif->clear(); 00117 00118 cout << "Reading from " << s << endl; 00119 rif->read(s); 00120 00121 blocks = rif->rectinfo_blocks(); 00122 00123 for (RectificationInfoFile::RectInfoBlockVector::iterator i = blocks->begin(); i != blocks->end(); ++i) { 00124 RectificationLutInfoBlock *rlib = dynamic_cast<RectificationLutInfoBlock *>(*i); 00125 if ( rlib == NULL ) { 00126 printf("Got rectification info block of unknown type"); 00127 continue; 00128 00129 } 00130 00131 printf("LUT: type: %u camera: %u size: %zu\n", 00132 rlib->type(), rlib->camera(), rlib->block_size()); 00133 00134 cout << "Looking for non-zero mappings" << endl; 00135 uint16_t x, y, to_x, to_y; 00136 for ( y = 0; y < HEIGHT; ++y) { 00137 for ( x = 0; x < WIDTH; ++x) { 00138 // Use evil (slow) method here, it's just for the QA... 00139 rlib->mapping(x, y, &to_x, &to_y); 00140 if ( (to_x != 0) || (to_y != 0) ) { 00141 printf("(%u, %u) maps to (%u, %u)\n", x, y, to_x, to_y); 00142 } 00143 } 00144 } 00145 } 00146 00147 delete blocks; 00148 00149 delete rif; 00150 return 0; 00151 } 00152 00153 00154 00155 /// @endcond