Wrapper package for OpenCV python bindings.
Project description
OpenCV on Wheels
Unofficial pre-built OpenCV packages for Python.
Installation and Usage
-
If you have previous/other manually installed (= not installed via
pip
) version of OpenCV installed (e.g. cv2 module in the root of Python's site-packages), remove it before installation to avoid conflicts. -
Select the correct package for your environment:
There are four different packages and you should select only one of them. Do not install multiple different packages in the same environment. There is no plugin architecture: all the packages use the same namespace (
cv2
). If you installed multiple different packages in the same environment, uninstall them all withpip uninstall
and reinstall only one package.a. Packages for standard desktop environments (Windows, macOS, almost any GNU/Linux distribution)
- run
pip install opencv-python
if you need only main modules - run
pip install opencv-contrib-python
if you need both main and contrib modules (check extra modules listing from OpenCV documentation)
b. Packages for server (headless) environments
These packages do not contain any GUI functionality. They are smaller and suitable for more restricted environments.
- run
pip install opencv-python-headless
if you need only main modules - run
pip install opencv-contrib-python-headless
if you need both main and contrib modules (check extra modules listing from OpenCV documentation)
- run
-
Import the package:
import cv2
All packages contain haarcascade files.
cv2.data.haarcascades
can be used as a shortcut to the data folder. For example:cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
-
Read OpenCV documentation
-
Before opening a new issue, read the FAQ below and have a look at the other issues which are already open.
Frequently Asked Questions
Q: Do I need to install also OpenCV separately?
A: No, the packages are special wheel binary packages and they already contain statically built OpenCV binaries.
Q: Pip fails with Could not find a version that satisfies the requirement ...
?
A: Most likely the issue is related to too old pip and can be fixed by running pip install --upgrade pip
. Note that the wheel (especially manylinux) format does not currently support properly ARM architecture so there are no packages for ARM based platforms in PyPI. However, opencv-python
packages for Raspberry Pi can be found from https://www.piwheels.org/.
Q: Import fails on Windows: ImportError: DLL load failed: The specified module could not be found.
?
A: If the import fails on Windows, make sure you have Visual C++ redistributable 2015 installed. If you are using older Windows version than Windows 10 and latest system updates are not installed, Universal C Runtime might be also required.
Windows N and KN editions do not include Media Feature Pack which is required by OpenCV. If you are using Windows N or KN edition, please install also Windows Media Feature Pack.
If you have Windows Server 2012+, media DLLs are probably missing too; please install the Feature called "Media Foundation" in the Server Manager. Beware, some posts advise to install "Windows Server Essentials Media Pack", but this one requires the "Windows Server Essentials Experience" role, and this role will deeply affect your Windows Server configuration (by enforcing active directory integration etc.); so just installing the "Media Foundation" should be a safer choice.
If the above does not help, check if you are using Anaconda. Old Anaconda versions have a bug which causes the error, see this issue for a manual fix.
If you still encounter the error after you have checked all the previous solutions, download Dependencies and open the cv2.pyd
(located usually at C:\Users\username\AppData\Local\Programs\Python\PythonXX\Lib\site-packages\cv2
) file with it to debug missing DLL issues.
Q: I have some other import errors?
A: Make sure you have removed old manual installations of OpenCV Python bindings (cv2.so or cv2.pyd in site-packages).
Q: Why the packages do not include non-free algorithms?
A: Non-free algorithms such as SURF are not included in these packages because they are patented / non-free and therefore cannot be distributed as built binaries. Note that SIFT is included in the builds due to patent expiration since OpenCV versions 4.3.0 and 3.4.10. See this issue for more info: https://github.com/skvark/opencv-python/issues/126
Q: Why the package and import are different (opencv-python vs. cv2)?
A: It's easier for users to understand opencv-python
than cv2
and it makes it easier to find the package with search engines. cv2
(old interface in old OpenCV versions was named as cv
) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet. Changing the import name or behaviour would be also confusing to experienced users who are accustomed to the import cv2
.
Documentation for opencv-python
The aim of this repository is to provide means to package each new OpenCV release for the most used Python versions and platforms.
CI build process
The project is structured like a normal Python package with a standard setup.py
file.
The build process for a single entry in the build matrices is as follows (see for example appveyor.yml
file):
-
In Linux and MacOS build: get OpenCV's optional C dependencies that we compile against
-
Checkout repository and submodules
- OpenCV is included as submodule and the version is updated manually by maintainers when a new OpenCV release has been made
- Contrib modules are also included as a submodule
-
Find OpenCV version from the sources
-
Build OpenCV
- tests are disabled, otherwise build time increases too much
- there are 4 build matrix entries for each build combination: with and without contrib modules, with and without GUI (headless)
- Linux builds run in manylinux Docker containers (CentOS 5)
- source distributions are separate entries in the build matrix
-
Rearrange OpenCV's build result, add our custom files and generate wheel
-
Linux and macOS wheels are transformed with auditwheel and delocate, correspondingly
-
Install the generated wheel
-
Test that Python can import the library and run some sanity checks
-
Use twine to upload the generated wheel to PyPI (only in release builds)
Steps 1--4 are handled by pip wheel
.
The build can be customized with environment variables. In addition to any variables that OpenCV's build accepts, we recognize:
CI_BUILD
. Set to1
to emulate the CI environment build behaviour. Used only in CI builds to force certain build flags on insetup.py
. Do not use this unless you know what you are doing.ENABLE_CONTRIB
andENABLE_HEADLESS
. Set to1
to build the contrib and/or headless versionENABLE_JAVA
, Set to1
to enable the Java client build. This is disabled by default.CMAKE_ARGS
. Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build.
See the next section for more info about manual builds outside the CI environment.
Manual builds
If some dependency is not enabled in the pre-built wheels, you can also run the build locally to create a custom wheel.
- Clone this repository:
git clone --recursive https://github.com/skvark/opencv-python.git
cd opencv-python
- Add custom Cmake flags if needed, for example:
export CMAKE_ARGS="-DSOME_FLAG=ON -DSOME_OTHER_FLAG=OFF"
(in Windows you need to set environment variables differently depending on Command Line or PowerShell) - Select the version which you wish to build with
ENABLE_CONTRIB
andENABLE_HEADLESS
: i.e.export ENABLE_CONTRIB=1
if you wish to buildopencv-contrib-python
- Run
pip wheel . --verbose
. NOTE: make sure you have the latestpip
, thepip wheel
command replaces the oldpython setup.py bdist_wheel
command which does not supportpyproject.toml
.- Optional: on Linux use the
manylinux
images as a build hosts if maximum portability is needed and runauditwheel
for the wheel after build - Optional: on macOS use
delocate
(same asauditwheel
but for macOS)
- Optional: on Linux use the
- You'll have the wheel file in the
dist
folder and you can do with that whatever you wish
Source distributions
Since OpenCV version 4.3.0, also source distributions are provided in PyPI. This means that if your system is not compatible with any of the wheels in PyPI, pip
will attempt to build OpenCV from sources.
You can also force pip
to build the wheels from the source distribution. Some examples:
pip install --no-binary opencv-python opencv-python
pip install --no-binary :all: opencv-python
If you need contrib modules or headless version, just change the package name (step 4 in the previous section is not needed). However, any additional CMake flags can be provided via environment variables as described in step 3 of the manual build section. If none are provided, OpenCV's CMake scripts will attempt to find and enable any suitable dependencies. Headless distributions have hard coded CMake flags which disable all possible GUI dependencies.
Please note that build tools and numpy
are required for the build to succeed. On slow systems such as Raspberry Pi the full build may take several hours. On a 8-core Ryzen 7 3700X the build takes about 6 minutes.
Licensing
Opencv-python package (scripts in this repository) is available under MIT license.
OpenCV itself is available under 3-clause BSD License.
Third party package licenses are at LICENSE-3RD-PARTY.txt.
All wheels ship with FFmpeg licensed under the LGPLv2.1.
Non-headless Linux and MacOS wheels ship with Qt 5 licensed under the LGPLv3.
The packages include also other binaries. Full list of licenses can be found from LICENSE-3RD-PARTY.txt.
Versioning
find_version.py
script searches for the version information from OpenCV sources and appends also a revision number specific to this repository to the version string. It saves the version information to version.py
file under cv2
in addition to some other flags.
Releases
A release is made and uploaded to PyPI when a new tag is pushed to master branch. These tags differentiate packages (this repo might have modifications but OpenCV version stays same) and should be incremented sequentially. In practice, release version numbers look like this:
cv_major.cv_minor.cv_revision.package_revision
e.g. 3.1.0.0
The master branch follows OpenCV master branch releases. 3.4 branch follows OpenCV 3.4 bugfix releases.
Development builds
Every commit to the master branch of this repo will be built. Possible build artifacts use local version identifiers:
cv_major.cv_minor.cv_revision+git_hash_of_this_repo
e.g. 3.1.0+14a8d39
These artifacts can't be and will not be uploaded to PyPI.
Manylinux wheels
Linux wheels are built using manylinux. These wheels should work out of the box for most of the distros (which use GNU C standard library) out there since they are built against an old version of glibc.
The default manylinux
images have been extended with some OpenCV dependencies. See Docker folder for more info.
Supported Python versions
Python 3.x releases are provided for officially supported versions (not in EOL).
Currently, builds for following Python versions are provided:
- 3.5 (EOL in 2020-09-13, builds for 3.5 will not be provided after this)
- 3.6
- 3.7
- 3.8
Backward compatibility
Starting from 4.2.0 and 3.4.9 builds the macOS Travis build environment was updated to XCode 9.4. The change effectively dropped support for older than 10.13 macOS versions.
Starting from 4.3.0 and 3.4.10 builds the Linux build environment was updated from manylinux1
to manylinux2014
. This dropped support for old Linux distributions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for opencv-python-headless-4.3.0.38.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 899fb67095efa4b9eb96f0370f8d1eff98cc09b6d5b82cacb1c6340d6fb68e73 |
|
MD5 | 940f5d71d2b17b254bb3f4830cc4e9a2 |
|
BLAKE2b-256 | c15e526e8888acf488cf311bcd3da220400ac5f56f60bb127f3706acefba25f7 |
Hashes for opencv_python_headless-4.3.0.38-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c14d253bc2d2ac09da81f5a01a76261830be6ae121a1a56c65e967ed2237cf2 |
|
MD5 | b2dc64c4e80912fb3933fbc7335a02a4 |
|
BLAKE2b-256 | 3d79359136d1e0323d4f0edbc8e07129f46ee7535e2a108b68171d7821e1c21c |
Hashes for opencv_python_headless-4.3.0.38-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f2082036f612d8bb2dd02fc27280e4e2b3a853bd1ae5f51a43ae8d3fbd61527 |
|
MD5 | a523be699effa85dc9a2c756b7b7a52d |
|
BLAKE2b-256 | 01cf29f5f09e347d2baa01f369ca9719b3fc7a1626fcbe97d74966cd42079fb0 |
Hashes for opencv_python_headless-4.3.0.38-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9c80ceaf58d763a40a6f5098eec316dc8fc8394ec60c7405105743e5a1a1d1a |
|
MD5 | ac10e4623cb30052426c263d45d8d8d8 |
|
BLAKE2b-256 | bf212201265aee8417a235bc2d1e4ac2c561aa4e3e26330473cb0c09e4f4925b |
Hashes for opencv_python_headless-4.3.0.38-cp38-cp38-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a1c730c6da39974e2ac1b232f78760c2c144bc67c736440e031eb8aa96e442a |
|
MD5 | 031145c0f960a7b3e5bd4eddca5fe374 |
|
BLAKE2b-256 | 09822b0b52953da47e85764d09a0cbfabd24adbf51a22bcb123473f66fbd934c |
Hashes for opencv_python_headless-4.3.0.38-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cd2c19f5ee390d4b26cbfccaa63d1794eebdf782b42c79ce30b2d6924578d8b |
|
MD5 | eac6eeaa3db22d0a0e7bdfb81a462f56 |
|
BLAKE2b-256 | 8703028b04a8e5884dde98caffcf5537e4a0cfec28b9ae70ee0b0c9d55e51b5a |
Hashes for opencv_python_headless-4.3.0.38-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a571f5a5d535859887682940ce6d4969d5f3da3a5295d85b0b9bdcb61f545e9 |
|
MD5 | 1f2359a93d8e412e544b3aa176f6572e |
|
BLAKE2b-256 | 668ce1c42957403e6ca7cc18f12e589016427f57def3a594a638b555565e4136 |
Hashes for opencv_python_headless-4.3.0.38-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a77dc098dbf29d805f78409776bf4b8699ab62b46f8882e75152a6625738b80 |
|
MD5 | 960b6cdcd18a65c407a378c43cbc6d27 |
|
BLAKE2b-256 | 1d0bb36e4e5c6ba5277c8c8c430970a762babde1bd2ff1cf8f66386c26cb1c38 |
Hashes for opencv_python_headless-4.3.0.38-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c36d5df90bb54ef71ffef8cb6dc8ec513b7aa0f2eb220eed89c2d30c4a57229e |
|
MD5 | e81c2869185afb01892f4fe056cd357e |
|
BLAKE2b-256 | d5edebee5056eec27d1f755f05bbdc8ae05d02286188845f7c1fbdc0ebcab0e4 |
Hashes for opencv_python_headless-4.3.0.38-cp37-cp37m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8a2543637eb9fcdf14c52804a45ec90ec55d0fe1b2b6a33d25e5189d92716f9 |
|
MD5 | 3d98171eeead1b0a2dc93be4c22068f0 |
|
BLAKE2b-256 | f369004eb88902288194b90175ba918322f44816c32e9f5fbc260a5550a2e1cb |
Hashes for opencv_python_headless-4.3.0.38-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30ebf68da55de21638a971a3051d2d423bce6185d7a59e7b2bccabbb2248227f |
|
MD5 | 7d02a81b5c20e183911a9caed6aedc8a |
|
BLAKE2b-256 | 963debbd220deec6fe08e192481922ba88139ed2b2cd4204b031551b5516a816 |
Hashes for opencv_python_headless-4.3.0.38-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32a36a14b5db8461e0a72cda23d22e0fd3c5d81584244003ea1bb29e85577e7a |
|
MD5 | 36207fe6705f252c3d8e756231d7adfb |
|
BLAKE2b-256 | 41b9c1abf5f329083ab148dfcacf67e32e748f7da24814511bac5a330c23d22d |
Hashes for opencv_python_headless-4.3.0.38-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c543939773ea59ee044d0e80994a4a83df760462d95da7fc00b65e07b87f387 |
|
MD5 | 844a8b22149fffc69d3726c3411a35b1 |
|
BLAKE2b-256 | 3881ba78676fcb0f6fd5a6bfd2c540b788d4f526b12b3bd923c4f3a719cd7ab9 |
Hashes for opencv_python_headless-4.3.0.38-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdf43d96d8e69e781bc9b4c0ca0ee7553749d1ba35d190e77afd127bc6d140f6 |
|
MD5 | 6f7436c8edb7e041a8ae90d7a4a6a5f7 |
|
BLAKE2b-256 | 11ccfabe217db6daad545b88cd3dc039cf9e64b74490ebb6bc6e1c2cdd6572c2 |
Hashes for opencv_python_headless-4.3.0.38-cp36-cp36m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e21a0fe810b159bc68622e3a0036b8b980de79345c9a200de6808b35025ae80d |
|
MD5 | 1beb81ec16d3e6b48c930a683efbe80b |
|
BLAKE2b-256 | d74d35e44934ec69c16a8911a61992b38d40c0176f2098e228447ad72b1a41b6 |
Hashes for opencv_python_headless-4.3.0.38-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | faf0646c52c0d5a19d4324306314706697211893f2489d11879254d2e4319287 |
|
MD5 | 50502c3b13f0b957de441c98d4355c93 |
|
BLAKE2b-256 | 6fbc65559efa400cd843624eca11b29f2ccef318ce5b69db638fee859fa2d370 |
Hashes for opencv_python_headless-4.3.0.38-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdaf4e09e6468e09fe870bce3e0a614d10e848261bc2af49177d893a10f6a9a6 |
|
MD5 | 6bdd18ce77b0035c8fdf2461ee56f4ca |
|
BLAKE2b-256 | 87bf13d9b0cef9016e5dc3b580f8f967c40b11bfcf1f30f68994f23e36f8de2a |
Hashes for opencv_python_headless-4.3.0.38-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d28a30466f4ac4e434022a64b21b79f5e8edf9f9579f70df5efd5f3cc46842d9 |
|
MD5 | 86d733054645f864f18124391d1a7de5 |
|
BLAKE2b-256 | 7bb390ea48fdffb7fe48f4e3540f190d21df8335b7f4f61ff2f45f6b08afda0a |
Hashes for opencv_python_headless-4.3.0.38-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 822f1b56575fbf396791530fac3f460ab4a55aed2eef08603038695f639f34dd |
|
MD5 | f41537e512f32975f6b45acc363d0edd |
|
BLAKE2b-256 | 0f40549d4d7b8852a475c3b7fb28fac0415a6d4db31a72339d42e2a34e9f005b |
Hashes for opencv_python_headless-4.3.0.38-cp35-cp35m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c389392b6c0e240bdebc22cb595b75ce9bc66fae7e6b8493e1d205376d370533 |
|
MD5 | 5d2362a8c08091b8cb09611a9bed54c8 |
|
BLAKE2b-256 | c5f38e1c0aee85b51d92c80e1146cdb82e7f200b2fa5d7ed3fc5f830e9baff9a |
Hashes for opencv_python_headless-4.3.0.38-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 656784690c20f4c8dbaaf6df906c6e9b2714c1bcd179c20a23c8eb1b9550f7cc |
|
MD5 | 2d5cc2ad8875165e743ee0e9fe2bc342 |
|
BLAKE2b-256 | f3f8e77078563ca9a7b1ace1175e7ed6c2c37b1e2bd9c313db0c0b00149ddb63 |