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  PyObject * cam_info_py = PyBytes_FromStringAndSize(cam_info.c_str(), cam_info.size());
67  return boost::python::make_tuple(
68  result,
69  camera_name,
70  boost::python::object(boost::python::handle<>(cam_info_py)));
71 }
72 
73 BOOST_PYTHON_MODULE(camera_calibration_parsers_wrapper)
74 {
75  boost::python::def("__readCalibrationWrapper", readCalibrationWrapper, boost::python::args("file_name"), "");
76 }
77 
78 } //namespace camera_calibration_parsers
ros::serialization::OStream
ros::serialization::serializationLength
uint32_t serializationLength(const boost::array< T, N > &t)
camera_calibration_parsers
Definition: parse.h:42
parse.h
camera_calibration_parsers::readCalibrationWrapper
boost::python::tuple readCalibrationWrapper(const std::string &file_name)
Definition: parse_wrapper.cpp:89
serialization.h
boost::shared_array< uint8_t >
parse_wrapper.h
camera_calibration_parsers::to_python
std::string to_python(const M &msg)
Definition: parse_wrapper.cpp:73
camera_calibration_parsers::readCalibration
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:86
ros::serialization::serialize
void serialize(Stream &stream, const boost::array< T, N > &t)
camera_calibration_parsers::BOOST_PYTHON_MODULE
BOOST_PYTHON_MODULE(camera_calibration_parsers_wrapper)
Definition: parse_wrapper.cpp:102


camera_calibration_parsers
Author(s): Patrick Mihelich
autogenerated on Sat Jan 20 2024 03:14:48