Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to build using pre-build linux OpenCV Libraries? #190

Closed
scottmudge opened this issue Apr 20, 2019 · 2 comments
Closed

How to build using pre-build linux OpenCV Libraries? #190

scottmudge opened this issue Apr 20, 2019 · 2 comments

Comments

@scottmudge
Copy link

I have pre-built a custom OpenCV version (from 4.1.0) with optimizations specific to my device. I had to carefully make additional tweaks in CMake as well.

Using the instructions here, opencv-python simply re-downloads the source code, re-runs the build cycle (without my customizations/optimizations), and bundles the wheel from that.

I have the Python3 shared library (.so) built from my custom version, how do I wrap that with opencv-python?

The cv2 module works as is (installed by 'make install' from the custom OpenCV build). This is installed to /usr/local/lib/python3.6/dist-packages/cv2.

The .so file can be found in:

/usr/local/lib/python3.6/dist-packages/cv2/python-3.6/cv2.cpython-36m-x86_64-linux-gnu.so

However, with the standard OpenCV python installation, static analysis often fails, and tools like PyCharm do not see the cv2 package. The only way to get it to work is to use opencv-python.

Is it possible to wrap my existing installation with opencv-python?

@skvark
Copy link
Member

skvark commented Apr 20, 2019

In short, this is what this repository does to build the Linux version:

  1. Carefully crafts a specific environment (see .travis.yml and multibuild)
  2. Runs python setup.py bdist_wheel
    • customized scikit-build logic runs the cmake build and finally copies the resulting OpenCV binary to cv2 folder
  3. Runs audits for the wheel files with auditwheel

The build logic is defined in the setup.py file. On Linux and macOS it's somewhat specific to this repository and does not work out of the box when running python setup.py bdist_wheel locally (that's why there is no source distribution yet in PyPI: #43).

If you built a custom binary separately without any setup.py file / package structure and wish to create a custom opencv-python version, then you should probably create a custom setup.py file and run python setup.py bdist_wheel with similar folder structure. The setup.py file should copy your custom binary to the cv2 folder.

The current setup.py file could also work for you if you remove all unnecessary code from it and alter it so that it contains the additional cmake flags. After that run python setup.py bdist_wheel. The actual "wrapper" code in this package is at https://github.com/skvark/opencv-python/blob/master/cv2/__init__.py.

I hope this answers at least partly to your questions.

@skvark skvark closed this as completed Aug 29, 2019
@zrss
Copy link

zrss commented Mar 13, 2020

thx @skvark , finally i make my own opencv-python wheel, cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants