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