Fawkes API  Fawkes Development Version
qa_rectlut.cpp
1 
2 /***************************************************************************
3  * qa_rectlut.h - QA for rectification LUT
4  *
5  * Generated: Wed Oct 32 18:03:48 2007
6  * Copyright 2007 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 /// @cond QA
25 
26 #include <fvutils/rectification/rectfile.h>
27 #include <fvutils/rectification/rectinfo_lut_block.h>
28 
29 #include <list>
30 #include <cstdlib>
31 #include <iostream>
32 #include <cstdio>
33 
34 using namespace std;
35 using namespace firevision;
36 
37 #define WIDTH 640
38 #define HEIGHT 480
39 
40 int
41 main(int argc, char **argv)
42 {
43  srand(23423);
44 
45  const char *s = "qatest.rif";
46  if ( argc > 1 ) {
47  s = argv[1];
48  }
49 
50  RectificationInfoFile *rif = new RectificationInfoFile(0xDEADBEEF, "No real camera");
51 
52  RectificationLutInfoBlock *rlib = new RectificationLutInfoBlock(WIDTH, HEIGHT,
53  FIREVISION_RECTINFO_CAMERA_MAIN);
54 
55  RectificationLutInfoBlock *rlib2 = new RectificationLutInfoBlock(WIDTH, HEIGHT,
56  FIREVISION_RECTINFO_CAMERA_LEFT);
57 
58  /* Random alternative, harder to read though
59  for ( int i = 0; i < 10; ++i ) {
60  uint16_t x, y, to_x, to_y;
61  x=1+(uint16_t)(1.f * WIDTH * rand() / (RAND_MAX + 1.f));
62  y=1+(uint16_t)(1.f * HEIGHT * rand() / (RAND_MAX + 1.f));
63  to_x=1+(uint16_t)(1.f * WIDTH * rand() / (RAND_MAX + 1.f));
64  to_y=1+(uint16_t)(1.f * HEIGHT * rand() / (RAND_MAX + 1.f));
65 
66  printf("Mapping (%u, %u) to (%u, %u)\n", x, y, to_x, to_y);
67  rlib->set_mapping(x, y, to_x, to_y);
68  }
69  */
70 
71  for ( int i = 0; i < 10; ++i ) {
72  uint16_t x = i, y = i, to_x = i * 2, to_y = i * 2;
73  printf("Mapping (%u, %u) to (%u, %u)\n", x, y, to_x, to_y);
74  rlib->set_mapping(x, y, to_x, to_y);
75  }
76 
77  for ( int i = 10; i < 20; ++i ) {
78  uint16_t x = i, y = i, to_x = i * 2, to_y = i * 2;
79  printf("Mapping2 (%u, %u) to (%u, %u)\n", x, y, to_x, to_y);
80  rlib2->set_mapping(x, y, to_x, to_y);
81  }
82 
83  rif->add_rectinfo_block(rlib);
84  rif->add_rectinfo_block(rlib2);
85 
87 
88  for (RectificationInfoFile::RectInfoBlockVector::iterator i = blocks->begin(); i != blocks->end(); ++i) {
89  RectificationLutInfoBlock *rlib = dynamic_cast<RectificationLutInfoBlock *>(*i);
90  if ( rlib == NULL ) {
91  printf("Got rectification info block of unknown type");
92  continue;
93  }
94 
95  printf("LUT: type: %u camera: %u size: %zu\n",
96  rlib->type(), rlib->camera(), rlib->block_size());
97 
98  cout << "Looking for non-zero mappings" << endl;
99  uint16_t x, y, to_x, to_y;
100  for ( y = 0; y < HEIGHT; ++y) {
101  for ( x = 0; x < WIDTH; ++x) {
102  // Use evil (slow) method here, it's just for the QA...
103  rlib->mapping(x, y, &to_x, &to_y);
104  if ( (to_x != 0) || (to_y != 0) ) {
105  printf("(%u, %u) maps to (%u, %u)\n", x, y, to_x, to_y);
106  }
107  }
108  }
109  }
110 
111  delete blocks;
112 
113  cout << "Writing to " << s << endl;
114  rif->write(s);
115 
116  rif->clear();
117 
118  cout << "Reading from " << s << endl;
119  rif->read(s);
120 
121  blocks = rif->rectinfo_blocks();
122 
123  for (RectificationInfoFile::RectInfoBlockVector::iterator i = blocks->begin(); i != blocks->end(); ++i) {
124  RectificationLutInfoBlock *rlib = dynamic_cast<RectificationLutInfoBlock *>(*i);
125  if ( rlib == NULL ) {
126  printf("Got rectification info block of unknown type");
127  continue;
128 
129  }
130 
131  printf("LUT: type: %u camera: %u size: %zu\n",
132  rlib->type(), rlib->camera(), rlib->block_size());
133 
134  cout << "Looking for non-zero mappings" << endl;
135  uint16_t x, y, to_x, to_y;
136  for ( y = 0; y < HEIGHT; ++y) {
137  for ( x = 0; x < WIDTH; ++x) {
138  // Use evil (slow) method here, it's just for the QA...
139  rlib->mapping(x, y, &to_x, &to_y);
140  if ( (to_x != 0) || (to_y != 0) ) {
141  printf("(%u, %u) maps to (%u, %u)\n", x, y, to_x, to_y);
142  }
143  }
144  }
145  }
146 
147  delete blocks;
148 
149  delete rif;
150  return 0;
151 }
152 
153 
154 
155 /// @endcond
unsigned int type() const
Get block type.
Recitification Lookup Table Block.
STL namespace.
void add_rectinfo_block(RectificationInfoBlock *block)
Add a rectification info block.
Definition: rectfile.cpp:128
Vector that is used for maintaining the rectification info blocks.
Definition: rectfile.h:49
virtual void write(const char *file_name)
Write file.
Definition: fvfile.cpp:262
virtual void mapping(uint16_t x, uint16_t y, uint16_t *to_x, uint16_t *to_y)
Get mapping (to_x, to_y) for (x, y).
virtual void read(const char *filename)
Read file.
Definition: rectfile.cpp:157
void set_mapping(uint16_t x, uint16_t y, uint16_t to_x, uint16_t to_y)
Set mapping.
size_t block_size() const
Size of blocks.
virtual void clear()
Clear internal storage.
Definition: fvfile.cpp:130
Rectification Info File.
Definition: rectfile.h:38
uint8_t camera() const
Get block camera identifier.
RectInfoBlockVector * rectinfo_blocks()
Get all rectification info blocks.
Definition: rectfile.cpp:138