Ask Your Question

How to convert cv::Mat to std::string?

asked 2012-06-18 22:55:40 -0600

I would like to store cv::Mat in std::string and read it back. Is there an easy way to do this using OpenCV?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2012-06-26 11:09:02 -0600

Kirill Kornyakov gravatar image

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;
edit flag offensive delete link more

answered 2013-09-23 02:19:52 -0600

Michael Burdinov gravatar image

updated 2013-09-23 05:47:22 -0600

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.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2012-06-18 22:55:40 -0600

Seen: 7,978 times

Last updated: Sep 23 '13