This question already has answers here:
FileStorage for OpenCV Python API
(6 answers)
Closed 7 years ago.
With openCV you can save/load data with YML or XML format. It is easy with cv::FileStorage using c++ API. I cannot make it work with python API.`
Here is an example of an YML file created using opencv c++ API.
If someone succeed to load it with openCV python API, let me know !
I'm late to the party, but I didn't find any way to do it in pure Python, as the YAML files created by OpenCV (YAML 1.0) aren't wholly compatible, nor easily read with the YAML libraries available in Python (YAML 1.1).
The Python/OpenCV bindings exist, but are just a bunch of C methods with absolutely no documentation, so they're pretty much unusable at this point.
However, writing a small C extension and wrapping it in a class was pretty easy to do, so I suggest you try it out. In case you (or anybody else) still need it, I may be able to release the code of the small module I wrote that, I'll ask that at work on Friday.
To give you some ideas, here is how I use my module :
with FileStorage("my/file.yml") as fs:
print(fs["string"]) # Prints the "string" string key
print(fs["int"]) # Prints the "int" integer key
print(fs["matrix”]) # Prints a matrix (read as a NumPy array)
Related
I have compiled seshat but it requires input in inkml or scgink format. As the code is in cpp I am unable to understand. How can I use this work (seshat) on normal math images?
Any help will be much appreciated!!
Note: I have seen other answers on stack overflow regarding this but I was not able to get them
If any python work is there (Because I am only familiar with python)
or is there any way I could convert normal image to the format that seshat accepts
I've written a code in python that opens and reads a file that is saved as an .hdf5 format. If I don't have an hdf viewer installed on my computer can this code still run?
I'm not using it to open the file so I can look at it, I'm trying read the file & extract data before manipulating it in python. Probably a silly question but I'm very new to this coding thing. Would my code be unable to open a file type that can not be opened on my computer?
Cheers,
Claire
An hdf5 viewer is a program that knows how to interpret the contents of an hdf5 file — much like the program you are trying to write. So your program would at least need to include code (most likely in the form of a module) that knows how to do that.
I'm not very familiar with hdf5. But I think you couldn't manipulate it directly if the file is binary since it's not human readable and you could use something like viewer to "decode" those binary data.
According to this though, I think the answer is you don't have to have the hdf5 viewer to run your code.
So the python code has h5py but the code itself does not need the computer I'm working on to have the hdfviewer software.
It is still capable of running the code without opening the file with the hdfviewer.
This question already has answers here:
Using mat file in C++ program
(3 answers)
Closed 8 years ago.
I am doing one of my project on Pattern Recognition, Earlier I was training data with .mat file in Matlab, but now I need to use the same in C++.
MATLAB makes available a MAT-file API that can be used to read and write MAT files from C/C++ (or Fortran).
Although there are some external libraries that allow c++ to read .mat files, most of them are not well supported, and can load files of much earlier versions.
However, I would suggest you just save your variables in plain text format
save('output.txt', 'variable_name', '-ascii');
This is simple, since you work with numbers, and safe (any other language you use will be forever able to read text files, in constrast to relying on libraries that may not work next year). A file containing numbers has a natural interpretation, and can be viewed and manipulated by any program (excel, text editor, etc...)
If you are doing pattern recognition, you should probably keep your dataset in one file, with one pattern per line, eg:
a1 a2 a3 a4 ... 1 0 0
where a_i is the value of the i-th attribute, and 1 0 0 is the class of the pattern. The weights of the neural network/ svm parameters/whatever else you are using, should be saved to a different, also text file. It will give you much less problems than a .mat file, the contents of which you cannot view and use in any other way other than loading it on matlab.
I am trying to export a .mat file which has data stored with datatype struc to a hd5 format so as to make it compatible with c++ porting using coder. But hd5 only accepts numeric values. The code is giving following error -
Error using ==> h5write at 54 Argument 'Data' failed validation isnumeric.
I am unsure whether I am using it correctly though here's my code
h5write('myfile.h5','/model/filters',model.filters,1,146);
and also tried but got same error -
h5write('myfile.h5','/model/filters','face_p146_small.mat',1,146);
My doubt is in continuation with my previous question here.
Any help regarding porting code from Matlab to C++ having data in .mat file format is much appreciated.
Finally i found the answer for my scenario. Since the algorithm I am using uses a very complex data, I need to use the binary data format but all the binary data formats supported by Matlab are not supported for conversion/porting to C++.
List of all the functions supported in conversion of Matlab code to C++
http://www.mathworks.in/help/simulink/ug/functions-supported-for-code-generation--alphabetical-list.html
List of Data formats supported by Matlab
http://www.mathworks.in/help/matlab/import_export/supported-file-formats.html
It seems none of the functions data formats supported by matlab are supported in conversion.
Hence I will definitely have to rewrite the code
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Excel files and C++
I am using an API called UltimateGrid which allows me to easily create Excel-like grids using C++/MFC. I need a way to export all of the contents of these grids to an actual Excel document. I could not find anything about this in the documentation for this API. Then I got to thinking ... exporting contents to an Excel document is a common requirement in applications. I was thinking about creating a right-click menu option for exporting a grid to Excel. I feel like I am reinventing the wheel as I start to code this. I googled around and saw a lot of common ways of dealing with this when database tables are involved. But that is not the case here. My underlying "datasource" is not a database table, but rather just some business objects internal to the application. Am I going to have to just write my own custom handler that iterates through the business objects corresponding to the rows and output them to a CSV file to be used by Excel?
I'm not sure how automated you want this to be. I did this a while back (as in years ago), so forgive me if this info is out of date. Here's what I remember:
CSV is fine, as long as you don't want to export formats, graphs, etc...
You should be able to access the Excel object from your C++ code, and Microsoft should have documentation on how to do this.
It may be easier to have your C++ generate a VBScript to access the component, since last I checked, there was much less red tape to doing it that way, but you could run into permissions/security issues with this method.
Also, have you checked to see if UltimateGrid supports other export formats that are compatible with Excel?
If there are no other options, I think you might want to look into DDE (Dynamic Data Exchange).
There could be a limitation on that OS should be Microsoft Windows, however you might be able to find some open source/runtime that supports other OSs as well.
One that I used long ago was NDde.