35 #include <gtest/gtest.h> 38 #include <laser_cb_detector/ConfigGoal.h> 40 #include <opencv/highgui.h> 46 static const double eps = 1e-6;
52 #define xstr(s) str(s) 56 calibration_msgs::DenseLaserSnapshot
getSnapshot(
const string& filename)
59 image = cvLoadImage(filename.c_str(), 0);
60 EXPECT_TRUE(image) <<
"could not open image file [" << filename <<
"]" << endl;
63 IplImage* float_image;
64 float_image = cvCreateImage( cvSize(image->width, image->height), IPL_DEPTH_32F, 1);
65 cvConvert(image, float_image);
67 calibration_msgs::DenseLaserSnapshot snapshot;
68 snapshot.readings_per_scan = image->width;
69 snapshot.num_scans = image->height;
70 snapshot.intensities.resize(image->height * image->width);
72 for (
int i=0; i<float_image->height; i++)
74 memcpy(&snapshot.intensities[i*snapshot.readings_per_scan],
75 (float_image->imageData + i*float_image->widthStep),
76 sizeof(
float)*snapshot.readings_per_scan);
81 for (
unsigned int i=0; i<snapshot.num_scans; i++)
83 for (
unsigned int j=0; j<snapshot.readings_per_scan; j++)
85 if (snapshot.intensities[i*snapshot.readings_per_scan + j] < 100.0)
94 cvReleaseImage(&float_image);
95 cvReleaseImage(&image);
106 config.spacing_x = 1.0;
107 config.spacing_y = 1.0;
109 config.width_scaling = 1.0;
110 config.height_scaling = 1.0;
112 config.min_intensity = 0.0;
113 config.max_intensity = 100.0;
115 config.subpixel_window = 3;
116 config.subpixel_zero_zone = 1;
118 config.flip_horizontal = 0;
124 void check3x4(
const calibration_msgs::CalibrationPattern& result,
double pix_eps,
bool flipped)
126 EXPECT_TRUE(result.success);
129 EXPECT_NEAR(result.object_points[0].x, 0.0,
eps);
130 EXPECT_NEAR(result.object_points[0].y, 0.0,
eps);
131 EXPECT_NEAR(result.object_points[0].z, 0.0,
eps);
133 EXPECT_NEAR(result.object_points[2].x, 2.0,
eps);
134 EXPECT_NEAR(result.object_points[2].y, 0.0,
eps);
135 EXPECT_NEAR(result.object_points[2].z, 0.0,
eps);
137 EXPECT_NEAR(result.object_points[5].x, 2.0,
eps);
138 EXPECT_NEAR(result.object_points[5].y, 1.0,
eps);
139 EXPECT_NEAR(result.object_points[5].z, 0.0,
eps);
144 EXPECT_NEAR(result.image_points[0].x, 81.5, pix_eps);
145 EXPECT_NEAR(result.image_points[0].y, 72.0, pix_eps);
147 EXPECT_NEAR(result.image_points[1].x, 81.5, pix_eps);
148 EXPECT_NEAR(result.image_points[1].y, 118.5, pix_eps);
150 EXPECT_NEAR(result.image_points[11].x, 223.5, pix_eps);
151 EXPECT_NEAR(result.image_points[11].y, 166.5, pix_eps);
155 EXPECT_NEAR(result.image_points[0].x, 223.0, pix_eps);
156 EXPECT_NEAR(result.image_points[0].y, 72.0, pix_eps);
158 EXPECT_NEAR(result.image_points[1].x, 223.0, pix_eps);
159 EXPECT_NEAR(result.image_points[1].y, 119.0, pix_eps);
161 EXPECT_NEAR(result.image_points[11].x, 81.0, pix_eps);
162 EXPECT_NEAR(result.image_points[11].y, 166.0, pix_eps);
169 calibration_msgs::DenseLaserSnapshot snapshot;
173 ASSERT_EQ(snapshot.readings_per_scan, (
unsigned int) 303);
174 ASSERT_EQ(snapshot.num_scans, (
unsigned int) 325);
179 calibration_msgs::CalibrationPattern result;
180 return_result = detector.
detect(snapshot, result);
181 EXPECT_TRUE(return_result);
189 calibration_msgs::DenseLaserSnapshot snapshot;
193 ASSERT_EQ(snapshot.readings_per_scan, (
unsigned int) 303);
194 ASSERT_EQ(snapshot.num_scans, (
unsigned int) 325);
197 config.width_scaling = 2.0;
198 config.height_scaling = 4.0;
202 calibration_msgs::CalibrationPattern result;
203 return_result = detector.
detect(snapshot, result);
204 EXPECT_TRUE(return_result);
213 calibration_msgs::DenseLaserSnapshot snapshot;
217 ASSERT_EQ(snapshot.readings_per_scan, (
unsigned int) 303);
218 ASSERT_EQ(snapshot.num_scans, (
unsigned int) 325);
221 config.flip_horizontal = 1;
225 calibration_msgs::CalibrationPattern result;
226 return_result = detector.
detect(snapshot, result);
227 EXPECT_TRUE(return_result);
238 calibration_msgs::DenseLaserSnapshot snapshot;
242 snapshot.num_scans = 10;
245 calibration_msgs::CalibrationPattern result;
246 return_result = detector.
detect(snapshot, result);
248 EXPECT_FALSE(return_result);
255 calibration_msgs::DenseLaserSnapshot snapshot;
263 calibration_msgs::CalibrationPattern result;
264 return_result = detector.
detect(snapshot, result);
266 EXPECT_TRUE(return_result);
267 EXPECT_FALSE(result.success);
272 int main(
int argc,
char **argv){
273 testing::InitGoogleTest(&argc, argv);
274 return RUN_ALL_TESTS();
bool detect(const calibration_msgs::DenseLaserSnapshot &snapshot, calibration_msgs::CalibrationPattern &result)
calibration_msgs::DenseLaserSnapshot getSnapshot(const string &filename)
static const string test_path
void check3x4(const calibration_msgs::CalibrationPattern &result, double pix_eps, bool flipped)
int main(int argc, char **argv)
static const double pix_eps_
TEST(LaserCbDetector, easy_cb_3x4)
bool configure(const ConfigGoal &config)