Load numpy .npy files Opencv C++ - python

I am trying to load data saved from python as .npy files in Opencv C++.
I found about Filestorage XML/YML in Opencv, but is there a direct way to do that ?
Regards
SMW

There is a C++ .npy reader at https://github.com/rogersce/cnpy
.npy is documented at https://github.com/numpy/numpy/blob/master/doc/neps/npy-format.txt should you want to know how write your own (doesn't look like a big job).

I know i am late but you can use xtensor to load and save npy files
docs
github

Related

How to create an new format of image?

I have read a lot of essays and articles about (Compressing Image Algorithm). There are many algorithms which I can only understand some of them because I'm a student and I haven't gone to high school yet. I read this article which it helps me a lot! Article In page 3 at this part (Run length code). It's a very EZ and helpful algorithm but I don't know how do I make new format of image. I am a python developer but I don't know how to make a new format which it has a separate algorithm and program. --> like .jpeg, ,jpg, .png, .bmp
(Sorry I have studied English for 1 years so if I have some problems such as grammar or vocabulary just excuse me )
Sure, you can make your own image file format. Choose a filename extension, define how it will be stored and write Python code to:
read the format from disk into a Numpy array, and
write an image contained in a Numpy array to disk
That way you will be interoperable with all the major image processing libraries such as OpenCV, scikit-image, PIL, wand.
Have a look how NetPBM works to get started with a simple format. Maybe look at PCX format if you like the thought of RLE.
Read up on how to write binary to a file with Python.

Python: Load numpy arrays (npys) with specific columns

I have saved arrays as npy with sizes around 2GB. Can I somehow load only specific columns,rows with numpy.load ? I did not find a command for that or is there a workaround for that case?
This is not possible with .npy files. For that kind of problems, it is better recommended to use .h5 files, with the h5py package. You will find an example in this post: h5py: how to read selected rows of an hdf5 file?.

How to provide image to Tesseract from memory

I'm using Tesseract to do OCR on millions of PDFs, and I'm trying to squeeze out as much performance as I can.
My current pipeline uses convert to convert a PDF to PNG files (one per page), and then uses Tesseract on each of those.
During profiling, I've discovered that a lot of time is spent writing files to disk, then reading them again, so I'd like to move all of this into memory.
I've got the PDF to PNG conversion working in memory, so now I need a way to pass the in-memory blob to Tesseract instead of giving it a path to a file? I haven't been able to find any documentation or examples of this?

How to extract data from Matlab .fig files in Python?

If I have some X vs Y data saved in a Matlab .fig file, is there a way to extract that data in Python? I've tried using the method shown in a previous discussion, but this does not work for me. I have also tried to open the files using h5py and PyTables, since .mat files are actually HDF5 files now, but this results in an error where a valid file signature can't be found.
Currently I'm trying to do this with the Anaconda distribution of Python 3.4.
EDIT: I managed to figure out something that works, but I don't know why. This has me worried something might break in the future and I won't be able to debug it. If anyone can explain why this works, but the method in the old discussion doesn't I'd really appreciate it.
from scipy.io import loadmat
d = loadmat('linear.fig', squeeze_me=True, struct_as_record=False)
x = d['hgS_070000'].children.children.properties.XData
y = d['hgS_070000'].children.children.properties.YData
The best way I can think of is using any of the Matlab-Python bridge (such as pymatbridge).
You can call Matlab code directly on python files and transform the data from one to the other. You could use some Matlab code to load the fig and extract the data and then convert the numerical variables to python arrays (or numpy arrays) easily.

Any way to get a figure from Python's matplotlib into Matlab?

I'm processing some data for a research project, and I'm writing all my scripts in python. I've been using matplotlib to create graphs to present to my supervisor. However, he is a die-hard MATLAB user and he wants me to send him MATLAB .fig files rather than SVG images.
I've looked all over but can't find anything to do the job. Is there any way to either export .fig files from matplotlib, convert .svg files to .fig, or import .svg files into MATLAB?
Without access to (or experience with matlab) this is going to be a bit tricky. As Amro stated, .fig files store the underlying data, and not just an image, and you're going to have a hard time saving .fig files from python. There are however a couple of things which might work in your favour, these are:
numpy/scipy can read and write matlab .mat files
the matplotlib plotting commands are very similar to/ based on the matlab ones, so the code to generate plots from the data is going to be nearly identical (modulo round/square brackets and 0/1 based indexing).
My approach would be to write your data out as .mat files, and then just put your plotting commands in a script and give that to your supervisor - with any luck it shouldn't be too hard for him to recreate the plots based on that information.
If you had access to Matlab to test/debug, I'm sure it would be possible to create some code which automagically created .mat files and a matlab .m file which would recreate the figures.
There's a neat list of matlab/scipy equivalent commands on the scipy web site.
good luck!

Categories

Resources