Skip to content

Commit 8e4ef80

Browse files
committed
merge
2 parents f411d56 + a115f4b commit 8e4ef80

14 files changed

+399
-362
lines changed

LICENSE-3RD-PARTY.txt

Lines changed: 232 additions & 285 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ The build can be customized with environment variables. In addition to any varia
113113

114114
- ``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.
115115
- ``ENABLE_CONTRIB`` and ``ENABLE_HEADLESS``. Set to ``1`` to build the contrib and/or headless version
116+
- ``ENABLE_JAVA``, Set to ``1`` to enable the Java client build. This is disabled by default.
116117
- ``CMAKE_ARGS``. Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build.
117118

118119
See the next section for more info about manual builds outside the CI environment.
@@ -123,7 +124,7 @@ If some dependency is not enabled in the pre-built wheels, you can also run the
123124

124125
1. Clone this repository: `git clone --recursive https://github.com/skvark/opencv-python.git`
125126
2. ``cd opencv-python``
126-
3. Add custom Cmake flags if needed, for example: `export CMAKE_FLAGS="-DSOME_FLAG=ON -DSOME_OTHER_FLAG=OFF"` (in Windows you need to set environment variables differently depending on Command Line or PowerShell)
127+
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)
127128
4. Select the version 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`
128129
5. Run ``pip wheel . --verbose``. NOTE: make sure you have the latest ``pip``, the ``pip wheel`` command replaces the old ``python setup.py bdist_wheel`` command which does not support ``pyproject.toml``.
129130
- Optional: on Linux use the `manylinux` images as a build hosts if maximum portability is needed and run `auditwheel` for the wheel after build
@@ -153,9 +154,7 @@ Third party package licenses are at [LICENSE-3RD-PARTY.txt](https://github.com/s
153154

154155
All wheels ship with [FFmpeg](http://ffmpeg.org) licensed under the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
155156

156-
Non-headless Linux wheels ship with [Qt 4.8.7](http://doc.qt.io/qt-4.8/lgpl.html) licensed under the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
157-
158-
Non-headless MacOS wheels ship with [Qt 5](http://doc.qt.io/qt-5/lgpl.html) licensed under the [LGPLv3](http://www.gnu.org/licenses/lgpl-3.0.html).
157+
Non-headless Linux and MacOS wheels ship with [Qt 5](http://doc.qt.io/qt-5/lgpl.html) licensed under the [LGPLv3](http://www.gnu.org/licenses/lgpl-3.0.html).
159158

160159
The packages include also other binaries. Full list of licenses can be found from [LICENSE-3RD-PARTY.txt](https://github.com/skvark/opencv-python/blob/master/LICENSE-3RD-PARTY.txt).
161160

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ build_script:
141141
- cmd: |
142142
"%PYTHON%/python.exe" -m pip install --upgrade pip
143143
"%PYTHON%/python.exe" -m pip install --upgrade setuptools
144-
set "CI_BUILD=True" && "%PYTHON%/python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
144+
set "CI_BUILD=1" && "%PYTHON%/python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
145145
146146
before_test:
147147
- ps: |

cv2/__init__.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,27 @@
77

88
# wildcard import above does not import "private" variables like __version__
99
# this makes them available
10-
globals().update(importlib.import_module('cv2.cv2').__dict__)
10+
globals().update(importlib.import_module("cv2.cv2").__dict__)
1111

12-
is_ci_build = False
12+
ci_and_not_headless = False
1313

1414
try:
15-
from .version import ci_build
16-
is_ci_build = ci_build
15+
from .version import ci_build, headless
16+
17+
ci_and_not_headless = ci_build and not headless
1718
except:
1819
pass
1920

2021
# the Qt plugin is included currently only in the pre-built wheels
21-
if sys.platform == 'darwin' and is_ci_build:
22-
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.join(
23-
os.path.dirname(os.path.abspath(__file__)), 'qt', 'plugins'
22+
if (
23+
sys.platform == "darwin" or sys.platform.startswith("linux")
24+
) and ci_and_not_headless:
25+
os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.path.join(
26+
os.path.dirname(os.path.abspath(__file__)), "qt", "plugins"
27+
)
28+
29+
# Qt will throw warning on Linux if fonts are not found
30+
if sys.platform.startswith("linux") and ci_and_not_headless:
31+
os.environ["QT_QPA_FONTDIR"] = os.path.join(
32+
os.path.dirname(os.path.abspath(__file__)), "qt", "fonts"
2433
)

cv2/data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import os
22

3-
haarcascades = os.path.join(os.path.dirname(__file__), '')
3+
haarcascades = os.path.join(os.path.dirname(__file__), "")

docker/manylinux2014/Dockerfile_i686

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
FROM quay.io/pypa/manylinux2014_i686:latest
22

3-
RUN yum install bzip2-devel curl-devel zlib-devel qt-devel -y
3+
RUN yum install bzip2-devel curl-devel zlib-devel xcb-util-renderutil-devel xcb-util-devel xcb-util-image-devel xcb-util-keysyms-devel xcb-util-wm-devel mesa-libGL-devel libxkbcommon-devel libxkbcommon-x11-devel libXi-devel freetype-devel -y
4+
5+
RUN curl -O -L https://download.qt.io/official_releases/qt/5.15/5.15.0/single/qt-everywhere-src-5.15.0.tar.xz && \
6+
tar -xf qt-everywhere-src-5.15.0.tar.xz && \
7+
cd qt-everywhere* && \
8+
export MAKEFLAGS=-j$(nproc) && \
9+
./configure -prefix /opt/Qt5.15.0 -release -opensource -confirm-license -qtnamespace QtOpenCVPython -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -no-dbus -skip qt3d -skip qtactiveqt -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmultimedia -skip qtpurchasing -skip qtqa -skip qtremoteobjects -skip qtrepotools -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qttranslations -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip xmlpatterns -skip declarative -make libs && \
10+
make && \
11+
make install && \
12+
cd .. && \
13+
rm -rf qt-everywhere-src-5.15.0 && \
14+
rm qt-everywhere-src-5.15.0.tar.xz
15+
16+
ENV QTDIR /opt/Qt5.15.0
17+
ENV PATH "$QTDIR/bin:$PATH"
418

519
RUN mkdir ~/ffmpeg_sources && \
620
cd ~/ffmpeg_sources && \

docker/manylinux2014/Dockerfile_x86_64

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
FROM quay.io/pypa/manylinux2014_x86_64:latest
22

3-
RUN yum install bzip2-devel curl-devel zlib-devel qt-devel -y
3+
RUN yum install bzip2-devel curl-devel zlib-devel xcb-util-renderutil-devel xcb-util-devel xcb-util-image-devel xcb-util-keysyms-devel xcb-util-wm-devel mesa-libGL-devel libxkbcommon-devel libxkbcommon-x11-devel libXi-devel freetype-devel -y
4+
5+
RUN curl -O -L https://download.qt.io/official_releases/qt/5.15/5.15.0/single/qt-everywhere-src-5.15.0.tar.xz && \
6+
tar -xf qt-everywhere-src-5.15.0.tar.xz && \
7+
cd qt-everywhere* && \
8+
export MAKEFLAGS=-j$(nproc) && \
9+
./configure -prefix /opt/Qt5.15.0 -release -opensource -confirm-license -qtnamespace QtOpenCVPython -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -no-dbus -skip qt3d -skip qtactiveqt -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmultimedia -skip qtpurchasing -skip qtqa -skip qtremoteobjects -skip qtrepotools -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qttranslations -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip xmlpatterns -skip declarative -make libs && \
10+
make && \
11+
make install && \
12+
cd .. && \
13+
rm -rf qt-everywhere-src-5.15.0 && \
14+
rm qt-everywhere-src-5.15.0.tar.xz
15+
16+
ENV QTDIR /opt/Qt5.15.0
17+
ENV PATH "$QTDIR/bin:$PATH"
418

519
RUN mkdir ~/ffmpeg_sources && \
620
cd ~/ffmpeg_sources && \

find_version.py

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,66 @@
33
import subprocess
44

55
if __name__ == "__main__":
6-
contrib = sys.argv[1]
7-
headless = sys.argv[2]
8-
ci_build = sys.argv[3]
9-
10-
opencv_version = ""
11-
# dig out the version from OpenCV sources
12-
version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp"
13-
14-
with open(version_file_path, 'r') as f:
15-
for line in f:
16-
words = line.split()
17-
18-
if "CV_VERSION_MAJOR" in words:
19-
opencv_version += words[2]
20-
opencv_version += "."
21-
22-
if "CV_VERSION_MINOR" in words:
23-
opencv_version += words[2]
24-
opencv_version += "."
25-
26-
if "CV_VERSION_REVISION" in words:
27-
opencv_version += words[2]
28-
break
29-
30-
# used in local dev releases
31-
git_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).splitlines()[0].decode()
32-
# this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
33-
try:
34-
tag = subprocess.check_output(['git', 'describe', '--tags'], stderr = subprocess.STDOUT).splitlines()[0].decode().split('-')
35-
except subprocess.CalledProcessError as e:
36-
# no tags reachable (e.g. on a topic branch in a fork), see
37-
# https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
38-
if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
39-
tag=[]
40-
else:
41-
print(e.output); raise
42-
43-
if len(tag) == 1:
44-
# tag identifies the build and should be a sequential revision number
45-
version = tag[0]
46-
opencv_version += ".{}".format(version)
47-
else:
48-
# local version identifier, not to be published on PyPI
49-
version = git_hash
50-
opencv_version += "+{}".format(version)
51-
52-
with open('cv2/version.py', 'w') as f:
53-
f.write("opencv_version = \"{}\"\n".format(opencv_version))
54-
f.write("contrib = {}\n".format(contrib))
55-
f.write("headless = {}\n".format(headless))
56-
f.write("ci_build = {}".format(ci_build))
6+
contrib = sys.argv[1]
7+
headless = sys.argv[2]
8+
ci_build = sys.argv[3]
9+
10+
opencv_version = ""
11+
# dig out the version from OpenCV sources
12+
version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp"
13+
14+
with open(version_file_path, "r") as f:
15+
for line in f:
16+
words = line.split()
17+
18+
if "CV_VERSION_MAJOR" in words:
19+
opencv_version += words[2]
20+
opencv_version += "."
21+
22+
if "CV_VERSION_MINOR" in words:
23+
opencv_version += words[2]
24+
opencv_version += "."
25+
26+
if "CV_VERSION_REVISION" in words:
27+
opencv_version += words[2]
28+
break
29+
30+
# used in local dev releases
31+
git_hash = (
32+
subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
33+
.splitlines()[0]
34+
.decode()
35+
)
36+
# this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
37+
try:
38+
tag = (
39+
subprocess.check_output(
40+
["git", "describe", "--tags"], stderr=subprocess.STDOUT
41+
)
42+
.splitlines()[0]
43+
.decode()
44+
.split("-")
45+
)
46+
except subprocess.CalledProcessError as e:
47+
# no tags reachable (e.g. on a topic branch in a fork), see
48+
# https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
49+
if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
50+
tag = []
51+
else:
52+
print(e.output)
53+
raise
54+
55+
if len(tag) == 1:
56+
# tag identifies the build and should be a sequential revision number
57+
version = tag[0]
58+
opencv_version += ".{}".format(version)
59+
else:
60+
# local version identifier, not to be published on PyPI
61+
version = git_hash
62+
opencv_version += "+{}".format(version)
63+
64+
with open("cv2/version.py", "w") as f:
65+
f.write('opencv_version = "{}"\n'.format(opencv_version))
66+
f.write("contrib = {}\n".format(contrib))
67+
f.write("headless = {}\n".format(headless))
68+
f.write("ci_build = {}".format(ci_build))

patch_auditwheel_whitelist.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from os.path import join, dirname, abspath
2+
import json
3+
4+
from auditwheel import policy
5+
6+
policies = None
7+
8+
with open(join(dirname(abspath(policy.__file__)), "policy.json")) as f:
9+
policies = json.load(f)
10+
11+
for p in policies:
12+
if p["name"] == "manylinux2014":
13+
p["lib_whitelist"].append("libxcb.so.1")
14+
15+
with open(join(dirname(abspath(policy.__file__)), "policy.json"), "w") as f:
16+
f.write(json.dumps(policies))

patches/patchQtPlugins

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt
2-
index 8ccad4d03a..0d5e2a79e9 100644
2+
index 4c0b3880fc..dffa0a4caa 100644
33
--- a/opencv/CMakeLists.txt
44
+++ b/opencv/CMakeLists.txt
5-
@@ -1164,6 +1164,7 @@ if(WITH_QT OR HAVE_QT)
5+
@@ -1187,6 +1187,13 @@ if(WITH_QT OR HAVE_QT)
66
if(HAVE_QT5)
77
status(" QT:" "YES (ver ${Qt5Core_VERSION_STRING})")
88
status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt5OpenGL_LIBRARIES} ${Qt5OpenGL_VERSION_STRING})" ELSE NO)
9-
+ install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
9+
+ if(APPLE)
10+
+ install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
11+
+ endif()
12+
+ if(UNIX AND NOT APPLE)
13+
+ install(DIRECTORY /opt/Qt5.15.0/plugins DESTINATION lib/qt)
14+
+ install(DIRECTORY /usr/share/fonts DESTINATION lib/qt)
15+
+ endif()
1016
elseif(HAVE_QT)
1117
status(" QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
1218
status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)

setup.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ def main():
1414
os.chdir(os.path.dirname(os.path.abspath(__file__)))
1515

1616
CI_BUILD = os.environ.get("CI_BUILD", "False")
17-
is_CI_build = True if CI_BUILD == "True" else False
17+
is_CI_build = True if CI_BUILD == "1" else False
1818
cmake_source_dir = "opencv"
1919
minimum_supported_numpy = "1.13.1"
2020
build_contrib = get_build_env_var_by_name("contrib")
2121
build_headless = get_build_env_var_by_name("headless")
22+
build_java = 'ON' if get_build_env_var_by_name("java") else 'OFF'
2223

2324
if sys.version_info[:2] >= (3, 6):
2425
minimum_supported_numpy = "1.13.3"
@@ -121,6 +122,8 @@ def main():
121122
"-DPYTHON3_LIBRARY=%s" % python_lib_path,
122123
"-DBUILD_opencv_python3=ON",
123124
"-DBUILD_opencv_python2=OFF",
125+
# Disable the Java build by default as it is not needed
126+
"-DBUILD_opencv_java=%s" % build_java,
124127
# When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
125128
"-DOPENCV_SKIP_PYTHON_LOADER=ON",
126129
# Relative dir to install the built module to in the build tree.
@@ -158,16 +161,30 @@ def main():
158161

159162
# OS-specific components during CI builds
160163
if is_CI_build:
161-
if sys.platform.startswith("linux") and not build_headless:
162-
cmake_args.append("-DWITH_QT=4")
163164

164-
if sys.platform == "darwin" and not build_headless:
165-
if "bdist_wheel" in sys.argv:
166-
cmake_args.append("-DWITH_QT=5")
165+
if not build_headless and "bdist_wheel" in sys.argv:
166+
cmake_args.append("-DWITH_QT=5")
167+
subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
168+
169+
if sys.platform.startswith("linux"):
170+
rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
171+
(r"lib/qt/plugins/platforms/libqxcb\.so")
172+
]
173+
174+
# add fonts for Qt5
175+
fonts = []
176+
for file in os.listdir("/usr/share/fonts/dejavu"):
177+
if file.endswith(".ttf"):
178+
fonts.append(
179+
(r"lib/qt/fonts/dejavu/%s\.ttf" % file.split(".")[0])
180+
)
181+
182+
rearrange_cmake_output_data["cv2.qt.fonts"] = fonts
183+
184+
if sys.platform == "darwin":
167185
rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
168186
(r"lib/qt/plugins/platforms/libqcocoa\.dylib")
169187
]
170-
subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
171188

172189
if sys.platform.startswith("linux"):
173190
cmake_args.append("-DWITH_V4L=ON")

tests/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ def test_import(self):
1212
def test_video_capture(self):
1313

1414
import cv2
15+
1516
cap = cv2.VideoCapture("SampleVideo_1280x720_1mb.mp4")
1617
self.assertTrue(cap.isOpened())

travis_config.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function bdist_wheel_cmd {
1616
local abs_wheelhouse=$1
1717
CI_BUILD=1 pip wheel --wheel-dir="$PWD/dist" . --verbose $BDIST_PARAMS
1818
cp dist/*.whl $abs_wheelhouse
19+
/opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py
1920
if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
2021
}
2122

@@ -24,6 +25,7 @@ if [ -n "$IS_OSX" ]; then
2425
export MAKEFLAGS="-j$(sysctl -n hw.ncpu)"
2526
else
2627
echo " > Linux environment "
28+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt5.15.0/lib
2729
export MAKEFLAGS="-j$(grep -E '^processor[[:space:]]*:' /proc/cpuinfo | wc -l)"
2830
fi
2931

0 commit comments

Comments
 (0)