Opencv python package manage - python

Recently I used opencv Python to handle Video Steam.
Normally I should install opencv-python via pip.
However I found that the opencv-python in pypi is unofficial package.
And it's just a package with opencv core, which does NOT including packages like contrib and FFmpeg...
If you wanted a version of opencv with extra packages, you should possibly download the opencv source code and build your own Opencv Python Bindings.
For me, this is not a friendly way to manage Opencv compared to other python libs in pypi.
Does anyone have a more elegant way to manage opencv python in both Mac and Linux OS please?

if u have anaconda then just open anaconda prompt and you can try
conda install -c conda-forge opencv
or for opencv 3 version you can try
conda install -c menpo opencv3

The easies way to install opencv-python is link or this link.
pip install will just install opencv-core, which does not include FFmpeg lib...

Related

PyCharm does not find cv2 no matter what I try

I tried to install OpenCV in so many ways. I tried this tutorial:
https://docs.opencv.org/master/d0/db2/tutorial_macos_install.html
I tried using conda:
conda install -c conda-forge opencv
etc. etc.
But when I type in import cv2 it says:
PyCharm Image OpenCV
Does somebody have an idea?
To install opencv you can either build it with CMake (like the link you tagged) or install a pre-built version of it (easier).
You can do the pre-built via PyCharm going to your project settings and adding the 'opencv-python' package or running pip install opencv-python
If you need both main and contrib modules you can install 'opencv-contrib-python' instead
Here's the package's page: https://pypi.org/project/opencv-python/

How do I install opencv using pip?

I need to install cv2 for a script that has been written for me. I tried pip install cv2 and pip install open_cv and got the same problem - a warning message from dist.py and complains about zlib being not found. No cv2 installed. I also tried pyopenvc and pip install opencv-python.
So, I went to the opencv site and downloaded the relevant exe. Ran it - generated a heap of subdirectories and a make file and stuff.
What do I do now?
Install opencv-python (which is an unofficial pre-built OpenCV package for Python) by issuing the following command:
pip install opencv-python
run the following command by creating a virtual enviroment using python 3 and run
pip3 install opencv-python
to check it has installed correctly run
python3 -c "import cv2"
In pip package management, there are 4 different OpenCV packages all using the same namespace, cv2. Although they are not officially supported by OpenCV.org, they are commonly used in developers' community. You could install any of them using the following command:
pip install PACKAGE_NAME
where PACKAGE_NAME can be
opencv-python (only contains main modules)
opencv-contrib-python (contains both main and contrib modules)
opencv-python-headless (same as opencv-python but without GUI functionality)
opencv-contrib-python-headless (same as opencv-contrib-python but without GUI functionality)
You should only install one of them depending on your needs. If you accidentally installed multiple of them in the same environment, you can remove them using pip uninstall before installing the correct one again.
For more details, you can refer to the project description of OpenCV on Wheels.
As of 2021, all of these 4 packages are official OpenCV projects. Source: OpenCV Website.
To Install the Current Latest version of OpenCV then use the below commands:
Use this Command:
pip install --upgrade opencv-python
If you're facing problem in above command then try this :
pip install --upgrade opencv-contrib-python
To check the version of installed OpenCV:
import cv2
print(cv2.__version__)
Simply use this for the so far latest version 4.1.0.
pip install opencv-contrib-python==4.1.0.25
For the default version use this:
pip install opencv-contrib-python
If you have a new Raspberry Pi and want to install OpenCV then this tutorial would be a good choice.
For Ubuntu/Linux users:
sudo apt install python3-opencv
As of 10/22/2019, I think the best answer is simply
conda install opencv
It appears opencv is now in the main Anaconda channel.
To see which packages (including opencv) are in the main Anaconda channel go to Anaconda Package Lists and follow the link corresponding to your python version and os version.
Everybody struggles initially while installing OpenCV. OpenCV requires a lot of dependencies in the backend. The best way to start with OpenCV is, install it in a virtual environment. I suggest that you use the Python Anaconda distribution and create a virtual environment using it. Then inside the virtual environment, you can install OpenCV using this command:
conda install -c conda-forge opencv
Please follow the command:
pip install opencv-python
then if you want to use:
import cv2
If it's not worked due to any update, please follow the documentation
Make a virtual enviroment using python3
virtualenv env_name --python="python3"
and run the following command
pip3 install opencv-python
to check it has installed correctly run
python3 -c "import cv2"
To install open_cv you can go to this website or do this,
pip install opencv-contrib-python --upgrade
pip install opencv-python
You can test it by:
C:\> python
>>> import cv2
>>> print(cv2.__version__)
'4.5.1' # your version may be a newer one
You can install opencv the normal way:
pip install opencv-python
If you are getting errors, you can do this:
pip install opencv-python-headless
Open anaconda command prompt and type in below command.
conda install -c conda-forge opencv
Once the 'Solving environment' is done. It will ask to download dependencies. Type 'y'.
It will install all the dependencies and then you are ready to code.
I recommend this for Python 3: Please install it this way with pip
pip3 install opencv-python
This will download and install the latest version of OpenCV.
You could try using below command-
pip install opencv-contrib-python
It will basically download the compatible version. If this command fails, you could upgrade you pip using below command-
python -m pip install –upgrade pip
If you need a pictorial guide, head over to Simple Steps to Install OpenCV in Windows
You can also try installing OpenCV from prebuilt binaries from the official OpenCV site.
->pip install opencv-python you can use this.
But if this code does not working then you can check python version on cmd and anaconda because they are different. So you type command in anaconda prompt and cmd, it will work. You can check this -> pip list
Open terminal
Run the following command
pip install --trusted-host=pypi.org --trusted-host=files.pythonhosted.org opencv-python.
Hope it will work.
Installing cv2 or opencv-python using pip is sometimes a problem. I was having the same problem of installing cv2 with pip. The installation wasn't a problem the problem was to import cv2 after installation. I was getting an Import Error so to fix this i import main from pip to install opencv-python. Try to run the following code in your python file then opencv-python will be installed
from pip._internal import main as install
try:
import cv2
except ImportError as e:
install(["install", "opencv-python"])
finally:
pass
I hope this will help someone
As a reference it might help someone... On Debian system I hard to do the following:
apt-get install -y libsm6 libxext6 libxrender-dev
pip3 install opencv-python
python3 -c "import cv2"
On Ubuntu you can install it for the system Python with
sudo apt install python3-opencv
if you are using Pycharm navigate settings > Project:name > Project interpreter just search the module by name(in this case OpenCV-python) and install it. worked for me
In case you use aarch64 platform with ARM64 cpu - and/or docker
On a development board on ARM64, no python-opencv version were found at all
version: NONE.
I've had to build from source. This allowed to include CUDA support.
In my case it was already available on the board but it wasn't found on the development environment.
If compiling from source is out of reach, there are Dockers
Of course compiling will take some time (few hours on ARM core), but it is worthy process to know as most open source tools can be built this way in case of issues.
I've had this problem in Google Colab, It only worked with this specific package version.
!pip install "opencv-python-headless<4.3"
There are two options-
pip install cv2
or
pip install opencv-python
Hope it helps.

Install `opencv_contrib` on Windows for Python via Anaconda

My computer is running Windows 10, and I have installed OpenCV 3.2.0 with Python 2.7.
I want to use the opencv_contrib repository.
Does anyone know how to acheive this via Anaconda?
You can try conda installing this OpenCV package from a community channel: https://anaconda.org/jlaura/OpenCV3. It should come with the extra OpenCV modules.
You can also try pip installing opencv-contrib-python into your Anaconda environment (you may want to remove OpenCV first):
pip install opencv-contrib-python

how to get opencv_contrib module in anaconda

Can anyone tell me commands to get contrib module for anaconda
I need that module for
matches = flann.knnMatch(des1,des2,k=2)
to run correctly
error thrown is
cv2.error: ......\modules\python\src2\cv2.cpp:163: error: (-215) The data should normally be NULL! in function NumpyAllocator::allocate
Also I am using Anaconda openCV version 3, and strictly dont want to switch to lower versions
P.S. as suggested at many places to edit file cv2.cpp option is not available with anaconda.
I would recommend installing pip in your anaconda environment then just doing: pip install opencv-contrib-python. This comes will opencv and opencv-contrib.
Anaconda supports pip install to install package into conda environment. You can download OpenCV 3.2.0 with opencv_contrib from this well known Unofficial Windows Binaries for Python Extension Packages website. See the filename below for the right version. Then type the command in Anaconda Prompt window to install the package:
For Python 3.5 and 64-bit Windows:
pip install opencv_python‑3.2.0+contrib‑cp35‑cp35m‑win_amd64.whl
For Python 3.6 and 64-bit Windows:
pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl
Most of the OpenCV 3.2.0 packages in Anaconda repository didn't specific if they come with opencv_contrib. The pip install approach is easier and proven, see one of the SO post. The only drawback is that conda list will not show pip installed package there but actually it's.
However, if you want to have trial on conda install, below is the command for installing OpenCV 3.2.0 for Python 3.5 or 3.6 but likely without opencv_contrib.
conda install -c conda-forge opencv=3.2.0
Hope this help.
You can try this: https://anaconda.org/michael_wild/opencv-contrib
To install this package with conda run:
conda install -c michael_wild opencv-contrib
These anaconda packages include the contrib modules with base OpenCV3. Though the file list says it's currently for Windows only!
The question is old but I thought to update the answer with the latest information. My Anaconda version is 2019.10 and build channel is py_37_0 . I used pip install opencv-python==3.4.2.17 and pip install opencv-contrib-python==3.4.2.17. Now they are also visible as installed packages in Anaconda navigator and I am able to use patented methods like SIFT etc.
Method 1: in Anaconda Prompt write this, will install opencv-contrib v4.6
pip install opencv-contrib-python
Method 2: Install previous version of opencv-contrib v3.3.1
According to https://anaconda.org/michael_wild/opencv-contrib it says it support win64bit only and python 3.6.x.
So, first you need to create new enviroment support python 3.6
conda create --opencv_contrib36 python=3.6.13
then, install the packages
conda install -c michael_wild opencv-contrib
There is repo in conda-forge which includes opencv-contrib: https://github.com/conda-forge/opencv-feedstock
To use it:
conda install --channel=conda-forge libopencv opencv py-opencv
if you run into Numpy error, try pinning more recent version (of Numpy).
This worked for me in Windows 10 on Anaconda 5.3 with python 3.6
conda install -c conda-forge opencv

Install openCV without build the project

I want to install OpenCV for use it in Python. I found a tutorial how to install it at: http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/. But I have a limited spaces, around 3Gb so. I can't compile the project. How can I install OpenCV in this case? I use Ubuntu.
You can install the conda package manager via pip install condaand install opencv3 via conda install -c https://conda.anaconda.org/menpo opencv3
Another option is to use the pre-compiled Windows binaries from: http://www.lfd.uci.edu/~gohlke/pythonlibs/ and install them with pip (this just works for Windows).

Categories