I have a matrix
Mat B(480,640,CV_32FC1);
containing floating values..I want to write this matrix to a file which could be opened in notepad or Ms word or Excel to see the values inside and for storage....imwrite function can save 8-bit or 16-bit image only..
Drop in your suggestions if this could be done?? if yes, how ??
Using pure OpenCV API calls:
The file extension can be xml or yml. In both cases you get a small header that you can easily remove/parse, then you have access to the data in a floating point format. I used this approach successfully (with yml files) to get data into Matlab and Matplotlib
To get the data:
Voilà. You may have to reshape the resulting matrix in matlab command line if it didn't guess correctly the image size.
I wrote this code:
use write binary :
then you can read in in matlab read size and then reshape (type=single)
You can write
cv::Mat
to text file using simple C++ file handling.Here is how you can do it:
OpenCV can serialize (save) its objects in
JSON
,XML
orYAML
formats. You can use any editors, which understand these formats, in order to read these files, or use OpenCV to download data (de-serialize) from these files. Detailed explanation how this is done can be found here. In short, to store the data intoxml
-file, you have to callIf you want to use
JSON
orYAML
, just change the extension to.json
or.yaml/.yml
- openCV will automatically understand your intentions.The important thing is the command
the string
"cameraMatrix"
is the tag name, under which this matrix will be stored and using which this matrix can be found later in the file.Note that
xml
format will not allow you to use tag names with spaces and some special characters, since only alphanumeric values, dots, dashes and underscores are allowed (seeXML
specification for details), while inYAML
andJSON
you can have something like