3 #include <gtest/gtest.h>
18 double D[] = {-0.08857683871674071, 0.0708113094372378, -0.09127623055964429, 0.04006922269778478};
19 double K[] = {403.603063319358, 0.0, 306.15842863283063,
20 0.0, 403.7028851121003, 261.09715697592696,
22 double R[] = {0.999963944103842, -0.008484152966323483, 0.00036005656766869323,
23 0.008484153516269438, 0.9999640089218772, 0.0,
24 -0.0003600436088446379, 3.0547751946422504e-06, 0.999999935179632};
25 double P[] = {347.2569964503485, 0.0, 350.5, 0.0,
26 0.0, 347.2569964503485, 256.0, 0.0,
49 EXPECT_STREQ(
"tf_frame", model_.tfFrame().c_str());
50 EXPECT_EQ(cam_info_.P[0], model_.fx());
51 EXPECT_EQ(cam_info_.P[5], model_.fy());
52 EXPECT_EQ(cam_info_.P[2], model_.cx());
53 EXPECT_EQ(cam_info_.P[6], model_.cy());
60 cv::Point2d uv(100, 100);
61 cv::Point3d xyz = model_.projectPixelTo3dRay(uv);
62 EXPECT_NEAR(-0.72136775518018115, xyz.x, 1e-8);
63 EXPECT_NEAR(-0.449235009214005, xyz.y, 1e-8);
64 EXPECT_DOUBLE_EQ(1.0, xyz.z);
69 cv::Point2d uv(model_.cx(), model_.cy());
70 cv::Point3d xyz = model_.projectPixelTo3dRay(uv);
71 EXPECT_DOUBLE_EQ(0.0, xyz.x);
72 EXPECT_DOUBLE_EQ(0.0, xyz.y);
73 EXPECT_DOUBLE_EQ(1.0, xyz.z);
77 const size_t step = 10;
78 for (
size_t row = 0; row <= cam_info_.height; row += step) {
79 for (
size_t col = 0; col <= cam_info_.width; col += step) {
80 cv::Point2d uv(row, col), uv_back;
81 cv::Point3d xyz = model_.projectPixelTo3dRay(uv);
82 uv_back = model_.project3dToPixel(xyz);
84 EXPECT_NEAR(uv.x, uv_back.x, 1.14e-13) <<
"at (" << row <<
", " << col <<
")";
85 EXPECT_NEAR(uv.y, uv_back.y, 1.14e-13) <<
"at (" << row <<
", " << col <<
")";
94 cv::Point2d uv_raw(100, 100), uv_rect;
95 uv_rect = model_.rectifyPoint(uv_raw);
96 EXPECT_DOUBLE_EQ(135.45747375488281, uv_rect.x);
97 EXPECT_DOUBLE_EQ(84.945091247558594, uv_rect.y);
103 double cxp = model_.intrinsicMatrix()(0,2), cyp = model_.intrinsicMatrix()(1,2);
105 cv::Point2d uv_raw(cxp, cyp), uv_rect;
106 model_.rectifyPoint(uv_raw, uv_rect);
107 EXPECT_NEAR(uv_rect.x, model_.cx(), 1e-4);
108 EXPECT_NEAR(uv_rect.y, model_.cy(), 1e-4);
113 cv::Point2d uv_rect(model_.cx(), model_.cy()), uv_raw;
114 model_.unrectifyPoint(uv_rect, uv_raw);
115 EXPECT_NEAR(uv_raw.x, cxp, 1e-4);
116 EXPECT_NEAR(uv_raw.y, cyp, 1e-4);
121 const size_t step = 5;
122 for (
size_t row = 0; row <= cam_info_.height; row += step) {
123 for (
size_t col = 0; col <= cam_info_.width; col += step) {
124 cv::Point2d uv_raw(row, col), uv_rect, uv_unrect;
125 uv_rect = model_.rectifyPoint(uv_raw);
126 uv_unrect = model_.unrectifyPoint(uv_rect);
127 EXPECT_NEAR(uv_raw.x, uv_unrect.x, 0.01);
128 EXPECT_NEAR(uv_raw.y, uv_unrect.y, 0.01);
135 double u = 100.0, v = 200.0, du = 17.0, dv = 23.0, Z = 2.0;
136 cv::Point2d uv0(u, v), uv1(u + du, v + dv);
137 cv::Point3d xyz0, xyz1;
138 xyz0 = model_.projectPixelTo3dRay(uv0);
139 xyz0 *= (Z / xyz0.z);
140 xyz1 = model_.projectPixelTo3dRay(uv1);
141 xyz1 *= (Z / xyz1.z);
143 EXPECT_NEAR(model_.getDeltaU(xyz1.x - xyz0.x, Z), du, 1e-4);
144 EXPECT_NEAR(model_.getDeltaV(xyz1.y - xyz0.y, Z), dv, 1e-4);
145 EXPECT_NEAR(model_.getDeltaX(du, Z), xyz1.x - xyz0.x, 1e-4);
146 EXPECT_NEAR(model_.getDeltaY(dv, Z), xyz1.y - xyz0.y, 1e-4);
152 sensor_msgs::CameraInfo info;
189 cv::Mat distorted_image(cv::Size(cam_info_.width, cam_info_.height), CV_8UC3, cv::Scalar(0, 0, 0));
192 const cv::Scalar color = cv::Scalar(255, 255, 255);
195 const int thickness = 7;
197 for (
size_t y = 0; y <= cam_info_.height; y += cam_info_.height/10)
199 cv::line(distorted_image,
200 cv::Point(0, y), cv::Point(cam_info_.width, y),
201 color, type, thickness);
203 for (
size_t x = 0; x <= cam_info_.width; x += cam_info_.width/10)
206 cv::line(distorted_image,
207 cv::Point(x, 0), cv::Point(x, cam_info_.height),
208 color, type, thickness);
211 cv::Mat rectified_image;
215 const double diff_threshold = 10000.0;
220 model_.rectifyImage(distorted_image, rectified_image);
221 error = cv::norm(distorted_image, rectified_image, cv::NORM_L1);
223 EXPECT_GT(error, diff_threshold);
228 sensor_msgs::CameraInfo cam_info_2 = cam_info_;
229 cam_info_2.D[0] = 0.0;
230 model_.fromCameraInfo(cam_info_2);
231 model_.rectifyImage(distorted_image, rectified_image);
232 error = cv::norm(distorted_image, rectified_image, cv::NORM_L1);
233 EXPECT_GT(error, diff_threshold);
236 cam_info_2.D.assign(cam_info_2.D.size(), 0);
237 model_.fromCameraInfo(cam_info_2);
238 model_.rectifyImage(distorted_image, rectified_image);
239 error = cv::norm(distorted_image, rectified_image, cv::NORM_L1);
243 cam_info_2.D.clear();
244 model_.fromCameraInfo(cam_info_2);
245 model_.rectifyImage(distorted_image, rectified_image);
246 error = cv::norm(distorted_image, rectified_image, cv::NORM_L1);
250 model_.fromCameraInfo(cam_info_);
253 int main(
int argc,
char** argv)
255 testing::InitGoogleTest(&argc, argv);
256 return RUN_ALL_TESTS();