Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CALIBRATION_JOB_HPP_
00020 #define CALIBRATION_JOB_HPP_
00021
00022 #include <iostream>
00023 #include <industrial_extrinsic_cal/basic_types.h>
00024 #include <industrial_extrinsic_cal/camera_observer.hpp>
00025 #include <boost/shared_ptr.hpp>
00026 #include "ceres/ceres.h"
00027 #include <ros/console.h>
00028
00029 namespace industrial_extrinsic_cal
00030 {
00031
00033 class Camera
00034 {
00035 public:
00037 Camera();
00038
00044 Camera(std::string name, CameraParameters camera_parameters, bool is_moving);
00045
00047 ~Camera();
00048
00053 bool isMoving();
00054 boost::shared_ptr<DummyCameraObserver> camera_observer_;
00055 CameraParameters camera_parameters_;
00056
00057
00058 std::string camera_name_;
00060 bool fixed_intrinsics_;
00061 bool fixed_extrinsics_;
00063 private:
00064 bool is_moving_;
00065 };
00066
00067
00069 typedef struct
00070 {
00071 int trigger_type;
00072 std::string trigger_popup_msg;
00073 } Trigger;
00074
00076 typedef struct
00077 {
00078 boost::shared_ptr<Camera> camera;
00079 boost::shared_ptr<Target> target;
00080 Roi roi;
00081 } ObservationCmd;
00082
00084 class ObservationScene
00085 {
00086 public:
00090 ObservationScene(Trigger trig, int scene_id) :
00091 trig_(trig), scene_id_(scene_id)
00092 {
00093 }
00094 ;
00095
00097 ObservationScene()
00098 {
00099 observation_command_list_.clear();
00100 cameras_in_scene_.clear();
00101 }
00102 ;
00103
00105 void clear();
00106
00112 void addObservationToScene(ObservationCmd observation_command);
00114 int get_id()
00115 {
00116 return (scene_id_);
00117 }
00118 ;
00119
00121 Trigger get_trigger()
00122 {
00123 return (trig_);
00124 }
00125 ;
00126
00127 std::vector<ObservationCmd> observation_command_list_;
00128 std::vector<boost::shared_ptr<Camera> > cameras_in_scene_;
00130 private:
00131 Trigger trig_;
00132 int scene_id_;
00133 };
00134
00135
00138 typedef struct MovingCamera
00139 {
00140 boost::shared_ptr<Camera> cam;
00141 int scene_id;
00142 } MovingCamera;
00143
00145 typedef struct MovingTarget
00146 {
00147 boost::shared_ptr<Target> targ;
00148 int scene_id;
00149 } MovingTarget;
00150
00151 class ObservationDataPoint
00152 {
00153 public:
00154
00168 ObservationDataPoint(std::string c_name, std::string t_name, int s_id, P_BLOCK c_intrinsics, P_BLOCK c_extrinsics,
00169 int point_id, P_BLOCK t_pose, P_BLOCK p_position, double image_x, double image_y)
00170 {
00171 camera_name_ = c_name;
00172 target_name_ = t_name;
00173 scene_id_ = s_id;
00174 camera_intrinsics_ = c_intrinsics;
00175 camera_extrinsics_ = c_extrinsics;
00176 target_pose_ = t_pose;
00177 point_id_ = point_id;
00178 point_position_ = p_position;
00179 image_x_ = image_x;
00180 image_y_ = image_y;
00181 }
00182 ;
00183
00184 ~ObservationDataPoint()
00185 {
00186 }
00187 ;
00188
00189 std::string camera_name_;
00190 std::string target_name_;
00191 int scene_id_;
00192 int point_id_;
00193 P_BLOCK camera_extrinsics_;
00194 P_BLOCK camera_intrinsics_;
00195 P_BLOCK target_pose_;
00196 P_BLOCK point_position_;
00197 double image_x_;
00198 double image_y_;
00199 };
00200
00201
00206 class ObservationDataPointList
00207 {
00208 public:
00209 ObservationDataPointList();
00210
00211 ~ObservationDataPointList();
00212
00213 void addObservationPoint(ObservationDataPoint new_data_point);
00214
00215 std::vector<ObservationDataPoint> items;
00216 };
00217
00224 class CeresBlocks
00225 {
00226 public:
00228 CeresBlocks();
00230 ~CeresBlocks();
00231
00233 void clearCamerasTargets();
00234
00239 bool addStaticCamera(boost::shared_ptr<Camera> camera_to_add);
00240
00245 bool addStaticTarget(boost::shared_ptr<Target> target_to_add);
00246
00252 bool addMovingCamera(boost::shared_ptr<Camera> camera_to_add, int scene_id);
00253
00259 bool addMovingTarget(boost::shared_ptr<Target> target_to_add, int scene_id);
00260
00265 P_BLOCK getStaticCameraParameterBlockIntrinsics(std::string camera_name);
00266
00275 P_BLOCK getMovingCameraParameterBlockIntrinsics(std::string camera_name);
00276
00281 P_BLOCK getStaticCameraParameterBlockExtrinsics(std::string camera_name);
00282
00291 P_BLOCK getMovingCameraParameterBlockExtrinsics(std::string camera_name, int scene_id);
00292
00297 P_BLOCK getStaticTargetPoseParameterBlock(std::string target_name);
00298
00304 P_BLOCK getStaticTargetPointParameterBlock(std::string target_name, int point_id);
00305
00315 P_BLOCK getMovingTargetPoseParameterBlock(std::string target_name, int scene_id);
00316
00326 P_BLOCK getMovingTargetPointParameterBlock(std::string target_name, int pnt_id);
00327
00328
00329 std::vector<boost::shared_ptr<Camera> > static_cameras_;
00330 std::vector<boost::shared_ptr<MovingCamera> > moving_cameras_;
00331 std::vector<boost::shared_ptr<Target> > static_targets_;
00332 std::vector<boost::shared_ptr<MovingTarget> > moving_targets_;
00333 };
00334
00336 class CalibrationJob
00337 {
00338 public:
00340 CalibrationJob(std::string camera_fn, std::string target_fn, std::string caljob_fn) :
00341 camera_def_file_name_(camera_fn), target_def_file_name_(target_fn), caljob_def_file_name_(caljob_fn)
00342 {
00343 }
00344 ;
00345
00347 ~CalibrationJob()
00348 {
00349 }
00350 ;
00351
00355 bool load();
00356
00360 bool store();
00361
00365 bool run();
00366
00370 bool runObservations();
00371
00375 bool runOptimization();
00376
00381 bool addCameraObserver(Camera camera_to_add);
00382
00387 bool addTarget(Target target_to_add);
00388
00392 bool clearJobCameraObservers();
00393
00397 bool clearJobTargets();
00398
00402 bool clearObservationData();
00403
00407 bool selectScene(int scene_id);
00408
00414 bool addObservationToCurrentScene(boost::shared_ptr<DummyCameraObserver> camera_observer,
00415 boost::shared_ptr<Target> target);
00416
00420 bool clearCurrentScene();
00421
00426 bool appendNewScene(Trigger trig);
00427
00428 ObservationDataPointList observation_data_point_list_;
00429
00430
00431 private:
00432 std::string camera_def_file_name_;
00433 std::string target_def_file_name_;
00434 std::string caljob_def_file_name_;
00435 std::vector<ObservationScene> scene_list_;
00436 int current_scene_;
00437 std::vector<DummyCameraObserver> camera_observers_;
00438 std::vector<Target> defined_target_set_;
00439 CeresBlocks ceres_blocks_;
00440 ceres::Problem problem_;
00442 };
00443
00444 }
00445 #endif