Installing openCV with contrib modules - python

I was running python3.6 (32 bit) with opencv3.3.1.
I saw this tutorial so I was trying out the brute force matching with SIFT descriptors: http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_matcher/py_matcher.html
I read that some modules including SIFT were no longer included in the default installation and needed to be installed separately. I found on the official python website a download for opencv3 with the contrib modules (which I assumed contains SIFT). Specifically I downloaded opencv_contrib_python-3.3.0.10-cp36-cp36m-win32.whl (md5) from here: https://pypi.python.org/pypi/opencv-contrib-python#downloads
I have uninstalled my previous opencv and installed and imported this new version of opencv and verified that I am running the new version.
However, still when I try to use cv2.SIFT() I am still getting the error that module cv2.cv2 has no attribute 'SIFT'.
Did I download the correct package? Are all opencv modules including SIFT supposed to be included in the package I installed?

For enabling opencv-contrib modules, you have to rebuild your opencv lib from source. In CMake config, you have to enable it, specifying variable OPENCV_EXTRA_MODULES_PATH with path where you have opencv_contrib modules such as ...wherever_you_downloaded_it/opencv_contrib/opencv_contrib-master/modules.
Then, building opencv with make will build modules, and make install will install these libs with other opencv libs.

Related

Why Python fatal error occurs after OpenCV build?

I've built OpenCV 4.5.5 on Windows with Cmake / VS19. I did PATH and copy&paste .pyd file as well. Now I am getting the Fatal Python error, I have no clue what is the problem.
Fatal Python error: _PyInterpreterState_GET: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: unknown
The reason I built opencv myself was to use some library I wanted to use which requires the Nonfree OpenCV module. So I removed the OpenCV package which I installed by pip install opencv-python. Then I followed Cmake build instructions with OpenCV/OpenCV-contrib source. Is there any possibility that I installed the OpenCV module before?
I've tried to modify / repair Python but no luck. When I import other library (for example : Numpy) it works fine. Any suggestions?

OpenCV won't install to python

I am trying to install OpenCV 4.5.5 with CUDA support. I installed the source from their GitHub and the additional OpenCV contrib and built it with CMAKE. I checked BUILD_opencv_python3 when it was done configuring and generating it showed that it had detected python3 and had installed cv2 in site-packages.
But cv2 isn't in the site-packages.
So it doesn't load in python. But it does give an interesting error
What should I do?
I already tried doing a fresh build with CMAKE but it didn't work.
After building OpenCV it generates a PYD file in the lib folder. I don't know if that is helpful or not.
Thanks
You must have missed a step in the process.
"Configure" step in cmake-gui, investigates the environment (various paths, e.g. where python wants packages to go) and prepares information for the build
"Generate" step in cmake-gui, generates the actual build files (VS Solution)
open the .sln in Visual Studio
build the ALL_BUILD target
build the INSTALL target, and this installs the files, also the python package

Is there any documention as to what versions of external libs (libfreetype, etc) were used to produce a PyPi build of Pillow?

For compliance uses, I'm looking to see if there is any documentation anywhere that lists what versions of the external libs were used to build a given version of Pillow.
Eg: if I "pip install Pillow==6.0.0", what versions of the external libs am I getting?

unable to find vcvarsall,bat error while installing simplecv on windows 10?

During the installation phase, I get this, "Unable to find vcvarsall.bat" error. The installation process did complete, though. However, I was unable to see the shell on my desktop (I am using windows) and neither was I able to open it manually. I scoured the internet for the error but was unable to find any solution for this case.
The installation process is through a superpack that downloads Python 2.7
SimpleCV is not receiving much love in the past few years, and most of it's code don't got upgrade like the libraries it depends on.
The problem you got is the Superpack trying to compile an older version of OpenCV.
When running the Superpack, you should have seen and redtext error, and if you try to run a code it should show you something like this:
File "C:\Python27\lib\site-packages\SimpleCV\base.py", line 59, in <module>
raise ImportError("Cannot load OpenCV library which is required by SimpleCV")
ImportError: Cannot load OpenCV library which is required by SimpleCV
There are a few paths you can try from there:
1. You can try to install Microsoft Visual C++ Compiler for Python 2.7
Uninstall everything SuperPack installed in your PC or it may not work
It may fixes some other uses when using pip.
Now you have to install SimpleCV again.
2. Try to install OpenCV(2.3) on your own:
You can use pip for it, just remember to chose 32bits to keep compatibility with (Super Pack)
Just run on CMD
pip install OpenCV or python -m pip install OpenCV
3. Give up on SuperPack and install everything on your own.
You can try this guide
https://github.com/sightmachine/SimpleCV#windows-7vista
Or use pip for all dependencies
numpy (Numpy+MKL make sure to install this one first)
scipy
PIL
ipython
svgwrite
pygame==1.9.1release
OpenCV
You can find a useful list of wheels here
http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
Sources:
https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/
http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
https://github.com/sightmachine/SimpleCV#windows-7vista

Install and use OpenCV from source

I have tried this to install opencv. The terminal output after installing was:
OpenCV 2.4.13 ready to be used
But when I try to import the module, it says the module doesn't exist.
When I tried:
pkg-config opencv --cflags
to check if opencv was installed, I got:
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
How can I fix this? Is there any other way to install opencv?
Since you are using Python3, You can only choose to build your own cv2.pyd. There is no pre-built version for you to download.
I found another link of installing the Package, which is installing from the source, means that you need to compile the source code.
The general idea is to download the source code you want first. After that, yor will use CMake to build the libraries and the Python wrapper (based on the specific Python version you are using). After build successful, you will then get the cv2.pyd and several OpenCV libraries, you just copy them into your Python site-package. Finally you should be able to import cv2.
I did the same thing in Window for Python3.3, 3.4, and 3.5 by following this tutorial, the general idea is the same but only on different platform. I think it should be helpful as a reference for you.

Categories