Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00042 cv::Mat mat_in;
00043 convert_to_CvMat2(obj_in.ptr(), mat_in);
00044
00045
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
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(cv_image,
00071 encoding_out,
00072 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
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 }