c++ - converting std::string back to cv::Mat which was generated with std::stringstream << cv::Mat -


I am saving the subscription data for stereo-visions, rather than the YAML data given from opencv in special data-format - The architecture which allows me more flexibility.

For that reason I am using little hack to convert cv :: mat to std :: string:

  cv: mat mat; // some code std :: stringstream sstrMat; SstrMat & lt; & Lt; Mat; SaveFoo (sstrMat.str ()); // something like this to save the matrix  

as output I get from sstrMat.str () : All data that I want:

  [2316.74172 9 37253, 0, 418.0432610206069; 0, 2316.74172 9 37253, 253.5597342849773; 0, 0, 1]  

My problem is its reverse operation: converting this std :: string back into CV :: MET.

I have tried the code like this:

  cv :: mat mat; Std :: stringstream sstrStr; SstrStr & lt; & Lt; GetFoo () // Some such saved matrix sstrtrtr & gt; & Gt; Mat; // Idea-1: Compilation error mat generated & lt; & Lt; SstrStr; // Idea-2: Also generates compile error  

All of my attempts have failed, so I ask you if you have a method of OpenCVI to change that string back. Know or write i operator & lt; & Lt; (Std :) "post-text" itemprop = "text">

: Ostream and Construm Mate & amp;) itself? If this is the case, then you have to do a reverse operation clearly, if you want it.

From your output, I think that the type of matrix was CV_64F with 3 channels, be sure to remember the size of your matrix, and check.

You can create your metrics with these specifications, and fill it while reading your stream. There are many instances of reading the stream on the Internet, but in your case this is quite easy. The characters you do not need ( [],; ) with a std :: istream :: read in a dummy buffer, and the operator & gt; & Gt;

What's good about that you can iterate like cv: Mat s; (Std :: istream & amp; double) You will be on a standard library container, so if you are using C ++ 11 then it may look like (not tested):

  int size [2] = {x, y}; // matrix cols and rows cv :: Mat mat (3, size, CV_F64); // for 3-dimensional matrix (auto & amp; elem: mat) {cv :: Vec3d new_elem; // A 3D Vector with Double Values ​​// Read your 3 Doubles in new_elem // ... elem = new_elem; // matrix element}  

Again, I have not used OpenCV in widespread use, so look for the document to see everything properly.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -