camera.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 
51 #include "camera.h"
52 #include "names.h"
53 #include <sstream>
54 #include <visp_bridge/image.h>
55 #include "visp_camera_calibration/calibrate.h"
56 #include <visp/vpImage.h>
57 #include <visp/vpDot2.h>
58 #include <visp/vpCalibration.h>
61 
62 
63 #include <visp/vpDisplayX.h>
64 #include "visp/vpTrackingException.h"
65 #include <boost/format.hpp>
66 
67 
69 {
71  spinner(0),
72  queue_size_(1000),
73  nb_points_(4),
74  img_(360,480,255)
75 
76 {
77  std::string images_path;
78 
79  //prepare function objects
80  set_camera_info_service_callback_t set_camera_info_callback = boost::bind(&Camera::setCameraInfoCallback, this, _1,_2);
81 
82  //define services
84 
86 
87  calibrate_service_ = n_.serviceClient<visp_camera_calibration::calibrate> (visp_camera_calibration::calibrate_service);
88 
90 
91  reader_.setFileName(images_path.c_str());
92  reader_.setFirstFrameIndex(1);
93  reader_.open(img_);
94 
95  ROS_INFO_STREAM("str=" << images_path);
96  vpDisplay* disp = new vpDisplayX();
97  disp->init(img_);
98  disp->setTitle("camera");
99 
100  vpDisplay::display(img_);
101  vpDisplay::displayCharString(img_,img_.getHeight()/2,img_.getWidth()/4,"Click to publish camera feed.",vpColor::red);
102  vpDisplay::flush(img_);
103 
104  spinner.start();
105 }
106 
108  double gray_level_precision;
109  double size_precision;
110 
113  ROS_INFO("Click to start sending image data");
114  while(ros::ok() && !vpDisplay::getClick(img_,false));
115 
116  for(unsigned int i=0;i<(unsigned int)reader_.getLastFrameIndex() && ros::ok();i++){
117  reader_.acquire(img_);
118  sensor_msgs::Image image;
119 
121 
122  vpDisplay::display(img_);
123 
124  vpDisplay::displayCharString(img_,img_.getHeight()/2,img_.getWidth()/4,boost::str(boost::format("publishing frame %1% on %2%") % (i+1) % raw_image_publisher_.getTopic()).c_str(),vpColor::red);
125  vpDisplay::flush(img_);
126 
128 
129  ROS_INFO("Sending image %d/%d",i+1,(int)reader_.getLastFrameIndex());
130  //vpDisplay::getClick(img_);
131  }
132 
133  ROS_INFO("When finished selecting points, click on the camera window for calibration");
134  vpDisplay::displayCharString(img_,img_.getHeight()/2+30,img_.getWidth()/4,"When finished selecting points, click here for calibration",vpColor::red);
135  vpDisplay::flush(img_);
136  while(ros::ok() && !vpDisplay::getClick(img_,false));
137  visp_camera_calibration::calibrate calibrate_comm;
138  calibrate_comm.request.method = vpCalibration::CALIB_VIRTUAL_VS_DIST;
139  calibrate_comm.request.sample_width= img_.getWidth();
140  calibrate_comm.request.sample_height = img_.getHeight();
141  if (calibrate_service_.call(calibrate_comm)){
142  ROS_INFO("service called successfully");
143 
144  ROS_INFO("standard deviation with distorsion:");
145  for(std::vector<double>::iterator i = calibrate_comm.response.stdDevErrs.begin();i!=calibrate_comm.response.stdDevErrs.end();i++)
146  ROS_INFO("%f",*i);
147  }else{
148  ROS_ERROR("Failed to call service");
149  }
150 }
151 
152 bool Camera::setCameraInfoCallback(sensor_msgs::SetCameraInfo::Request &req,
153  sensor_msgs::SetCameraInfo::Response &res){
154  std::string calib_info;
155  std::stringstream ss(calib_info);
156 
157  //std::ostream os;
158  ROS_INFO("setting camera info");
160  ROS_INFO("%s",ss.str().c_str());
162 
163 
164  ROS_INFO("end of setting camera info");
165  return true;
166 }
167 
169 {
170  // TODO Auto-generated destructor stub
171 }
172 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
vpImage< unsigned char > img_
Definition: camera.h:73
std::string raw_image_topic
void publish(const boost::shared_ptr< M > &message) const
std::string size_precision_param
bool call(MReq &req, MRes &res)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
std::string calibrate_service
ros::ServiceServer set_camera_info_service_
Definition: camera.h:67
ros::AsyncSpinner spinner
Definition: camera.h:63
std::string gray_level_precision_param
bool setCameraInfoCallback(sensor_msgs::SetCameraInfo::Request &req, sensor_msgs::SetCameraInfo::Response &res)
service setting camera parameters.
Definition: camera.cpp:152
#define ROS_INFO(...)
ros::Publisher raw_image_publisher_
Definition: camera.h:64
ROSCPP_DECL bool ok()
bool writeCalibration(const std::string &file_name, const std::string &camera_name, const sensor_msgs::CameraInfo &cam_info)
bool writeCalibrationIni(std::ostream &out, const std::string &camera_name, const sensor_msgs::CameraInfo &cam_info)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL bool getCached(const std::string &key, std::string &s)
sensor_msgs::Image toSensorMsgsImage(const vpImage< unsigned char > &src)
std::string images_path_param
#define ROS_INFO_STREAM(args)
std::string set_camera_info_service
ros::ServiceClient calibrate_service_
Definition: camera.h:65
std::string getTopic() const
#define ROS_ERROR(...)
boost::function< bool(sensor_msgs::SetCameraInfo::Request &, sensor_msgs::SetCameraInfo::Response &res)> set_camera_info_service_callback_t
service type declaration for calibrate service
Definition: camera.h:84


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