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 <cstdio>
30#include <cstdlib>
31#include <iostream>
32#include <list>
33
34using namespace std;
35using namespace firevision;
36
37#define WIDTH 640
38#define HEIGHT 480
39
40int
41main(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
53 new RectificationLutInfoBlock(WIDTH, HEIGHT, FIREVISION_RECTINFO_CAMERA_MAIN);
54
56 new RectificationLutInfoBlock(WIDTH, HEIGHT, 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();
89 ++i) {
90 RectificationLutInfoBlock *rlib = dynamic_cast<RectificationLutInfoBlock *>(*i);
91 if (rlib == NULL) {
92 printf("Got rectification info block of unknown type");
93 continue;
94 }
95
96 printf("LUT: type: %u camera: %u size: %zu\n",
97 rlib->type(),
98 rlib->camera(),
99 rlib->block_size());
100
101 cout << "Looking for non-zero mappings" << endl;
102 uint16_t x, y, to_x, to_y;
103 for (y = 0; y < HEIGHT; ++y) {
104 for (x = 0; x < WIDTH; ++x) {
105 // Use evil (slow) method here, it's just for the QA...
106 rlib->mapping(x, y, &to_x, &to_y);
107 if ((to_x != 0) || (to_y != 0)) {
108 printf("(%u, %u) maps to (%u, %u)\n", x, y, to_x, to_y);
109 }
110 }
111 }
112 }
113
114 delete blocks;
115
116 cout << "Writing to " << s << endl;
117 rif->write(s);
118
119 rif->clear();
120
121 cout << "Reading from " << s << endl;
122 rif->read(s);
123
124 blocks = rif->rectinfo_blocks();
125
126 for (RectificationInfoFile::RectInfoBlockVector::iterator i = blocks->begin(); i != blocks->end();
127 ++i) {
128 RectificationLutInfoBlock *rlib = dynamic_cast<RectificationLutInfoBlock *>(*i);
129 if (rlib == NULL) {
130 printf("Got rectification info block of unknown type");
131 continue;
132 }
133
134 printf("LUT: type: %u camera: %u size: %zu\n",
135 rlib->type(),
136 rlib->camera(),
137 rlib->block_size());
138
139 cout << "Looking for non-zero mappings" << endl;
140 uint16_t x, y, to_x, to_y;
141 for (y = 0; y < HEIGHT; ++y) {
142 for (x = 0; x < WIDTH; ++x) {
143 // Use evil (slow) method here, it's just for the QA...
144 rlib->mapping(x, y, &to_x, &to_y);
145 if ((to_x != 0) || (to_y != 0)) {
146 printf("(%u, %u) maps to (%u, %u)\n", x, y, to_x, to_y);
147 }
148 }
149 }
150 }
151
152 delete blocks;
153
154 delete rif;
155 return 0;
156}
157
158/// @endcond
unsigned int type() const
Get block type.
size_t block_size() const
Size of blocks.
virtual void clear()
Clear internal storage.
Definition: fvfile.cpp:122
virtual void write(const char *file_name)
Write file.
Definition: fvfile.cpp:243
uint8_t camera() const
Get block camera identifier.
Vector that is used for maintaining the rectification info blocks.
Definition: rectfile.h:48
Rectification Info File.
Definition: rectfile.h:37
virtual void read(const char *filename)
Read file.
Definition: rectfile.cpp:146
RectInfoBlockVector * rectinfo_blocks()
Get all rectification info blocks.
Definition: rectfile.cpp:128
void add_rectinfo_block(RectificationInfoBlock *block)
Add a rectification info block.
Definition: rectfile.cpp:119
Recitification Lookup Table Block.
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).
void set_mapping(uint16_t x, uint16_t y, uint16_t to_x, uint16_t to_y)
Set mapping.