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?
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,524 times
Last updated: Sep 23 '13
How to create a binary image mat?
Mat to String and back in OpenCV4Android
converting CBitMap (MVC) direct to cv::Map ?
unknown dot on using FileStorage to write Mat
What is the most effective way to access cv::Mat elements in a loop?
How to convert Floating point image to 32-bit single-channel?
Record/Store constant refreshing coordinates points into notepad
How to save opencv data in Excel format?