32 #define TEST_NAME "base/warp"
41 void GenerateRandomBitmap(
const int width,
const int height,
const bool as_rgb,
47 color.r = RandomInteger<int>(0, 255);
48 color.g = RandomInteger<int>(0, 255);
49 color.b = RandomInteger<int>(0, 255);
56 void CheckBitmapsEqual(
const Bitmap& bitmap1,
const Bitmap& bitmap2) {
58 BOOST_REQUIRE_EQUAL(bitmap1.
IsRGB(), bitmap2.
IsRGB());
59 BOOST_REQUIRE_EQUAL(bitmap1.
Width(), bitmap2.
Width());
61 for (
int x = 1;
x < bitmap1.
Width() - 1; ++
x) {
62 for (
int y = 1;
y < bitmap1.
Height() - 1; ++
y) {
67 BOOST_CHECK_EQUAL(color1, color2);
73 void CheckBitmapsTransposed(
const Bitmap& bitmap1,
const Bitmap& bitmap2) {
75 BOOST_REQUIRE_EQUAL(bitmap1.
IsRGB(), bitmap2.
IsRGB());
76 BOOST_REQUIRE_EQUAL(bitmap1.
Width(), bitmap2.
Width());
78 for (
int x = 1;
x < bitmap1.
Width() - 1; ++
x) {
79 for (
int y = 1;
y < bitmap1.
Height() - 1; ++
y) {
84 BOOST_CHECK_EQUAL(color1, color2);
94 Camera target_camera = source_camera;
96 GenerateRandomBitmap(100, 100,
false, &source_image_gray);
100 CheckBitmapsEqual(source_image_gray, target_image_gray);
102 GenerateRandomBitmap(100, 100,
true, &source_image_rgb);
106 CheckBitmapsEqual(source_image_rgb, target_image_rgb);
112 Camera target_camera = source_camera;
115 GenerateRandomBitmap(100, 100,
true, &source_image_gray);
119 for (
int x = 0;
x < target_image_gray.
Width(); ++
x) {
120 for (
int y = 0;
y < target_image_gray.
Height(); ++
y) {
127 if (source_image_gray.
GetPixel(
x + 50,
y, &source_color) &&
129 BOOST_CHECK_EQUAL(
color, source_color);
138 GenerateRandomBitmap(100, 100,
false, &source_image_gray);
140 target_image_gray.
Allocate(100, 100,
false);
143 CheckBitmapsEqual(source_image_gray, target_image_gray);
146 GenerateRandomBitmap(100, 100,
true, &source_image_rgb);
148 target_image_rgb.
Allocate(100, 100,
true);
151 CheckBitmapsEqual(source_image_rgb, target_image_rgb);
156 H << 0, 1, 0, 1, 0, 0, 0, 0, 1;
159 GenerateRandomBitmap(100, 100,
false, &source_image_gray);
161 target_image_gray.
Allocate(100, 100,
false);
163 CheckBitmapsTransposed(source_image_gray, target_image_gray);
166 GenerateRandomBitmap(100, 100,
true, &source_image_rgb);
168 target_image_rgb.
Allocate(100, 100,
true);
170 CheckBitmapsTransposed(source_image_rgb, target_image_rgb);
176 Camera target_camera = source_camera;
179 GenerateRandomBitmap(100, 100,
false, &source_image_gray);
181 target_image_gray.
Allocate(100, 100,
false);
183 source_camera, target_camera,
184 source_image_gray, &target_image_gray);
185 CheckBitmapsEqual(source_image_gray, target_image_gray);
188 GenerateRandomBitmap(100, 100,
true, &source_image_rgb);
190 target_image_rgb.
Allocate(100, 100,
true);
192 source_camera, target_camera,
193 source_image_rgb, &target_image_rgb);
194 CheckBitmapsEqual(source_image_rgb, target_image_rgb);
200 Camera target_camera = source_camera;
203 H << 0, 1, 0, 1, 0, 0, 0, 0, 1;
206 GenerateRandomBitmap(100, 100,
false, &source_image_gray);
208 target_image_gray.
Allocate(100, 100,
false);
210 source_image_gray, &target_image_gray);
211 CheckBitmapsTransposed(source_image_gray, target_image_gray);
214 GenerateRandomBitmap(100, 100,
true, &source_image_rgb);
216 target_image_rgb.
Allocate(100, 100,
true);
218 source_image_rgb, &target_image_rgb);
219 CheckBitmapsTransposed(source_image_rgb, target_image_rgb);
223 std::vector<float>
image(16);
224 for (
size_t i = 0; i <
image.size(); ++i) {
228 std::vector<float> resampled(4);
231 BOOST_CHECK_EQUAL(resampled[0], 2.5);
232 BOOST_CHECK_EQUAL(resampled[1], 4.5);
233 BOOST_CHECK_EQUAL(resampled[2], 10.5);
234 BOOST_CHECK_EQUAL(resampled[3], 12.5);
238 std::vector<float>
image(16);
239 for (
size_t i = 0; i <
image.size(); ++i) {
243 std::vector<float> smoothed(16);
246 BOOST_CHECK_CLOSE(smoothed[0], 1.81673253, 1
e-3);
247 BOOST_CHECK_CLOSE(smoothed[1], 2.51182437, 1
e-3);
248 BOOST_CHECK_CLOSE(smoothed[2], 3.39494729, 1
e-3);
249 BOOST_CHECK_CLOSE(smoothed[3], 4.09003973, 1
e-3);
250 BOOST_CHECK_CLOSE(smoothed[4], 4.59710073, 1
e-3);
251 BOOST_CHECK_CLOSE(smoothed[5], 5.29219341, 1
e-3);
252 BOOST_CHECK_CLOSE(smoothed[6], 6.17531633, 1
e-3);
253 BOOST_CHECK_CLOSE(smoothed[7], 6.87040806, 1
e-3);
257 std::vector<float>
image(16);
258 for (
size_t i = 0; i <
image.size(); ++i) {
262 std::vector<float> downsampled(4);
265 BOOST_CHECK_CLOSE(downsampled[0], 2.76810598, 1
e-3);
266 BOOST_CHECK_CLOSE(downsampled[1], 4.66086388, 1
e-3);
267 BOOST_CHECK_CLOSE(downsampled[2], 10.3391361, 1
e-3);
268 BOOST_CHECK_CLOSE(downsampled[3], 12.2318935, 1
e-3);
std::shared_ptr< core::Tensor > image
bool SetPixel(const int x, const int y, const BitmapColor< uint8_t > &color)
bool GetPixel(const int x, const int y, BitmapColor< uint8_t > *color) const
bool Allocate(const int width, const int height, const bool as_rgb)
void InitializeWithName(const std::string &model_name, const double focal_length, const size_t width, const size_t height)
void SetPrincipalPointX(const double ppx)
void WarpImageBetweenCameras(const Camera &source_camera, const Camera &target_camera, const Bitmap &source_image, Bitmap *target_image)
void ResampleImageBilinear(const float *data, const int rows, const int cols, const int new_rows, const int new_cols, float *resampled)
void SmoothImage(const float *data, const int rows, const int cols, const float sigma_r, const float sigma_c, float *smoothed)
void WarpImageWithHomography(const Eigen::Matrix3d &H, const Bitmap &source_image, Bitmap *target_image)
void WarpImageWithHomographyBetweenCameras(const Eigen::Matrix3d &H, const Camera &source_camera, const Camera &target_camera, const Bitmap &source_image, Bitmap *target_image)
void DownsampleImage(const float *data, const int rows, const int cols, const int new_rows, const int new_cols, float *downsampled)
BOOST_AUTO_TEST_CASE(TestIdenticalCameras)