calibrator.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * $Id: file.cpp 3496 2011-11-22 15:14:32Z fnovotny $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  * Contact visp@irisa.fr if any conditions of this licensing are
34  * not clear to you.
35  *
36  * Description:
37  *
38  *
39  * Authors:
40  * Filip Novotny
41  *
42  *
43  *****************************************************************************/
44 
50 #include "calibrator.h"
51 #include "names.h"
52 #include <visp_bridge/image.h>
53 #include <visp_bridge/camera.h>
54 #include "sensor_msgs/SetCameraInfo.h"
55 #include "sensor_msgs/CameraInfo.h"
56 #include "visp_camera_calibration/CalibPoint.h"
57 
58 #include <vector>
59 
61 {
63  queue_size_(1000)
64  {
65  //prepare function objects
66  point_correspondence_subscriber_callback_t point_correspondence_callback = boost::bind(&Calibrator::pointCorrespondenceCallback, this, _1);
67  calibrate_service_callback_t calibrate_callback = boost::bind(&Calibrator::calibrateCallback, this, _1, _2);
68  //define subscribers
70  point_correspondence_callback);
71 
72  //define services
74 
75  //connect to services
78 
79  }
80 
81  void Calibrator::pointCorrespondenceCallback(const visp_camera_calibration::CalibPointArray::ConstPtr& point_correspondence){
82  vpCalibration calib_all_points;
83  calib_all_points.clearPoint();
84 
85  for(std::vector<visp_camera_calibration::CalibPoint>::const_iterator i = point_correspondence->points.begin();
86  i != point_correspondence->points.end();
87  i++
88  ){
89  vpImagePoint ip(i->i,i->j);
90  calib_all_points.addPoint(i->X,i->Y,i->Z,ip);
91  }
92  calibrations_.push_back(calib_all_points);
93 
94  }
95 
96  bool Calibrator::calibrateCallback(visp_camera_calibration::calibrate::Request &req, visp_camera_calibration::calibrate::Response &res){
97  std::vector<double> dev;
98  std::vector<double> dev_dist;
99  double lambda = .5;
100  ROS_INFO("called service calibrate");
101  vpCameraParameters cam;
102 
103  double px = cam.get_px();
104  double py = cam.get_px();
105  double u0 = req.sample_width/2;
106  double v0 = req.sample_height/2;
107  double error = 0.;
108 
109  cam.initPersProjWithoutDistortion(px, py, u0, v0);
110  vpCalibration::setLambda(lambda);
111 
112  vpCalibration::computeCalibrationMulti(vpCalibration::vpCalibrationMethodType(req.method), calibrations_, cam, error, false);
113 
114  for(std::vector<vpCalibration>::iterator i=calibrations_.begin();
115  i!=calibrations_.end();
116  i++
117  ){
118  double deviation;
119  double deviation_dist;
120  i->cam = cam;
121  i->cam_dist = cam;
122  i->computeStdDeviation(deviation,deviation_dist);
123  dev.push_back(deviation);
124  dev_dist.push_back(deviation_dist);
125  }
126  switch(req.method){
127  case vpCalibration::CALIB_LAGRANGE_VIRTUAL_VS:
128  case vpCalibration::CALIB_VIRTUAL_VS:
129  res.stdDevErrs = dev;
130  break;
131  case vpCalibration::CALIB_LAGRANGE_VIRTUAL_VS_DIST:
132  case vpCalibration::CALIB_VIRTUAL_VS_DIST:
133  res.stdDevErrs= dev_dist;
134  break;
135  }
136 
137 
138  ROS_INFO_STREAM("" << cam);
139  sensor_msgs::SetCameraInfo set_camera_info_comm;
140 
141  set_camera_info_comm.request.camera_info = visp_bridge::toSensorMsgsCameraInfo(cam,req.sample_width,req.sample_height);
142 
143  set_camera_info_service_.call(set_camera_info_comm);
144  if(set_camera_info_bis_service_.call(set_camera_info_comm)){
145  ROS_INFO("set_camera_info service called successfully");
146  }else{
147  ROS_ERROR("Failed to call service set_camera_info");
148  }
149  return true;
150  }
152  ros::spin();
153  }
154 
156  {
157  // TODO Auto-generated destructor stub
158  }
159 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
ros::Subscriber point_correspondence_subscriber_
Definition: calibrator.h:69
ros::ServiceServer calibrate_service_
Definition: calibrator.h:72
std::vector< vpCalibration > calibrations_
Definition: calibrator.h:76
sensor_msgs::CameraInfo toSensorMsgsCameraInfo(vpCameraParameters &cam_info, unsigned int cam_image_width, unsigned int cam_image_height)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool call(MReq &req, MRes &res)
bool calibrateCallback(visp_camera_calibration::calibrate::Request &req, visp_camera_calibration::calibrate::Response &res)
service performing the calibration from all previously computed calibration objects.
Definition: calibrator.cpp:96
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
std::string point_correspondence_topic
std::string calibrate_service
boost::function< bool(visp_camera_calibration::calibrate::Request &, visp_camera_calibration::calibrate::Response &res)> calibrate_service_callback_t
service type declaration for calibrate service
Definition: calibrator.h:97
std::string set_camera_info_bis_service
ros::ServiceClient set_camera_info_bis_service_
Definition: calibrator.h:71
#define ROS_INFO(...)
ROSCPP_DECL void spin()
boost::function< void(const visp_camera_calibration::CalibPointArray::ConstPtr &)> point_correspondence_subscriber_callback_t
subscriber type declaration for raw_image topic subscriber
Definition: calibrator.h:93
#define ROS_INFO_STREAM(args)
ros::ServiceClient set_camera_info_service_
Definition: calibrator.h:70
std::string set_camera_info_service
void pointCorrespondenceCallback(const visp_camera_calibration::CalibPointArray::ConstPtr &point_correspondence)
callback corresponding to the point_correspondence topic. Adds the obtained calibration pairs objects...
Definition: calibrator.cpp:81
#define ROS_ERROR(...)


visp_camera_calibration
Author(s): Filip Novotny
autogenerated on Wed Jul 3 2019 19:48:03