|
| 1 | +.. image:: https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows |
| 2 | + :target: https://ci.appveyor.com/project/skvark/opencv-python |
| 3 | + :alt: AppVeyor CI test status (Windows) |
| 4 | + |
| 5 | +.. image:: https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label="Linux / OS X" |
| 6 | + :target: https://travis-ci.org/skvark/opencv-python |
| 7 | + :alt: Travis CI test status (Linux and OS X) |
| 8 | + |
| 9 | +OpenCV on Wheels |
| 10 | +================ |
| 11 | + |
| 12 | +**Unofficial** OpenCV packages for Python with contrib modules. |
| 13 | + |
| 14 | +**Usage of opencv-contrib-python might be restricted in some countries since the contrib package contains some patented algorithms/non-free modules.** |
| 15 | + |
| 16 | +If you are looking for a version without the contrib modules, please install `opencv-python <https://pypi.python.org/pypi/opencv-python>`__ instead. |
| 17 | + |
| 18 | +The packages contain pre-compiled OpenCV binary with Python bindings. |
| 19 | +This enables super fast (usually < 10 seconds) OpenCV installation for Python. |
| 20 | + |
| 21 | +If you need only OpenCV Python bindings, no separate OpenCV installation is required. |
| 22 | + |
| 23 | +**IMPORTANT NOTE** |
| 24 | + |
| 25 | +MacOS and Linux wheels have currently some limitations: |
| 26 | + |
| 27 | +- video related functionality is not supported (not compiled with FFmpeg) |
| 28 | +- for example ``cv2.imshow()`` will not work (not compiled with GTK+ 2.x or Carbon support) |
| 29 | + |
| 30 | +Installation and Usage |
| 31 | +---------------------- |
| 32 | + |
| 33 | +1. If you have previous/other version of OpenCV installed (e.g. cv2 module in the root of Python's site-packages), remove it before installation to avoid conflicts. |
| 34 | + - To further avoid conflicts and to make development easier, Python's `virtual environments <https://docs.python.org/3/library/venv.html>`__ are highly recommended for development purposes. |
| 35 | +2. Install this package: |
| 36 | + |
| 37 | +``pip install opencv-python`` |
| 38 | + |
| 39 | +3. Import the package: |
| 40 | + |
| 41 | +``import cv2`` |
| 42 | + |
| 43 | +4. Read `OpenCV documentation <http://docs.opencv.org/>`__ |
| 44 | + |
| 45 | +5. Before opening a new issue, read the FAQ below and have a look at the other issues which are already open. |
| 46 | + |
| 47 | +Frequently Asked Questions |
| 48 | +-------------------------- |
| 49 | + |
| 50 | +Q: Do I need to install also OpenCV separately? |
| 51 | +A: No, the packages are special wheel binary packages and they already contain statically built OpenCV binaries. |
| 52 | + |
| 53 | +Q: Pip does not find package opencv-contrib-python? |
| 54 | +A: The wheel package format and manylinux builds are pretty new things. Most likely the issue is related to too old pip and can be fixed by running ``pip install --upgrade pip``. |
| 55 | + |
| 56 | +Q: Import fails on Windows to some DLL load error? |
| 57 | +A: If the import fails on Windows, make sure you have `Visual C++ redistributable 2015 <https://www.microsoft.com/en-us/download/details.aspx?id=48145>`__ installed. If you are using older Windows version than Windows 10 and latest system updates are not installed, `Universal C Runtime <https://support.microsoft.com/en-us/help/2999226/update-for-universal-c-runtime-in-windows>`__ might be also required. |
| 58 | + |
| 59 | +Q: I have some other import errors? |
| 60 | +A: Make sure you have removed old manual installations of OpenCV Python bindings (cv2.so or cv2.pyd in site-packages). |
| 61 | + |
| 62 | +Q: Why I can't open video files on GNU/Linux distribution X or on macOS? |
| 63 | +A: OpenCV video I/O depends heavily on FFmpeg. Manylinux and macOS OpenCV binaries are not compiled against it. |
| 64 | +The purpose of these packages is to provide as easy as possible installation experience for OpenCV Python bindings and they should work directly out-of-the-box. |
| 65 | +Adding FFmpeg as an additional dependency without a "universal" FFmpeg build (e.g. LGPL licensed static build like in the Windows wheels) the goal is considerably harder to achieve. This might change in the future. |
| 66 | + |
| 67 | +Q: Why I can't open GUI windows (``cv2.imshow()``) on GNU/Linux distribution X or on macOS? |
| 68 | +A: Like above, OpenCV was not compiled against GTK or Carbon. Support for these might be added in the future. |
| 69 | + |
| 70 | +Documentation for opencv-python |
| 71 | +------------------------------- |
| 72 | + |
| 73 | +The aim of this repository is to provide means to package each new |
| 74 | +`OpenCV release <https://github.com/opencv/opencv/releases>`__ for the |
| 75 | +most used Python versions and platforms. |
| 76 | + |
| 77 | +At the same time it allows anyone to build a custom version of OpenCV |
| 78 | +for any Python version: just fork this repo and modify the build files |
| 79 | +and scripts to fit your needs. |
| 80 | + |
| 81 | +Build process |
| 82 | +------------- |
| 83 | + |
| 84 | +The project is structured like a normal Python package with a standard |
| 85 | +``setup.py`` file. The build process is as follows (see for example |
| 86 | +``appveyor.yml`` file): |
| 87 | + |
| 88 | +1. Checkout repository and submodules |
| 89 | + |
| 90 | + - OpenCV is included as submodule and the version is updated |
| 91 | + manually by maintainers when a new OpenCV release has been made |
| 92 | + |
| 93 | +2. Find OpenCV version from the sources |
| 94 | +3. Upgrade pip and install numpy for each Python version |
| 95 | +4. Build OpenCV |
| 96 | + |
| 97 | + - tests are disabled, otherwise build time increases too much |
| 98 | + |
| 99 | +5. Copy each ``.pyd/.so`` file to cv2 folder of this project and |
| 100 | + generate wheel |
| 101 | +6. Install the generated wheels for each Python version |
| 102 | +7. Test that the Python versions can import them |
| 103 | +8. Use twine to upload all wheels to PyPI |
| 104 | + |
| 105 | +Currently the ``find_version.py`` file parses OpenCV version information |
| 106 | +from the OpenCV sources. OpenCV depends on numpy, so ``setup.py`` checks |
| 107 | +the numpy version also with the help of pip. |
| 108 | + |
| 109 | +The ``cv2.pyd`` file for example on Windows is normally copied to site-packages. |
| 110 | +To avoid polluting the root folder the ``__init__.py`` file in cv2 folder |
| 111 | +handles the import logic correctly by importing the actual ``.pyd`` module |
| 112 | +and replacing the imported cv2 package in ``sys.modudes`` with the |
| 113 | +cv2 module to retain backward compatibility. |
| 114 | + |
| 115 | +Licensing |
| 116 | +--------- |
| 117 | + |
| 118 | +Opencv-python package (scripts in this repository) is available under |
| 119 | +MIT license. |
| 120 | + |
| 121 | +OpenCV itself is available under `3-clause BSD |
| 122 | +License <https://github.com/opencv/opencv/blob/master/LICENSE>`__ |
| 123 | +(`LICENSE-3RD-PARTY.txt <https://github.com/skvark/opencv-python/blob/master/LICENSE-3RD-PARTY.txt>`__). |
| 124 | + |
| 125 | +Windows wheels ship with `FFmpeg <http://ffmpeg.org>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__. |
| 126 | + |
| 127 | +Versioning |
| 128 | +---------- |
| 129 | + |
| 130 | +Currently the ``find_version.py`` script searches for the version |
| 131 | +information from OpenCV sources and appends also a revision number |
| 132 | +specific to this repository to the version string. |
| 133 | + |
| 134 | +Releases |
| 135 | +~~~~~~~~ |
| 136 | + |
| 137 | +A release is made and uploaded to PyPI when a new tag is pushed to |
| 138 | +master branch. These tags differentiate packages (this repo might have |
| 139 | +modifications but OpenCV version stays same) and should be incremented |
| 140 | +sequentially. In practice, release version numbers look like this: |
| 141 | + |
| 142 | +``cv_major.cv_minor.cv_revision.package_revision`` e.g. ``3.1.0.0`` |
| 143 | + |
| 144 | +Development builds |
| 145 | +~~~~~~~~~~~~~~~~~~ |
| 146 | + |
| 147 | +Every commit to the master branch of this repo will be built. Possible |
| 148 | +build artifacts use local version identifiers: |
| 149 | + |
| 150 | +``cv_major.cv_minor.cv_revision+git_hash_of_this_repo`` e.g. |
| 151 | +``3.1.0+14a8d39`` |
| 152 | + |
| 153 | +These artifacts can't be and will not be uploaded to PyPI. |
| 154 | + |
| 155 | +Manylinux wheels |
| 156 | +---------------- |
| 157 | + |
| 158 | +Linux wheels are built using |
| 159 | +`manylinux <https://github.com/pypa/python-manylinux-demo>`__. These |
| 160 | +wheels should work out of the box for most of the distros |
| 161 | +(which use GNU C standard library) out there since they are built |
| 162 | +against an old version of glibc. |
| 163 | + |
| 164 | +Supported Python versions |
| 165 | +------------------------- |
| 166 | + |
| 167 | +Python 2.7 is the only supported version in 2.x series. |
| 168 | +Python 3.x releases follow Numpy releases, for example |
| 169 | +Python 3.3 is no longer supported by Numpy so the support |
| 170 | +for it has been dropped in ``opencv-python`` too. |
| 171 | + |
| 172 | +Currently, builds for following Python versions are provided: |
| 173 | + |
| 174 | +- 2.7 |
| 175 | +- 3.4 |
| 176 | +- 3.5 |
| 177 | +- 3.6 |
0 commit comments