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
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00050 #include "calibrator.h"
00051 #include "names.h"
00052 #include <visp_bridge/image.h>
00053 #include <visp_bridge/camera.h>
00054 #include "sensor_msgs/SetCameraInfo.h"
00055 #include "sensor_msgs/CameraInfo.h"
00056 #include "visp_camera_calibration/CalibPoint.h"
00057
00058 #include <vector>
00059
00060 namespace visp_camera_calibration
00061 {
00062 Calibrator::Calibrator() :
00063 queue_size_(1000)
00064 {
00065
00066 point_correspondence_subscriber_callback_t point_correspondence_callback = boost::bind(&Calibrator::pointCorrespondenceCallback, this, _1);
00067 calibrate_service_callback_t calibrate_callback = boost::bind(&Calibrator::calibrateCallback, this, _1, _2);
00068
00069 point_correspondence_subscriber_ = n_.subscribe(visp_camera_calibration::point_correspondence_topic, queue_size_,
00070 point_correspondence_callback);
00071
00072
00073 calibrate_service_ = n_.advertiseService(visp_camera_calibration::calibrate_service,calibrate_callback);
00074
00075
00076 set_camera_info_service_ = n_.serviceClient<sensor_msgs::SetCameraInfo> (visp_camera_calibration::set_camera_info_service);
00077 set_camera_info_bis_service_ = n_.serviceClient<sensor_msgs::SetCameraInfo> (visp_camera_calibration::set_camera_info_bis_service);
00078
00079 }
00080
00081 void Calibrator::pointCorrespondenceCallback(const visp_camera_calibration::CalibPointArray::ConstPtr& point_correspondence){
00082 vpCalibration calib_all_points;
00083 calib_all_points.clearPoint();
00084
00085 for(std::vector<visp_camera_calibration::CalibPoint>::const_iterator i = point_correspondence->points.begin();
00086 i != point_correspondence->points.end();
00087 i++
00088 ){
00089 vpImagePoint ip(i->i,i->j);
00090 calib_all_points.addPoint(i->X,i->Y,i->Z,ip);
00091 }
00092 calibrations_.push_back(calib_all_points);
00093
00094 }
00095
00096 bool Calibrator::calibrateCallback(visp_camera_calibration::calibrate::Request &req, visp_camera_calibration::calibrate::Response &res){
00097 std::vector<double> dev;
00098 std::vector<double> dev_dist;
00099 double lambda = .5;
00100 ROS_INFO("called service calibrate");
00101 vpCameraParameters cam;
00102
00103 double px = cam.get_px();
00104 double py = cam.get_px();
00105 double u0 = req.sample_width/2;
00106 double v0 = req.sample_height/2;
00107 double error = 0.;
00108
00109 cam.initPersProjWithoutDistortion(px, py, u0, v0);
00110 vpCalibration::setLambda(lambda);
00111
00112 vpCalibration::computeCalibrationMulti(vpCalibration::vpCalibrationMethodType(req.method), calibrations_, cam, error, false);
00113
00114 for(std::vector<vpCalibration>::iterator i=calibrations_.begin();
00115 i!=calibrations_.end();
00116 i++
00117 ){
00118 double deviation;
00119 double deviation_dist;
00120 i->cam = cam;
00121 i->cam_dist = cam;
00122 i->computeStdDeviation(deviation,deviation_dist);
00123 dev.push_back(deviation);
00124 dev_dist.push_back(deviation_dist);
00125 }
00126 switch(req.method){
00127 case vpCalibration::CALIB_LAGRANGE_VIRTUAL_VS:
00128 case vpCalibration::CALIB_VIRTUAL_VS:
00129 res.stdDevErrs = dev;
00130 break;
00131 case vpCalibration::CALIB_LAGRANGE_VIRTUAL_VS_DIST:
00132 case vpCalibration::CALIB_VIRTUAL_VS_DIST:
00133 res.stdDevErrs= dev_dist;
00134 break;
00135 }
00136
00137
00138 ROS_INFO_STREAM("" << cam);
00139 sensor_msgs::SetCameraInfo set_camera_info_comm;
00140
00141 set_camera_info_comm.request.camera_info = visp_bridge::toSensorMsgsCameraInfo(cam,req.sample_width,req.sample_height);
00142
00143 set_camera_info_service_.call(set_camera_info_comm);
00144 if(set_camera_info_bis_service_.call(set_camera_info_comm)){
00145 ROS_INFO("set_camera_info service called successfully");
00146 }else{
00147 ROS_ERROR("Failed to call service set_camera_info");
00148 }
00149 return true;
00150 }
00151 void Calibrator::spin(){
00152 ros::spin();
00153 }
00154
00155 Calibrator::~Calibrator()
00156 {
00157
00158 }
00159 }