parse_wrapper.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * * Neither the name of the Willow Garage nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *********************************************************************/
31 
34 
35 #include <boost/python.hpp>
36 #include <ros/serialization.h>
37 
39 
40 /* Write a ROS message into a serialized string.
41  * @from https://github.com/galou/python_bindings_tutorial/blob/master/src/add_two_ints_wrapper.cpp#L27
42 */
43 template <typename M>
44 std::string to_python(const M& msg)
45 {
46  size_t serial_size = ros::serialization::serializationLength(msg);
47  boost::shared_array<uint8_t> buffer(new uint8_t[serial_size]);
48  ros::serialization::OStream stream(buffer.get(), serial_size);
49  ros::serialization::serialize(stream, msg);
50  std::string str_msg;
51  str_msg.reserve(serial_size);
52  for (size_t i = 0; i < serial_size; ++i)
53  {
54  str_msg.push_back(buffer[i]);
55  }
56  return str_msg;
57 }
58 
59 // Wrapper for readCalibration()
60 boost::python::tuple readCalibrationWrapper(const std::string& file_name)
61 {
62  std::string camera_name;
63  sensor_msgs::CameraInfo camera_info;
64  bool result = readCalibration(file_name, camera_name, camera_info);
65  std::string cam_info = to_python(camera_info);
66  return boost::python::make_tuple(result, camera_name, cam_info);
67 }
68 
69 BOOST_PYTHON_MODULE(camera_calibration_parsers_wrapper)
70 {
71  boost::python::def("__readCalibrationWrapper", readCalibrationWrapper, boost::python::args("file_name"), "");
72 }
73 
74 } //namespace camera_calibration_parsers
bool readCalibration(const std::string &file_name, std::string &camera_name, sensor_msgs::CameraInfo &cam_info)
Read calibration parameters from a file.
Definition: parse.cpp:54
std::string to_python(const M &msg)
boost::python::tuple readCalibrationWrapper(const std::string &file_name)
void serialize(Stream &stream, const T &t)
uint32_t serializationLength(const T &t)
BOOST_PYTHON_MODULE(camera_calibration_parsers_wrapper)


camera_calibration_parsers
Author(s): Patrick Mihelich
autogenerated on Thu Jun 6 2019 19:22:45