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 "conversions/image.h"
00053 #include "conversions/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
00108 cam.initPersProjWithoutDistortion(px, py, u0, v0);
00109 vpCalibration::setLambda(lambda);
00110
00111 vpCalibration::computeCalibrationMulti(vpCalibration::vpCalibrationMethodType(req.method),calibrations_.size(),&(calibrations_[0]),cam,false);
00112
00113 for(std::vector<vpCalibration>::iterator i=calibrations_.begin();
00114 i!=calibrations_.end();
00115 i++
00116 ){
00117 double deviation;
00118 double deviation_dist;
00119 i->cam = cam;
00120 i->cam_dist = cam;
00121 i->computeStdDeviation(deviation,deviation_dist);
00122 dev.push_back(deviation);
00123 dev_dist.push_back(deviation_dist);
00124 }
00125 switch(req.method){
00126 case vpCalibration::CALIB_LAGRANGE_VIRTUAL_VS:
00127 case vpCalibration::CALIB_VIRTUAL_VS:
00128 res.stdDevErrs = dev;
00129 break;
00130 case vpCalibration::CALIB_LAGRANGE_VIRTUAL_VS_DIST:
00131 case vpCalibration::CALIB_VIRTUAL_VS_DIST:
00132 res.stdDevErrs= dev_dist;
00133 break;
00134 }
00135
00136
00137 ROS_INFO_STREAM("" << cam);
00138 sensor_msgs::SetCameraInfo set_camera_info_comm;
00139
00140 set_camera_info_comm.request.camera_info = visp_bridge::toSensorMsgsCameraInfo(cam,req.sample_width,req.sample_height);
00141
00142 set_camera_info_service_.call(set_camera_info_comm);
00143 if(set_camera_info_bis_service_.call(set_camera_info_comm)){
00144 ROS_INFO("set_camera_info service called successfully");
00145 }else{
00146 ROS_ERROR("Failed to call service set_camera_info");
00147 }
00148 return true;
00149 }
00150 void Calibrator::spin(){
00151 ros::spin();
00152 }
00153
00154 Calibrator::~Calibrator()
00155 {
00156
00157 }
00158 }