35 #include <gtest/gtest.h>
38 #include <laser_cb_detector/ConfigGoal.h>
40 #include <opencv2/opencv.hpp>
41 #include <opencv2/highgui/highgui.hpp>
42 #include <opencv2/core/types_c.h>
50 static const double eps = 1e-6;
56 #define xstr(s) str(s)
60 calibration_msgs::DenseLaserSnapshot
getSnapshot(
const string& filename)
64 image = cv::imread(filename.c_str(), 0);
65 EXPECT_TRUE(!image.empty()) <<
"could not open image file [" << filename <<
"]" << endl;
71 image.convertTo(float_image, CV_32FC1, 1/255.0);
74 calibration_msgs::DenseLaserSnapshot snapshot;
75 snapshot.readings_per_scan = image.cols;
76 snapshot.num_scans = image.rows;
77 snapshot.intensities.resize(0);
81 for (
int i=0; i<float_image.rows; i++)
83 snapshot.intensities.insert(snapshot.intensities.end(), float_image.ptr<
float>(i), float_image.ptr<
float>(i)+float_image.cols);
92 for (
unsigned int i=0; i<snapshot.num_scans; i++)
94 for (
unsigned int j=0; j<snapshot.readings_per_scan; j++)
96 if (snapshot.intensities[i*snapshot.readings_per_scan + j] < 100.0)
118 config.spacing_x = 1.0;
119 config.spacing_y = 1.0;
121 config.width_scaling = 1.0;
122 config.height_scaling = 1.0;
124 config.min_intensity = 0.0;
125 config.max_intensity = 100.0;
127 config.subpixel_window = 3;
128 config.subpixel_zero_zone = 1;
130 config.flip_horizontal = 0;
136 void check3x4(
const calibration_msgs::CalibrationPattern& result,
double pix_eps,
bool flipped)
138 EXPECT_TRUE(result.success);
141 EXPECT_NEAR(result.object_points[0].x, 0.0,
eps);
142 EXPECT_NEAR(result.object_points[0].y, 0.0,
eps);
143 EXPECT_NEAR(result.object_points[0].z, 0.0,
eps);
145 EXPECT_NEAR(result.object_points[2].x, 2.0,
eps);
146 EXPECT_NEAR(result.object_points[2].y, 0.0,
eps);
147 EXPECT_NEAR(result.object_points[2].z, 0.0,
eps);
149 EXPECT_NEAR(result.object_points[5].x, 2.0,
eps);
150 EXPECT_NEAR(result.object_points[5].y, 1.0,
eps);
151 EXPECT_NEAR(result.object_points[5].z, 0.0,
eps);
156 EXPECT_NEAR(result.image_points[0].x, 81.5, pix_eps);
157 EXPECT_NEAR(result.image_points[0].y, 72.0, pix_eps);
159 EXPECT_NEAR(result.image_points[1].x, 81.5, pix_eps);
160 EXPECT_NEAR(result.image_points[1].y, 118.5, pix_eps);
162 EXPECT_NEAR(result.image_points[11].x, 223.5, pix_eps);
163 EXPECT_NEAR(result.image_points[11].y, 166.5, pix_eps);
167 EXPECT_NEAR(result.image_points[0].x, 223.0, pix_eps);
168 EXPECT_NEAR(result.image_points[0].y, 72.0, pix_eps);
170 EXPECT_NEAR(result.image_points[1].x, 223.0, pix_eps);
171 EXPECT_NEAR(result.image_points[1].y, 119.0, pix_eps);
173 EXPECT_NEAR(result.image_points[11].x, 81.0, pix_eps);
174 EXPECT_NEAR(result.image_points[11].y, 166.0, pix_eps);
181 calibration_msgs::DenseLaserSnapshot snapshot;
187 ASSERT_EQ(snapshot.readings_per_scan, (
unsigned int) 303);
188 ASSERT_EQ(snapshot.num_scans, (
unsigned int) 325);
193 calibration_msgs::CalibrationPattern result;
194 return_result = detector.
detect(snapshot, result);
195 EXPECT_TRUE(return_result);
203 calibration_msgs::DenseLaserSnapshot snapshot;
207 ASSERT_EQ(snapshot.readings_per_scan, (
unsigned int) 303);
208 ASSERT_EQ(snapshot.num_scans, (
unsigned int) 325);
211 config.width_scaling = 2.0;
212 config.height_scaling = 4.0;
216 calibration_msgs::CalibrationPattern result;
217 return_result = detector.
detect(snapshot, result);
218 EXPECT_TRUE(return_result);
227 calibration_msgs::DenseLaserSnapshot snapshot;
231 ASSERT_EQ(snapshot.readings_per_scan, (
unsigned int) 303);
232 ASSERT_EQ(snapshot.num_scans, (
unsigned int) 325);
235 config.flip_horizontal = 1;
239 calibration_msgs::CalibrationPattern result;
240 return_result = detector.
detect(snapshot, result);
241 EXPECT_TRUE(return_result);
252 calibration_msgs::DenseLaserSnapshot snapshot;
256 snapshot.num_scans = 10;
259 calibration_msgs::CalibrationPattern result;
260 return_result = detector.
detect(snapshot, result);
262 EXPECT_FALSE(return_result);
269 calibration_msgs::DenseLaserSnapshot snapshot;
277 calibration_msgs::CalibrationPattern result;
278 return_result = detector.
detect(snapshot, result);
280 EXPECT_TRUE(return_result);
281 EXPECT_FALSE(result.success);
286 int main(
int argc,
char **argv){
287 testing::InitGoogleTest(&argc, argv);
288 return RUN_ALL_TESTS();