module.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2012, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 #include "module.hpp"
00036 
00037 PyObject *mod_opencv;
00038 
00039 bp::object
00040 cvtColor2Wrap(bp::object obj_in, const std::string & encoding_in, const std::string & encoding_out) {
00041   // Convert the Python input to an image
00042   cv::Mat mat_in;
00043   convert_to_CvMat2(obj_in.ptr(), mat_in);
00044 
00045   // Call cv_bridge for color conversion
00046   cv_bridge::CvImagePtr cv_image(new cv_bridge::CvImage(std_msgs::Header(), encoding_in, mat_in));
00047 
00048   cv::Mat mat = cv_bridge::cvtColor(cv_image, encoding_out)->image;
00049 
00050   return bp::object(boost::python::handle<>(pyopencv_from(mat)));
00051 }
00052 
00053 bp::object
00054 cvtColorForDisplayWrap(bp::object obj_in,
00055                        const std::string & encoding_in,
00056                        const std::string & encoding_out,
00057                        bool do_dynamic_scaling = false,
00058                        double min_image_value = 0.0,
00059                        double max_image_value = 0.0) {
00060   // Convert the Python input to an image
00061   cv::Mat mat_in;
00062   convert_to_CvMat2(obj_in.ptr(), mat_in);
00063 
00064   cv_bridge::CvImagePtr cv_image(new cv_bridge::CvImage(std_msgs::Header(), encoding_in, mat_in));
00065 
00066   cv_bridge::CvtColorForDisplayOptions options;
00067   options.do_dynamic_scaling = do_dynamic_scaling;
00068   options.min_image_value = min_image_value;
00069   options.max_image_value = max_image_value;
00070   cv::Mat mat = cv_bridge::cvtColorForDisplay(/*source=*/cv_image,
00071                                               /*encoding_out=*/encoding_out,
00072                                               /*options=*/options)->image;
00073 
00074   return bp::object(boost::python::handle<>(pyopencv_from(mat)));
00075 }
00076 
00077 BOOST_PYTHON_FUNCTION_OVERLOADS(cvtColorForDisplayWrap_overloads, cvtColorForDisplayWrap, 3, 6)
00078 
00079 int CV_MAT_CNWrap(int i) {
00080   return CV_MAT_CN(i);
00081 }
00082 
00083 int CV_MAT_DEPTHWrap(int i) {
00084   return CV_MAT_DEPTH(i);
00085 }
00086 
00087 BOOST_PYTHON_MODULE(cv_bridge_boost)
00088 {
00089   do_numpy_import();
00090   mod_opencv = PyImport_ImportModule("cv2");
00091 
00092   // Wrap the function to get encodings as OpenCV types
00093   boost::python::def("getCvType", cv_bridge::getCvType);
00094   boost::python::def("cvtColor2", cvtColor2Wrap);
00095   boost::python::def("CV_MAT_CNWrap", CV_MAT_CNWrap);
00096   boost::python::def("CV_MAT_DEPTHWrap", CV_MAT_DEPTHWrap);
00097   boost::python::def("cvtColorForDisplay", cvtColorForDisplayWrap,
00098                      cvtColorForDisplayWrap_overloads(
00099                        boost::python::args("source", "encoding_in", "encoding_out", "do_dynamic_scaling",
00100                                            "min_image_value", "max_image_value"),
00101                        "Convert image to display with specified encodings.\n\n"
00102                        "Args:\n"
00103                        "  - source (numpy.ndarray): input image\n"
00104                        "  - encoding_in (str): input image encoding\n"
00105                        "  - encoding_out (str): encoding to which the image conveted\n"
00106                        "  - do_dynamic_scaling (bool): flag to do dynamic scaling with min/max value\n"
00107                        "  - min_image_value (float): minimum pixel value for dynamic scaling\n"
00108                        "  - max_image_value (float): maximum pixel value for dynamic scaling\n"
00109                      ));
00110 }


cv_bridge
Author(s): Patrick Mihelich, James Bowman
autogenerated on Thu Jun 6 2019 21:23:27