00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <industrial_extrinsic_cal/calibration_job_definition.h>
00020
00021 #include <gtest/gtest.h>
00022 #include <yaml-cpp/yaml.h>
00023 #include <fstream>
00024
00025 using namespace industrial_extrinsic_cal;
00026 using industrial_extrinsic_cal::CalibrationJob;
00027
00028 void print_AAtoH(double x, double y, double z, double tx, double ty, double tz);
00029
00030 std::string camera_file_name("/home/cgomez/ros/hydro/catkin_ws/src/industrial_calibration/industrial_extrinsic_cal/yaml/test1_camera_def.yaml");
00031 std::string target_file_name("/home/cgomez/ros/hydro/catkin_ws/src/industrial_calibration/industrial_extrinsic_cal/yaml/test1_target_def.yaml");
00032 std::string caljob_file_name("/home/cgomez/ros/hydro/catkin_ws/src/industrial_calibration/industrial_extrinsic_cal/yaml/test1_caljob_def.yaml");
00033
00034
00035 CalibrationJob Cal_job(camera_file_name, target_file_name, caljob_file_name);
00036
00037
00038
00039 std::vector<int> point_ids;
00040 std::vector<float> obs_x;
00041 std::vector<float> obs_y;
00042
00043 P_BLOCK intrinsics;
00044 P_BLOCK extrinsics;
00045 P_BLOCK target_pose;
00046 P_BLOCK pnt_pos;
00047
00048
00049 TEST(DISABLED_IndustrialExtrinsicCalSuite, load_check)
00050 {
00051
00052
00053
00054 EXPECT_TRUE(Cal_job.load());
00055
00056
00057 std::ifstream obs_input_file("/home/cgomez/ros/hydro/catkin_ws/src/industrial_calibration/industrial_extrinsic_cal/observations.txt");
00058 YAML::Parser obs_parser(obs_input_file);
00059
00060 YAML::Node obs_doc;
00061 obs_parser.GetNextDocument(obs_doc);
00062
00063
00064 if (const YAML::Node *observations = obs_doc.FindValue("Points"))
00065 {
00066 ROS_DEBUG_STREAM("Found "<<observations->size() <<" observations ");
00067 point_ids.resize(observations->size());
00068 obs_x.resize(observations->size());
00069 obs_y.resize(observations->size());
00070 for (unsigned int i = 0; i < observations->size(); i++)
00071 {
00072 (*observations)[i]["Point_id"] >> point_ids.at(i);
00073
00074 const YAML::Node *points_node = (*observations)[i].FindValue("Pnts");
00075 std::vector<float> temp_pnt;
00076 (*points_node) >> temp_pnt;
00077 obs_x.at(i) = temp_pnt[0];
00078 obs_y.at(i) = temp_pnt[1];
00079 }
00080 }
00081
00082 }
00083
00084 TEST(DISABLED_IndustrialExtrinsicCalSuite, param_check)
00085 {
00086
00087
00088 std::vector<ObservationScene> obs_scene_list_ = Cal_job.getSceneList();
00089
00090 EXPECT_STRCASEEQ("Asus1", obs_scene_list_.at(0).cameras_in_scene_.at(0)->camera_name_.c_str());
00091
00092 EXPECT_STRCASEEQ("Checkerboard",
00093 obs_scene_list_.at(0).observation_command_list_.at(0).target->target_name.c_str());
00094
00095 CeresBlocks c_blocks_ = Cal_job.getCeresBlocks();
00096 ASSERT_GT(c_blocks_.static_cameras_.size(), 0);
00097
00098 intrinsics = c_blocks_.getStaticCameraParameterBlockIntrinsics("Asus1");
00099 extrinsics = c_blocks_.getStaticCameraParameterBlockExtrinsics("Asus1");
00100
00101 target_pose = c_blocks_.getStaticTargetPoseParameterBlock("Checkerboard");
00102 pnt_pos = c_blocks_.getStaticTargetPointParameterBlock("Checkerboard", 0);
00103
00104
00105
00106 EXPECT_EQ(525, intrinsics[0]);
00107 EXPECT_EQ(525, intrinsics[1]);
00108 EXPECT_EQ(320, intrinsics[2]);
00109 EXPECT_EQ(240, intrinsics[3]);
00110 EXPECT_EQ(0.01, intrinsics[4]);
00111 EXPECT_EQ(0.02, intrinsics[5]);
00112 EXPECT_EQ(0.03, intrinsics[6]);
00113 EXPECT_EQ(0.01, intrinsics[7]);
00114 EXPECT_EQ(0.01, intrinsics[8]);
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 EXPECT_EQ(1.0, extrinsics[0]);
00131 EXPECT_EQ(1.1, extrinsics[1]);
00132 EXPECT_EQ(1.2, extrinsics[2]);
00133 EXPECT_EQ(1.3, extrinsics[3]);
00134 EXPECT_EQ(1.4, extrinsics[4]);
00135 EXPECT_EQ(1.5, extrinsics[5]);
00136
00137
00138
00139
00140
00141
00142 EXPECT_EQ(2.2, target_pose[0]);
00143 EXPECT_EQ(2.3, target_pose[1]);
00144 EXPECT_EQ(2.4, target_pose[2]);
00145 EXPECT_EQ(1.1, target_pose[3]);
00146 EXPECT_EQ(2.0, target_pose[4]);
00147 EXPECT_EQ(2.1, target_pose[5]);
00148
00149
00150 EXPECT_EQ(0.0, pnt_pos[0]);
00151 EXPECT_EQ(0.0, pnt_pos[1]);
00152 EXPECT_EQ(0.0, pnt_pos[2]);
00153 pnt_pos = c_blocks_.getStaticTargetPointParameterBlock("Checkerboard", 120);
00154 EXPECT_FLOAT_EQ(0.40, pnt_pos[0]);
00155 EXPECT_FLOAT_EQ(0.40, pnt_pos[1]);
00156 EXPECT_EQ(0.0, pnt_pos[2]);
00157
00158 ASSERT_GT(point_ids.size(), 0);
00159
00160 EXPECT_EQ(0,point_ids.at(0));
00161 EXPECT_EQ(120,point_ids.at(120));
00162 EXPECT_FLOAT_EQ(64.8908386230469,obs_x.at(0));
00163 EXPECT_FLOAT_EQ(58.9467353820801,obs_y.at(0));
00164 EXPECT_FLOAT_EQ(282.849487304688,obs_x.at(120));
00165 EXPECT_FLOAT_EQ(280.590637207031,obs_y.at(120));
00166 }
00167
00168 TEST(DISABLED_IndustrialExtrinsicCalSuite, ceres_check)
00169 {
00170
00171 CeresBlocks c_blocks_ = Cal_job.getCeresBlocks();
00172 ceres::Problem problem;
00173 for (int i=0; i<point_ids.size(); i++)
00174 {
00175
00176 pnt_pos = c_blocks_.getStaticTargetPointParameterBlock("Checkerboard", i);
00177
00178 ceres::CostFunction* cost_function = TargetCameraReprjErrorNoDistortion::Create(obs_x.at(i), obs_y.at(i),
00179 intrinsics[0],
00180 intrinsics[1],
00181 intrinsics[2],
00182 intrinsics[3],
00183 pnt_pos[0],
00184 pnt_pos[1],
00185 pnt_pos[2]);
00186 problem.AddResidualBlock(cost_function, NULL , extrinsics, target_pose);
00187 }
00188 ceres::Solver::Options options;
00189 options.linear_solver_type = ceres::DENSE_SCHUR;
00190 options.minimizer_progress_to_stdout = true;
00191 options.max_num_iterations = 1000;
00192
00193 ceres::Solver::Summary summary;
00194 ceres::Solve(options, &problem, &summary);
00195 std::cout << summary.BriefReport() << "\n";
00196
00197
00198
00199 printf("World to Camera\n");
00200 printf("Optimized Camera\n");
00201 print_AAtoH(extrinsics[0], extrinsics[1], extrinsics[2],
00202 extrinsics[3], extrinsics[4], extrinsics[5]);
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 }
00222
00223 void print_AAtoH(double x, double y, double z, double tx, double ty, double tz)
00224 {
00225 double R[9];
00226 double aa[3];
00227 aa[0] = x;
00228 aa[1] = y;
00229 aa[2] = z;
00230 ceres::AngleAxisToRotationMatrix(aa, R);
00231 printf("%6.3lf %6.3lf %6.3lf %6.3lf\n", R[0], R[3], R[6], tx);
00232 printf("%6.3lf %6.3lf %6.3lf %6.3lf\n", R[1], R[4], R[7], ty);
00233 printf("%6.3lf %6.3lf %6.3lf %6.3lf\n", R[2], R[5], R[8], tz);
00234 printf("%6.3lf %6.3lf %6.3lf %6.3lf\n", 0.0, 0.0, 0.0, 1.0);
00235 }
00236
00237
00238
00239 int main(int argc, char **argv)
00240 {
00241 ros::init(argc, argv, "test");
00242 testing::InitGoogleTest(&argc, argv);
00243 return RUN_ALL_TESTS();
00244 }