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 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
00058
00059
00060
00061
00062
00063
00064
00065
00066
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
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
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