Port Matlab code to C++ having .mat dataset - c++

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

Related

How to use .rec format for training in MXNet C++ implementation?

C++ examples of MXNet contain model training examples for MNISTIter, MNIST data set (.idx3-ubyte or .idx1-ubyte). However the same code actually recommends to use im2rec tool to produce the data, and it produces the different .rec format. Looks like the .rec format contains images and labels in the same file, because im2rec takes a prepared .lst file with both (number, label and image file name per each line).
I have produced the code like
auto val_iter = MXDataIter("ImageRecordIter");
setDataIter(&val_iter, "Train", vector < string >
{"output_train.rec", "output_validate.rec"}, batch_size));
with all files present but it fails because four files are still required in the vector (segmentation fault). But why, should not labels be inside the file now?
Digging more into the code, I found that setDataIter actually sets the parameters. Parameters for ImageRecordIter can be found here. I tried to set parameters like path_imgrec, path.imgrec, then call .CreateDataIter() but all this was not helpful - segmentation fault on the first attempt to use the iterator.
I was not able to find a single example in the whole Internet about how to train any MxNet neural network in C++ using .rec file format for training and validation sets. Is it possible? The only work around I found is to try original MNIST tools that produce files covered by MNIST output examples.
Eventually I have used Mnisten to produce the matching data set so that may input format is now the same as MxNet examples use. Mnisten is a good tool to work, just it is important not to forget that it normalizes grayscale pixels into 0..1 range (no more 0..255).
It is a command line tool but with all C++ code available (and there is not really a lot if it), the converter can also be integrated with existing code of the project to handle various specifics. I have never been affiliated with this project before.

How can I use seshat on normal images as input in seshat (mathematical expression recognition library in C++)?

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

How can I convert MATLAB image processing library build-in function to c++ that is not supported by matlab coder code generation?

How can I convert built-in functions like imagesc and bwareafilt to c++/c code that are not supported for code generation by Matlab coder?
If it is not supported by the Matlab Coder , manual conversion may be the option.
You can use OpenCV for C++ . Here is a cheat sheet that links Matlab Commands and equivalent OpenCV commands .
https://github.com/ingenuitas/SimpleCV/blob/master/doc/CheatSheet/cheatsheet.pdf?raw=true
I have personally converted Matlab Code to OpenCV code manually.
Though simple functions are similar in both , Matlab offers complex ones like imfindcircles , imagesc etc which may not be available as a single line command in OpenCv as it would be in Matlab.
For this , read the .m file of the specific function in matlab , understand the logic and try to convert it or just google that algorithm . Do this in steps , write down the pseudocode / algo and then try to convert it .
It works !

Find a value in webpage source code (Fortran)

how can i extract numerical data from a webpage source code that is embedded in a text file using fortran? (e.g https://www.google.com/finance?q=NYSE:KO) My aim is to retrieve the stock price through the source code. Any help will be appreciated!
Thanks in advance.
Do you really want to do that in Fortran? Fortran is not very well suited for string manipulation (in my opinion)!
I would recommend to get and process the HTML in another language (e.g. Python), and write in the data in a structured way that Fortran can directly read. You could call that script / program from Fortran using the statement
call system('command')

XML or YML parsing in OpenCV with Python [duplicate]

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)