I am trying to perform Bayer demosaicing of a raw image but I need to keep library dependencies and size to the minimum. Initially, I used cv2.cvtColor() for the demosaicing part but I found colour-demosaicing library to be much lighter and did also work for me.
However, there is a dependency with Scipy's method convolve(), which calls _correlate_or_convolve(), and eventually _nd_image.correlate().
I managed to take all the code from Scipy so I don't need to install the whole library by extracting ndimage module. The problem is that _nd_image seems to be a binary or something that should be built (sorry if terminology is incorrect, I'm new on this) which I am not sure how to bring to the final device where demosaicing should happen.
Any hint is appreciated.
Related
I have used OpenCV in the past for a project of mine, and I remember the AruCo library being very useful to specify certain regions, to calibrate the camera, etc.
I am currently working on another project that will get involved with image processing, and I've been working with SciPy in general for data-related tasks. As I will be using SciPy, I've been considering to work with skimage, as it may be more related to the other packages I will use.
Here's the question: I want to use something similar to, if not the same as, the AruCo library for skimage as it will be convenient to work with. Is there such a solution for skimage?
Here's the library in question,
AruCo library for OpenCV
After some digging around, I've noticed that OpenCV and skimage are compatible with each other to a great extent. The only issue I've encountered so far is with io.imshow() and cv2.imshow() yielding negative-like colors with respect to each other (in Colab, that is).
If that (and other potential minor issues) could be resolved, it is quite easy to just use AruCo with cv2 and use skimage wherever needed. It could take some work, but it is possible.
Here's a great example from the skimage library itself, where the library cv is used to capture webcam feeds. So they are actually compatible.
Note: This is deprecated, so just consider it as a proof. There may be better solutions to use a webcam feed than this (could just use cv2 for it)
https://gist.github.com/stefanv/5160329
I am relatively new to coding and I apologize if my questions are straightforward to you.
I am trying to understand OpenCV code to be able to add my contributions (mainly converting 2D tools to 3D as it would be useful for my machine learning projects and for medical projects). There is also some extra-curiosity since I like to understand how things work.
1) On the example of the GaussianBlur method. What happens when I call it in Python? Namely, how the Python code is bind to the C++ one? When I browse the repository, there are all C++ files, and I do not find where it is done. When I installed cv2 with pip all was automatic, but I would like to understand the process.
2) if I want to understand the whole GaussianBlur algorithm, I am also not familiar with C++ browsing, so how should I proceed to retrieve what files are used (methods and also inherited classes).
I've found on another answer that https://github.com/opencv/opencv/blob/9c23f2f1a682faa9f0b2c2223a857c7d93ba65a6/modules/imgproc/src/smooth.cpp#L4085 contains the method, but how can I find any method on my own? Why isn't it in the master folder but in the blob folder? How to find then the other methods or classes called by this one?
3) this is more a curiosity question since I am not familiar with makefiles, but when is done the binding between Python and C++? When I install OpenCV with pip it is done automatically, but I would like to understand the process.
Thanks a lot for your answers! I would appreciate any tutorial since I've googled a lot before asking, of course, but did not find what could help me on my own.
In C++ you have to download the library and link them in the compilation and linking process (when creating an executable from source code).
The C++ bind is done with python.h library for c++. using this binding OpenCV module is created for python.
For learning gaussian blur, etc. you can learn image processing.
The methods of Opencv are kept in their respective files. like opencv2/highgui.hpp for OpenCV GUI like imshow. you can import them to C++ with #include <opencv2/highgui.hpp>(the methods are separated to different files to reduce importing unnecessary methods).
CMake is like a scripting language(its a tool) where you can write a script on how the tool should build the executable from source code.
The starter tutorial is Here
So my project uses the gaussian_filter1d from scipy.ndimage.filters package. I'm am in the process of making the setup.py file that will tell pip which dependencies should be installed with my project. I really don't want my package to require a full download of scipy for one function. I realize that gaussian_filter1d uses other functions from scipy in its code but I was wondering if there is a way to only include the gaussian_filter1d and functions it requires instead of the whole scipy project.
My gut tells me no but I thought I would ask just in case :P
If you really need this feature and cannot find a light-weight replacement or code it yourself, then I guess you have to include it in the requirements. If your project isn't sensitive to slug size, then adding a widely used dependency isn't really a big problem. Be sure to specify the version of scipy in your project, though.
from scipy.ndimage.filter import gaussian_filter1d
will do the job. But any basic Python textbook will tell you that.
I am currently working on a Raspberry Pi project in which I am trying to calculate a FFT on some numpy arrays containing some measurement data. I would like to get this done on the GPU to free resources on the CPU. I found the GPU_FFT library of Andrew Holme that apparently allows exactly that.
http://www.aholme.co.uk/GPU_FFT/Main.htm
However, I do not know how to use this library exactly (I read the included instructions) as I have no knowledge of interaction between Python and C (I have never used C before). Further, I could not find any instructions on how to use GPU_FFT on the internet.
Is there any documentation/explanation that I could not find myself or can I use other Python libaries like PyFFT?
Have you tried using the Mathematica package on the rpi? I haven't but they advertise that their code is very fast and use the gpu.
Is there a good (small and light) alternative to numpy for python, to do linear algebra?
I only need matrices (multiplication, addition), inverses, transposes and such.
Why?
I am tired of trying to install numpy/scipy - it is such a pita to get
it to work - it never seems to install correctly (esp. since I have
two machines, one linux and one windows): no matter what I do: compile
it or install from pre-built binaries. How hard is it to make a
"normal" installer that just works?
I'm surprised nobody mentioned SymPy, which is written entirely in Python and does not require compilation like Numpy.
There is also tinynumpy, which is a pure python alternative to Numpy with limited features.
Given your question, I decided just factor out the matrix code from where I were using it, and put it in a publicly accessible place -
So, this is basically a pure python ad-hoc implementation of a Matrix class which can perform addition, multiplication, matrix determinant and matrix inversion - should be of some use -
Since it is in pure python, and not worried with performance at all it unsuitable for any real calculation - but it is good enough for playing around with matrices in an interactive way, or where matrix algebra is far from being the critical part of the code.
The repository is here,
https://bitbucket.org/jsbueno/toymatrix/
And you can download it straight from here:
https://bitbucket.org/jsbueno/toymatrix/downloads/toymatrix_0.1.tar.gz
I hear you, I have been there as well. Numpy/scipy are really wonderful libraries and it is a pity that installation problems get somewhat often in the way of their usage.
Also, as far as I understand there are not very many good (easier to use) options either. The only possibly easier solution for you I know about is the "Yet Another Matrix Module" (see NumericAndScientific/Libraries listing on python.org). I am not aware of the status of this library (stability, speed, etc.). The possibility is that in the long run your needs will outgrow any simple library and you will end up installing numpy anyway.
Another notable downside on using any other library is that your code will potentially be incompatible with numpy, which happens to be the de facto library for linear algebra in python. Note also that numpy has been heavily optimized - speed is something you are not guaranteed to get with other libraries.
I would really just put more effort on solving the installation/setup problems. The alternatives are potentially much worse.
Have you ever tried anaconda? https://www.anaconda.com/download
This should allow it to install those packages easily.
conda install -c conda-forge scipy
conda install -c conda-forge numpy
Apart from offering you an easy way to install them in linux/mac/linux you will get virtualenviroments management too
I sometimes have this problem..not sure if this works but I often install it using my own account then try to run it in an IDE(komodo in my case) and it doesn't work. Like your issue it says it cannot find it. The way I solve this is to use sudo -i to get into root and then install it from there.
If that does not work can you update your answer to provide a bit more info about the type of system your using(linux, mac, windows), version of python/numpy and how your accessing it so it'll be easier to help.
For people who still have the problem: Try python portable:
http://portablepython.com/wiki/Download/
Have a look: tinynumpy, tinyarray and sympy
https://github.com/wadetb/tinynumpy
https://github.com/kwant-project/tinyarray
https://docs.sympy.org/latest/index.html