Sending data from OpenCV matrix to Matlab Engine, C++ -


i sending data opencv matrices matlab using c++ , matlab engine. tried convert column major row major confused on how that. cannot understand how deal matlab pointer mxarray , put data engine.

has worked opencv matlab send matrices? didn't find information , think interesting tool. welcomed.

i have function works if have created matlab engine. creating singletone template matlab engine:

my header looks this:

/** singletone class definition   *    */ class matlabwrapper     {     private:         static matlabwrapper *_theinstance; ///< private instance of class         matlabwrapper(){}           ///< private constructor         static engine *eng;       public:         static matlabwrapper *getinstance() ///< instance public method         {             if(!_theinstance) _theinstance = new matlabwrapper(); ///< if instance=null, create      return _theinstance;            ///< if instance exists, return instance         }     public:     static void openengine();               ///< starts matlab engine.     static void cvloadmatrixtomatlab(const mat& m, string name);     }; 

my cpp:

#include <iostream> using namespace std;  matlabwrapper *matlabwrapper::_theinstance = null;              ///< initialize instance null     engine *matlabwrapper::eng=null; void matlabwrapper::openengine() {         if (!(eng = engopen(null)))          {             cerr << "can't start matlab engine" << endl;             exit(-1);         }        } void matlabwrapper::cvloadmatrixtomatlab(const mat& m, const string name) {     int rows=m.rows;     int cols=m.cols;         string text;     mxarray *t=mxcreatedoublematrix(cols, rows, mxreal);      memcpy((char*)mxgetpr(t), (char*)m.data, rows*cols*sizeof(double));     engputvariable(eng, name.c_str(), t);     text = name + "=" + name + "'";                    // column major row major     engevalstring(eng, text.c_str());     mxdestroyarray(t); } 

when want send matrix, example

mat = mat::zeros(13, 1, cv_32fc1); 

it's simple this:

matlabwrapper::getinstance()->cvloadmatrixtomatlab(a,"a"); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -