mat.cpp
Go to the documentation of this file.
00001 /*
00002  * opencv.cpp
00003  *
00004  *  Created on: Dec 17, 2010
00005  *      Author: erublee
00006  */
00007 
00008 #include <boost/python.hpp>
00009 #include <boost/python/stl_iterator.hpp>
00010 #include <iostream>
00011 #include <string>
00012 #include <vector>
00013 #include <list>
00014 #include <iterator>
00015 #include <boost/foreach.hpp>
00016 #include <pano_core/pano_core.h>
00017 #include <pano_py/opencv.h>
00018 #include <opencv2/highgui/highgui.hpp>
00019 #include "wrappers.h"
00020 
00021 using namespace pano;
00022 namespace bp = boost::python;
00023 using namespace cv;
00024 
00025 namespace{
00026 
00027 template<typename T>
00028   void mat_set_t(cv::Mat&m, bp::object o)
00029   {
00030 
00031     int length = bp::len(o);
00032     CV_Assert(length == m.size().area())
00033       ;
00034     bp::stl_input_iterator<T> begin(o), end;
00035     typename cv::Mat_<T>::iterator it = m.begin<T> (), itEnd = m.end<T> ();
00036     for (; it != itEnd; ++it)
00037       *it = *(begin++);
00038   }
00039 
00040 void mat_set(cv::Mat& m, bp::object o, int type)
00041 {
00042   //switch on the given type and use this type as the cv::Mat element type
00043   switch (type)
00044   {
00045     case cv::DataType<unsigned char>::type:
00046       mat_set_t<unsigned char> (m, o);
00047       break;
00048     case cv::DataType<int>::type:
00049       mat_set_t<int> (m, o);
00050       break;
00051     case cv::DataType<float>::type:
00052       mat_set_t<float> (m, o);
00053       break;
00054     case cv::DataType<double>::type:
00055       mat_set_t<double> (m, o);
00056 
00057       break;
00058   }
00059 
00060 }
00061 cv::Size mat_size(const cv::Mat&m){
00062         return m.size();
00063 }
00064 void mat_set(cv::Mat& m, bp::object o)
00065 {
00066         //use the m.type and implicitly assume that o is of this type
00067         mat_set (m,o,m.type());
00068 }
00069 
00070 void mat_from_numpy_array(cv::Mat& m, bp::object o)
00071 {
00072   pano_py::numpy_to_mat(o.ptr(),m);
00073 }
00074 
00075 //overloaded function pointers
00076 void  (*mat_set_p2)(cv::Mat&, bp::object) = mat_set;
00077 void  (*mat_set_p3)(cv::Mat&, bp::object, int) = mat_set;
00078 
00079 }
00080 
00081 namespace pano_py
00082 {
00083 void wrapMat(){
00084   //mat definition
00085    bp::class_<cv::Mat>("Mat")
00086        .def(bp::init<>())
00087        .def(bp::init<int, int, int>())
00088        .def_readonly("rows", &cv::Mat::rows, "the number of rows")
00089        .def_readonly("cols",&cv::Mat::cols, "the number of columns")
00090        .def("row",&cv::Mat::row, "get the row at index")
00091        .def("col",&cv::Mat::col, "get the column at index")
00092        .def("fromarray",mat_set_p2)
00093        .def("fromarray",mat_set_p3)
00094        .def("from_numpy_array",mat_from_numpy_array)
00095        .def("size",&mat_size)
00096        ;
00097 }
00098 
00099 }


pano_py
Author(s): Ethan Rublee
autogenerated on Mon Oct 6 2014 08:05:14