Coder Social home page Coder Social logo

opencv / opencv-python Goto Github PK

View Code? Open in Web Editor NEW
4.3K 88.0 809.0 1.81 MB

Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.

Home Page: https://pypi.org/project/opencv-python/

License: MIT License

Python 50.41% Shell 49.59%
opencv python wheel python-3 opencv-python opencv-contrib-python precompiled pypi manylinux

opencv-python's Introduction

Downloads

Keep OpenCV Free

OpenCV is raising funds to keep the library free for everyone, and we need the support of the entire community to do it. Donate to OpenCV on Github to show your support.

OpenCV on Wheels

Pre-built CPU-only OpenCV packages for Python.

Check the manual build section if you wish to compile the bindings from source to enable additional modules such as CUDA.

Installation and Usage

  1. 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.

  2. Make sure that your pip version is up-to-date (19.3 is the minimum supported version): pip install --upgrade pip. Check version with pip -V. For example Linux distributions ship usually with very old pip versions which cause a lot of unexpected problems especially with the manylinux format.

  3. Select the correct package for your environment:

    There are four different packages (see options 1, 2, 3 and 4 below) 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 with pip uninstall and reinstall only one package.

    a. Packages for standard desktop environments (Windows, macOS, almost any GNU/Linux distribution)

    • Option 1 - Main modules package: pip install opencv-python
    • Option 2 - Full package (contains both main modules and contrib/extra modules): pip install opencv-contrib-python (check contrib/extra modules listing from OpenCV documentation)

    b. Packages for server (headless) environments (such as Docker, cloud environments etc.), no GUI library dependencies

    These packages are smaller than the two other packages above because they do not contain any GUI functionality (not compiled with Qt / other GUI components). This means that the packages avoid a heavy dependency chain to X11 libraries and you will have for example smaller Docker images as a result. You should always use these packages if you do not use cv2.imshow et al. or you are using some other package (such as PyQt) than OpenCV to create your GUI.

    • Option 3 - Headless main modules package: pip install opencv-python-headless
    • Option 4 - Headless full package (contains both main modules and contrib/extra modules): pip install opencv-contrib-python-headless (check contrib/extra modules listing from OpenCV documentation)
  4. Import the package:

    import cv2

    All packages contain Haar cascade 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")

  5. Read OpenCV documentation

  6. 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 install fails with ModuleNotFoundError: No module named 'skbuild'?

Since opencv-python version 4.3.0.*, manylinux1 wheels were replaced by manylinux2014 wheels. If your pip is too old, it will try to use the new source distribution introduced in 4.3.0.38 to manually build OpenCV because it does not know how to install manylinux2014 wheels. However, source build will also fail because of too old pip because it does not understand build dependencies in pyproject.toml. To use the new manylinux2014 pre-built wheels (or to build from source), your pip version must be >= 19.3. Please upgrade pip with pip install --upgrade pip.

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: Function foo() or method bar() returns wrong result, throws exception or crashes interpreter. What should I do?

A: The repository contains only OpenCV-Python package build scripts, but not OpenCV itself. Python bindings for OpenCV are developed in official OpenCV repository and it's the best place to report issues. Also please check OpenCV wiki and the official OpenCV forum before file new bugs.

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: #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

Windows Build Status (Linux Build status) (Mac OS Build status)

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 .github/workflows/build_wheels_linux.yml file):

  1. In Linux and MacOS build: get OpenCV's optional C dependencies that we compile against

  2. 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
  3. Find OpenCV version from the sources

  4. 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
  5. Rearrange OpenCV's build result, add our custom files and generate wheel

  6. Linux and macOS wheels are transformed with auditwheel and delocate, correspondingly

  7. Install the generated wheel

  8. Test that Python can import the library and run some sanity checks

  9. 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 to 1 to emulate the CI environment build behaviour. Used only in CI builds to force certain build flags on in setup.py. Do not use this unless you know what you are doing.
  • ENABLE_CONTRIB and ENABLE_HEADLESS. Set to 1 to build the contrib and/or headless version
  • ENABLE_JAVA, Set to 1 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.

  1. Clone this repository: git clone --recursive https://github.com/opencv/opencv-python.git
  2. cd opencv-python
    • you can use git to checkout some other version of OpenCV in the opencv and opencv_contrib submodules if needed
  3. 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)
  4. Select the package flavor which you wish to build with ENABLE_CONTRIB and ENABLE_HEADLESS: i.e. export ENABLE_CONTRIB=1 if you wish to build opencv-contrib-python
  5. Run pip wheel . --verbose. NOTE: make sure you have the latest pip version, the pip wheel command replaces the old python setup.py bdist_wheel command which does not support pyproject.toml.
    • this might take anything from 5 minutes to over 2 hours depending on your hardware
  6. Pip will print fresh will location at the end of build procedure. If you use old approach with setup.py file wheel package will be placed in dist folder. Package is ready and you can do with that whatever you wish.
    • Optional: on Linux use some of the manylinux images as a build hosts if maximum portability is needed and run auditwheel for the wheel after build
    • Optional: on macOS use delocate (same as auditwheel but for macOS) for better portability

Manual debug builds

In order to build opencv-python in an unoptimized debug build, you need to side-step the normal process a bit.

  1. Install the packages scikit-build and numpy via pip.
  2. Run the command python setup.py bdist_wheel --build-type=Debug.
  3. Install the generated wheel file in the dist/ folder with pip install dist/wheelname.whl.

If you would like the build produce all compiler commands, then the following combination of flags and environment variables has been tested to work on Linux:

export CMAKE_ARGS='-DCMAKE_VERBOSE_MAKEFILE=ON'
export VERBOSE=1

python3 setup.py bdist_wheel --build-type=Debug

See this issue for more discussion: #424

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. If you need a OpenCV version which is not available in PyPI as a source distribution, please follow the manual build guidance above instead of this one.

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.

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 Apache 2 license.

Third party package licenses are at LICENSE-3RD-PARTY.txt.

All wheels ship with FFmpeg licensed under the LGPLv2.1.

Non-headless Linux 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 manylinux2014. 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 manylinux2014 images have been extended with some OpenCV dependencies. See Docker folder for more info.

Supported Python versions

Python 3.x compatible pre-built wheels are provided for the officially supported Python versions (not in EOL):

  • 3.7
  • 3.8
  • 3.9
  • 3.10
  • 3.11
  • 3.12

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.

Starting from version 4.7.0 the Mac OS GitHub Actions build environment was update to version 11. Mac OS 10.x support depricated. See actions/runner-images#5583

Starting from version 4.9.0 the Mac OS GitHub Actions build environment was update to version 12. Mac OS 10.x support depricated by Brew and most of used packages.

opencv-python's People

Contributors

abhitronix avatar asenyaev avatar asmorkalov avatar bertsky avatar c-martinez avatar cclauss avatar dkurt avatar dlech avatar engnadeau avatar glitchassassin avatar henryiii avatar illume avatar johnthagen avatar kianmeng avatar kvalev avatar mbdevpl avatar native-api avatar niyas-sait avatar pakal avatar peter-kovacs-aimotive avatar rockywhisper avatar scivision avatar sergregory avatar skvark avatar stweil avatar techdragon avatar techtonik avatar tomsweeting avatar vallentin avatar williamjacksn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opencv-python's Issues

Unwanted Horizontal Lines Appears when using cv2.putText()

System information (version)
  • OpenCV => opencv-python==3.2.0.7
  • Operating System / Platform => Windows 10 64 Bit
  • Python 3.5.3 and installed with PIP with a virtualenv
Detailed description

I use the following dummy_code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, cv2, time
import numpy as np

video_capture = cv2.VideoCapture(0)

h_offset  = 150
font      = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 0.5
fontColor = (0, 255, 0)
thickness = 2

while True:
    
    start    = time.time()
    v_offset = 50 
    
    # Capture frame-by-frame
    ret, frame = video_capture.read()
    
    print("\n####################\n")
    
    for _ in range(5):
    
        printed_txt = "DOG" + " => " +str(round(25.3 ,1))+"%"
        cv2.putText(frame, printed_txt, (h_offset, v_offset), font, fontScale, fontColor, thickness)
        
        v_offset += 50
        
        print(printed_txt)

    cv2.imshow('Video', frame)

    key = cv2.waitKey(1)
    if key & 0xFF == ord('q'):
        break
    elif key & 0xFF == ord(' '):
        #raw_input("Press any key to stop pause")
        cv2.waitKey(0)       

    print("\nframe_rate: %2.2f images/sec" % (1 / (time.time() - start)))

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()

Which leads to this screen :
image

Could anyone tell me why am I having these horizontal lines and how to remove them ?

Firstly posted here : opencv/opencv#8824

Thanks a lot dear friends

ARM support

ARM builds would be needed to support for example Raspberry Pi.

Assertion failed (scn == 3 || scn == 4)

I am currently experiencing this on a Mi 13.3 laptop when trying to run a basic example like:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

Complete output:

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /io/opencv/modules/imgproc/src/color.cpp, line 10638
Traceback (most recent call last):
  File "main.py", line 11, in <module>
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: /io/opencv/modules/imgproc/src/color.cpp:10638: error: (-215) scn == 3 || scn == 4 in function cvtColor

I have checked this from two distributions: a Ubuntu 17.04 and a Kali from a Live USB.

Inconsistent return type from CascadeClassifier.detectMultiScale

Expected behaviour

I expected the library to return an empty ndarray when there is no detection.

Actual behaviour

The library returns a single empty tuple when there is NO detection, and a numpy.ndarray when there are detections.

  • operating system : Windows 10
  • opencv-python version: 3.3.1

Is this a problem with the package or with the opencv library?

Include headers to support binary linking?

First off, thanks for this project, it saves a ton of time and I'm really happy that it exists. It makes it a lot easier to get OpenCV installed for the high school students I work with.

I'd like to take a C++ library that uses OpenCV, wrap it with cython, and link it to the OpenCV bits in the binary provided by the installed wheel. This would allow users to just install the wheel of the other library + the opencv-python wheel, as opposed to having to compile their own version.

Has anyone tried this yet? A cursory look at the linux .so files indicate that it exports all of the normal OpenCV symbols, so in theory if you just include the right headers and link to it then it should just work (though maybe not for Windows)... I think that one would add an additional cv2 module (cv2.distutils?) that could provide a list of includes/libraries, similar to how numpy works.

If there's no opposition to this, I might try this out in a week or three to see how it goes.

Install Fails on OS X

On OS X 10.11 with python 2.7.12:

$ pip install opencv-python
Collecting opencv-python
  Could not find a version that satisfies the requirement opencv-python (from versions: )
No matching distribution found for opencv-python

If I try to explicitly install the wheel, I get:

opencv_python-3.1.0.3-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl is not a supported wheel on this platform.

Add GUI support (Qt)

Hi, I am having trouble with the library, I installed it and tried to use it on:

https://github.com/gliese581gg/YOLO_tensorflow

But the error I get when trying to run it is:

OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /io/opencv/modules/highgui/src/window.cpp, line 545
Traceback (most recent call last):
  File "YOLO_small_tf.py", line 250, in <module>
    main(sys.argv)
  File "YOLO_small_tf.py", line 245, in main
    yolo = YOLO_TF(argvs)
  File "YOLO_small_tf.py", line 30, in __init__
    if self.fromfile is not None: self.detect_from_file(self.fromfile)
  File "YOLO_small_tf.py", line 137, in detect_from_file
    self.detect_from_cvmat(img)
  File "YOLO_small_tf.py", line 129, in detect_from_cvmat
    self.show_results(img,self.result)
  File "YOLO_small_tf.py", line 225, in show_results
    cv2.imshow('YOLO_small detection',img_cp)
cv2.error: /io/opencv/modules/highgui/src/window.cpp:545: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage

Relax numpy version requirements

Hi
Currently opencv-python requires numpy >=1.11.3 to be installed despite requirements.txt and .travis.yml specifying >= 1.11.1.

We want to use this with Anaconda 4.1.1, which installs numpy 1.11.1.
Would it be possible to relax these dependencies, and install/test/publish with version 1.11.1?

JPEG decoding and encoding is significant slower than from Ubuntu package

First of all thanks for your work!

OpenCV version in Ubuntu 16.04 is still 2.4.9.1, so most users have to install OpenCV from this wheels.

Surprisingly, these wheels have much lower JPEG decoding and encoding speed than shipped with Ubuntu.

Cv2 load 2560×1600 RGB image
    Jpeg load           0.05430 s    75.43 Mpx/s
    Jpeg save           0.10867 s    37.69 Mpx/s
Cv2 load 2560×1600 RGB image
    Jpeg load           0.03277 s   124.99 Mpx/s
    Jpeg save           0.03084 s   132.82 Mpx/s

Here is perf report for both cases:

screen shot 2017-10-16 at 1 39 58

screen shot 2017-10-16 at 1 17 12

It's clear that these wheels don't use system-provided libjpeg library (which is libjpeg-turbo for some systems). Instead, they are decoding and encoding using some build-in libjpeg library which is much slower.

I see two solutions: use libjpeg-turbo for wheels or use system libraries.

opencv GUI does not work

cv2.namedWindow('test', cv2.WINDOW_AUTOSIZE) results in an error:

QObject::moveToThread: Current thread (0xca9110) is not the object's thread (0x1256140).
Cannot move to target thread (0xca9110)

here is the version:

cv2.__version__
Out[3]: '3.3.0'
QtCore.QT_VERSION_STR
Out[7]: '5.6.2'

Error with setup.py install_requires?

Expected behaviour

I can pip install opencv-python without a hitch on my dev box, but am running into problems when setup.py's install_requires is trying to do it. I'm assuming the issue lies here, perhaps some of you are familiar with the error message?

Actual behaviour

Processing dependencies for autocrop==0.1                                      
Searching for opencv-python            
Reading https://pypi.python.org/simple/opencv-python/                          
No local packages or working download links found for opencv-python            
error: Could not find suitable distribution for Requirement.parse('opencv-python')                                                                             

Steps to reproduce

  • example code
setup(install_requires='opencv-python')

in my package's setup.py, when running python setup.py install

  • operating system

    • Manjaro Linux
  • architecture (e.g. x86)

    • x86
  • opencv-python version

    • Latest (any)

Package metadata

The package should contain some metadata. There are some things to consider:

  • authors/maintainers
    • probably only maintainers, since we are not the authors of OpenCV
  • license must be probably the same as in OpenCV
  • Readme in rst format, there's probably some conversion tool which can be run in setup.py

"cv2.img_hash_PHash()"

I have problem to calculate the opencv-contrib "phash()"

import cv2
image = cv2.imread( '/tmp/test.jpg' )
hashcode = cv2.img_hash_PHash( image )
print hashcode

Result -> phash-object:

<img_hash_PHash 0x7fbc4761d330>

Are there any docs?
Thanks a lot!

cv2.imshow()

is there any way to show the image in this instead of cv2.imshow() ? you said it has limits for it

Problem when installing inside docker image ubuntu:14.04

Hi, I have problem when installing inside docker image

root@6296a40bde67:~/SDC2017Round1/src/object_awareness# pip3 install opencv-python
Downloading/unpacking opencv-python
  Could not find any downloads that satisfy the requirement opencv-python
Cleaning up...
No distributions at all found for opencv-python
Storing debug log for failure in /root/.pip/pip.log

is it the issue of manylinux or something?

Thanks

Cannot `pip install opencv-python` in ubuntu 14.04

Logs:


/usr/bin/pip run on Mon Jun 26 17:25:27 2017
Downloading/unpacking opencv-python
Getting page https://pypi.python.org/simple/opencv-python/
URLs to search for versions for opencv-python:

The travis building failed in Linux/OSX, is it the reason?

https://travis-ci.org/skvark/opencv-python

My environment: Ubuntu 14.04, Python 2.7.6

Python 3.4 doesn't install through pip

C:\Users\drebbe>c:\python34\scripts\pip.exe install opencv_python
Collecting opencv-python
  Could not find a version that satisfies the requirement opencv-python (from versions: )
No matching distribution found for opencv-python
Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Inspecting the cv2.pyd inside opencv_python-3.4.0.12-cp34-cp34m-win32.whl (Used PEiD) looks like it was built with Visual Studio's 2015 compiler/linker whereas Python 3.4 requires Visual Studio 2010.

Non-free opencv_contrib modules are not available

I try to use opencv-contrib-python wheel package from PyPI

Expected behaviour

import cv2
out_img = cv2.xphoto.bm3dDenoising(inp_img)
# No any errors

Actual behaviour

I get the following error

cv2.error: C:\projects\opencv-python\opencv_contrib\modules\xphoto\src\bm3d_image_denoising.cpp:341: error: (-213) This algorithm is patented and is excluded in this configuration;Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function cv::xphoto::bm3dDenoising

3.3.0.10 breaks on ubuntu server without X11

We're running an opencv python application in docker (with GPU support via nvidia-docker but no GUI). The most recent release has added a dependency on Qt, but it is also linking against X11, which is not typically installed in such environments. Would it be possible to provide a headless version, or include X11 and other libs in the build (which would make the resulting package a fair bit larger I'd imagine).

In version opencv_python-3.3.0.9-cp35-cp35m-manylinux1_x86_64.whl (8.8MB), ldd shows the following.

root@3b68495a9aa8:/usr/local/lib/python3.5/dist-packages/cv2# ldd cv2.cpython-35m-x86_64-linux-gnu.so
linux-vdso.so.1 => (0x00007ffc9d7aa000)
libz-a147dcb0.so.1.2.3 => /usr/local/lib/python3.5/dist-packages/cv2/./.libs/libz-a147dcb0.so.1.2.3 (0x00007fe2c6f04000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fe2c6cfb000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fe2c69ea000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe2c6668000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe2c6463000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe2c6246000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fe2c603e000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe2c5d34000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe2c5b1e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe2c5754000)
/lib64/ld-linux-x86-64.so.2 (0x00005569d85ea000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fe2c54e3000)

In version opencv_python-3.3.0.10-cp35-cp35m-manylinux1_x86_64.whl (15.4MB) ldd shows the following:

root@a867b910c313:/usr/local/lib/python3.5/dist-packages/cv2# ldd cv2.cpython-35m-x86_64-linux-gnu.so
linux-vdso.so.1 => (0x00007fffbed3e000)
libz-a147dcb0.so.1.2.3 => /usr/local/lib/python3.5/dist-packages/cv2/./.libs/libz-a147dcb0.so.1.2.3 (0x00007f2862370000)
libQtGui-6d0f14dd.so.4.8.7 => /usr/local/lib/python3.5/dist-packages/cv2/./.libs/libQtGui-6d0f14dd.so.4.8.7 (0x00007f28614de000)
libQtTest-1183da5d.so.4.8.7 => /usr/local/lib/python3.5/dist-packages/cv2/./.libs/libQtTest-1183da5d.so.4.8.7 (0x00007f28612b1000)
libQtCore-ba1dc80c.so.4.8.7 => /usr/local/lib/python3.5/dist-packages/cv2/./.libs/libQtCore-ba1dc80c.so.4.8.7 (0x00007f2860da5000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f2860a1c000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f2860818000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f28605fb000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f28603f2000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f28600e9000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f285fed3000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f285fb08000)
/lib64/ld-linux-x86-64.so.2 (0x000055aedf75a000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f285f906000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f285f5f5000)
libSM.so.6 => not found
libICE.so.6 => not found
libXrender.so.1 => not found
libXext.so.6 => not found
libX11.so.6 => not found
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f285f382000)

Running the application results in the following error:

File "/usr/local/lib/python3.5/dist-packages/cv2/init.py", line 9, in
from .cv2 import *
ImportError: libSM.so.6: cannot open shared object file: No such file or directory

MacOS builds with FFMPEG shared libraries

I've just taken my first attempt to get the homebrew formula for FFMPEG to support compiling an LGPL version -> Homebrew/homebrew-core#18909

If I've read your FAQ answer correctly... Assuming I can get those changes into HomeBrew, or I include an appropriately customised homebrew formula in this repo, it should be possible to build a version of FFMPEG suitable for use in a MacOS wheel. Is this correct?

DLL load fails on Anaconda/Windows install (python3.dll)

After doing a simple pip install opencv-python or pip install opencv-contrib-python and trying to import the library, I ran into this issue:

λ python
Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda3\lib\site-packages\cv2\__init__.py", line 7, in <module>
    from . import cv2
ImportError: DLL load failed: The specified module could not be found.

The readme suggests installing the Visual C++ Redistributable for Visual Studio 2015
but I already had it installed (actually had Visual Studio itself installed as well).

Checking the dependencies of the pyd binary in this package (using dumpbin which comes with Visual Studio):

λ dumpbin.exe C:\Anaconda3\Lib\site-packages\cv2\cv2.cp35-win_amd64.pyd /IMPORTS | grep dll
    python3.dll
    python35.dll
    MSVFW32.dll
    AVIFIL32.dll
    AVICAP32.dll
    KERNEL32.dll
    USER32.dll
    GDI32.dll
    ole32.dll
    OLEAUT32.dll
    COMDLG32.dll
    ADVAPI32.dll

After checking if these were in the PATH I was surprised to find that python3.dll was the only one that wasn't!

Although python3.dll comes with the standard CPython install, it's not packaged with Anaconda for some reason. ContinuumIO/anaconda-issues#1394 references this and it seems like it's just not supported(?).

As a workaround suggested in that thread, I solved this by just copying python3.dll from the official CPython 3.5.2 binaries (specifically from the Windows x86-64 embeddable zip file) into C:\Anaconda3, although I imagine it would work being anywhere in your PATH.

I thought I'd share this bit of troubleshooting since Anaconda is a popular distribution among academics and so is OpenCV, so I figure I might not be the only one running into this issue. Maybe a note in the readme might help others until Anaconda resolves this?

Alternatively, the menpo/opencv3 Anaconda package would also work but I don't think it supports ffmpeg nor opencv-contrib.

For reference, I'm running on Python 3.5.2 which came with Anaconda 4.2.0 (official installer), although conda info reports a slightly newer version:

λ conda info
Current conda install:

               platform : win-64
          conda version : 4.3.16
       conda is private : False
      conda-env version : 4.3.16
    conda-build version : 2.0.2
         python version : 3.5.2.final.0
       requests version : 2.12.4
       root environment : C:\Anaconda3  (writable)
    default environment : C:\Anaconda3
       envs directories : C:\Anaconda3\envs
                          C:\Users\Talmo\AppData\Local\conda\conda\envs
                          C:\Users\Talmo\.conda\envs
          package cache : C:\Anaconda3\pkgs
                          C:\Users\Talmo\AppData\Local\conda\conda\pkgs
           channel URLs : https://repo.continuum.io/pkgs/free/win-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/win-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/win-64
                          https://repo.continuum.io/pkgs/pro/noarch
                          https://repo.continuum.io/pkgs/msys2/win-64
                          https://repo.continuum.io/pkgs/msys2/noarch
            config file : None
           offline mode : False
             user-agent : conda/4.3.16 requests/2.12.4 CPython/3.5.2 Windows/10 Windows/10.0.15063

Cheers and thanks for all the work you put into this repo!

Please publish source distribution

I would love to try opencv-python, but running into issues pip-installing it (via pygradle, https://github.com/linkedin/pygradle)

Could you by any chance also publish an sdist with your pypi package?
Wheels is great, but having an sdist (as usual) would be awesome too for things that don't quite use wheels yet (and also if one wants to rebuild the complete package on target machine)

cv2.imshow "The function is not implemented. Rebuild the library"

OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /io/opencv/modules/highgui/src/window.cpp, line 545

please, OpenCV version :3.1.0
Python version: 2.7.12
OS: Elementary OS Loki.

Thanks!

Problem caused by the change from libjpeg to libjpeg-turbo

Expected behaviour

cv2.imread in different versions should return same values for the same JPG file.

Actual behaviour

001
For this image(w=153, h=209), pixel[0, 207] will get different value between 3.3 and 3.4
screenshot from 2018-01-19 18-41-01
In 3.3, pixel[0, 207] = [115, 52, 226]
screenshot from 2018-01-19 18-42-01
In 3.4, pixel[0, 207] = [111, 52, 223]

Steps to reproduce

  • example code
    import cv2
    print(cv2.__version__)
    img = cv2.imread('001.jpg')
    print(img[0, 207])
  • operating system
    linux
  • architecture (e.g. x86)
    x64
  • opencv-python version
    3.4

I have tested the libjpeg and libjpeg-turbo, and this difference is caused by these two libs. (Test code in https://github.com/Marco-LIU/libjpeg-test)

Though the libjpeg-turbo has better performance than libjpeg, this difference will make a TRAP, and cause some machine learning models give DIFFERENT results for same input file. We've trained a model in v3.3, but got a wrong test result in v3.4 for that beauty pic.

A hand-greyscaled image is not "showed" but "written well"

Expected behaviour

A hand-greyscaled image should be imshow() on a screen.

Actual behaviour

It could be imwrite() into a file well but be not imshow() on a screen.
Am I missing something?

Steps to reproduce

  • example code
import cv2

def rgb_to_gray(src):
     r, g, b = src[:,:,0], src[:,:,1], src[:,:,2]
     gray = 0.2989 * r + 0.5870 * g + 0.1140 * b   
     return gray   
    
def main():
    img = cv2.imread("input.jpg")
    gray1 = rgb_to_gray(img)
    cv2.imwrite("gray1.jpg", gray1) # works well :-)
    cv2.imshow("gray1.jpg", gray1) # does not work :-(
    cv2.waitKey(0)
    cv2.destroyAllWindows()

if __name__ == "__main__":
    main()

  • operating system
    Windows 10

  • architecture (e.g. x86)
    x86 64bit

  • opencv-python version

numpy (1.13.3)
opencv-python (3.4.0.12)

OSX and sudo install requirements

When trying to install opencv-python on OS X (python3 installed via Homebrew), installing as an unprivileged user failed with the following message:

Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
File "/usr/local/lib/python3.6/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
File "/usr/local/lib/python3.6/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
File "/usr/local/lib/python3.6/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/usr/local/lib/python3.6/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
File "/usr/local/lib/python3.6/site-packages/pip/wheel.py", line 377, in move_wheel_files
    clobber(source, dest, False, fixer=fixer, filter=filter)
File "/usr/local/lib/python3.6/site-packages/pip/wheel.py", line 323, in clobber
    shutil.copyfile(srcfile, destfile)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shutil.py", line 121, in copyfile
    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '/usr/local/LICENSE-3RD-PARTY.txt'

After installing with sudo -H pip3 install opencv-python, the package worked.

Can the sudo requirement be eliminated by not writing the license to /usr/local/?

DLL Dependencies fail in virtual environment

First of all, thanks a lot for the work on this distribution, it has been very helpful so far!

I have been running opencv-python on a win10/x64 device with python 2.7 and 3.6 successfully. Now, I wanted to use it on a new device, also win10/x64. I've installed it through the PyCharm-GUI, in a fresh virtualenv with python 3.6. Same simple process as my other device.

When I want to import cv2, I get the error "ImportError: DLL load failed (...)". Using find_module(), the correct path to the folder cv2 in site-packages is returned. But during interpretation of init.py, the "from . import cv2" line fails.

I have checked dependencies with dependencywalker, and I have scanned for broken dlls. I have all Redistributable packages since 2010 installed (2010, 2012, 2013, 2015). I also reinstalled all those once already.

I have tried copying around cv2.pyd. At one point, the error message changed: When I used a x86 file, I got the (expected) error message "Not a win32 ...". So the pyd is found by python, but for some reason, loading it fails.

A seemingly identical setup (at least concerning the virtualenv) works on one device and not on another. Do you have a clue what could be missing?

Alpine linux

It's possible install this package for alpine linux?

Fail to open capture device (Linux and macOS builds are not compiled with FFmpeg)

My system is

Ubuntu 14.04.5 LTS
Python 3.5

I have a virtual environment with

$ pip freeze
numpy==1.11.1
opencv-python==3.1.0.2

Any try on opening a VideoCapture fails... Any of the following always return False when I test with cap.isOpened()

cap = cv2.VideoCapture(full_path_to_video_file)
cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture(-1)

I have ffmpeg installed and other OpenCV installations from source on my system work fine.
I was now giving a try with your package but it is not working. What am I missing? Do I need to link ffmpeg in some way?

Build using FFMPEG

Hi

I need to use cv2 for video files on my cloud foundry python app. Could you guide me on how to build this package with ffmpeg compatibility for ubuntu trusty?

Thanks

Missing haarcascades xml files

First thanks for putting this package together!

I'm trying to perform face detection by following this tutorial: http://docs.opencv.org/trunk/d7/d8b/tutorial_py_face_detection.html, however this leads to an error as the haarcascade xml files appear to be missing from the wheel:

import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
print(face_cascade.empty())
img = cv2.imread(<path/to/an/image/file>)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)

This should print False and then perform face detection. However, it prints True and then leads to an error:

opencv-python/opencv/modules/objdetect/src/cascadedetect.cpp:1698: error: (-215) !empty() in function detectMultiScale

It looks as though the files under https://github.com/opencv/opencv/tree/master/data are missing from the wheels so I guess that adding them should fix this.

(This works as expected using the conda package).

  • macOS Sierra 10.12.6
  • x86-64
  • opencv-python v3.3.0.10

Thanks!

[Question] Complete opencv installation using pip

Hello Olli-Pekka,

First of all I must say thank you for starting this repository. I am very new to both Python and OpenCV.
I'm trying to start a new project that will intensively use OpenCV. Could you please clarify whether it is possible or not to have a complete OpenCV installation entirely based on pip or easy_install packages? If yes, than what are the steps I should follow.

Drawing a parallel with .NET/Java, I'd like to introduce a single dependency on NuGet/Maven package of OpenCV. In my scenario, development is going to be all in Python, though.

I understand, this question does not really belong here but I can't find a better place and more knowledgeable person to get it answered.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.