00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00057
00058
00059
00060
00061
00062
00063
00064
00065
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
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
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