How to convert cv::Mat to std::string?
I would like to store cv::Mat in std::string and read it back. Is there an easy way to do this using OpenCV?
Yes, OpenCV 2.4.1 adds such functionality, you can check ChangeLog for the sample code.
BTW, for debugging purposes you can use something like this:
cout << myMatrix << endl;
For creating string from Mat you should use iterators:
string matAsString (src.begin<unsigned char>(), src.end<unsigned char>());
This way you will get all the relevant content of src even if it is not continuous.
@Michael Burdinov Your method works for gray scale images, how can I use this for 3 channel BGR images?
Asked: 2012-06-18 22:55:40 -0600
Seen: 15,623 times
Last updated: Sep 23 '13