32 #define TEST_NAME "base/undistortion"
47 BOOST_CHECK_EQUAL(undistorted_camera.
ModelName(),
"PINHOLE");
50 BOOST_CHECK_EQUAL(undistorted_camera.
Width(), 1);
51 BOOST_CHECK_EQUAL(undistorted_camera.
Height(), 1);
55 BOOST_CHECK_EQUAL(undistorted_camera.
ModelName(),
"PINHOLE");
58 BOOST_CHECK_EQUAL(undistorted_camera.
Width(), 1);
59 BOOST_CHECK_EQUAL(undistorted_camera.
Height(), 1);
62 distorted_camera.
Params(3) = 0.5;
64 BOOST_CHECK_EQUAL(undistorted_camera.
ModelName(),
"PINHOLE");
65 BOOST_CHECK_EQUAL(undistorted_camera.
FocalLengthX(), 100);
66 BOOST_CHECK_EQUAL(undistorted_camera.
FocalLengthY(), 100);
69 BOOST_CHECK_EQUAL(undistorted_camera.
Width(), 84);
70 BOOST_CHECK_EQUAL(undistorted_camera.
Height(), 84);
74 BOOST_CHECK_EQUAL(undistorted_camera.
ModelName(),
"PINHOLE");
75 BOOST_CHECK_EQUAL(undistorted_camera.
FocalLengthX(), 100);
76 BOOST_CHECK_EQUAL(undistorted_camera.
FocalLengthY(), 100);
77 BOOST_CHECK_EQUAL(undistorted_camera.
Width(), 90);
78 BOOST_CHECK_EQUAL(undistorted_camera.
Height(), 90);
82 BOOST_CHECK_EQUAL(undistorted_camera.
ModelName(),
"PINHOLE");
83 BOOST_CHECK_EQUAL(undistorted_camera.
FocalLengthX(), 100);
84 BOOST_CHECK_EQUAL(undistorted_camera.
FocalLengthY(), 100);
85 BOOST_CHECK_EQUAL(undistorted_camera.
Width(), 75);
86 BOOST_CHECK_EQUAL(undistorted_camera.
Height(), 75);
94 BOOST_CHECK_EQUAL(undistorted_camera.
ModelName(),
"PINHOLE");
95 BOOST_CHECK_EQUAL(undistorted_camera.
FocalLengthX(), 100);
96 BOOST_CHECK_EQUAL(undistorted_camera.
FocalLengthY(), 100);
97 BOOST_CHECK_EQUAL(undistorted_camera.
Width(), 80);
98 BOOST_CHECK_EQUAL(undistorted_camera.
Height(), 60);
109 distorted_camera.
Params(3) = 0.5;
112 distorted_image.
Allocate(100, 100,
false);
116 Camera undistorted_camera;
117 UndistortImage(options, distorted_image, distorted_camera, &undistorted_image,
118 &undistorted_camera);
120 BOOST_CHECK_EQUAL(undistorted_camera.
ModelName(),
"PINHOLE");
121 BOOST_CHECK_EQUAL(undistorted_camera.
FocalLengthX(), 100);
122 BOOST_CHECK_EQUAL(undistorted_camera.
FocalLengthY(), 100);
125 BOOST_CHECK_EQUAL(undistorted_camera.
Width(), 90);
126 BOOST_CHECK_EQUAL(undistorted_camera.
Height(), 90);
129 size_t num_blank_pixels = 0;
130 for (
int y = 0;
y < undistorted_image.
Height(); ++
y) {
131 for (
int x = 0;
x < undistorted_image.
Width(); ++
x) {
135 num_blank_pixels += 1;
140 BOOST_CHECK_GT(num_blank_pixels, 0);
149 distorted_camera.
Params(3) = 0.5;
152 distorted_image.
Allocate(100, 100,
false);
156 Camera undistorted_camera;
157 UndistortImage(options, distorted_image, distorted_camera, &undistorted_image,
158 &undistorted_camera);
160 BOOST_CHECK_EQUAL(undistorted_camera.
ModelName(),
"PINHOLE");
161 BOOST_CHECK_EQUAL(undistorted_camera.
FocalLengthX(), 100);
162 BOOST_CHECK_EQUAL(undistorted_camera.
FocalLengthY(), 100);
165 BOOST_CHECK_EQUAL(undistorted_camera.
Width(), 84);
166 BOOST_CHECK_EQUAL(undistorted_camera.
Height(), 84);
169 for (
int y = 0;
y < undistorted_image.
Height(); ++
y) {
170 for (
int x = 0;
x < undistorted_image.
Width(); ++
x) {
173 BOOST_CHECK_NE(
color.r, 0);
174 BOOST_CHECK_EQUAL(
color.g, 0);
175 BOOST_CHECK_EQUAL(
color.b, 0);
181 const size_t kNumImages = 10;
182 const size_t kNumPoints2D = 10;
192 for (
image_t image_id = 1; image_id <= kNumImages; ++image_id) {
194 image.SetImageId(image_id);
195 image.SetCameraId(1);
198 std::vector<Eigen::Vector2d>(kNumPoints2D, Eigen::Vector2d::Ones()));
205 for (
const auto& camera : reconstruction.
Cameras()) {
206 BOOST_CHECK_EQUAL(camera.second.
ModelName(),
"PINHOLE");
209 for (
const auto&
image : reconstruction.
Images()) {
210 for (
const auto& point2D :
image.second.Points2D()) {
211 BOOST_CHECK_NE(point2D.XY(), Eigen::Vector2d::Ones());
225 const Eigen::Vector4d qvec =
227 const Eigen::Vector3d tvec(0.1, 0.2, 0.3);
236 Eigen::Matrix3d H1_ref;
237 H1_ref << -0.202759, -0.815848, -0.897034, 0.416329, 0.733069, -0.199657,
238 0.910839, -0.175408, 0.942638;
239 BOOST_CHECK(H1.isApprox(H1_ref.transpose(), 1
e-5));
241 Eigen::Matrix3d H2_ref;
242 H2_ref << -0.082173, -1.01288, -0.698868, 0.301854, 0.472844, -0.465336,
243 0.963533, 0.292411, 1.12528;
244 BOOST_CHECK(H2.isApprox(H2_ref.transpose(), 1
e-5));
246 Eigen::Matrix4d Q_ref;
247 Q_ref << 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -2.67261, -0.5, -0.5, 1, 0;
248 BOOST_CHECK(Q.isApprox(Q_ref, 1
e-5));
std::shared_ptr< core::Tensor > image
bool GetPixel(const int x, const int y, BitmapColor< uint8_t > *color) const
void Fill(const BitmapColor< uint8_t > &color)
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)
double FocalLengthY() const
const std::vector< double > & Params() const
std::string ModelName() const
void SetCameraId(const camera_t camera_id)
double FocalLengthX() const
double PrincipalPointX() const
double PrincipalPointY() const
void AddImage(const class Image &image)
const std::unordered_map< image_t, class Image > & Images() const
void AddCamera(const class Camera &camera)
const std::unordered_map< camera_t, class Camera > & Cameras() const
void RegisterImage(const image_t image_id)
void RectifyStereoCameras(const Camera &camera1, const Camera &camera2, const Eigen::Vector4d &qvec, const Eigen::Vector3d &tvec, Eigen::Matrix3d *H1, Eigen::Matrix3d *H2, Eigen::Matrix4d *Q)
void UndistortImage(const UndistortCameraOptions &options, const Bitmap &distorted_bitmap, const Camera &distorted_camera, Bitmap *undistorted_bitmap, Camera *undistorted_camera)
Eigen::Matrix3d EulerAnglesToRotationMatrix(const double rx, const double ry, const double rz)
Eigen::Vector4d RotationMatrixToQuaternion(const Eigen::Matrix3d &rot_mat)
void UndistortReconstruction(const UndistortCameraOptions &options, Reconstruction *reconstruction)
Camera UndistortCamera(const UndistortCameraOptions &options, const Camera &camera)
std::string to_string(const T &n)
BOOST_AUTO_TEST_CASE(TestUndistortCamera)