From 424ec6a1f8817068eab8ea964374e948ecf8b365 Mon Sep 17 00:00:00 2001
From: native-api <ivan_pozdeev@mail.ru>
Date: Fri, 1 Dec 2017 09:06:09 +0300
Subject: [PATCH 001/566] PATH editing only needed in Windows (#55)

* PATH editing only needed in Windows

* DLL load works without in Windows, too
---
 cv2/__init__.py | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/cv2/__init__.py b/cv2/__init__.py
index 74b5b896..1410d1ee 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -1,10 +1,5 @@
-import sys
-import os
 import importlib
 
-# FFmpeg dll is not found on Windows without this
-os.environ["PATH"] += os.pathsep + os.path.dirname(os.path.realpath(__file__))
-
 # make IDE's (PyCharm) autocompletion happy
 from .cv2 import *
 

From 228b6abf65fb94f39e1122f1e17e932e8c19a3c0 Mon Sep 17 00:00:00 2001
From: Jonathan DEKHTIAR <DEKHTIARJonathan@users.noreply.github.com>
Date: Thu, 14 Dec 2017 07:42:58 +0100
Subject: [PATCH 002/566]  Update setup.py file to flag compatibility with
 Python 2.7-3.4-3.5-3.6 (#57)

---
 setup.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/setup.py b/setup.py
index c556ff82..587c285f 100644
--- a/setup.py
+++ b/setup.py
@@ -99,6 +99,12 @@ def __len__(self):
         'Operating System :: POSIX',
         'Operating System :: Unix',
         'Programming Language :: Python',
+        'Programming Language :: Python :: 2',
+        'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3',
+        'Programming Language :: Python :: 3.4',
+        'Programming Language :: Python :: 3.5',
+        'Programming Language :: Python :: 3.6',
         'Programming Language :: C++',
         'Programming Language :: Python :: Implementation :: CPython',
         'Topic :: Scientific/Engineering',

From 731e0d4361d230cdddb4acaf7f50cea520c8f246 Mon Sep 17 00:00:00 2001
From: Samuel Bishop <lucractius@me.com>
Date: Wed, 20 Dec 2017 00:17:48 +0800
Subject: [PATCH 003/566] MacOS FFMpeg builds.  (#56)

* Build LGPL FFmpeg shared libraries.

OpenCV should automatically use them.

* Also disable the x264 encoder.

* Also disable xvid

* Confirm FFmpeg is being built correctly.

* Make log easier to read.

* Travis-CI Mac environment only has 2 cores.
---
 travis/build-wheels-osx.sh | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/travis/build-wheels-osx.sh b/travis/build-wheels-osx.sh
index a48f89bc..9ecc9ea5 100644
--- a/travis/build-wheels-osx.sh
+++ b/travis/build-wheels-osx.sh
@@ -10,9 +10,15 @@ echo 'PIP and brew installs'
 
 pip install "$BUILD_DEPENDS"
 
+echo 'Installing QT4'
 brew tap cartr/qt4
 brew tap-pin cartr/qt4
 brew install qt@4
+echo '-----------------'
+echo 'Installing FFmpeg'
+brew install ffmpeg --without-x264 --without-xvid --without-gpl
+brew info ffmpeg
+echo '-----------------'
 
 qmake -query
 
@@ -113,13 +119,13 @@ echo 'Begin build'
 
 if [[ $PYTHON_VERSION == 2* ]]; then
   echo 'Build for Py2'
-  make -j8 opencv_python2
+  make -j2 opencv_python2
 
 fi
 
 if [[ $PYTHON_VERSION == 3* ]]; then
   echo 'Build for Py3'
-  make -j8 opencv_python3
+  make -j2 opencv_python3
 
 fi
 

From 8b596d06cbf7de99519173700bff0112206ab383 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Wed, 20 Dec 2017 12:38:53 +0200
Subject: [PATCH 004/566] Linux FFmpeg + libjpeg-turbo builds (#59)

* try new images, make sure that ffmpeg is built as LGPL library

* prepend ~/bin to PATH

* enable linux video test

* add ffmpeg pkg config location

* cherry-pick FFmpeg fix from OpenCV upstream

* add FFmpeg lib path to linker flags

* add also libjepg-turbo

* add additional flags

* add missing $

* update READMEs

* enable all video tests
---
 README.rst             | 14 ++------------
 README_CONTRIB.rst     | 14 ++------------
 tests/test.py          | 11 +++++------
 travis/build-wheels.sh | 43 ++++++++++++++++++++++++++++++++++++++----
 4 files changed, 48 insertions(+), 34 deletions(-)

diff --git a/README.rst b/README.rst
index 6f8eed53..1d9d0eb0 100644
--- a/README.rst
+++ b/README.rst
@@ -11,10 +11,6 @@ This enables super fast (usually < 10 seconds) OpenCV installation for Python.
 
 If you need only OpenCV Python bindings, no separate OpenCV installation is required.
 
-**IMPORTANT NOTE**
-
-MacOS and Linux packages do not support video related functionality (not compiled with FFmpeg).
-
 Installation and Usage
 ----------------------
 
@@ -49,7 +45,7 @@ A: The wheel package format and manylinux builds are pretty new things. Most lik
 
 **Q: I need contrib modules?**
 
-A: Please install `opencv-contrib-python <https://pypi.python.org/pypi/opencv-contrib-python>`__ instead. However, note that commercial usage might be restricted in some countries since the contrib modules contain some non-free/patented algorithms.
+A: Please install `opencv-contrib-python <https://pypi.python.org/pypi/opencv-contrib-python>`__ instead. However, note that commercial usage might be restricted in some countries since the contrib modules might contain some non-free/patented algorithms.
 
 **Q: Import fails on Windows to some DLL load error?**
 
@@ -61,12 +57,6 @@ See also `this issue <https://github.com/skvark/opencv-python/issues/36>`__ if y
 
 A: Make sure you have removed old manual installations of OpenCV Python bindings (cv2.so or cv2.pyd in site-packages).
 
-**Q: Why I can't open video files on GNU/Linux distribution X or on macOS?**
-
-A: OpenCV video I/O depends heavily on FFmpeg. Manylinux and macOS OpenCV binaries are not compiled against it.
-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.
-Adding FFmpeg as an additional dependency without a "universal" FFmpeg build (e.g. LGPL licensed build like in the Windows wheels) the goal is considerably harder to achieve. This might change in the future.
-
 Documentation for opencv-python
 -------------------------------
 
@@ -139,7 +129,7 @@ OpenCV itself is available under `3-clause BSD
 License <https://github.com/opencv/opencv/blob/master/LICENSE>`__
 (`LICENSE-3RD-PARTY.txt <https://github.com/skvark/opencv-python/blob/master/LICENSE-3RD-PARTY.txt>`__).
 
-Windows wheels ship with `FFmpeg <http://ffmpeg.org>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__.
+All wheels ship with `FFmpeg <http://ffmpeg.org>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__.
 
 Linux and MacOS 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>`__.
 
diff --git a/README_CONTRIB.rst b/README_CONTRIB.rst
index 11bf61e7..53f60e0b 100644
--- a/README_CONTRIB.rst
+++ b/README_CONTRIB.rst
@@ -3,7 +3,7 @@ OpenCV on Wheels
 
 **Unofficial** OpenCV packages for Python with contrib modules.
 
-**Note: the usage of opencv-contrib-python might be restricted in some countries since the contrib package contains some patented algorithms/non-free modules.**
+**Note: the (commercial) usage of opencv-contrib-python might be restricted in some countries since the contrib package might contain some patented algorithms/non-free modules.**
 
 If you are looking for a version without the contrib modules, please install `opencv-python <https://pypi.python.org/pypi/opencv-python>`__ instead.
 
@@ -12,10 +12,6 @@ This enables super fast (usually < 10 seconds) OpenCV installation for Python.
 
 If you need only OpenCV Python bindings, no separate OpenCV installation is required.
 
-**IMPORTANT NOTE**
-
-MacOS and Linux wheels do not support video related functionality (not compiled with FFmpeg).
-
 Installation and Usage
 ----------------------
 
@@ -57,12 +53,6 @@ See also `this issue <https://github.com/skvark/opencv-python/issues/36>`__ if y
 
 A: Make sure you have removed old manual installations of OpenCV Python bindings (cv2.so or cv2.pyd in site-packages).
 
-**Q: Why I can't open video files on GNU/Linux distribution X or on macOS?**
-
-A: OpenCV video I/O depends heavily on FFmpeg. Manylinux and macOS OpenCV binaries provided withing these packages are not compiled against it.
-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.
-Adding FFmpeg as an additional dependency without a "universal" FFmpeg build (e.g. LGPL licensed build like in the Windows wheels) the goal is considerably harder to achieve. This might change in the future.
-
 Documentation for opencv-python
 -------------------------------
 
@@ -135,7 +125,7 @@ OpenCV itself is available under `3-clause BSD
 License <https://github.com/opencv/opencv/blob/master/LICENSE>`__
 (`LICENSE-3RD-PARTY.txt <https://github.com/skvark/opencv-python/blob/master/LICENSE-3RD-PARTY.txt>`__).
 
-Windows wheels ship with `FFmpeg <http://ffmpeg.org>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__.
+All wheels ship with `FFmpeg <http://ffmpeg.org>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__.
 
 Linux and MacOS 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>`__.
 
diff --git a/tests/test.py b/tests/test.py
index cd560763..e520814f 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -1,5 +1,6 @@
 import unittest
-import os
+import sys
+
 
 class OpenCVTest(unittest.TestCase):
     """ Simple functionality tests. """
@@ -10,8 +11,6 @@ def test_import(self):
 
     def test_video_capture(self):
 
-        if os.name != 'posix':
-            import cv2
-
-            cap = cv2.VideoCapture("SampleVideo_1280x720_1mb.mp4")
-            self.assertTrue(cap.isOpened())
\ No newline at end of file
+        import cv2
+        cap = cv2.VideoCapture("SampleVideo_1280x720_1mb.mp4")
+        self.assertTrue(cap.isOpened())
diff --git a/travis/build-wheels.sh b/travis/build-wheels.sh
index 4378d768..6a8dd0a7 100755
--- a/travis/build-wheels.sh
+++ b/travis/build-wheels.sh
@@ -26,8 +26,27 @@ echo "Python numpy version: $PYTHON_NUMPY_VERSION"
 # Begin build
 echo 'Begin build'
 cd opencv
+
+# FFmpeg version is too new.
+# This is a temporary fix from upstream until we have a new OpenCV release.
+git cherry-pick b1d208891b9f
+
 mkdir build
 
+export JPEG_INCLUDE_DIR="/opt/libjpeg-turbo/include"
+export JPEG_LIBRARY="/opt/libjpeg-turbo/lib32/libjpeg.a"
+
+MACHINE_TYPE=$(uname -m)
+if [[ ${MACHINE_TYPE} == 'x86_64' ]]; then
+  JPEG_LIBRARY="/opt/libjpeg-turbo/lib64/libjpeg.a"
+fi
+
+export LDFLAGS=-L/root/ffmpeg_build/lib
+export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/root/ffmpeg_build/lib/pkgconfig
+export PATH=~/bin:$PATH
+
+ffmpeg -L
+
 export QTDIR=/opt/Qt4.8.7
 export PATH=$QTDIR/bin:$PATH
 
@@ -45,7 +64,11 @@ if [[ $PYTHON_VERSION == 2* ]] && [[ $ENABLE_CONTRIB == 0 ]]; then
     -DPYTHON2_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
     -DPYTHON2_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
     -DPYTHON2_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
-    -DPYTHON2_NUMPY_VERSION="$PYTHON_NUMPY_VERSION"
+    -DPYTHON2_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
+    -DWITH_JPEG=ON \
+    -DBUILD_JPEG=OFF \
+    -DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
+    -DJPEG_LIBRARY="$JPEG_LIBRARY"
 
 fi
 
@@ -61,7 +84,11 @@ if [[ $PYTHON_VERSION == 3* ]] && [[ $ENABLE_CONTRIB == 0 ]]; then
     -DPYTHON3_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
     -DPYTHON3_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
     -DPYTHON3_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
-    -DPYTHON3_NUMPY_VERSION="$PYTHON_NUMPY_VERSION"
+    -DPYTHON3_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
+    -DWITH_JPEG=ON \
+    -DBUILD_JPEG=OFF \
+    -DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
+    -DJPEG_LIBRARY="$JPEG_LIBRARY"
 
 fi
 
@@ -77,7 +104,11 @@ if [[ $PYTHON_VERSION == 2* ]] && [[ $ENABLE_CONTRIB == 1 ]]; then
     -DPYTHON2_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
     -DPYTHON2_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
     -DPYTHON2_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
-    -DPYTHON2_NUMPY_VERSION="$PYTHON_NUMPY_VERSION"
+    -DPYTHON2_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
+    -DWITH_JPEG=ON \
+    -DBUILD_JPEG=OFF \
+    -DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
+    -DJPEG_LIBRARY="$JPEG_LIBRARY"
 
 fi
 
@@ -93,7 +124,11 @@ if [[ $PYTHON_VERSION == 3* ]] && [[ $ENABLE_CONTRIB == 1 ]]; then
     -DPYTHON3_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
     -DPYTHON3_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
     -DPYTHON3_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
-    -DPYTHON3_NUMPY_VERSION="$PYTHON_NUMPY_VERSION"
+    -DPYTHON3_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
+    -DWITH_JPEG=ON \
+    -DBUILD_JPEG=OFF \
+    -DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
+    -DJPEG_LIBRARY="$JPEG_LIBRARY"
 
 fi
 

From 635f492340f552f60239be32fe7825aab9512df6 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 20 Dec 2017 19:18:27 +0200
Subject: [PATCH 005/566] try to enable v4l (which should be on by default...)

---
 travis/build-wheels.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/travis/build-wheels.sh b/travis/build-wheels.sh
index 6a8dd0a7..990b9d86 100755
--- a/travis/build-wheels.sh
+++ b/travis/build-wheels.sh
@@ -68,7 +68,8 @@ if [[ $PYTHON_VERSION == 2* ]] && [[ $ENABLE_CONTRIB == 0 ]]; then
     -DWITH_JPEG=ON \
     -DBUILD_JPEG=OFF \
     -DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
-    -DJPEG_LIBRARY="$JPEG_LIBRARY"
+    -DJPEG_LIBRARY="$JPEG_LIBRARY" \
+    -DWITH_V4L=ON
 
 fi
 
@@ -88,7 +89,8 @@ if [[ $PYTHON_VERSION == 3* ]] && [[ $ENABLE_CONTRIB == 0 ]]; then
     -DWITH_JPEG=ON \
     -DBUILD_JPEG=OFF \
     -DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
-    -DJPEG_LIBRARY="$JPEG_LIBRARY"
+    -DJPEG_LIBRARY="$JPEG_LIBRARY" \
+    -DWITH_V4L=ON
 
 fi
 
@@ -108,7 +110,8 @@ if [[ $PYTHON_VERSION == 2* ]] && [[ $ENABLE_CONTRIB == 1 ]]; then
     -DWITH_JPEG=ON \
     -DBUILD_JPEG=OFF \
     -DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
-    -DJPEG_LIBRARY="$JPEG_LIBRARY"
+    -DJPEG_LIBRARY="$JPEG_LIBRARY" \
+     -DWITH_V4L=ON
 
 fi
 
@@ -128,7 +131,8 @@ if [[ $PYTHON_VERSION == 3* ]] && [[ $ENABLE_CONTRIB == 1 ]]; then
     -DWITH_JPEG=ON \
     -DBUILD_JPEG=OFF \
     -DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
-    -DJPEG_LIBRARY="$JPEG_LIBRARY"
+    -DJPEG_LIBRARY="$JPEG_LIBRARY" \
+    -DWITH_V4L=ON
 
 fi
 

From 49237b58f9aa421dfe1154a99323e57854486de5 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 20 Dec 2017 20:05:05 +0200
Subject: [PATCH 006/566] try if docker ENV command worked

---
 travis/build-wheels.sh | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/travis/build-wheels.sh b/travis/build-wheels.sh
index 990b9d86..b61bd96c 100755
--- a/travis/build-wheels.sh
+++ b/travis/build-wheels.sh
@@ -33,23 +33,7 @@ git cherry-pick b1d208891b9f
 
 mkdir build
 
-export JPEG_INCLUDE_DIR="/opt/libjpeg-turbo/include"
-export JPEG_LIBRARY="/opt/libjpeg-turbo/lib32/libjpeg.a"
-
-MACHINE_TYPE=$(uname -m)
-if [[ ${MACHINE_TYPE} == 'x86_64' ]]; then
-  JPEG_LIBRARY="/opt/libjpeg-turbo/lib64/libjpeg.a"
-fi
-
-export LDFLAGS=-L/root/ffmpeg_build/lib
-export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/root/ffmpeg_build/lib/pkgconfig
-export PATH=~/bin:$PATH
-
 ffmpeg -L
-
-export QTDIR=/opt/Qt4.8.7
-export PATH=$QTDIR/bin:$PATH
-
 qmake -query
 
 if [[ $PYTHON_VERSION == 2* ]] && [[ $ENABLE_CONTRIB == 0 ]]; then

From 2d0bad83e4484c00d791b392fc58224239b9ed8e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 21 Dec 2017 20:23:21 +0200
Subject: [PATCH 007/566] add haarcascade xml files to the package

---
 .travis.yml          | 1 +
 appveyor/build.cmd   | 1 +
 cv2/__init__.py      | 5 +++--
 cv2/data/__init__.py | 3 +++
 setup.py             | 5 +++--
 5 files changed, 11 insertions(+), 4 deletions(-)
 create mode 100644 cv2/data/__init__.py

diff --git a/.travis.yml b/.travis.yml
index 8ef74530..52778286 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -203,6 +203,7 @@ before_install:
     - source multibuild/travis_steps.sh
     - python find_version.py
     - cp LICENSE*.txt cv2/
+    - cp opencv/data/haarcascades/*.xml cv2/data/
     - before_install
 
 install:
diff --git a/appveyor/build.cmd b/appveyor/build.cmd
index 2d85a693..a5c802a9 100644
--- a/appveyor/build.cmd
+++ b/appveyor/build.cmd
@@ -26,6 +26,7 @@ if %PYTHON_VERSION% LSS 3 xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\%BUILD_DIR%\lib\
 
 xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\%BUILD_DIR%\bin\Release\*.dll" .\cv2 /I
 xcopy "%APPVEYOR_BUILD_FOLDER%\LICENSE*.txt" .\cv2 /I
+xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\data\haarcascades\*.xml" .\cv2\data /I
 
 dir
 
diff --git a/cv2/__init__.py b/cv2/__init__.py
index 1410d1ee..ca2cb308 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -1,8 +1,9 @@
 import importlib
+import os
 
-# make IDE's (PyCharm) autocompletion happy
 from .cv2 import *
+from .data import *
 
 # wildcard import above does not import "private" variables like __version__
 # this makes them available
-globals().update(importlib.import_module('cv2.cv2').__dict__)
\ No newline at end of file
+globals().update(importlib.import_module('cv2.cv2').__dict__)
diff --git a/cv2/data/__init__.py b/cv2/data/__init__.py
new file mode 100644
index 00000000..12c818d9
--- /dev/null
+++ b/cv2/data/__init__.py
@@ -0,0 +1,3 @@
+import os
+
+haarcascades = os.path.join(os.path.dirname(__file__), '')
diff --git a/setup.py b/setup.py
index 587c285f..2a89aa6f 100644
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
-from setuptools import setup
+from setuptools import setup, find_packages
 from setuptools.dist import Distribution
 import pip
 import os
@@ -49,6 +49,7 @@
     package_data['cv2'] = ['*.pyd', '*.dll']
 
 package_data['cv2'] += ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"]
+package_data[''] = ['*.xml']
 
 """
 
@@ -80,7 +81,7 @@ def __len__(self):
       license='MIT',
       description='Wrapper package for OpenCV python bindings.',
       long_description=long_description,
-      packages=['cv2'],
+      packages=find_packages(),
       package_data=package_data,
       maintainer="Olli-Pekka Heinisuo",
       include_package_data=True,

From 72632a74d072a4522fd1ca02e1bf3cde1215fa73 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 22 Dec 2017 17:04:54 +0200
Subject: [PATCH 008/566] add note about haarcascades helper to readmes

---
 README.rst         | 4 ++++
 README_CONTRIB.rst | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/README.rst b/README.rst
index 1d9d0eb0..795a359b 100644
--- a/README.rst
+++ b/README.rst
@@ -28,6 +28,10 @@ Installation and Usage
 
 ``import cv2``
 
+The package contains 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")``
+
 5. Read `OpenCV documentation <http://docs.opencv.org/>`__
 
 6. Before opening a new issue, read the FAQ below and have a look at the other issues which are already open.
diff --git a/README_CONTRIB.rst b/README_CONTRIB.rst
index 53f60e0b..0fe36e50 100644
--- a/README_CONTRIB.rst
+++ b/README_CONTRIB.rst
@@ -28,6 +28,10 @@ Installation and Usage
 
 ``import cv2``
 
+The package contains 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")``
+
 5. Read `OpenCV documentation <http://docs.opencv.org/>`__
 
 6. Before opening a new issue, read the FAQ below and have a look at the other issues which are already open.

From 1d15de3d3c706dbd8f13bd21ffaa868418b4602c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 22 Dec 2017 21:57:18 +0200
Subject: [PATCH 009/566] bump OpenCV version to 3.3.1

---
 .travis.yml    | 2 +-
 opencv         | 2 +-
 opencv_contrib | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 52778286..e3d73151 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,7 +2,7 @@ env:
     global:
         - REPO_DIR=opencv
         # Commit from opencv that you want to build
-        - BUILD_COMMIT=4af3ca4e4d7be246a49d751a79c6392e848ac2aa
+        - BUILD_COMMIT=a871f9e4f7d83dc5851f965bdba5cd01bb7527fe
         # pip dependencies to _build_ your project
         - BUILD_DEPENDS="numpy==1.11.1"
         # pip dependencies to _test_ your project.  Include any dependencies
diff --git a/opencv b/opencv
index 4af3ca4e..a871f9e4 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 4af3ca4e4d7be246a49d751a79c6392e848ac2aa
+Subproject commit a871f9e4f7d83dc5851f965bdba5cd01bb7527fe
diff --git a/opencv_contrib b/opencv_contrib
index 2a9d1b22..0bd061f0 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 2a9d1b22ed76eb22fad1a5edf6faf4d05f207b13
+Subproject commit 0bd061f07b665a7fb3f744122550393b337c50e5

From 4fc48d6134f6284900f48b055c29a08442f52450 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 27 Dec 2017 17:52:16 +0200
Subject: [PATCH 010/566] bump OpenCV version to 3.4.0

---
 .travis.yml    | 2 +-
 opencv         | 2 +-
 opencv_contrib | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index e3d73151..26493e18 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,7 +2,7 @@ env:
     global:
         - REPO_DIR=opencv
         # Commit from opencv that you want to build
-        - BUILD_COMMIT=a871f9e4f7d83dc5851f965bdba5cd01bb7527fe
+        - BUILD_COMMIT=6d4f66472e14b29b8e1623859cfebfdc67f677c3
         # pip dependencies to _build_ your project
         - BUILD_DEPENDS="numpy==1.11.1"
         # pip dependencies to _test_ your project.  Include any dependencies
diff --git a/opencv b/opencv
index a871f9e4..6d4f6647 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit a871f9e4f7d83dc5851f965bdba5cd01bb7527fe
+Subproject commit 6d4f66472e14b29b8e1623859cfebfdc67f677c3
diff --git a/opencv_contrib b/opencv_contrib
index 0bd061f0..81ca8dab 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 0bd061f07b665a7fb3f744122550393b337c50e5
+Subproject commit 81ca8dab8697ae6acc5d8bc45f03b6b10f4d7d24

From 4b071374a96136bb315e4ae8ca0bd1681959a453 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 27 Dec 2017 17:53:29 +0200
Subject: [PATCH 011/566] remove cherry-pick

---
 travis/build-wheels.sh | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/travis/build-wheels.sh b/travis/build-wheels.sh
index b61bd96c..c6598d20 100755
--- a/travis/build-wheels.sh
+++ b/travis/build-wheels.sh
@@ -27,10 +27,6 @@ echo "Python numpy version: $PYTHON_NUMPY_VERSION"
 echo 'Begin build'
 cd opencv
 
-# FFmpeg version is too new.
-# This is a temporary fix from upstream until we have a new OpenCV release.
-git cherry-pick b1d208891b9f
-
 mkdir build
 
 ffmpeg -L

From 4c67d1c49ab6297fb90a43fdd2238ce75fd7bfe6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ren=C3=A9=20Dudfield?= <renesd@gmail.com>
Date: Sat, 17 Feb 2018 14:17:40 +0100
Subject: [PATCH 012/566] xcode7.3 for Mac OSX 10.11 el capitan support.

---
 .travis.yml | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 26493e18..9af0e198 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -31,25 +31,25 @@ matrix:
     # default builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -57,25 +57,25 @@ matrix:
     # Contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1

From 86e87d7db828e6f70463fd0e44fefca2f0e28edc Mon Sep 17 00:00:00 2001
From: native-api <ivan_pozdeev@mail.ru>
Date: Mon, 19 Feb 2018 20:25:34 +0300
Subject: [PATCH 013/566] Build via setup.py proper using scikit-build (#58)

* Adjust build environment as per https://docs.opencv.org/3.1.0/d5/de5/tutorial_py_setup_in_windows.html and https://wiki.python.org/moin/WindowsCompilers#Which_Microsoft_Visual_C.2B-.2B-_compiler_to_use_with_a_specific_Python_version_.3F

* The best practice is to only use requirements.txt for deployments, not for packaging

* ignore PyCharm metadata

* refactor to be more modular

* the warnings are irrelevant in older versions

* v110 toolset might introduce dependency on older runtime not likely to be present in newer systems, potentially breaking upgrade

* build locally with scikit-build

* adjust appveyor config to local build

* cleanup

* DLL load works without

* fail appveyor build immediately when one job fails

* * cmd doesn't expand globs
* - diplication
* - WinXP-related bits
* pip erroneously considers cv2/ as installed package when in sourceroot
* require CMake output entries to be found
* 3.5+ uses different .pyd naming scheme
* .pyd is placed differently in Linux
* DLL is only in Windows

* ignore temporary config files

* Yet another .pyd naming convention in Py35 Linux.
Screw checking.

* Update setup.py file to flag compatibility with Python 2.7-3.4-3.5-3.6 (#57)

# Conflicts:
#	setup.py

* Adjust build environment as per https://docs.opencv.org/3.1.0/d5/de5/tutorial_py_setup_in_windows.html and https://wiki.python.org/moin/WindowsCompilers#Which_Microsoft_Visual_C.2B-.2B-_compiler_to_use_with_a_specific_Python_version_.3F

* The best practice is to only use requirements.txt for deployments, not for packaging

* ignore PyCharm metadata

* refactor to be more modular

* the warnings are irrelevant in older versions

* v110 toolset might introduce dependency on older runtime not likely to be present in newer systems, potentially breaking upgrade

* build locally with scikit-build

* adjust appveyor config to local build

* cleanup

* DLL load works without

* fail appveyor build immediately when one job fails

* * cmd doesn't expand globs
* - diplication
* - WinXP-related bits
* pip erroneously considers cv2/ as installed package when in sourceroot
* require CMake output entries to be found
* 3.5+ uses different .pyd naming scheme
* .pyd is placed differently in Linux
* DLL is only in Windows

* ignore temporary config files

* fail fast on error

* * custom build logic should be unneeded now, will uncomment as needed

* use the latest upstream multibuild

* enable tracing
- more suspicious things

* save some build time

* these somehow cause "Server does not allow request for unadvertised object" for GitHub

* Revert "use the latest upstream multibuild"

This reverts commit 915ba421f97acebb3edcf55b5e46ea7aab8fea42.

* Yet another .pyd naming convention in Py35 Linux.
Screw checking.

* Update setup.py file to flag compatibility with Python 2.7-3.4-3.5-3.6 (#57)

# Conflicts:
#	setup.py

* add diagnostics

* * Use upstream multubuild due to the forked one abusing prebuild as build

* save some time

* looks like clean_code() isn't required

* * Don't make CMake try Ninja first
* MacOS LAPACK on Travis is still broken

* See build progress as it goes

* update submodules on demand

* fetch source in time for find_version.py

* use custom docker image

* use custom multibuild

* bump submodule

* Linux/OSX are supposed to build with Qt support

* * make shallow copies to save on download time
* manylinux git is an old version

* * clean up redundant syntax
* reformat codeas YML multiline with dedent

* IPP IW broken in Linux

* + ffmpeg patch

* additional deps required due to multibuild bug

* +cv2.data

* Use upstream multibuild with monkey patch

* don't do anything if upload not needed

* filter out irrelevant debug output

* * clean up unused scripts
* inline the remaining standalone scripts

* https://github.com/matthew-brett/multibuild/issues/106 fixed

* * bump OpenCV version to 3.4.0

* * https://github.com/opencv/opencv/pull/10011 is available in 3.4.0
* allow for if the sourcetree is a submodule

* * don't reinstall whatever happens to be preinstalled
* re-add workaround for https://github.com/travis-ci/travis-ci/issues/9055

* * rearrange custom CMake flags
* -DWITH_GTK=OFF proved to be unneeded, gthread is among manylinux requirements

* fix linux detection to work in 3.3+, too

* fix data path for other OSes

* don't do anything unless deployment is requested

* use upstream ``devel`` multibuild

* restore from backup after rebase

* catch fetch error

* use `devel` multibuild

* comment not using --depth

* remove redundant command after merge
---
 .gitignore                   |   7 +
 .gitmodules                  |   3 +-
 .travis.yml                  | 117 ++++++----
 appveyor.yml                 | 112 ++-------
 appveyor/build.cmd           |  33 ---
 config.sh                    |  57 +++--
 cv2/__init__.py              |   2 +-
 multibuild                   |   2 +-
 multibuild_customize.sh      |   6 +
 requirements.txt             |   2 -
 setup.py                     | 430 +++++++++++++++++++++++++++--------
 travis/build-wheels-osx.sh   | 148 ------------
 travis/build-wheels.sh       | 148 ------------
 travis/deploy.sh             |  13 --
 travis/disable_i386.patch    |  14 --
 travis/test-wheels.sh        |   8 -
 travis/toolchain_macos.cmake |   9 -
 17 files changed, 479 insertions(+), 632 deletions(-)
 delete mode 100644 appveyor/build.cmd
 create mode 100644 multibuild_customize.sh
 delete mode 100644 requirements.txt
 delete mode 100644 travis/build-wheels-osx.sh
 delete mode 100755 travis/build-wheels.sh
 delete mode 100644 travis/deploy.sh
 delete mode 100644 travis/disable_i386.patch
 delete mode 100755 travis/test-wheels.sh
 delete mode 100644 travis/toolchain_macos.cmake

diff --git a/.gitignore b/.gitignore
index 1dbc687d..87caa5f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -60,3 +60,10 @@ target/
 
 #Ipython Notebook
 .ipynb_checkpoints
+
+#PyCharm
+/.idea
+
+# Build temporary files
+/contrib.enabled
+/cv_version.py
diff --git a/.gitmodules b/.gitmodules
index 33e5752e..ce3da2e1 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -3,7 +3,8 @@
 	url = https://github.com/Itseez/opencv.git
 [submodule "multibuild"]
 	path = multibuild
-	url = https://github.com/skvark/multibuild.git
+	url = https://github.com/matthew-brett/multibuild.git
+    branch = devel
 [submodule "opencv_contrib"]
 	path = opencv_contrib
 	url = https://github.com/opencv/opencv_contrib.git
diff --git a/.travis.yml b/.travis.yml
index 26493e18..9f7750e4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,54 +1,50 @@
 env:
     global:
-        - REPO_DIR=opencv
-        # Commit from opencv that you want to build
-        - BUILD_COMMIT=6d4f66472e14b29b8e1623859cfebfdc67f677c3
-        # pip dependencies to _build_ your project
-        - BUILD_DEPENDS="numpy==1.11.1"
-        # pip dependencies to _test_ your project.  Include any dependencies
-        # that you need, that are also specified in BUILD_DEPENDS, this will be
-        # a separate install.
+        - "PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'"
+        # pip dependencies to _test_ your project
         - TEST_DEPENDS="numpy==1.11.1"
+
         - PLAT=x86_64
         - UNICODE_WIDTH=32
         - secure: "mU040XIYWtDjRms27deQy5fNg9HBFF9fiLfSteBaMjopZKXFUBsdMTKYGEVvX8DA879guMdjG8Prw1aCFhTTYlWgJ0Afm4YucRC0vAD4HLNhqLJ2lIpRceR3+2qPX+Oz5ATVVRi3ghBeJ20LLtNgOgf6esQVjdrYNC+YqmguClHKEYAxS7ngW42iQP8HX2anRcz9q9H7exZ9fX/D1PJfMNka/mNaB5KXZu5zdLuk/E0VbWU2tMWVIDUvx4uBlpE1d8HixEV5LHnuVE/QI36BcyucYxstTNKW6pGYgrhkYf+0PX4BphZXwY7EUBwzXsYLmyge6yH8W6NfvTW0ZasFF6xzQc9bsj+gAZN7H+hN2a42VQqIpkoJw9sU0hqzCOQf6ZvWUQgwFdAHJRHqe/zk4456WxnF0kAgbZdKaGOl0/n0WvgHNqD5bgO8Zzb1XyJTKoR+eAtYKXuz3KgpxKvZMMQVr8wMlI1cFEuGjIm+7ZrYB5jPvQrVzV/DgOq4gkPHOjjhu478UFlhGA9/XWwcyidC3b7zuBN2E7xVuTMlKdk7URB3AHXfG5bZgUG80vllQDGXQDpHVnv4Qi8bGCzI4iKTpp4fCibbqxFLxW1jhjmgePseGcie7Avpe+zXznkbmM2BqMCu3QRmtmFL3eCifwMf3rCNlAs0Sd3iLmEvyos="
         - secure: "omn6B+H6s0g1p9rhLGhFtFN1bSB80HCsNUUD9ROEpUirk7Sj7Wxms4CDi1f7aACANsZPXD7YZ72oNpWDJ6hSfTBf2yN1/d1iPILs7F5jt0yeratkDEOXkys1QpfMNO7r3DZ17X3IwvUGy9Mm+Sv15k+DaBdQ/65qwQ4ORIbHZRv3/lwkQ7Z88utjx6DLa9Jwc8fnEjjzIry51lO3OGJoWrjOZlOi2HV9MZ69PuuBdEEuicwfeLnV64QWRle++B51TQZC/3HF5+BBvYXm0LdvV4nSQVa9nTXaOWYcBROPNZizktJI91G6vG6gghWmI1cDR53n9LgCbA3YkPTJm/5Gjn9D+gfU5F16WQ4PFOHfzPZD8nTVmlUDUiuQ30W9QZ+O2ct7wi/xF4/Ff7V+0RIqGSnjhX6SGWk7UziQyGgCjBvYiRIQzfUyGu+86vrqNVXCyBlKOz6rWStTyq/Z0KEIXZFqop+ddeYdsEem5ZxCQ51uTpRMynVgEdKj++1Hn5411Rhntw0Am7RWdDEbFJ65OUyIpNtvlcHVM7ur03oz0hGcZIIkxWHJrCdr80Nw9r/s6KXYvidCNsu4SPx0XYo8KiTA6E2lkIAa5Ct6dZR6m5gjG2vmvlKzRmoD/7byJZN66usNxBh2LuKlgNFuHfG6iR+I6f3XCNmSUOJfm7KZYVI="
 
-language: python
-# The travis Python version is unrelated to the version we build and test
-# with.  This is set with the MB_PYTHON_VERSION variable.
-python: 3.5
+
+# Host Python is never used
+language: generic
+# Required to invoke docker ourselves as per https://docs.travis-ci.com/user/docker/
 sudo: required
-dist: trusty
 services: docker
+# https://docs.travis-ci.com/user/reference/trusty/
+dist: trusty
+
+# Save some time, we and setup check them out on demand instead
+# https://docs.travis-ci.com/user/customizing-the-build/#Git-Clone-Depth
+git:
+    submodules: false
+
 
 matrix:
-  exclude:
-    # Exclude the default Python 3.5 build
-    - python: 3.5
+  fast_finish: true
   include:
 
     # default builds for MacOS
     - os: osx
-      language: generic
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
     - os: osx
-      language: generic
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
     - os: osx
-      language: generic
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
     - os: osx
-      language: generic
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
@@ -56,25 +52,21 @@ matrix:
 
     # Contrib builds for MacOS
     - os: osx
-      language: generic
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
     - os: osx
-      language: generic
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
     - os: osx
-      language: generic
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
     - os: osx
-      language: generic
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
@@ -123,14 +115,14 @@ matrix:
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
-        - BUILD_DEPENDS=numpy==1.11.3
+
         - TEST_DEPENDS=numpy==1.11.3
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
         - ENABLE_CONTRIB=0
-        - BUILD_DEPENDS=numpy==1.11.3
+
         - TEST_DEPENDS=numpy==1.11.3
 
     # contrib builds for Linux
@@ -184,7 +176,7 @@ matrix:
       env:
         - MB_PYTHON_VERSION=3.6
 
-        - BUILD_DEPENDS=numpy==1.11.3
+
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
 
@@ -193,29 +185,54 @@ matrix:
         - MB_PYTHON_VERSION=3.6
 
         - PLAT=i686
-        - BUILD_DEPENDS=numpy==1.11.3
+
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
 
-before_install:
-    - echo $ENABLE_CONTRIB > contrib.enabled
-    - source multibuild/common_utils.sh
-    - source multibuild/travis_steps.sh
-    - python find_version.py
-    - cp LICENSE*.txt cv2/
-    - cp opencv/data/haarcascades/*.xml cv2/data/
-    - before_install
-
-install:
-    # Maybe get and clean and patch source
-    - clean_code $REPO_DIR $BUILD_COMMIT
-    - travis_wait 120 build_wheel $REPO_DIR $PLAT
-
-script:
-    - install_run $PLAT
-
-after_success:
-    # Upload wheels to pypi
-    - pip install twine
-    - if [ -n "$TRAVIS_TAG" ]; then twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*; else echo "Tag not set, deployment skipped."; fi
-    - source travis/deploy.sh
+# The first line is printed in the folding header in Travis output
+before_install: |
+    # Check out and prepare the source
+    set -e
+    #Multibuild doesn't have releases, so --depth would break eventually (see
+    #https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+    git submodule update --init multibuild
+    source multibuild/common_utils.sh
+    # https://github.com/matthew-brett/multibuild/issues/116
+    if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+    source multibuild/travis_steps.sh
+    # This sets -x
+    source multibuild_customize.sh
+    echo $ENABLE_CONTRIB > contrib.enabled
+    before_install
+    # Not interested in travis internal scripts' output
+    set +x
+
+install: |
+    # Build and package
+    set -x
+    build_wheel $REPO_DIR $PLAT
+    set +x
+
+script: |
+    # Install and run tests
+    set -x
+    install_run $PLAT
+    set +x
+
+after_success: |
+    # Upload wheels to pypi if requested
+    if [ -n "$TRAVIS_TAG" ]; then
+        set -x
+        pip install twine
+
+        if [[ $ENABLE_CONTRIB == 0 ]]; then
+            echo "This is default build. Deployment will be done to to PyPI entry opencv-python."
+        else
+            echo "This is contrib build. Deployment will be done to to PyPI entry opencv-contrib-python."
+        fi
+
+        twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
+        set +x
+    else
+        echo "Tag not set, deployment skipped."
+    fi
diff --git a/appveyor.yml b/appveyor.yml
index 090c7d8d..80bd5e97 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -7,145 +7,73 @@ environment:
 
   matrix:
     - PYTHON: "C:/Python27"
-      BUILD_ENV: "Visual Studio 14"
-      BUILD_DIR: "build"
-      PYTHON_VERSION: "2.7"
-      NP_VERSION: "1.11.1"
       ENABLE_CONTRIB: 0
 
     - PYTHON: "C:/Python27-x64"
-      BUILD_ENV: "Visual Studio 14 Win64"
-      BUILD_DIR: "build64"
-      PYTHON_VERSION: "2.7"
-      NP_VERSION: "1.11.1"
       ENABLE_CONTRIB: 0
 
     - PYTHON: "C:/Python34"
-      BUILD_ENV: "Visual Studio 14"
-      BUILD_DIR: "build"
-      PYTHON_VERSION: "3.4"
-      NP_VERSION: "1.11.1"
       ENABLE_CONTRIB: 0
 
     - PYTHON: "C:/Python34-x64"
-      BUILD_ENV: "Visual Studio 14 Win64"
-      BUILD_DIR: "build64"
-      PYTHON_VERSION: "3.4"
-      NP_VERSION: "1.11.1"
       ENABLE_CONTRIB: 0
 
     - PYTHON: "C:/Python35"
-      BUILD_ENV: "Visual Studio 14"
-      BUILD_DIR: "build"
-      PYTHON_VERSION: "3.5"
-      NP_VERSION: "1.11.1"
       ENABLE_CONTRIB: 0
 
     - PYTHON: "C:/Python35-x64"
-      BUILD_ENV: "Visual Studio 14 Win64"
-      BUILD_DIR: "build64"
-      PYTHON_VERSION: "3.5"
-      NP_VERSION: "1.11.1"
       ENABLE_CONTRIB: 0
 
     - PYTHON: "C:/Python36"
-      BUILD_ENV: "Visual Studio 14"
-      BUILD_DIR: "build"
-      PYTHON_VERSION: "3.6"
-      NP_VERSION: "1.11.3"
       ENABLE_CONTRIB: 0
 
     - PYTHON: "C:/Python36-x64"
-      BUILD_ENV: "Visual Studio 14 Win64"
-      BUILD_DIR: "build64"
-      PYTHON_VERSION: "3.6"
-      NP_VERSION: "1.11.3"
       ENABLE_CONTRIB: 0
 
     - PYTHON: "C:/Python27"
-      BUILD_ENV: "Visual Studio 14"
-      BUILD_DIR: "build"
-      PYTHON_VERSION: "2.7"
-      NP_VERSION: "1.11.1"
       ENABLE_CONTRIB: 1
 
     - PYTHON: "C:/Python27-x64"
-      BUILD_ENV: "Visual Studio 14 Win64"
-      BUILD_DIR: "build64"
-      PYTHON_VERSION: "2.7"
-      NP_VERSION: "1.11.1"
       ENABLE_CONTRIB: 1
 
     - PYTHON: "C:/Python34"
-      BUILD_ENV: "Visual Studio 14"
-      BUILD_DIR: "build"
-      PYTHON_VERSION: "3.4"
-      NP_VERSION: "1.11.1"
       ENABLE_CONTRIB: 1
 
     - PYTHON: "C:/Python34-x64"
-      BUILD_ENV: "Visual Studio 14 Win64"
-      BUILD_DIR: "build64"
-      PYTHON_VERSION: "3.4"
-      NP_VERSION: "1.11.1"
       ENABLE_CONTRIB: 1
 
     - PYTHON: "C:/Python35"
-      BUILD_ENV: "Visual Studio 14"
-      BUILD_DIR: "build"
-      PYTHON_VERSION: "3.5"
-      NP_VERSION: "1.11.1"
       ENABLE_CONTRIB: 1
 
     - PYTHON: "C:/Python35-x64"
-      BUILD_ENV: "Visual Studio 14 Win64"
-      BUILD_DIR: "build64"
-      PYTHON_VERSION: "3.5"
-      NP_VERSION: "1.11.1"
       ENABLE_CONTRIB: 1
 
     - PYTHON: "C:/Python36"
-      BUILD_ENV: "Visual Studio 14"
-      BUILD_DIR: "build"
-      PYTHON_VERSION: "3.6"
-      NP_VERSION: "1.11.3"
       ENABLE_CONTRIB: 1
 
     - PYTHON: "C:/Python36-x64"
-      BUILD_ENV: "Visual Studio 14 Win64"
-      BUILD_DIR: "build64"
-      PYTHON_VERSION: "3.6"
-      NP_VERSION: "1.11.3"
       ENABLE_CONTRIB: 1
 
-install:
-- cmd: >-
-
-    git submodule update --init --recursive
-
-    C:\Python35\python.exe find_version.py
-
-    "%PYTHON%/python.exe" -m pip install --upgrade pip
-
-    "%PYTHON%/python.exe" -m pip install -r requirements.txt
-
-    "%PYTHON%/python.exe" -m pip install "numpy==%NP_VERSION%"
+matrix:
+    fast_finish: true
 
+      
 build_script:
-- appveyor\build.cmd
+- cmd: |
 
-before_test:
-- cmd: >-
+    "%PYTHON%/python.exe" setup.py bdist_wheel
 
-    cd ..
+before_test:
+- ps: |
 
-    if %ENABLE_CONTRIB% EQU 0 ("%PYTHON%/python.exe" -m pip install --no-index --find-links=%APPVEYOR_BUILD_FOLDER%\dist\ opencv-python) else ("%PYTHON%/python.exe" -m pip install --no-index --find-links=%APPVEYOR_BUILD_FOLDER%\dist\ opencv-contrib-python)
+    cd ${Env:APPVEYOR_BUILD_FOLDER}\tests
+    &"${Env:PYTHON}/python.exe" -m pip install --user (ls "../dist/opencv_*.whl")
+    if ($LastExitCode -ne 0) {throw $LastExitCode}
 
 test_script:
-- cmd: >-
+- cmd: |
 
     cd %APPVEYOR_BUILD_FOLDER%\tests
-
     "%PYTHON%/python.exe" -m unittest test
 
 artifacts:
@@ -153,8 +81,16 @@ artifacts:
   name: wheels
 
 deploy_script:
-- cd %APPVEYOR_BUILD_FOLDER%
-
-- if %ENABLE_CONTRIB% EQU 0 (echo "This is default build. Deplyoment will be done to to PyPI entry opencv-python.") else (echo "This is contrib build. Deplyoment will be done to to PyPI entry opencv-contrib-python.")
-
-- if "%APPVEYOR_REPO_TAG%"=="true" ("%PYTHON%/python.exe" -m twine upload -u %USER% -p %PASS% --skip-existing dist/opencv*) else (echo "Tag not set, deployment skipped.")
\ No newline at end of file
+- ps: |
+
+    if (${Env:APPVEYOR_REPO_TAG} -eq "true") {
+        cd ${Env:APPVEYOR_BUILD_FOLDER}
+        if (${Env:ENABLE_CONTRIB} -eq 0) `
+            {echo "This is a default build. Deployment will be done to PyPI entry opencv-python."} `
+        else `
+            {echo "This is a contrib build. Deployment will be done to PyPI entry opencv-contrib-python."}
+
+        &"${Env:PYTHON}/python.exe" -m pip install twine
+        &"${Env:PYTHON}/python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv* } `
+    else
+        {echo "Tag not set, deployment skipped."}
diff --git a/appveyor/build.cmd b/appveyor/build.cmd
deleted file mode 100644
index a5c802a9..00000000
--- a/appveyor/build.cmd
+++ /dev/null
@@ -1,33 +0,0 @@
-if not exist "%APPVEYOR_BUILD_FOLDER%\opencv\%BUILD_DIR%" mkdir "%APPVEYOR_BUILD_FOLDER%\opencv\%BUILD_DIR%"
-
-cd opencv
-
-if %ENABLE_CONTRIB% EQU 1 (
-
-  if %PYTHON_VERSION% GEQ 3 cmake -G "%BUILD_ENV%" -H"." -B"%BUILD_DIR%" -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DPYTHON3_EXECUTABLE="%PYTHON%/python.exe" -DPYTHON3_LIBRARY="%PYTHON%/libs/python3*.lib" -DPYTHON3_INCLUDE_DIR="%PYTHON%/include" -Wno-dev
-  if %PYTHON_VERSION% LSS 3 cmake -G "%BUILD_ENV%" -H"." -B"%BUILD_DIR%" -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -Wno-dev
-
-) else (
-
-  if %PYTHON_VERSION% GEQ 3 cmake -G "%BUILD_ENV%" -H"." -B"%BUILD_DIR%" -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DPYTHON3_EXECUTABLE="%PYTHON%/python.exe" -DPYTHON3_LIBRARY="%PYTHON%/libs/python3*.lib" -DPYTHON3_INCLUDE_DIR="%PYTHON%/include" -Wno-dev
-  if %PYTHON_VERSION% LSS 3 cmake -G "%BUILD_ENV%" -H"." -B"%BUILD_DIR%" -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -Wno-dev
-
-)
-
-cd %BUILD_DIR%
-
-cmake --build . --config Release
-
-cd ..\..
-cd
-
-if %PYTHON_VERSION% GEQ 3 xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\%BUILD_DIR%\lib\python3\Release\*.pyd" .\cv2 /I
-if %PYTHON_VERSION% LSS 3 xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\%BUILD_DIR%\lib\RELEASE\*.pyd" .\cv2 /I
-
-xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\%BUILD_DIR%\bin\Release\*.dll" .\cv2 /I
-xcopy "%APPVEYOR_BUILD_FOLDER%\LICENSE*.txt" .\cv2 /I
-xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\data\haarcascades\*.xml" .\cv2\data /I
-
-dir
-
-"%PYTHON%/python.exe" setup.py bdist_wheel
\ No newline at end of file
diff --git a/config.sh b/config.sh
index 3817bbb7..3eba50b3 100644
--- a/config.sh
+++ b/config.sh
@@ -1,50 +1,71 @@
 #!/bin/bash
-set +e
+#Customize multibuild logic that is run after entering docker.
+#Sourced by docker_build_wrap.sh and docker_test_wrap.sh .
+#Runs in Docker, so only the vars passed to `docker run' exist.
+#See multibuild/README.rst
 echo "===  Loading config.sh  === "
 
+# To see build progress
+function build_wheel {
+    build_bdist_wheel $@
+}
+
 if [ -n "$IS_OSX" ]; then
   echo "    > OSX environment "
-  function build_wheel {
-      # Custom build_wheel function for OSX
-      # Run using '.' instead of '$REPO_DIR' to build from
-      # opencv-python instead of opencv
-      build_pip_wheel . $@
-  }
 else
   echo "    > Linux environment "
 fi
 
 function pre_build {
   echo "Starting pre-build"
+  set -e
 
-  set +e
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
-    source travis/build-wheels-osx.sh
+
+    # For some reason, gt@4 and ffmpeg can be preinstalled in Travis Mac env
+    echo 'Installing QT4'
+    brew tap | grep -qxF cartr/qt4 || brew tap -v cartr/qt4
+    brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin -v cartr/qt4
+    brew list --versions qt@4 || brew install -v qt@4
+    echo '-----------------'
+    echo 'Installing FFmpeg'
+    # brew install does produce output regularly on a regular MacOS,
+    # but Travis doesn't see it for some reason
+    brew list --versions ffmpeg || \
+    travis_wait brew install -v ffmpeg --without-x264 --without-xvid --without-gpl
+    brew info ffmpeg
+    echo '-----------------'
   else
     echo "Running for linux"
-    source /io/travis/build-wheels.sh
   fi
+  qmake -query  
 }
 
 function run_tests {
     # Runs tests on installed distribution from an empty directory
-    # python --version
-    # python -c 'import sys; import yourpackage; sys.exit(yourpackage.test())'
-    set +e
     echo "Run tests..."
     echo $PWD
-    ls -lh
 
     if [ -n "$IS_OSX" ]; then
       echo "Running for OS X"
       cd ../tests/
-      source ../travis/test-wheels.sh
     else
       echo "Running for linux"
-      apt-get update
-      apt-get -y install --fix-missing libglib2.0-0 libsm6
       cd /io/tests/
-      source /io/travis/test-wheels.sh
     fi
+    
+    test_wheels
+}
+
+function test_wheels {
+    PYTHON=python$PYTHON_VERSION
+
+    echo "Starting tests..."
+
+    #Test package
+    $PYTHON -m unittest test
 }
+
+export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
+set -x
\ No newline at end of file
diff --git a/cv2/__init__.py b/cv2/__init__.py
index ca2cb308..3c176752 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -1,6 +1,6 @@
 import importlib
-import os
 
+# make IDE's (PyCharm) autocompletion happy
 from .cv2 import *
 from .data import *
 
diff --git a/multibuild b/multibuild
index ad0ab85c..9330c3dc 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit ad0ab85c3d3e3ec352c2c9bac973bd96da265c85
+Subproject commit 9330c3dcc318b7b2b734ab00485d2ab253761811
diff --git a/multibuild_customize.sh b/multibuild_customize.sh
new file mode 100644
index 00000000..9b798c90
--- /dev/null
+++ b/multibuild_customize.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+# Customize multibuild logic that is run before entering Docker. Sourced from travis.yml .
+export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
+set -x
+REPO_DIR=$(dirname "${BASH_SOURCE[0]}")
+DOCKER_IMAGE='quay.io/skvark/manylinux_$plat'
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index 6c4932c1..00000000
--- a/requirements.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-wheel
-twine
diff --git a/setup.py b/setup.py
index 2a89aa6f..039136d7 100644
--- a/setup.py
+++ b/setup.py
@@ -1,115 +1,349 @@
-from setuptools import setup, find_packages
-from setuptools.dist import Distribution
-import pip
-import os
-import sys
-import io
-
-# cv_version.py should be generated by running find_version.py
-from cv_version import opencv_version
-
-contrib_build = False
-package_name = "opencv-python"
-numpy_version = ""
-long_description = ""
-package_data = {}
-
-contrib = os.getenv('ENABLE_CONTRIB', None)
-
-if contrib is not None:
-    if int(contrib) == 1:
-        contrib_build = True
-else:
-    try:
-        print("Trying to read contrib enable flag from file...")
-        with open("contrib.enabled") as f:
-            flag = int(f.read(1))
-            if flag == 1:
-                contrib_build = True
-    except:
-        pass
+# No 3rd-party modules here, see "3rd-party" note below
+import io, os, os.path, sys, runpy, subprocess, re, sysconfig
 
-# Use different README and package name for contrib build.
-if contrib_build:
-    package_name = "opencv-contrib-python"
-    with io.open('README_CONTRIB.rst', encoding="utf-8") as f:
-        long_description = f.read()
-else:
-    with io.open('README.rst', encoding="utf-8") as f:
-        long_description = f.read()
 
-# Get required numpy version
-for package in pip.get_installed_distributions():
-    if package.key == "numpy":
-        numpy_version = package.version
+def main():
+    os.chdir(os.path.dirname(os.path.abspath(__file__)))
 
-if os.name == 'posix':
-    package_data['cv2'] = ['*.so']
-else:
-    package_data['cv2'] = ['*.pyd', '*.dll']
+    # These are neede for source fetching
+    cmake_source_dir = "opencv"
+    build_contrib = get_build_contrib()
 
-package_data['cv2'] += ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"]
-package_data[''] = ['*.xml']
 
-"""
+    # Only import 3rd-party modules after having installed all the build dependencies:
+    # any of them, or their dependencies, can be updated during that process,
+    # leading to version conflicts
+    numpy_version = get_or_install("numpy", "1.11.3" if sys.version_info[:2] >= (3, 6) else "1.11.1")
+    get_or_install("scikit-build")
+    import skbuild
+    
+    if os.path.exists('.git'):
+        import pip.vcs.git
+        g = pip.vcs.git.Git()
+        use_depth = g.get_git_version() >= type(g.get_git_version())("1.8.4")
+        g.run_command(["submodule", "update", "--init", "--recursive"] + \
+            (["--depth=1"] if use_depth else []) + \
+            [cmake_source_dir])
+        if build_contrib:
+            g.run_command(["submodule", "update", "--init", "--recursive"] + \
+            (["--depth=1"] if use_depth else []) + \
+            ["opencv_contrib"])
+        del use_depth, g, pip
 
-This is my old hack to force binary distribution.
 
-However, it doesn't work properly because the binaries
-are placed into purelib instead of platlib.
+    # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
+    x64 = sys.maxsize>2**32
 
-class BinaryDistribution(Distribution):
-    def has_ext_modules(self):
-        return True
 
-    def is_pure(self):
-        return False
-"""
+    package_name = "opencv-contrib-python" if build_contrib else "opencv-python"
+    long_description = io.open('README_CONTRIB.rst' if build_contrib else 'README.rst', encoding="utf-8").read()
+    package_version = get_opencv_version()
 
-# This creates a list which is empty but returns a length of 1.
-# Should make the wheel a binary distribution and platlib compliant.
+    packages = ['cv2', 'cv2.data']
+    package_data = \
+        {'cv2':
+            ['*%s' % sysconfig.get_config_var('SO')] + (['*.dll'] if os.name == 'nt' else []) +
+            ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
+         'cv2.data':
+            ["*.xml"]
+         }
+
+    # Files from CMake output to copy to package.
+    # Path regexes with forward slashes relative to CMake install dir.
+    rearrange_cmake_output_data = \
+        {'cv2':
+            ([r'bin/opencv_ffmpeg\d{3}%s\.dll' %
+                ('_64' if x64 else '')] if os.name == 'nt' else []
+            ) + \
+            # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
+            # Naming conventions vary so widely between versions and OSes
+            # had to give up on checking them.
+            ['python/([^/]+/){1,2}cv2[^/]*%(ext)s' % {
+                'ext':   re.escape(sysconfig.get_config_var('SO'))
+                }
+            ],
+         'cv2.data':
+            [ # OPENCV_OTHER_INSTALL_PATH
+            ('etc' if os.name =='nt' else 'share/OpenCV')
+            + r'/haarcascades/.*\.xml']
+         }
+    # Files in sourcetree outside package dir that should be copied to package.
+    # Raw paths relative to sourcetree root.
+    files_outside_package_dir = \
+        {'cv2':
+            ['LICENSE.txt', 'LICENSE-3RD-PARTY.txt']
+         }
+
+    cmake_args = ([
+        "-G", "Visual Studio 14" + (" Win64" if x64 else '')
+    ] if os.name == 'nt' else [
+        "-G", "Unix Makefiles"  #don't make CMake try (and fail) Ninja first
+    ]) + \
+    [
+        # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
+        "-DPYTHON%d_EXECUTABLE=%s" % (sys.version_info[0], sys.executable),
+        "-DBUILD_opencv_python%d=ON" % sys.version_info[0],
+        # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
+        # and skbuild bails out on seeing that
+        "-DINSTALL_CREATE_DISTRIB=ON",
+        # See opencv/CMakeLists.txt for options and defaults
+        "-DBUILD_opencv_apps=OFF",
+        "-DBUILD_SHARED_LIBS=OFF",
+        "-DBUILD_TESTS=OFF",
+        "-DBUILD_PERF_TESTS=OFF",
+        "-DBUILD_DOCS=OFF"
+    ] + \
+    ([ "-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules") ]
+       if build_contrib else [])
+       
+    # OS-specific components
+    if sys.platform == 'darwin' or sys.platform.startswith('linux'):
+        cmake_args.append( "-DWITH_QT=4" )
+    if sys.platform.startswith('linux'):
+        cmake_args.append( "-DWITH_V4L=ON" )
+        if all(v in os.environ for v in ('JPEG_INCLUDE_DIR', 'JPEG_LIBRARY')):
+            cmake_args += [
+            "-DBUILD_JPEG=OFF",
+            "-DJPEG_INCLUDE_DIR=%s" % os.environ['JPEG_INCLUDE_DIR'],
+            "-DJPEG_LIBRARY=%s" % os.environ['JPEG_LIBRARY']
+            ]
+            
+    # Turn off broken components
+    if sys.platform == 'darwin':
+        cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
+                                                # https://github.com/skvark/opencv-python/issues/21
+    if sys.platform.startswith('linux'):
+        cmake_args.append( "-DWITH_IPP=OFF" )   # https://github.com/opencv/opencv/issues/10411
+
+
+
+    # ABI config variables are introduced in PEP 425
+    if sys.version_info[:2] < (3, 2):
+        import warnings
+        warnings.filterwarnings('ignore', r"Config variable '[^']+' is unset, "
+                                          r"Python ABI tag may be incorrect",
+                                category=RuntimeWarning)
+        del warnings
+
+
+    # works via side effect
+    RearrangeCMakeOutput(rearrange_cmake_output_data,
+                         files_outside_package_dir,
+                         package_data.keys())
+
+    skbuild.setup(
+        name=package_name,
+        version=package_version,
+        url='https://github.com/skvark/opencv-python',
+        license='MIT',
+        description='Wrapper package for OpenCV python bindings.',
+        long_description=long_description,
+        packages=packages,
+        package_data=package_data,
+        maintainer="Olli-Pekka Heinisuo",
+        include_package_data=True,
+        ext_modules=EmptyListWithLength(),
+        install_requires="numpy>=%s" % numpy_version,
+        classifiers=[
+          'Development Status :: 5 - Production/Stable',
+          'Environment :: Console',
+          'Intended Audience :: Developers',
+          'Intended Audience :: Education',
+          'Intended Audience :: Information Technology',
+          'Intended Audience :: Science/Research',
+          'License :: OSI Approved :: MIT License',
+          'Operating System :: MacOS',
+          'Operating System :: Microsoft :: Windows',
+          'Operating System :: POSIX',
+          'Operating System :: Unix',
+          'Programming Language :: Python',
+          'Programming Language :: Python :: 2',
+          'Programming Language :: Python :: 2.7',
+          'Programming Language :: Python :: 3',
+          'Programming Language :: Python :: 3.4',
+          'Programming Language :: Python :: 3.5',
+          'Programming Language :: Python :: 3.6',
+          'Programming Language :: C++',
+          'Programming Language :: Python :: Implementation :: CPython',
+          'Topic :: Scientific/Engineering',
+          'Topic :: Scientific/Engineering :: Image Recognition',
+          'Topic :: Software Development',
+        ],
+        cmake_args=cmake_args,
+        cmake_source_dir=cmake_source_dir,
+          )
+
+
+class RearrangeCMakeOutput(object):
+    """Patch SKBuild logic to only take files related to the Python package
+    and construct a file hierarchy that SKBuild expects (see below)"""
+    _setuptools_wrap = None
+
+    # Have to wrap a function reference, or it's converted
+    # into an instance method on attr assignment
+    import argparse
+    wraps = argparse.Namespace(
+        _classify_files=None)
+    del argparse
+
+    package_paths_re = None
+    packages = None
+    files_outside_package = None
+
+    def __init__(self, package_paths_re, files_outside_package, packages):
+        cls = self.__class__
+        assert not cls.wraps._classify_files, "Singleton object"
+        import skbuild.setuptools_wrap
+
+        cls._setuptools_wrap = skbuild.setuptools_wrap
+        cls.wraps._classify_files = cls._setuptools_wrap._classify_files
+        cls._setuptools_wrap._classify_files = self._classify_files_override
+
+        cls.package_paths_re = package_paths_re
+        cls.files_outside_package = files_outside_package
+        cls.packages = packages
+    def __del__(self):
+        cls = self.__class__
+        cls._setuptools_wrap._classify_files = cls.wraps._classify_files
+        cls.wraps._classify_files = None
+        cls._setuptools_wrap = None
+
+    def _classify_files_override(self, install_paths,
+            package_data, package_prefixes,
+            py_modules, new_py_modules,
+            scripts, new_scripts,
+            data_files,
+            cmake_source_dir, cmake_install_reldir):
+        """From all CMake output, we're only interested in a few files
+        and must place them into CMake install dir according
+        to Python conventions for SKBuild to find them:
+            package\
+                file
+                subpackage\
+                    etc.
+        """
+        cls = self.__class__
+        # 'relpath'/'reldir' = relative to CMAKE_INSTALL_DIR/cmake_install_dir
+        # 'path'/'dir' = relative to sourcetree root
+        cmake_install_dir = os.path.join(cls._setuptools_wrap.CMAKE_INSTALL_DIR,
+                                         cmake_install_reldir)
+        install_relpaths = [os.path.relpath(p, cmake_install_dir) for p in install_paths]
+        fslash_install_relpaths = [p.replace(os.path.sep, '/') for p in install_relpaths]
+        relpaths_zip = list(zip(fslash_install_relpaths, install_relpaths))
+        del install_relpaths, fslash_install_relpaths
+
+        final_install_relpaths = []
 
+        print("Copying files from CMake output")
+        for package_name, relpaths_re in cls.package_paths_re.items():
+            package_dest_reldir = package_name.replace('.', os.path.sep)
+            for relpath_re in relpaths_re:
+                found = False
+                r = re.compile(relpath_re+'$')
+                for fslash_relpath, relpath in relpaths_zip:
+                    m = r.match(fslash_relpath)
+                    if not m: continue
+                    found = True
+                    new_install_relpath = os.path.join(
+                        package_dest_reldir,
+                        os.path.basename(relpath))
+                    cls._setuptools_wrap._copy_file(
+                        os.path.join(cmake_install_dir, relpath),
+                        os.path.join(cmake_install_dir, new_install_relpath),
+                        hide_listing=False)
+                    final_install_relpaths.append(new_install_relpath)
+                    del m, fslash_relpath, new_install_relpath
+                else:
+                    if not found: raise Exception("Not found: '%s'" % relpath_re)
+                del r, found
 
+        del relpaths_zip
+
+        print("Copying files from non-default sourcetree locations")
+        for package_name, paths in cls.files_outside_package.items():
+            package_dest_reldir = package_name.replace('.', os.path.sep)
+            for path in paths:
+                new_install_relpath = os.path.join(
+                        package_dest_reldir,
+                        # Don't yet have a need to copy
+                        # to subdirectories of package dir
+                        os.path.basename(path))
+                cls._setuptools_wrap._copy_file(
+                    path, os.path.join(cmake_install_dir, new_install_relpath),
+                    hide_listing = False
+                )
+                final_install_relpaths.append(new_install_relpath)
+
+
+        final_install_paths = [os.path.join(cmake_install_dir, p) for p in final_install_relpaths]
+
+        return (cls.wraps._classify_files)(
+            final_install_paths,
+            package_data, package_prefixes,
+            py_modules, new_py_modules,
+            scripts, new_scripts,
+            data_files,
+            # To get around a demented check
+            # that prepends source dir to paths and breaks package detection code.
+            # Can't imagine what the authors were thinking that should be doing.
+            cmake_source_dir = '',
+            cmake_install_dir = cmake_install_reldir
+            )
+
+
+def install_packages(*requirements):
+    # No more convenient way until PEP 518 is implemented; setuptools only handles eggs
+    subprocess.check_call([sys.executable,
+                           "-m", "pip", "install"]
+                          + list(requirements))
+
+
+def get_opencv_version():
+    # cv_version.py should be generated by running find_version.py
+    runpy.run_path("find_version.py")
+    from cv_version import opencv_version
+    return opencv_version
+
+
+def get_build_contrib():
+    build_contrib = False
+    try:
+        build_contrib = bool(int(os.getenv('ENABLE_CONTRIB', None)))
+    except Exception:
+        pass
+
+    if not build_contrib:
+        try:
+            build_contrib = bool(int(open("contrib.enabled").read(1)))
+        except Exception:
+            pass
+    return build_contrib
+
+
+def get_or_install(name, version = None):
+    """If a package is already installed, build against it. If not, install"""
+    # Do not import 3rd-party modules into the current process
+    import json
+    js_packages = json.loads(
+        subprocess.check_output(
+        [sys.executable, "-m", "pip", "list", "--format=json"])
+        .decode('ascii'))  #valid names & versions are ASCII as per PEP 440
+    try:
+        [package] = (package for package in js_packages
+                     if package['name'] == name)
+    except ValueError:
+        install_packages("%s==%s"%(name, version) if version else name)
+        return version
+    else:
+        return package['version']
+
+
+# This creates a list which is empty but returns a length of 1.
+# Should make the wheel a binary distribution and platlib compliant.
 class EmptyListWithLength(list):
     def __len__(self):
         return 1
 
 
-setup(name=package_name,
-      version=opencv_version,
-      url='https://github.com/skvark/opencv-python',
-      license='MIT',
-      description='Wrapper package for OpenCV python bindings.',
-      long_description=long_description,
-      packages=find_packages(),
-      package_data=package_data,
-      maintainer="Olli-Pekka Heinisuo",
-      include_package_data=True,
-      ext_modules=EmptyListWithLength(),
-      install_requires="numpy>=%s" % numpy_version,
-      classifiers=[
-        'Development Status :: 5 - Production/Stable',
-        'Environment :: Console',
-        'Intended Audience :: Developers',
-        'Intended Audience :: Education',
-        'Intended Audience :: Information Technology',
-        'Intended Audience :: Science/Research',
-        'License :: OSI Approved :: MIT License',
-        'Operating System :: MacOS',
-        'Operating System :: Microsoft :: Windows',
-        'Operating System :: POSIX',
-        'Operating System :: Unix',
-        'Programming Language :: Python',
-        'Programming Language :: Python :: 2',
-        'Programming Language :: Python :: 2.7',
-        'Programming Language :: Python :: 3',
-        'Programming Language :: Python :: 3.4',
-        'Programming Language :: Python :: 3.5',
-        'Programming Language :: Python :: 3.6',
-        'Programming Language :: C++',
-        'Programming Language :: Python :: Implementation :: CPython',
-        'Topic :: Scientific/Engineering',
-        'Topic :: Scientific/Engineering :: Image Recognition',
-        'Topic :: Software Development',
-        ]
-      )
+if __name__ == '__main__':
+    main()
diff --git a/travis/build-wheels-osx.sh b/travis/build-wheels-osx.sh
deleted file mode 100644
index 9ecc9ea5..00000000
--- a/travis/build-wheels-osx.sh
+++ /dev/null
@@ -1,148 +0,0 @@
-#!/bin/bash
-set +e
-echo 'Begin build-wheel OSX ...'
-
-export PYTHON_VERSION=${MB_PYTHON_VERSION/./}
-echo 'MB_PYTHON_VERSION: ' "$MB_PYTHON_VERSION"
-echo 'PYTHON_VERSION: ' "$PYTHON_VERSION"
-
-echo 'PIP and brew installs'
-
-pip install "$BUILD_DEPENDS"
-
-echo 'Installing QT4'
-brew tap cartr/qt4
-brew tap-pin cartr/qt4
-brew install qt@4
-echo '-----------------'
-echo 'Installing FFmpeg'
-brew install ffmpeg --without-x264 --without-xvid --without-gpl
-brew info ffmpeg
-echo '-----------------'
-
-qmake -query
-
-cd opencv
-
-echo "Apply patch"
-
-git apply --ignore-space-change --ignore-whitespace ../travis/disable_i386.patch
-
-echo "Detect Python paths for OpenCV"
-
-PYTHON_VERSION_STRING=$(python -c "from platform import python_version; print(python_version())")
-PYTHON_INCLUDE_PATH=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")
-PYTHON_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
-PYTHON_NUMPY_INCLUDE_DIRS=$(python -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print(os.pathsep.join(numpy.distutils.misc_util.get_numpy_include_dirs()))")
-PYTHON_NUMPY_VERSION=$(python -c "import numpy; print(numpy.version.version)")
-
-echo "PYthon version string: $PYTHON_VERSION_STRING"
-echo "Python include path: $PYTHON_INCLUDE_PATH"
-echo "Python packages path: $PYTHON_PACKAGES_PATH"
-echo "Python numpy incude dirs: $PYTHON_NUMPY_INCLUDE_DIRS"
-echo "Python numpy version: $PYTHON_NUMPY_VERSION"
-
-echo 'Config make'
-
-mkdir build
-cd build
-
-if [[ $PYTHON_VERSION == 2* ]] && [[ $ENABLE_CONTRIB == 0 ]]; then
-  echo 'Config for Py2'
-  cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_TOOLCHAIN_FILE=../../travis/toolchain_macos.cmake \
-    -D BUILD_opencv_python3=OFF -D BUILD_opencv_java=OFF -D BUILD_SHARED_LIBS=OFF -D WITH_LAPACK=OFF -D WITH_QT=4 \
-    -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF \
-    -D BUILD_EXAMPLES=OFF \
-    -D PYTHON2INTERP_FOUND=ON -DPYTHON2LIBS_FOUND=ON \
-    -D PYTHON2_EXECUTABLE=python \
-    -D PYTHON2_VERSION_STRING="$PYTHON_VERSION_STRING" \
-    -D PYTHON2_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
-    -D PYTHON2_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
-    -D PYTHON2_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
-    -D PYTHON2_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
-    ..
-
-fi
-
-if [[ $PYTHON_VERSION == 3* ]] && [[ $ENABLE_CONTRIB == 0 ]]; then
-  echo 'Config for Py3'
-  cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_TOOLCHAIN_FILE=../../travis/toolchain_macos.cmake \
-    -D BUILD_opencv_python2=OFF -D BUILD_opencv_java=OFF -D BUILD_SHARED_LIBS=OFF -D WITH_LAPACK=OFF -D WITH_QT=4 \
-    -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF \
-    -D BUILD_EXAMPLES=OFF \
-    -D PYTHON3INTERP_FOUND=ON -DPYTHON3LIBS_FOUND=ON \
-    -D PYTHON3_EXECUTABLE=python \
-    -D PYTHON3_VERSION_STRING="$PYTHON_VERSION_STRING" \
-    -D PYTHON3_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
-    -D PYTHON3_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
-    -D PYTHON3_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
-    -D PYTHON3_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
-    ..
-
-fi
-
-if [[ $PYTHON_VERSION == 2* ]] && [[ $ENABLE_CONTRIB == 1 ]]; then
-  echo 'Config for Py2'
-  cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_TOOLCHAIN_FILE=../../travis/toolchain_macos.cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-    -D BUILD_opencv_python3=OFF -D BUILD_opencv_java=OFF -D BUILD_SHARED_LIBS=OFF -D WITH_LAPACK=OFF -D WITH_QT=4 \
-    -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF \
-    -D BUILD_EXAMPLES=OFF \
-    -D PYTHON2INTERP_FOUND=ON -DPYTHON2LIBS_FOUND=ON \
-    -D PYTHON2_EXECUTABLE=python \
-    -D PYTHON2_VERSION_STRING="$PYTHON_VERSION_STRING" \
-    -D PYTHON2_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
-    -D PYTHON2_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
-    -D PYTHON2_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
-    -D PYTHON2_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
-    ..
-
-fi
-
-if [[ $PYTHON_VERSION == 3* ]] && [[ $ENABLE_CONTRIB == 1 ]]; then
-  echo 'Config for Py3'
-  cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_TOOLCHAIN_FILE=../../travis/toolchain_macos.cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-    -D BUILD_opencv_python2=OFF -D BUILD_opencv_java=OFF -D BUILD_SHARED_LIBS=OFF -D WITH_LAPACK=OFF -D WITH_QT=4 \
-    -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF \
-    -D BUILD_EXAMPLES=OFF \
-    -D PYTHON3INTERP_FOUND=ON -DPYTHON3LIBS_FOUND=ON \
-    -D PYTHON3_EXECUTABLE=python \
-    -D PYTHON3_VERSION_STRING="$PYTHON_VERSION_STRING" \
-    -D PYTHON3_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
-    -D PYTHON3_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
-    -D PYTHON3_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
-    -D PYTHON3_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
-    ..
-
-fi
-
-echo 'Begin build'
-
-if [[ $PYTHON_VERSION == 2* ]]; then
-  echo 'Build for Py2'
-  make -j2 opencv_python2
-
-fi
-
-if [[ $PYTHON_VERSION == 3* ]]; then
-  echo 'Build for Py3'
-  make -j2 opencv_python3
-
-fi
-
-# Moving back to opencv-python
-cd ../..
-
-if [[ $PYTHON_VERSION == 2* ]]; then
-  echo 'Copying *.so for Py2'
-  cp opencv/build/lib/cv2.so cv2/
-
-fi
-
-if [[ $PYTHON_VERSION == 3* ]]; then
-  echo 'Copying *.so for Py3'
-  cp opencv/build/lib/python3/*.so cv2/
-
-fi
-
-echo 'Build wheel'
-
diff --git a/travis/build-wheels.sh b/travis/build-wheels.sh
deleted file mode 100755
index c6598d20..00000000
--- a/travis/build-wheels.sh
+++ /dev/null
@@ -1,148 +0,0 @@
-#!/bin/bash
-set +e
-echo 'Begin build-wheel...'
-
-export PYTHON_VERSION=${PYTHON_VERSION/./}
-echo 'PYTHON_VERSION: ' "$PYTHON_VERSION"
-
-ENABLE_CONTRIB=$(<contrib.enabled)
-
-pip install "$BUILD_DEPENDS"
-
-echo "Detect Python paths for OpenCV"
-
-PYTHON_VERSION_STRING=$(python -c "from platform import python_version; print(python_version())")
-PYTHON_INCLUDE_PATH=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")
-PYTHON_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
-PYTHON_NUMPY_INCLUDE_DIRS=$(python -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print(os.pathsep.join(numpy.distutils.misc_util.get_numpy_include_dirs()))")
-PYTHON_NUMPY_VERSION=$(python -c "import numpy; print(numpy.version.version)")
-
-echo "PYthon version string: $PYTHON_VERSION_STRING"
-echo "Python include path: $PYTHON_INCLUDE_PATH"
-echo "Python packages path: $PYTHON_PACKAGES_PATH"
-echo "Python numpy incude dirs: $PYTHON_NUMPY_INCLUDE_DIRS"
-echo "Python numpy version: $PYTHON_NUMPY_VERSION"
-
-# Begin build
-echo 'Begin build'
-cd opencv
-
-mkdir build
-
-ffmpeg -L
-qmake -query
-
-if [[ $PYTHON_VERSION == 2* ]] && [[ $ENABLE_CONTRIB == 0 ]]; then
-  echo 'Config for Py2'
-  cmake -H"." -B"build" -DCMAKE_BUILD_TYPE=Release -DBUILD_opencv_python3=OFF -DBUILD_opencv_java=OFF -DBUILD_SHARED_LIBS=OFF \
-    -DWITH_IPP=OFF -DBUILD_DOCS=OFF -DWITH_QT=4 \
-    -DINSTALL_C_EXAMPLES=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF \
-    -DBUILD_EXAMPLES=OFF \
-    -DPYTHON2INTERP_FOUND=ON -DPYTHON2LIBS_FOUND=ON \
-    -DPYTHON2_EXECUTABLE=python \
-    -DPYTHON2_VERSION_STRING="$PYTHON_VERSION_STRING" \
-    -DPYTHON2_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
-    -DPYTHON2_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
-    -DPYTHON2_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
-    -DPYTHON2_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
-    -DWITH_JPEG=ON \
-    -DBUILD_JPEG=OFF \
-    -DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
-    -DJPEG_LIBRARY="$JPEG_LIBRARY" \
-    -DWITH_V4L=ON
-
-fi
-
-if [[ $PYTHON_VERSION == 3* ]] && [[ $ENABLE_CONTRIB == 0 ]]; then
-  echo 'Config for Py3'
-  cmake -H"." -B"build" -DCMAKE_BUILD_TYPE=Release -DBUILD_opencv_python2=OFF -DBUILD_opencv_java=OFF -DBUILD_SHARED_LIBS=OFF \
-    -DWITH_IPP=OFF -DBUILD_DOCS=OFF -DWITH_QT=4 \
-    -DINSTALL_C_EXAMPLES=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF \
-    -DBUILD_EXAMPLES=OFF \
-    -DPYTHON3INTERP_FOUND=ON -DPYTHON3LIBS_FOUND=ON \
-    -DPYTHON3_EXECUTABLE=python \
-    -DPYTHON3_VERSION_STRING="$PYTHON_VERSION_STRING" \
-    -DPYTHON3_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
-    -DPYTHON3_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
-    -DPYTHON3_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
-    -DPYTHON3_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
-    -DWITH_JPEG=ON \
-    -DBUILD_JPEG=OFF \
-    -DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
-    -DJPEG_LIBRARY="$JPEG_LIBRARY" \
-    -DWITH_V4L=ON
-
-fi
-
-if [[ $PYTHON_VERSION == 2* ]] && [[ $ENABLE_CONTRIB == 1 ]]; then
-  echo 'Config for Py2'
-  cmake -H"." -B"build" -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -DCMAKE_BUILD_TYPE=Release -DBUILD_opencv_python3=OFF -DBUILD_opencv_java=OFF -DBUILD_SHARED_LIBS=OFF \
-    -DWITH_IPP=OFF -DBUILD_DOCS=OFF -DWITH_QT=4 \
-    -DINSTALL_C_EXAMPLES=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF \
-    -DBUILD_EXAMPLES=OFF \
-    -DPYTHON2INTERP_FOUND=ON -DPYTHON2LIBS_FOUND=ON \
-    -DPYTHON2_EXECUTABLE=python \
-    -DPYTHON2_VERSION_STRING="$PYTHON_VERSION_STRING" \
-    -DPYTHON2_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
-    -DPYTHON2_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
-    -DPYTHON2_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
-    -DPYTHON2_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
-    -DWITH_JPEG=ON \
-    -DBUILD_JPEG=OFF \
-    -DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
-    -DJPEG_LIBRARY="$JPEG_LIBRARY" \
-     -DWITH_V4L=ON
-
-fi
-
-if [[ $PYTHON_VERSION == 3* ]] && [[ $ENABLE_CONTRIB == 1 ]]; then
-  echo 'Config for Py3'
-  cmake -H"." -B"build" -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -DCMAKE_BUILD_TYPE=Release -DBUILD_opencv_python2=OFF -DBUILD_opencv_java=OFF -DBUILD_SHARED_LIBS=OFF \
-    -DWITH_IPP=OFF -DBUILD_DOCS=OFF -DWITH_QT=4 \
-    -DINSTALL_C_EXAMPLES=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF \
-    -DBUILD_EXAMPLES=OFF \
-    -DPYTHON3INTERP_FOUND=ON -DPYTHON3LIBS_FOUND=ON \
-    -DPYTHON3_EXECUTABLE=python \
-    -DPYTHON3_VERSION_STRING="$PYTHON_VERSION_STRING" \
-    -DPYTHON3_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
-    -DPYTHON3_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
-    -DPYTHON3_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
-    -DPYTHON3_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
-    -DWITH_JPEG=ON \
-    -DBUILD_JPEG=OFF \
-    -DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
-    -DJPEG_LIBRARY="$JPEG_LIBRARY" \
-    -DWITH_V4L=ON
-
-fi
-
-if [[ $PYTHON_VERSION == 2* ]]; then
-  echo 'Build for Py2'
-  (cd build; make -j8 opencv_python2)
-
-fi
-
-if [[ $PYTHON_VERSION == 3* ]]; then
-  echo 'Build for Py3'
-  (cd build; make -j8 opencv_python3)
-
-fi
-
-# Moving back to opencv-python
-cd ..
-
-if [[ $PYTHON_VERSION == 2* ]]; then
-  echo 'Copying *.so for Py2'
-  cp opencv/build/lib/cv2.so cv2/
-
-fi
-
-if [[ $PYTHON_VERSION == 3* ]]; then
-  echo 'Copying *.so for Py3'
-  cp opencv/build/lib/python3/*.so cv2/
-
-fi
-
-# Build wheel
-echo 'Build wheel'
-pip wheel . -w /io/wheelhouse/
\ No newline at end of file
diff --git a/travis/deploy.sh b/travis/deploy.sh
deleted file mode 100644
index adfd3fbd..00000000
--- a/travis/deploy.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-pip install twine
-
-if [[ $ENABLE_CONTRIB == 0 ]]; then
-	echo "This is default build. Deployment will be done to to PyPI entry opencv-python."
-else
-	echo "This is contrib build. Deployment will be done to to PyPI entry opencv-contrib-python."
-fi
-
-if [ -n "$TRAVIS_TAG" ]; then
-	twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*;
-else
-	echo "Tag not set, deployment skipped.";
-fi
\ No newline at end of file
diff --git a/travis/disable_i386.patch b/travis/disable_i386.patch
deleted file mode 100644
index d10401a4..00000000
--- a/travis/disable_i386.patch
+++ /dev/null
@@ -1,14 +0,0 @@
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index af5e2c1..cee9726 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -192,6 +192,9 @@ if(MINGW)
-   endif()
- endif()
- 
-+string(REPLACE "-arch i386" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
-+string(REPLACE "-arch i386" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
-+
- # ----------------------------------------------------------------------------
- # OpenCV cmake options
- # ----------------------------------------------------------------------------
diff --git a/travis/test-wheels.sh b/travis/test-wheels.sh
deleted file mode 100755
index cc7a9673..00000000
--- a/travis/test-wheels.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-
-PYTHON=python$PYTHON_VERSION
-
-echo "Starting tests..."
-
-#Test package
-$PYTHON -m unittest test
diff --git a/travis/toolchain_macos.cmake b/travis/toolchain_macos.cmake
deleted file mode 100644
index 3afcdf74..00000000
--- a/travis/toolchain_macos.cmake
+++ /dev/null
@@ -1,9 +0,0 @@
-SET(CMAKE_SYSTEM_NAME Darwin)
-SET(CMAKE_SYSTEM_VERSION 16)
-SET(CMAKE_SYSTEM_PROCESSOR x86_64)
-SET(ARCH x86_64)
-
-set(CMAKE_C_COMPILER gcc)
-set(CMAKE_C_COMPILER_TARGET ${arch})
-set(CMAKE_CXX_COMPILER g++)
-set(CMAKE_CXX_COMPILER_TARGET ${arch})
\ No newline at end of file

From 942270b67fe9dfda51858ad65b0af10d7a086fba Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 19 Feb 2018 19:45:38 +0200
Subject: [PATCH 014/566] remove extra newlines and add some spaces

---
 .travis.yml | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index ea3293e7..72b6d612 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -23,7 +23,6 @@ dist: trusty
 git:
     submodules: false
 
-
 matrix:
   fast_finish: true
   include:
@@ -115,77 +114,62 @@ matrix:
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
-
         - TEST_DEPENDS=numpy==1.11.3
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
         - ENABLE_CONTRIB=0
-
         - TEST_DEPENDS=numpy==1.11.3
 
     # contrib builds for Linux
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
-
         - ENABLE_CONTRIB=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
-
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
-
         - PLAT=i686
         - ENABLE_CONTRIB=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
-
         - PLAT=i686
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
-
         - ENABLE_CONTRIB=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
-
         - PLAT=i686
         - ENABLE_CONTRIB=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
-
         - ENABLE_CONTRIB=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
-
         - PLAT=i686
         - ENABLE_CONTRIB=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
-
-
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
-
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
-
         - PLAT=i686
-
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
 
@@ -193,8 +177,8 @@ matrix:
 before_install: |
     # Check out and prepare the source
     set -e
-    #Multibuild doesn't have releases, so --depth would break eventually (see
-    #https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+    # Multibuild doesn't have releases, so --depth would break eventually (see
+    # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
     git submodule update --init multibuild
     source multibuild/common_utils.sh
     # https://github.com/matthew-brett/multibuild/issues/116

From dfa0bb09f2c0ca28e8beca831520a36a578e8cab Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 19 Feb 2018 19:47:17 +0200
Subject: [PATCH 015/566] make tabs and spaces consistent

---
 multibuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multibuild b/multibuild
index 9330c3dc..ad0ab85c 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit 9330c3dcc318b7b2b734ab00485d2ab253761811
+Subproject commit ad0ab85c3d3e3ec352c2c9bac973bd96da265c85

From 22d47861493bbfb6c96c0d6a14f311b8d5d11117 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 19 Feb 2018 20:01:59 +0200
Subject: [PATCH 016/566] fix some PEP8 style issues in setup.py

---
 .gitmodules |   2 +-
 setup.py    | 150 ++++++++++++++++++++++++++--------------------------
 2 files changed, 77 insertions(+), 75 deletions(-)

diff --git a/.gitmodules b/.gitmodules
index ce3da2e1..ee33f9a3 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,7 +4,7 @@
 [submodule "multibuild"]
 	path = multibuild
 	url = https://github.com/matthew-brett/multibuild.git
-    branch = devel
+	branch = devel
 [submodule "opencv_contrib"]
 	path = opencv_contrib
 	url = https://github.com/opencv/opencv_contrib.git
diff --git a/setup.py b/setup.py
index 039136d7..7af72863 100644
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,12 @@
 # No 3rd-party modules here, see "3rd-party" note below
-import io, os, os.path, sys, runpy, subprocess, re, sysconfig
+import io
+import os
+import os.path
+import sys
+import runpy
+import subprocess
+import re
+import sysconfig
 
 
 def main():
@@ -9,76 +16,72 @@ def main():
     cmake_source_dir = "opencv"
     build_contrib = get_build_contrib()
 
-
     # Only import 3rd-party modules after having installed all the build dependencies:
     # any of them, or their dependencies, can be updated during that process,
     # leading to version conflicts
     numpy_version = get_or_install("numpy", "1.11.3" if sys.version_info[:2] >= (3, 6) else "1.11.1")
     get_or_install("scikit-build")
     import skbuild
-    
+
     if os.path.exists('.git'):
+
         import pip.vcs.git
         g = pip.vcs.git.Git()
         use_depth = g.get_git_version() >= type(g.get_git_version())("1.8.4")
-        g.run_command(["submodule", "update", "--init", "--recursive"] + \
-            (["--depth=1"] if use_depth else []) + \
-            [cmake_source_dir])
+
+        g.run_command(["submodule", "update", "--init", "--recursive"] +
+                      (["--depth=1"] if use_depth else []) +
+                      [cmake_source_dir])
+
         if build_contrib:
-            g.run_command(["submodule", "update", "--init", "--recursive"] + \
-            (["--depth=1"] if use_depth else []) + \
-            ["opencv_contrib"])
-        del use_depth, g, pip
+            g.run_command(["submodule", "update", "--init", "--recursive"] +
+                          (["--depth=1"] if use_depth else []) +
+                          ["opencv_contrib"])
 
+        del use_depth, g, pip
 
     # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
-    x64 = sys.maxsize>2**32
-
+    x64 = sys.maxsize > 2**32
 
     package_name = "opencv-contrib-python" if build_contrib else "opencv-python"
     long_description = io.open('README_CONTRIB.rst' if build_contrib else 'README.rst', encoding="utf-8").read()
     package_version = get_opencv_version()
 
     packages = ['cv2', 'cv2.data']
-    package_data = \
-        {'cv2':
-            ['*%s' % sysconfig.get_config_var('SO')] + (['*.dll'] if os.name == 'nt' else []) +
+    package_data = {
+        'cv2':
+            ['*%s' % sysconfig.get_config_var('SO')] +
+            ['*.dll'] if os.name == 'nt' else [] +
             ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
-         'cv2.data':
+        'cv2.data':
             ["*.xml"]
-         }
+    }
 
     # Files from CMake output to copy to package.
     # Path regexes with forward slashes relative to CMake install dir.
-    rearrange_cmake_output_data = \
-        {'cv2':
-            ([r'bin/opencv_ffmpeg\d{3}%s\.dll' %
-                ('_64' if x64 else '')] if os.name == 'nt' else []
-            ) + \
+    rearrange_cmake_output_data = {
+        'cv2': [r'bin/opencv_ffmpeg\d{3}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else [] +
             # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
             # Naming conventions vary so widely between versions and OSes
             # had to give up on checking them.
-            ['python/([^/]+/){1,2}cv2[^/]*%(ext)s' % {
-                'ext':   re.escape(sysconfig.get_config_var('SO'))
-                }
-            ],
-         'cv2.data':
-            [ # OPENCV_OTHER_INSTALL_PATH
-            ('etc' if os.name =='nt' else 'share/OpenCV')
-            + r'/haarcascades/.*\.xml']
-         }
+            ['python/([^/]+/){1,2}cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
+        'cv2.data': [  # OPENCV_OTHER_INSTALL_PATH
+            ('etc' if os.name == 'nt' else 'share/OpenCV') +
+            r'/haarcascades/.*\.xml'
+        ]
+    }
+
     # Files in sourcetree outside package dir that should be copied to package.
     # Raw paths relative to sourcetree root.
-    files_outside_package_dir = \
-        {'cv2':
-            ['LICENSE.txt', 'LICENSE-3RD-PARTY.txt']
-         }
+    files_outside_package_dir = {
+        'cv2': ['LICENSE.txt', 'LICENSE-3RD-PARTY.txt']
+    }
 
     cmake_args = ([
         "-G", "Visual Studio 14" + (" Win64" if x64 else '')
     ] if os.name == 'nt' else [
-        "-G", "Unix Makefiles"  #don't make CMake try (and fail) Ninja first
-    ]) + \
+        "-G", "Unix Makefiles"  # don't make CMake try (and fail) Ninja first
+    ]) +
     [
         # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
         "-DPYTHON%d_EXECUTABLE=%s" % (sys.version_info[0], sys.executable),
@@ -92,30 +95,29 @@ def main():
         "-DBUILD_TESTS=OFF",
         "-DBUILD_PERF_TESTS=OFF",
         "-DBUILD_DOCS=OFF"
-    ] + \
-    ([ "-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules") ]
-       if build_contrib else [])
-       
+    ] +
+    (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
+
     # OS-specific components
     if sys.platform == 'darwin' or sys.platform.startswith('linux'):
-        cmake_args.append( "-DWITH_QT=4" )
+        cmake_args.append("-DWITH_QT=4")
+
     if sys.platform.startswith('linux'):
-        cmake_args.append( "-DWITH_V4L=ON" )
+        cmake_args.append("-DWITH_V4L=ON")
+
         if all(v in os.environ for v in ('JPEG_INCLUDE_DIR', 'JPEG_LIBRARY')):
             cmake_args += [
-            "-DBUILD_JPEG=OFF",
-            "-DJPEG_INCLUDE_DIR=%s" % os.environ['JPEG_INCLUDE_DIR'],
-            "-DJPEG_LIBRARY=%s" % os.environ['JPEG_LIBRARY']
+                "-DBUILD_JPEG=OFF",
+                "-DJPEG_INCLUDE_DIR=%s" % os.environ['JPEG_INCLUDE_DIR'],
+                "-DJPEG_LIBRARY=%s" % os.environ['JPEG_LIBRARY']
             ]
-            
+
     # Turn off broken components
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
     if sys.platform.startswith('linux'):
-        cmake_args.append( "-DWITH_IPP=OFF" )   # https://github.com/opencv/opencv/issues/10411
-
-
+        cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411
 
     # ABI config variables are introduced in PEP 425
     if sys.version_info[:2] < (3, 2):
@@ -125,7 +127,6 @@ def main():
                                 category=RuntimeWarning)
         del warnings
 
-
     # works via side effect
     RearrangeCMakeOutput(rearrange_cmake_output_data,
                          files_outside_package_dir,
@@ -175,8 +176,10 @@ def main():
 
 
 class RearrangeCMakeOutput(object):
-    """Patch SKBuild logic to only take files related to the Python package
-    and construct a file hierarchy that SKBuild expects (see below)"""
+    """
+        Patch SKBuild logic to only take files related to the Python package
+        and construct a file hierarchy that SKBuild expects (see below)
+    """
     _setuptools_wrap = None
 
     # Have to wrap a function reference, or it's converted
@@ -202,6 +205,7 @@ def __init__(self, package_paths_re, files_outside_package, packages):
         cls.package_paths_re = package_paths_re
         cls.files_outside_package = files_outside_package
         cls.packages = packages
+
     def __del__(self):
         cls = self.__class__
         cls._setuptools_wrap._classify_files = cls.wraps._classify_files
@@ -214,15 +218,18 @@ def _classify_files_override(self, install_paths,
             scripts, new_scripts,
             data_files,
             cmake_source_dir, cmake_install_reldir):
-        """From all CMake output, we're only interested in a few files
-        and must place them into CMake install dir according
-        to Python conventions for SKBuild to find them:
-            package\
-                file
-                subpackage\
-                    etc.
         """
+            From all CMake output, we're only interested in a few files
+            and must place them into CMake install dir according
+            to Python conventions for SKBuild to find them:
+                package\
+                    file
+                    subpackage\
+                        etc.
+        """
+
         cls = self.__class__
+
         # 'relpath'/'reldir' = relative to CMAKE_INSTALL_DIR/cmake_install_dir
         # 'path'/'dir' = relative to sourcetree root
         cmake_install_dir = os.path.join(cls._setuptools_wrap.CMAKE_INSTALL_DIR,
@@ -283,19 +290,15 @@ def _classify_files_override(self, install_paths,
             py_modules, new_py_modules,
             scripts, new_scripts,
             data_files,
-            # To get around a demented check
-            # that prepends source dir to paths and breaks package detection code.
-            # Can't imagine what the authors were thinking that should be doing.
-            cmake_source_dir = '',
-            cmake_install_dir = cmake_install_reldir
-            )
+            # To get around a check that prepends source dir to paths and breaks package detection code.
+            cmake_source_dir='',
+            cmake_install_dir=cmake_install_reldir
+        )
 
 
 def install_packages(*requirements):
     # No more convenient way until PEP 518 is implemented; setuptools only handles eggs
-    subprocess.check_call([sys.executable,
-                           "-m", "pip", "install"]
-                          + list(requirements))
+    subprocess.check_call([sys.executable, "-m", "pip", "install"] + list(requirements))
 
 
 def get_opencv_version():
@@ -320,19 +323,18 @@ def get_build_contrib():
     return build_contrib
 
 
-def get_or_install(name, version = None):
+def get_or_install(name, version=None):
     """If a package is already installed, build against it. If not, install"""
     # Do not import 3rd-party modules into the current process
     import json
     js_packages = json.loads(
-        subprocess.check_output(
-        [sys.executable, "-m", "pip", "list", "--format=json"])
-        .decode('ascii'))  #valid names & versions are ASCII as per PEP 440
+        subprocess.check_output([sys.executable, "-m", "pip", "list", "--format=json"])
+        .decode('ascii'))  # valid names & versions are ASCII as per PEP 440
     try:
         [package] = (package for package in js_packages
                      if package['name'] == name)
     except ValueError:
-        install_packages("%s==%s"%(name, version) if version else name)
+        install_packages("%s==%s" % (name, version) if version else name)
         return version
     else:
         return package['version']

From 541fbdbc0da432ba56fe06c4486576c81e6e10c5 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 20 Feb 2018 17:00:40 +0200
Subject: [PATCH 017/566] small fixes

---
 setup.py | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/setup.py b/setup.py
index 7af72863..844f15ab 100644
--- a/setup.py
+++ b/setup.py
@@ -77,12 +77,11 @@ def main():
         'cv2': ['LICENSE.txt', 'LICENSE-3RD-PARTY.txt']
     }
 
-    cmake_args = ([
+    cmake_args = [
         "-G", "Visual Studio 14" + (" Win64" if x64 else '')
     ] if os.name == 'nt' else [
         "-G", "Unix Makefiles"  # don't make CMake try (and fail) Ninja first
-    ]) +
-    [
+    ] + [
         # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
         "-DPYTHON%d_EXECUTABLE=%s" % (sys.version_info[0], sys.executable),
         "-DBUILD_opencv_python%d=ON" % sys.version_info[0],
@@ -95,8 +94,7 @@ def main():
         "-DBUILD_TESTS=OFF",
         "-DBUILD_PERF_TESTS=OFF",
         "-DBUILD_DOCS=OFF"
-    ] +
-    (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
+    ] + ["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else []
 
     # OS-specific components
     if sys.platform == 'darwin' or sys.platform.startswith('linux'):
@@ -328,8 +326,7 @@ def get_or_install(name, version=None):
     # Do not import 3rd-party modules into the current process
     import json
     js_packages = json.loads(
-        subprocess.check_output([sys.executable, "-m", "pip", "list", "--format=json"])
-        .decode('ascii'))  # valid names & versions are ASCII as per PEP 440
+        subprocess.check_output([sys.executable, "-m", "pip", "list", "--format", "json"]).decode('ascii'))  # valid names & versions are ASCII as per PEP 440
     try:
         [package] = (package for package in js_packages
                      if package['name'] == name)

From cdfe4464018f8ad06593038efc2f7f555707ad13 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 20 Feb 2018 17:14:00 +0200
Subject: [PATCH 018/566] run git submodule sync due to some random errors in
 Travis

---
 setup.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index 844f15ab..e4fd52f1 100644
--- a/setup.py
+++ b/setup.py
@@ -27,15 +27,16 @@ def main():
 
         import pip.vcs.git
         g = pip.vcs.git.Git()
+        g.run_command(["submodule", "sync"])
         use_depth = g.get_git_version() >= type(g.get_git_version())("1.8.4")
 
         g.run_command(["submodule", "update", "--init", "--recursive"] +
-                      (["--depth=1"] if use_depth else []) +
+                      ["--depth=1"] if use_depth else [] +
                       [cmake_source_dir])
 
         if build_contrib:
             g.run_command(["submodule", "update", "--init", "--recursive"] +
-                          (["--depth=1"] if use_depth else []) +
+                          ["--depth=1"] if use_depth else [] +
                           ["opencv_contrib"])
 
         del use_depth, g, pip

From 62fe1dc25f9c7d2a27852a3b4cc425f6286ed2e9 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 20 Feb 2018 17:27:46 +0200
Subject: [PATCH 019/566] fix multibuild hash

---
 .gitmodules | 7 +++----
 multibuild  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/.gitmodules b/.gitmodules
index ee33f9a3..c18bf409 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,10 +1,9 @@
 [submodule "opencv"]
 	path = opencv
 	url = https://github.com/Itseez/opencv.git
-[submodule "multibuild"]
-	path = multibuild
-	url = https://github.com/matthew-brett/multibuild.git
-	branch = devel
 [submodule "opencv_contrib"]
 	path = opencv_contrib
 	url = https://github.com/opencv/opencv_contrib.git
+[submodule "multibuild"]
+	path = multibuild
+	url = https://github.com/matthew-brett/multibuild.git
diff --git a/multibuild b/multibuild
index ad0ab85c..9330c3dc 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit ad0ab85c3d3e3ec352c2c9bac973bd96da265c85
+Subproject commit 9330c3dcc318b7b2b734ab00485d2ab253761811

From 07e56463e772b91ce07c5ab7ccf28fca5d3c52e7 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 20 Feb 2018 18:22:17 +0200
Subject: [PATCH 020/566] ternary operators need parentheses

---
 setup.py | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/setup.py b/setup.py
index e4fd52f1..34cf9384 100644
--- a/setup.py
+++ b/setup.py
@@ -31,12 +31,12 @@ def main():
         use_depth = g.get_git_version() >= type(g.get_git_version())("1.8.4")
 
         g.run_command(["submodule", "update", "--init", "--recursive"] +
-                      ["--depth=1"] if use_depth else [] +
+                      (["--depth=1"] if use_depth else []) +
                       [cmake_source_dir])
 
         if build_contrib:
             g.run_command(["submodule", "update", "--init", "--recursive"] +
-                          ["--depth=1"] if use_depth else [] +
+                          (["--depth=1"] if use_depth else []) +
                           ["opencv_contrib"])
 
         del use_depth, g, pip
@@ -52,7 +52,7 @@ def main():
     package_data = {
         'cv2':
             ['*%s' % sysconfig.get_config_var('SO')] +
-            ['*.dll'] if os.name == 'nt' else [] +
+            (['*.dll'] if os.name == 'nt' else []) +
             ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
         'cv2.data':
             ["*.xml"]
@@ -61,7 +61,7 @@ def main():
     # Files from CMake output to copy to package.
     # Path regexes with forward slashes relative to CMake install dir.
     rearrange_cmake_output_data = {
-        'cv2': [r'bin/opencv_ffmpeg\d{3}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else [] +
+        'cv2': ([r'bin/opencv_ffmpeg\d{3}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else []) +
             # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
             # Naming conventions vary so widely between versions and OSes
             # had to give up on checking them.
@@ -78,11 +78,11 @@ def main():
         'cv2': ['LICENSE.txt', 'LICENSE-3RD-PARTY.txt']
     }
 
-    cmake_args = [
+    cmake_args = ([
         "-G", "Visual Studio 14" + (" Win64" if x64 else '')
     ] if os.name == 'nt' else [
         "-G", "Unix Makefiles"  # don't make CMake try (and fail) Ninja first
-    ] + [
+    ]) + [
         # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
         "-DPYTHON%d_EXECUTABLE=%s" % (sys.version_info[0], sys.executable),
         "-DBUILD_opencv_python%d=ON" % sys.version_info[0],
@@ -95,7 +95,7 @@ def main():
         "-DBUILD_TESTS=OFF",
         "-DBUILD_PERF_TESTS=OFF",
         "-DBUILD_DOCS=OFF"
-    ] + ["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else []
+    ] + (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
 
     # OS-specific components
     if sys.platform == 'darwin' or sys.platform.startswith('linux'):
@@ -280,7 +280,6 @@ def _classify_files_override(self, install_paths,
                 )
                 final_install_relpaths.append(new_install_relpath)
 
-
         final_install_paths = [os.path.join(cmake_install_dir, p) for p in final_install_relpaths]
 
         return (cls.wraps._classify_files)(
@@ -329,8 +328,7 @@ def get_or_install(name, version=None):
     js_packages = json.loads(
         subprocess.check_output([sys.executable, "-m", "pip", "list", "--format", "json"]).decode('ascii'))  # valid names & versions are ASCII as per PEP 440
     try:
-        [package] = (package for package in js_packages
-                     if package['name'] == name)
+        [package] = (package for package in js_packages if package['name'] == name)
     except ValueError:
         install_packages("%s==%s" % (name, version) if version else name)
         return version

From 66c09f5fa18e4b9d20bfb2d859f4a77c2fc109bb Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 20 Feb 2018 19:07:05 +0200
Subject: [PATCH 021/566] update old repo url

---
 .gitmodules | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.gitmodules b/.gitmodules
index c18bf409..f2e0d283 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,6 @@
 [submodule "opencv"]
 	path = opencv
-	url = https://github.com/Itseez/opencv.git
+	url = https://github.com/opencv/opencv.git
 [submodule "opencv_contrib"]
 	path = opencv_contrib
 	url = https://github.com/opencv/opencv_contrib.git

From d18b0eadeafab2709c01ed4a1b083dc2aafdcca3 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 20 Feb 2018 19:13:07 +0200
Subject: [PATCH 022/566] depth flag seems to break submodule fetch on macOS
 images

---
 setup.py | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/setup.py b/setup.py
index 34cf9384..f995605c 100644
--- a/setup.py
+++ b/setup.py
@@ -27,17 +27,12 @@ def main():
 
         import pip.vcs.git
         g = pip.vcs.git.Git()
-        g.run_command(["submodule", "sync"])
-        use_depth = g.get_git_version() >= type(g.get_git_version())("1.8.4")
 
-        g.run_command(["submodule", "update", "--init", "--recursive"] +
-                      (["--depth=1"] if use_depth else []) +
-                      [cmake_source_dir])
+        g.run_command(["submodule", "sync"])
+        g.run_command(["submodule", "update", "--init", "--recursive", cmake_source_dir])
 
         if build_contrib:
-            g.run_command(["submodule", "update", "--init", "--recursive"] +
-                          (["--depth=1"] if use_depth else []) +
-                          ["opencv_contrib"])
+            g.run_command(["submodule", "update", "--init", "--recursive", "opencv_contrib"])
 
         del use_depth, g, pip
 

From 63cdb56a8dcf7227169c869ea47a25ee737d491b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 20 Feb 2018 19:18:30 +0200
Subject: [PATCH 023/566] fix unreferenced variable

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index f995605c..134db622 100644
--- a/setup.py
+++ b/setup.py
@@ -34,7 +34,7 @@ def main():
         if build_contrib:
             g.run_command(["submodule", "update", "--init", "--recursive", "opencv_contrib"])
 
-        del use_depth, g, pip
+        del g, pip
 
     # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
     x64 = sys.maxsize > 2**32

From f58a8564075d30b2f561e469e8a33f9539d2f35b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 20 Feb 2018 20:27:41 +0200
Subject: [PATCH 024/566] qt4 install

---
 config.sh | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/config.sh b/config.sh
index 3eba50b3..76a0db9e 100644
--- a/config.sh
+++ b/config.sh
@@ -23,11 +23,10 @@ function pre_build {
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
 
-    # For some reason, gt@4 and ffmpeg can be preinstalled in Travis Mac env
     echo 'Installing QT4'
-    brew tap | grep -qxF cartr/qt4 || brew tap -v cartr/qt4
-    brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin -v cartr/qt4
-    brew list --versions qt@4 || brew install -v qt@4
+    brew tap cartr/qt4
+    brew tap-pin cartr/qt4
+    brew install qt@4
     echo '-----------------'
     echo 'Installing FFmpeg'
     # brew install does produce output regularly on a regular MacOS,
@@ -39,7 +38,7 @@ function pre_build {
   else
     echo "Running for linux"
   fi
-  qmake -query  
+  qmake -query
 }
 
 function run_tests {
@@ -54,7 +53,7 @@ function run_tests {
       echo "Running for linux"
       cd /io/tests/
     fi
-    
+
     test_wheels
 }
 

From 60ccdceb74d250361b2f6333ffabfcb87bc0f6ad Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 24 Feb 2018 18:17:02 +0200
Subject: [PATCH 025/566] try to get qt4 install working on macOS

---
 .travis.yml | 8 ++++++++
 config.sh   | 1 +
 2 files changed, 9 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index 72b6d612..9e3eb372 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -29,21 +29,25 @@ matrix:
 
     # default builds for MacOS
     - os: osx
+      language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
     - os: osx
+      language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
     - os: osx
+      language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
     - os: osx
+      language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.6
@@ -51,21 +55,25 @@ matrix:
 
     # Contrib builds for MacOS
     - os: osx
+      language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
     - os: osx
+      language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
     - os: osx
+      language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
     - os: osx
+      language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.6
diff --git a/config.sh b/config.sh
index 76a0db9e..7f35e0e8 100644
--- a/config.sh
+++ b/config.sh
@@ -24,6 +24,7 @@ function pre_build {
     echo "Running for OSX"
 
     echo 'Installing QT4'
+    brew update
     brew tap cartr/qt4
     brew tap-pin cartr/qt4
     brew install qt@4

From b5d097c0511c4effd9d0650facd29b9ff3dac64b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 25 Feb 2018 16:19:57 +0200
Subject: [PATCH 026/566] qt4 install changes

---
 config.sh | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/config.sh b/config.sh
index 7f35e0e8..ca089dad 100644
--- a/config.sh
+++ b/config.sh
@@ -23,11 +23,13 @@ function pre_build {
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
 
-    echo 'Installing QT4'
     brew update
-    brew tap cartr/qt4
-    brew tap-pin cartr/qt4
-    brew install qt@4
+
+    echo 'Installing QT4'
+    brew tap | grep -qxF cartr/qt4 || brew tap -v cartr/qt4
+    brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin -v cartr/qt4
+    brew list --versions qt@4 || brew install -v qt@4
+    echo '-----------------'
     echo '-----------------'
     echo 'Installing FFmpeg'
     # brew install does produce output regularly on a regular MacOS,

From bda4ee84166c955298c6a13c5350b7275ee0f8bf Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 24 Apr 2018 18:00:33 +0300
Subject: [PATCH 027/566] try new image

---
 multibuild_customize.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multibuild_customize.sh b/multibuild_customize.sh
index 9b798c90..e34f5b26 100644
--- a/multibuild_customize.sh
+++ b/multibuild_customize.sh
@@ -3,4 +3,4 @@
 export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
 set -x
 REPO_DIR=$(dirname "${BASH_SOURCE[0]}")
-DOCKER_IMAGE='quay.io/skvark/manylinux_$plat'
+DOCKER_IMAGE='quay.io/skvark/manylinux1_$plat'

From 91f52b880f9c4b881f79298d1ff235a26eb89ab0 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 24 Apr 2018 18:12:26 +0300
Subject: [PATCH 028/566] temporary fix for pip api changes

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 134db622..db549b70 100644
--- a/setup.py
+++ b/setup.py
@@ -26,7 +26,7 @@ def main():
     if os.path.exists('.git'):
 
         import pip.vcs.git
-        g = pip.vcs.git.Git()
+        g = pip._internal.vcs.git.Git() # NOTE: pip API's are internal, this has to be refactored
 
         g.run_command(["submodule", "sync"])
         g.run_command(["submodule", "update", "--init", "--recursive", cmake_source_dir])

From 6e42c0699e4730adebf7f545978546bed21daeb2 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 24 Apr 2018 18:35:21 +0300
Subject: [PATCH 029/566] fix import

---
 setup.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index db549b70..c754670b 100644
--- a/setup.py
+++ b/setup.py
@@ -25,8 +25,8 @@ def main():
 
     if os.path.exists('.git'):
 
-        import pip.vcs.git
-        g = pip._internal.vcs.git.Git() # NOTE: pip API's are internal, this has to be refactored
+        import pip._internal.vcs.git as git
+        g = git.Git()  # NOTE: pip API's are internal, this has to be refactored
 
         g.run_command(["submodule", "sync"])
         g.run_command(["submodule", "update", "--init", "--recursive", cmake_source_dir])

From eb120e07cc71986b35fe4cec0ebb4d1ad545ac96 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 24 Apr 2018 18:54:25 +0300
Subject: [PATCH 030/566] remove del

---
 setup.py | 2 --
 1 file changed, 2 deletions(-)

diff --git a/setup.py b/setup.py
index c754670b..d416c8d5 100644
--- a/setup.py
+++ b/setup.py
@@ -34,8 +34,6 @@ def main():
         if build_contrib:
             g.run_command(["submodule", "update", "--init", "--recursive", "opencv_contrib"])
 
-        del g, pip
-
     # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
     x64 = sys.maxsize > 2**32
 

From 34124650f0c2ec5e6c538b0f17a89c5b8c1b0e41 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 24 Apr 2018 19:28:44 +0300
Subject: [PATCH 031/566] update multibuild

---
 multibuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multibuild b/multibuild
index 9330c3dc..ae3e5598 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit 9330c3dcc318b7b2b734ab00485d2ab253761811
+Subproject commit ae3e559829d34a74c706baa9389a101e52d8e2d0

From afb6715917aae286607b73cc39d5966d1b3fac12 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 24 Apr 2018 19:34:24 +0300
Subject: [PATCH 032/566] update pip

---
 appveyor.yml | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index 80bd5e97..e777c48a 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -57,10 +57,9 @@ environment:
 matrix:
     fast_finish: true
 
-      
 build_script:
 - cmd: |
-
+    "%PYTHON%/python.exe" -m pip install --upgrade pip
     "%PYTHON%/python.exe" setup.py bdist_wheel
 
 before_test:

From 07c9d59723f3ec8433f7b846bcb6087dbcf94570 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 27 Apr 2018 20:34:35 +0300
Subject: [PATCH 033/566] disable precompiled headers

---
 setup.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index d416c8d5..d0b073fe 100644
--- a/setup.py
+++ b/setup.py
@@ -96,6 +96,7 @@ def main():
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_V4L=ON")
+        cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 
         if all(v in os.environ for v in ('JPEG_INCLUDE_DIR', 'JPEG_LIBRARY')):
             cmake_args += [

From 6dbdf957e4d269210180085fdf816a1237a332af Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 2 May 2018 23:04:50 +0300
Subject: [PATCH 034/566] add dockerfiles and readme

---
 docker/Dockerfile_i686   | 87 ++++++++++++++++++++++++++++++++++++++++
 docker/Dockerfile_x86_64 | 87 ++++++++++++++++++++++++++++++++++++++++
 docker/README.md         | 15 +++++++
 3 files changed, 189 insertions(+)
 create mode 100644 docker/Dockerfile_i686
 create mode 100644 docker/Dockerfile_x86_64
 create mode 100644 docker/README.md

diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
new file mode 100644
index 00000000..b788b96f
--- /dev/null
+++ b/docker/Dockerfile_i686
@@ -0,0 +1,87 @@
+FROM quay.io/pypa/manylinux1_i686:latest
+
+RUN wget --no-check-certificate https://download.qt.io/official_releases/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz && \
+	tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
+	cd qt-everywhere* && \
+	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license && \
+	gmake && \
+	gmake install && \
+	cd .. && \
+	rm -rf qt-everywhere-opensource-src-4.8.7 && \
+	rm qt-everywhere-opensource-src-4.8.7.tar.gz
+
+ENV QTDIR /opt/Qt4.8.7
+ENV PATH "$QTDIR/bin:$PATH"
+
+RUN wget --no-check-certificate https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
+	tar -zxf cmake-3.9.0.tar.gz && \
+	cd cmake-3.9.0 && \
+	yum -y install curl-devel zlib-devel && \
+	./configure --system-curl && \
+	make && \
+	make install && \
+	cd .. && \
+	rm -rf cmake-3.9.0*
+
+RUN yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ libtool make mercurial pkgconfig zlib-devel -y && \
+	yum remove nasm -y && \
+	mkdir ~/ffmpeg_sources && \
+	cd ~/ffmpeg_sources && \
+	curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
+	tar xjvf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+	make -j4 && \
+	make install && \
+	cd ~/ffmpeg_sources && \
+	curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
+	tar xzvf yasm-1.3.0.tar.gz && \
+	cd yasm-1.3.0 && \
+	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+	make -j4 && \
+	make install && \
+	cd ~/ffmpeg_sources && \
+	git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
+	cd libvpx && \
+	./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
+	make -j4 && \
+	make install && \
+	cd ~/ffmpeg_sources && \
+	curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
+	tar xjvf ffmpeg-snapshot.tar.bz2 && \
+	cd ffmpeg && \
+	PATH=~/bin:$PATH && \
+	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+	make -j4 && \
+	make install && \
+	echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
+	ldconfig && \
+	rm -rf ~/ffmpeg_sources
+
+ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
+ENV LDFLAGS -L/root/ffmpeg_build/lib
+
+RUN mkdir libjpeg-turbo && \
+	cd libjpeg-turbo && \
+	export PATH=~/bin:$PATH && \
+	curl -L https://kent.dl.sourceforge.net/project/libjpeg-turbo/1.5.3/libjpeg-turbo-1.5.3.tar.gz > libjpeg-turbo-1.5.3.tar.gz && \
+	tar xzvf libjpeg-turbo-1.5.3.tar.gz && \
+	cd libjpeg-turbo-1.5.3 && \
+	export CFLAGS="-fPIC" && \
+	export CXXFLAGS="-fPIC" && \
+	autoreconf -fiv && \
+	./configure --host=i686-pc-linux-gnu && \
+	make && \
+	make install && \
+	cd ../../ && \
+	rm -rf libjpeg-turbo
+
+ENV JPEG_LIBRARY /opt/libjpeg-turbo/lib32/libjpeg.a
+ENV JPEG_INCLUDE_DIR /opt/libjpeg-turbo/include
+
+RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/videodev2.h && \
+	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
+	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
+	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
+	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
+
+ENV PATH "$PATH=~/bin:$PATH"
\ No newline at end of file
diff --git a/docker/Dockerfile_x86_64 b/docker/Dockerfile_x86_64
new file mode 100644
index 00000000..4919f89f
--- /dev/null
+++ b/docker/Dockerfile_x86_64
@@ -0,0 +1,87 @@
+FROM quay.io/pypa/manylinux1_x86_64:latest
+
+RUN wget --no-check-certificate https://download.qt.io/official_releases/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz && \
+	tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
+	cd qt-everywhere* && \
+	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license && \
+	gmake && \
+	gmake install && \
+	cd .. && \
+	rm -rf qt-everywhere-opensource-src-4.8.7 && \
+	rm qt-everywhere-opensource-src-4.8.7.tar.gz
+
+ENV QTDIR /opt/Qt4.8.7
+ENV PATH "$QTDIR/bin:$PATH"
+
+RUN wget --no-check-certificate https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
+	tar -zxf cmake-3.9.0.tar.gz && \
+	cd cmake-3.9.0 && \
+	yum -y install curl-devel zlib-devel && \
+	./configure --system-curl && \
+	make && \
+	make install && \
+	cd .. && \
+	rm -rf cmake-3.9.0*
+
+RUN yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ libtool make mercurial pkgconfig zlib-devel -y && \
+	yum remove nasm -y && \
+	mkdir ~/ffmpeg_sources && \
+	cd ~/ffmpeg_sources && \
+	curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
+	tar xjvf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+	make -j4 && \
+	make install && \
+	cd ~/ffmpeg_sources && \
+	curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
+	tar xzvf yasm-1.3.0.tar.gz && \
+	cd yasm-1.3.0 && \
+	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+	make -j4 && \
+	make install && \
+	cd ~/ffmpeg_sources && \
+	git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
+	cd libvpx && \
+	./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
+	make -j4 && \
+	make install && \
+	cd ~/ffmpeg_sources && \
+	curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
+	tar xjvf ffmpeg-snapshot.tar.bz2 && \
+	cd ffmpeg && \
+	PATH=~/bin:$PATH && \
+	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+	make -j4 && \
+	make install && \
+	echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
+	ldconfig && \
+	rm -rf ~/ffmpeg_sources
+
+ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
+ENV LDFLAGS -L/root/ffmpeg_build/lib
+
+RUN mkdir libjpeg-turbo && \
+	cd libjpeg-turbo && \
+	export PATH=~/bin:$PATH && \
+	curl -L https://kent.dl.sourceforge.net/project/libjpeg-turbo/1.5.3/libjpeg-turbo-1.5.3.tar.gz > libjpeg-turbo-1.5.3.tar.gz && \
+	tar xzvf libjpeg-turbo-1.5.3.tar.gz && \
+	cd libjpeg-turbo-1.5.3 && \
+	export CFLAGS="-fPIC" && \
+	export CXXFLAGS="-fPIC" && \
+	autoreconf -fiv && \
+	./configure && \
+	make && \
+	make install && \
+	cd ../../ && \
+	rm -rf libjpeg-turbo
+
+ENV JPEG_LIBRARY /opt/libjpeg-turbo/lib64/libjpeg.a
+ENV JPEG_INCLUDE_DIR /opt/libjpeg-turbo/include
+
+RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/videodev2.h && \
+	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
+	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
+	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
+	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
+
+ENV PATH "$PATH=~/bin:$PATH"
\ No newline at end of file
diff --git a/docker/README.md b/docker/README.md
new file mode 100644
index 00000000..9e932c40
--- /dev/null
+++ b/docker/README.md
@@ -0,0 +1,15 @@
+### Customized manylinux images for opencv-python
+
+This folder includes Dockerfiles for extending both ``i686`` and ``x86_64`` manylinux images.
+
+The extended images were created to be able to build OpenCV in reasonable time with Travis.
+
+These images have been built locally because the process takes over an hour with modern i7 processor. The images are hosted at https://quay.io/user/skvark.
+
+The images have following extra software installed:
+
+- Qt 4.8.7
+- Cmake 3.9.0
+- FFmpeg with libvpx
+- libjpeg-turbo 1.5.3
+- Some missing headers included from more recent Linux to be able to enable V4L / V4L2 support in OpenCV
\ No newline at end of file

From 05a9709c1953e9a5e35dcfae5d116bb93e24f66e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 3 May 2018 19:35:40 +0300
Subject: [PATCH 035/566] test headless builds

---
 .travis.yml      | 223 ++++++++++++++++++++++++++++++++++++++++++++++-
 appveyor.yml     | 114 +++++++++++++++++++++---
 docker/README.md |   4 +-
 setup.py         |  39 +++++++--
 4 files changed, 357 insertions(+), 23 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 9e3eb372..dff66023 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -34,24 +34,58 @@ matrix:
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
     - os: osx
       language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
     - os: osx
       language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
     - os: osx
       language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+
+    # headless builds for MacOS
+    - os: osx
+      language: generic
+      osx_image: xcode7.3
+      env:
+        - MB_PYTHON_VERSION=2.7
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+    - os: osx
+      language: generic
+      osx_image: xcode7.3
+      env:
+        - MB_PYTHON_VERSION=3.4
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+    - os: osx
+      language: generic
+      osx_image: xcode7.3
+      env:
+        - MB_PYTHON_VERSION=3.5
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+    - os: osx
+      language: generic
+      osx_image: xcode7.3
+      env:
+        - MB_PYTHON_VERSION=3.6
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
 
     # Contrib builds for MacOS
     - os: osx
@@ -60,74 +94,179 @@ matrix:
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
     - os: osx
       language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
     - os: osx
       language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
     - os: osx
       language: generic
       osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+
+    # headless contrib builds for MacOS
+    - os: osx
+      language: generic
+      osx_image: xcode7.3
+      env:
+        - MB_PYTHON_VERSION=2.7
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+    - os: osx
+      language: generic
+      osx_image: xcode7.3
+      env:
+        - MB_PYTHON_VERSION=3.4
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+    - os: osx
+      language: generic
+      osx_image: xcode7.3
+      env:
+        - MB_PYTHON_VERSION=3.5
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+    - os: osx
+      language: generic
+      osx_image: xcode7.3
+      env:
+        - MB_PYTHON_VERSION=3.6
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
 
     # default builds for Linux
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=2.7
+        - UNICODE_WIDTH=16
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=2.7
+        - PLAT=i686
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=2.7
+        - PLAT=i686
+        - UNICODE_WIDTH=16
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.4
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.4
+        - PLAT=i686
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.5
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.5
+        - PLAT=i686
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.6
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.11.3
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.6
+        - PLAT=i686
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.11.3
+
+    # headless builds for Linux
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=2.7
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - PLAT=i686
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - PLAT=i686
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
         - PLAT=i686
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.11.3
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
         - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.11.3
 
     # contrib builds for Linux
@@ -135,51 +274,122 @@ matrix:
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=2.7
+        - UNICODE_WIDTH=16
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=2.7
+        - PLAT=i686
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=2.7
+        - PLAT=i686
+        - UNICODE_WIDTH=16
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.4
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.4
+        - PLAT=i686
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.5
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.5
+        - PLAT=i686
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.6
+        - TEST_DEPENDS=numpy==1.11.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.6
+        - PLAT=i686
+        - TEST_DEPENDS=numpy==1.11.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+
+    # headless contrib builds for Linux
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=2.7
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - PLAT=i686
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - PLAT=i686
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
         - PLAT=i686
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
 
 # The first line is printed in the folding header in Travis output
 before_install: |
@@ -195,6 +405,7 @@ before_install: |
     # This sets -x
     source multibuild_customize.sh
     echo $ENABLE_CONTRIB > contrib.enabled
+    echo $ENABLE_HEADLESS > headless.enabled
     before_install
     # Not interested in travis internal scripts' output
     set +x
@@ -218,9 +429,17 @@ after_success: |
         pip install twine
 
         if [[ $ENABLE_CONTRIB == 0 ]]; then
-            echo "This is default build. Deployment will be done to to PyPI entry opencv-python."
+            if [[ $ENABLE_HEADLESS == 0 ]]; then
+              echo "This is default build. Deployment will be done to to PyPI entry opencv-python."
+            else
+              echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-python-headless."
+            fi
         else
-            echo "This is contrib build. Deployment will be done to to PyPI entry opencv-contrib-python."
+            if [[ $ENABLE_HEADLESS == 0 ]]; then
+              echo "This is contrib build. Deployment will be done to to PyPI entry opencv-contrib-python."
+            else
+              echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-contrib-python-headless."
+            fi
         fi
 
         twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
diff --git a/appveyor.yml b/appveyor.yml
index e777c48a..c7a8b319 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -8,51 +8,131 @@ environment:
   matrix:
     - PYTHON: "C:/Python27"
       ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python27-x64"
       ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python34"
       ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python34-x64"
       ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python35-x64"
       ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python36-x64"
       ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python27"
       ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python27-x64"
       ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python34"
       ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python34-x64"
       ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python35-x64"
       ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
 
     - PYTHON: "C:/Python36-x64"
       ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python27"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python27-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python34"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python34-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python35"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python35-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python36"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python36-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python27"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python27-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python34"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python34-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python35"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python35-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python36"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python36-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
 
 matrix:
     fast_finish: true
@@ -83,13 +163,27 @@ deploy_script:
 - ps: |
 
     if (${Env:APPVEYOR_REPO_TAG} -eq "true") {
-        cd ${Env:APPVEYOR_BUILD_FOLDER}
-        if (${Env:ENABLE_CONTRIB} -eq 0) `
-            {echo "This is a default build. Deployment will be done to PyPI entry opencv-python."} `
-        else `
-            {echo "This is a contrib build. Deployment will be done to PyPI entry opencv-contrib-python."}
-
-        &"${Env:PYTHON}/python.exe" -m pip install twine
-        &"${Env:PYTHON}/python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv* } `
-    else
-        {echo "Tag not set, deployment skipped."}
+      cd ${Env:APPVEYOR_BUILD_FOLDER}
+      if (${Env:ENABLE_CONTRIB} -eq 0) {
+        if (${Env:ENABLE_HEADLESS} -eq 0) {
+          echo "This is a default build. Deployment will be done to PyPI entry opencv-python."
+        }
+        else {
+          echo "This is a headless build. Deployment will be done to PyPI entry opencv-python-headless."
+        }
+      }
+      else {
+        if (${Env:ENABLE_HEADLESS} -eq 0) {
+          echo "This is a contrib build. Deployment will be done to PyPI entry opencv-contrib-python."
+        }
+        else {
+          echo "This is a headless contrib build. Deployment will be done to PyPI entry opencv-contrib-python-headless."
+        }
+      }
+
+      &"${Env:PYTHON}/python.exe" -m pip install twine
+      &"${Env:PYTHON}/python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv*
+    }
+    else {
+      echo "Tag not set, deployment skipped."
+    }
diff --git a/docker/README.md b/docker/README.md
index 9e932c40..2e8602bf 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -4,12 +4,12 @@ This folder includes Dockerfiles for extending both ``i686`` and ``x86_64`` many
 
 The extended images were created to be able to build OpenCV in reasonable time with Travis.
 
-These images have been built locally because the process takes over an hour with modern i7 processor. The images are hosted at https://quay.io/user/skvark.
+These images have been built locally because the process takes over 1,5 hours with modern i7 processor. The images are hosted at https://quay.io/user/skvark.
 
 The images have following extra software installed:
 
 - Qt 4.8.7
 - Cmake 3.9.0
-- FFmpeg with libvpx
+- FFmpeg with libvpx (latest snapshots at the build time)
 - libjpeg-turbo 1.5.3
 - Some missing headers included from more recent Linux to be able to enable V4L / V4L2 support in OpenCV
\ No newline at end of file
diff --git a/setup.py b/setup.py
index d0b073fe..986f60bd 100644
--- a/setup.py
+++ b/setup.py
@@ -10,11 +10,14 @@
 
 
 def main():
+
     os.chdir(os.path.dirname(os.path.abspath(__file__)))
 
     # These are neede for source fetching
     cmake_source_dir = "opencv"
-    build_contrib = get_build_contrib()
+    build_contrib = get_build_env_var_by_name("contrib")
+    # headless flag to skip GUI deps if needed
+    build_headless = get_build_env_var_by_name("headless")
 
     # Only import 3rd-party modules after having installed all the build dependencies:
     # any of them, or their dependencies, can be updated during that process,
@@ -37,7 +40,17 @@ def main():
     # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
     x64 = sys.maxsize > 2**32
 
-    package_name = "opencv-contrib-python" if build_contrib else "opencv-python"
+    package_name = "opencv-python"
+
+    if build_contrib and !build_headless:
+        package_name = "opencv-contrib-python"
+
+    if build_contrib and build_headless
+        package_name = "opencv-contrib-python-headless"
+
+    if build_headless and !build_contrib:
+        package_name = "opencv-python-headless"
+
     long_description = io.open('README_CONTRIB.rst' if build_contrib else 'README.rst', encoding="utf-8").read()
     package_version = get_opencv_version()
 
@@ -91,9 +104,14 @@ def main():
     ] + (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
 
     # OS-specific components
-    if sys.platform == 'darwin' or sys.platform.startswith('linux'):
+    if (sys.platform == 'darwin' or sys.platform.startswith('linux')) and !build_headless:
         cmake_args.append("-DWITH_QT=4")
 
+    if build_headless:
+        # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
+        cmake_args.append("-DWITH_WIN32UI=OFF")
+        cmake_args.append("-DWITH_QT=OFF")
+
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_V4L=ON")
         cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
@@ -300,19 +318,22 @@ def get_opencv_version():
     return opencv_version
 
 
-def get_build_contrib():
-    build_contrib = False
+def get_build_env_var_by_name(flag_name):
+
+    flag_set = False
+
     try:
-        build_contrib = bool(int(os.getenv('ENABLE_CONTRIB', None)))
+        flag_set = bool(int(os.getenv('ENABLE_' + flag_name.upper() , None)))
     except Exception:
         pass
 
-    if not build_contrib:
+    if not flag_set:
         try:
-            build_contrib = bool(int(open("contrib.enabled").read(1)))
+            flag_set = bool(int(open(flag_name + ".enabled").read(1)))
         except Exception:
             pass
-    return build_contrib
+
+    return flag_set
 
 
 def get_or_install(name, version=None):

From b0ef67133aa03b4a6fe729a1997bdb99bfa939cc Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 3 May 2018 19:44:00 +0300
Subject: [PATCH 036/566] I haven't clearly coded python enough lately :D

---
 setup.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/setup.py b/setup.py
index 986f60bd..1d885d3e 100644
--- a/setup.py
+++ b/setup.py
@@ -42,13 +42,13 @@ def main():
 
     package_name = "opencv-python"
 
-    if build_contrib and !build_headless:
+    if build_contrib and not build_headless:
         package_name = "opencv-contrib-python"
 
     if build_contrib and build_headless
         package_name = "opencv-contrib-python-headless"
 
-    if build_headless and !build_contrib:
+    if build_headless and not build_contrib:
         package_name = "opencv-python-headless"
 
     long_description = io.open('README_CONTRIB.rst' if build_contrib else 'README.rst', encoding="utf-8").read()
@@ -104,7 +104,7 @@ def main():
     ] + (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
 
     # OS-specific components
-    if (sys.platform == 'darwin' or sys.platform.startswith('linux')) and !build_headless:
+    if (sys.platform == 'darwin' or sys.platform.startswith('linux')) and not build_headless:
         cmake_args.append("-DWITH_QT=4")
 
     if build_headless:

From b1a7fcc330e54c45f8bd7cf406e3b761b0ee7e8c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 3 May 2018 20:00:18 +0300
Subject: [PATCH 037/566] fix typo

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 1d885d3e..7e568028 100644
--- a/setup.py
+++ b/setup.py
@@ -45,7 +45,7 @@ def main():
     if build_contrib and not build_headless:
         package_name = "opencv-contrib-python"
 
-    if build_contrib and build_headless
+    if build_contrib and build_headless:
         package_name = "opencv-contrib-python-headless"
 
     if build_headless and not build_contrib:

From 9481238134f6361d6fdd8e4a0ea490f1ce07d843 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 4 May 2018 19:01:05 +0300
Subject: [PATCH 038/566] use only one README, convert README to markdown,
 update licenses, update setup.py

---
 LICENSE-3RD-PARTY.txt |  39 ++++++++-
 LICENSE.txt           |   2 +-
 README.md             | 145 ++++++++++++++++++++++++++++++++
 README.rst            | 190 ------------------------------------------
 README_CONTRIB.rst    | 186 -----------------------------------------
 setup.py              |  23 +++--
 6 files changed, 197 insertions(+), 388 deletions(-)
 create mode 100644 README.md
 delete mode 100644 README.rst
 delete mode 100644 README_CONTRIB.rst

diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index 8cbc4f5c..9daba95c 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -10,7 +10,7 @@ copy or use the software.
                For Open Source Computer Vision Library
                        (3-clause BSD License)
 
-Copyright (C) 2000-2016, Intel Corporation, all rights reserved.
+Copyright (C) 2000-2018, Intel Corporation, all rights reserved.
 Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
 Copyright (C) 2009-2016, NVIDIA Corporation, all rights reserved.
 Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
@@ -43,9 +43,44 @@ and on any theory of liability, whether in contract, strict liability,
 or tort (including negligence or otherwise) arising in any way out of
 the use of this software, even if advised of the possibility of such damage.
 
+------------------------------------------------------------------------------
+libvpx is redistributed within opencv-python Linux packages.
+This license applies to libvpx binary in the directory cv2/.
+
+Copyright (c) 2010, The WebM Project authors. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+  * Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+
+  * Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in
+    the documentation and/or other materials provided with the
+    distribution.
+
+  * Neither the name of Google, nor the WebM Project, nor the names
+    of its contributors may be used to endorse or promote products
+    derived from this software without specific prior written
+    permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 ------------------------------------------------------------------------------
 FFmpeg is redistributed within opencv-python Windows packages.
-Qt 4.8.7 is redistributed within opencv-python Linux and macOS packages
+Qt 4.8.7 is redistributed within opencv-python Linux and macOS packages.
 This license applies to FFmpeg and Qt binaries in the directory cv2/.
 
                   GNU LESSER GENERAL PUBLIC LICENSE
diff --git a/LICENSE.txt b/LICENSE.txt
index af1ba757..e8005c63 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,6 +1,6 @@
 MIT License
 
-Copyright (c) 2016-2017 Olli-Pekka Heinisuo and contributors
+Copyright (c) 2016-2018 Olli-Pekka Heinisuo and contributors
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..b0ff1159
--- /dev/null
+++ b/README.md
@@ -0,0 +1,145 @@
+## OpenCV on Wheels
+
+**Unofficial** pre-built OpenCV packages for Python.
+
+### Installation and Usage
+
+1. If you have previous/other manually installed version of OpenCV installed (e.g. cv2 module in the root of Python's site-packages), remove it before installation to avoid conflicts.
+2. 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 enviroment.
+
+    **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](https://docs.opencv.org/master/))
+
+    **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](https://docs.opencv.org/master/))
+
+3. 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")``
+
+5. Read [OpenCV documentation](https://docs.opencv.org/master/)
+
+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 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 PyPI does not currently support ARM architecture so you can't install these packages for example on Raspberry Pi.
+
+**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](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.
+
+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](https://github.com/skvark/opencv-python/issues/36) for a manual fix.
+
+**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).
+
+## Documentation for opencv-python
+
+.. image:: https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows
+   :target: https://ci.appveyor.com/project/skvark/opencv-python
+   :alt: AppVeyor CI test status (Windows)
+
+.. image:: https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label="Linux / OS X"
+   :target: https://travis-ci.org/skvark/opencv-python
+   :alt: Travis CI test status (Linux and OS X)
+
+The aim of this repository is to provide means to package each new [OpenCV release](https://github.com/opencv/opencv/releases>) for the most used Python versions and platforms.
+
+### 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):
+
+1. 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
+
+2. Find OpenCV version from the sources
+3. Install dependencies (numpy)
+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)
+
+5. Copy each ``.pyd/.so`` file to cv2 folder of this project and
+   generate wheel
+
+   - Linux and macOS wheels are checked with auditwheel and delocate
+
+6. Install the generated wheel
+7. Test that Python can import the library and run some sanity checks
+8. Use twine to upload the generated wheel to PyPI (only in release builds)
+
+The ``cv2.pyd/.so`` file is normally copied to site-packages. To avoid polluting the root folder this package wraps the statically built binary into cv2 package and ``__init__.py`` file in the package handles the import logic correctly.
+
+Since all packages use the same ``cv2`` namespace explained above, uninstall the other package before switching for example from ``opencv-python`` to ``opencv-contrib-python``.
+
+### Licensing
+
+Opencv-python package (scripts in this repository) is available under MIT license.
+
+OpenCV itself is available under [3-clause BSD License](https://github.com/opencv/opencv/blob/master/LICENSE).
+
+Third party package licenses are at [LICENSE-3RD-PARTY.txt](https://github.com/skvark/opencv-python/blob/master/LICENSE-3RD-PARTY.txt).
+
+All wheels ship with [FFmpeg](http://ffmpeg.org) licensed under the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
+
+Linux and MacOS 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).
+
+### 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.
+
+### 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``
+
+### 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](https://github.com/pypa/python-manylinux-demo). 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](https://github.com/skvark/opencv-python/tree/master/docker) for more info.
+
+### Supported Python versions
+
+Python 2.7 is the only supported version in 2.x series. Python 3.x releases follow Numpy releases. For example Python 3.3 is no longer supported by Numpy so support for it has been dropped in ``opencv-python``, too.
+
+Currently, builds for following Python versions are provided:
+
+- 2.7
+- 3.4
+- 3.5
+- 3.6
diff --git a/README.rst b/README.rst
deleted file mode 100644
index 795a359b..00000000
--- a/README.rst
+++ /dev/null
@@ -1,190 +0,0 @@
-OpenCV on Wheels
-================
-
-**Unofficial** OpenCV packages for Python.
-
-This package contains only the OpenCV core modules without the optional contrib modules.
-If you are looking for a version which includes OpenCV contrib modules, please install `opencv-contrib-python <https://pypi.python.org/pypi/opencv-contrib-python>`__ instead.
-
-The packages contain pre-compiled OpenCV binary with Python bindings.
-This enables super fast (usually < 10 seconds) OpenCV installation for Python.
-
-If you need only OpenCV Python bindings, no separate OpenCV installation is required.
-
-Installation and Usage
-----------------------
-
-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.
-
- - 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.
-
-2. If you have an existing ``opencv-contrib-python`` installation, run ``pip uninstall opencv-contrib-python``
-
-3. Install this package:
-
-``pip install opencv-python``
-
-4. Import the package:
-
-``import cv2``
-
-The package contains 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")``
-
-5. Read `OpenCV documentation <http://docs.opencv.org/>`__
-
-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 does not find package ``opencv-python``?**
-
-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`` and ``pip install wheel``.
-
-**Q: I need contrib modules?**
-
-A: Please install `opencv-contrib-python <https://pypi.python.org/pypi/opencv-contrib-python>`__ instead. However, note that commercial usage might be restricted in some countries since the contrib modules might contain some non-free/patented algorithms.
-
-**Q: Import fails on Windows to some DLL load error?**
-
-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.
-
-See also `this issue <https://github.com/skvark/opencv-python/issues/36>`__ if you are using Anaconda.
-
-**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).
-
-Documentation for opencv-python
--------------------------------
-
-.. image:: https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows
-   :target: https://ci.appveyor.com/project/skvark/opencv-python
-   :alt: AppVeyor CI test status (Windows)
-
-.. image:: https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label="Linux / OS X"
-   :target: https://travis-ci.org/skvark/opencv-python
-   :alt: Travis CI test status (Linux and OS X)
-
-The aim of this repository is to provide means to package each new
-`OpenCV release <https://github.com/opencv/opencv/releases>`__ for the
-most used Python versions and platforms.
-
-At the same time it allows anyone to build a custom version of OpenCV
-for any Python version: just fork this repo and modify the build files
-and scripts to fit your needs.
-
-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):
-
-1. 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
-
-2. Find OpenCV version from the sources
-3. Install dependencies (numpy)
-4. Build OpenCV
-
-   -  tests are disabled, otherwise build time increases too much
-   -  there are 2 build matrix entries for each build combination: with and without contrib modules
-   -  Linux builds run in manylinux Docker containers (CentOS 5)
-
-5. Copy each ``.pyd/.so`` file to cv2 folder of this project and
-   generate wheel
-
-   - Linux and macOS wheels are checked with auditwheel and delocate
-
-6. Install the generated wheel
-7. Test that Python can import the library and run some sanity checks
-8. Use twine to upload the generated wheel to PyPI (only in release builds)
-
-Currently the ``find_version.py`` file parses OpenCV version information
-from the OpenCV sources. OpenCV depends on numpy, so ``setup.py`` checks
-the minimum required numpy version also with the help of pip.
-
-The ``cv2.pyd/.so`` file is normally copied to site-packages.
-To avoid polluting the root folder this package wraps
-the statically built binary into cv2 package and ``__init__.py``
-file in the package handles the import logic correctly.
-
-Since both ``opencv-python`` and ``opencv-contrib-python`` use the same namespace explained above,
-it is highly recommended to uninstall the other package before switching from example from
-``opencv-python`` to ``opencv-contrib-python`` package.
-
-Licensing
----------
-
-Opencv-python package (scripts in this repository) is available under
-MIT license.
-
-OpenCV itself is available under `3-clause BSD
-License <https://github.com/opencv/opencv/blob/master/LICENSE>`__
-(`LICENSE-3RD-PARTY.txt <https://github.com/skvark/opencv-python/blob/master/LICENSE-3RD-PARTY.txt>`__).
-
-All wheels ship with `FFmpeg <http://ffmpeg.org>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__.
-
-Linux and MacOS 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>`__.
-
-Versioning
-----------
-
-Currently the ``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.
-
-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``
-
-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 <https://github.com/pypa/python-manylinux-demo>`__. 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.
-
-Supported Python versions
--------------------------
-
-Python 2.7 is the only supported version in 2.x series.
-Python 3.x releases follow Numpy releases, for example
-Python 3.3 is no longer supported by Numpy so the support
-for it has been dropped in ``opencv-python`` too.
-
-Currently, builds for following Python versions are provided:
-
-- 2.7
-- 3.4
-- 3.5
-- 3.6
diff --git a/README_CONTRIB.rst b/README_CONTRIB.rst
deleted file mode 100644
index 0fe36e50..00000000
--- a/README_CONTRIB.rst
+++ /dev/null
@@ -1,186 +0,0 @@
-OpenCV on Wheels
-================
-
-**Unofficial** OpenCV packages for Python with contrib modules.
-
-**Note: the (commercial) usage of opencv-contrib-python might be restricted in some countries since the contrib package might contain some patented algorithms/non-free modules.**
-
-If you are looking for a version without the contrib modules, please install `opencv-python <https://pypi.python.org/pypi/opencv-python>`__ instead.
-
-The packages contain pre-compiled OpenCV binary with Python bindings.
-This enables super fast (usually < 10 seconds) OpenCV installation for Python.
-
-If you need only OpenCV Python bindings, no separate OpenCV installation is required.
-
-Installation and Usage
-----------------------
-
-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.
-
- - 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.
-
-2. If you have an existing ``opencv-python`` installation, run ``pip uninstall opencv-python``
-3. Install this package:
-
-``pip install opencv-contrib-python``
-
-4. Import the package:
-
-``import cv2``
-
-The package contains 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")``
-
-5. Read `OpenCV documentation <http://docs.opencv.org/>`__
-
-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 does not find package opencv-contrib-python?**
-
-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`` and ``pip install wheel``.
-
-**Q: Import fails on Windows to some DLL load error?**
-
-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.
-
-See also `this issue <https://github.com/skvark/opencv-python/issues/36>`__ if you are using Anaconda.
-
-**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).
-
-Documentation for opencv-python
--------------------------------
-
-.. image:: https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows
-   :target: https://ci.appveyor.com/project/skvark/opencv-python
-   :alt: AppVeyor CI test status (Windows)
-
-.. image:: https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label="Linux / OS X"
-   :target: https://travis-ci.org/skvark/opencv-python
-   :alt: Travis CI test status (Linux and OS X)
-
-The aim of this repository is to provide means to package each new
-`OpenCV release <https://github.com/opencv/opencv/releases>`__ for the
-most used Python versions and platforms.
-
-At the same time it allows anyone to build a custom version of OpenCV
-for any Python version: just fork this repo and modify the build files
-and scripts to fit your needs.
-
-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):
-
-1. 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
-
-2. Find OpenCV version from the sources
-3. Install dependencies (numpy)
-4. Build OpenCV
-
-   -  tests are disabled, otherwise build time increases too much
-   -  there are 2 build matrix entries for each build combination: with and without contrib modules
-   -  Linux builds run in manylinux Docker containers (CentOS 5)
-
-5. Copy each ``.pyd/.so`` file to cv2 folder of this project and
-   generate wheel
-
-   - Linux and macOS wheels are checked with auditwheel and delocate
-
-6. Install the generated wheel
-7. Test that python can import the library and run some sanity checks
-8. Use twine to upload the generated wheel to PyPI (only in release builds)
-
-Currently the ``find_version.py`` file parses OpenCV version information
-from the OpenCV sources. OpenCV depends on numpy, so ``setup.py`` checks
-the minimum required numpy version also with the help of pip.
-
-The ``cv2.pyd/.so`` file is normally copied to site-packages.
-To avoid polluting the root folder this package wraps
-the statically built binary into cv2 package and ``__init__.py``
-file in the package handles the import logic correctly.
-
-Since both ``opencv-python`` and ``opencv-python-contrib`` use the same namespace explained above,
-it is highly recommended to uninstall the other package before switching from example from
-``opencv-python`` to ``opencv-python-contrib`` package.
-
-Licensing
----------
-
-Opencv-python package (scripts in this repository) is available under
-MIT license.
-
-OpenCV itself is available under `3-clause BSD
-License <https://github.com/opencv/opencv/blob/master/LICENSE>`__
-(`LICENSE-3RD-PARTY.txt <https://github.com/skvark/opencv-python/blob/master/LICENSE-3RD-PARTY.txt>`__).
-
-All wheels ship with `FFmpeg <http://ffmpeg.org>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__.
-
-Linux and MacOS 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>`__.
-
-Versioning
-----------
-
-Currently the ``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.
-
-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``
-
-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 <https://github.com/pypa/python-manylinux-demo>`__. 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.
-
-Supported Python versions
--------------------------
-
-Python 2.7 is the only supported version in 2.x series.
-Python 3.x releases follow Numpy releases, for example
-Python 3.3 is no longer supported by Numpy so the support
-for it has been dropped in ``opencv-python`` too.
-
-Currently, builds for following Python versions are provided:
-
-- 2.7
-- 3.4
-- 3.5
-- 3.6
diff --git a/setup.py b/setup.py
index 7e568028..6874e290 100644
--- a/setup.py
+++ b/setup.py
@@ -51,10 +51,11 @@ def main():
     if build_headless and not build_contrib:
         package_name = "opencv-python-headless"
 
-    long_description = io.open('README_CONTRIB.rst' if build_contrib else 'README.rst', encoding="utf-8").read()
+    long_description = io.open('README.md', encoding="utf-8").read()
     package_version = get_opencv_version()
 
     packages = ['cv2', 'cv2.data']
+
     package_data = {
         'cv2':
             ['*%s' % sysconfig.get_config_var('SO')] +
@@ -67,11 +68,13 @@ def main():
     # Files from CMake output to copy to package.
     # Path regexes with forward slashes relative to CMake install dir.
     rearrange_cmake_output_data = {
+
         'cv2': ([r'bin/opencv_ffmpeg\d{3}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else []) +
-            # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
-            # Naming conventions vary so widely between versions and OSes
-            # had to give up on checking them.
-            ['python/([^/]+/){1,2}cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
+        # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
+        # Naming conventions vary so widely between versions and OSes
+        # had to give up on checking them.
+        ['python/([^/]+/){1,2}cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
+
         'cv2.data': [  # OPENCV_OTHER_INSTALL_PATH
             ('etc' if os.name == 'nt' else 'share/OpenCV') +
             r'/haarcascades/.*\.xml'
@@ -150,6 +153,7 @@ def main():
         license='MIT',
         description='Wrapper package for OpenCV python bindings.',
         long_description=long_description,
+        long_description_content_type="text/markdown",
         packages=packages,
         package_data=package_data,
         maintainer="Olli-Pekka Heinisuo",
@@ -196,8 +200,7 @@ class RearrangeCMakeOutput(object):
     # Have to wrap a function reference, or it's converted
     # into an instance method on attr assignment
     import argparse
-    wraps = argparse.Namespace(
-        _classify_files=None)
+    wraps = argparse.Namespace(_classify_files=None)
     del argparse
 
     package_paths_re = None
@@ -253,6 +256,7 @@ def _classify_files_override(self, install_paths,
         final_install_relpaths = []
 
         print("Copying files from CMake output")
+
         for package_name, relpaths_re in cls.package_paths_re.items():
             package_dest_reldir = package_name.replace('.', os.path.sep)
             for relpath_re in relpaths_re:
@@ -278,6 +282,7 @@ def _classify_files_override(self, install_paths,
         del relpaths_zip
 
         print("Copying files from non-default sourcetree locations")
+
         for package_name, paths in cls.files_outside_package.items():
             package_dest_reldir = package_name.replace('.', os.path.sep)
             for path in paths:
@@ -288,7 +293,7 @@ def _classify_files_override(self, install_paths,
                         os.path.basename(path))
                 cls._setuptools_wrap._copy_file(
                     path, os.path.join(cmake_install_dir, new_install_relpath),
-                    hide_listing = False
+                    hide_listing=False
                 )
                 final_install_relpaths.append(new_install_relpath)
 
@@ -337,7 +342,7 @@ def get_build_env_var_by_name(flag_name):
 
 
 def get_or_install(name, version=None):
-    """If a package is already installed, build against it. If not, install"""
+    """ If a package is already installed, build against it. If not, install """
     # Do not import 3rd-party modules into the current process
     import json
     js_packages = json.loads(

From 4db144a2f7ded50edac0ef73ece0d573bc84e44e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 4 May 2018 19:06:45 +0300
Subject: [PATCH 039/566] fix badges

---
 README.md | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md
index b0ff1159..47ed4b77 100644
--- a/README.md
+++ b/README.md
@@ -56,13 +56,8 @@ A: Make sure you have removed old manual installations of OpenCV Python bindings
 
 ## Documentation for opencv-python
 
-.. image:: https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows
-   :target: https://ci.appveyor.com/project/skvark/opencv-python
-   :alt: AppVeyor CI test status (Windows)
-
-.. image:: https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label="Linux / OS X"
-   :target: https://travis-ci.org/skvark/opencv-python
-   :alt: Travis CI test status (Linux and OS X)
+[![AppVeyor CI test status (Windows)](https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows)](https://ci.appveyor.com/project/skvark/opencv-python)
+[![Travis CI test status (Linux and OS X)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label="Linux / OS X")](https://travis-ci.org/skvark/opencv-python)
 
 The aim of this repository is to provide means to package each new [OpenCV release](https://github.com/opencv/opencv/releases>) for the most used Python versions and platforms.
 

From 3a99c1ae76c98a921281d89fedfdab6f4d953732 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 4 May 2018 19:12:19 +0300
Subject: [PATCH 040/566] fix travis badge

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 47ed4b77..eb47e1d6 100644
--- a/README.md
+++ b/README.md
@@ -57,7 +57,7 @@ A: Make sure you have removed old manual installations of OpenCV Python bindings
 ## Documentation for opencv-python
 
 [![AppVeyor CI test status (Windows)](https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows)](https://ci.appveyor.com/project/skvark/opencv-python)
-[![Travis CI test status (Linux and OS X)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label="Linux / OS X")](https://travis-ci.org/skvark/opencv-python)
+[![Travis CI test status (Linux and OS X)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label=Linux+macOS)](https://travis-ci.org/skvark/opencv-python)
 
 The aim of this repository is to provide means to package each new [OpenCV release](https://github.com/opencv/opencv/releases>) for the most used Python versions and platforms.
 

From f382a4bc28cc72f495ea3a5c68dada405636914a Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 10 May 2018 14:50:54 +0300
Subject: [PATCH 041/566] remove misleading comment [skip ci]

---
 cv2/__init__.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/cv2/__init__.py b/cv2/__init__.py
index 3c176752..7612351b 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -1,6 +1,5 @@
 import importlib
 
-# make IDE's (PyCharm) autocompletion happy
 from .cv2 import *
 from .data import *
 

From 77dc8c7737f0fc7a71898d13052ef6c62c48cdfb Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 10 May 2018 15:00:39 +0300
Subject: [PATCH 042/566] add clarification to README

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index eb47e1d6..16921fcd 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
 
 ### Installation and Usage
 
-1. If you have previous/other manually installed version of OpenCV installed (e.g. cv2 module in the root of Python's site-packages), remove it before installation to avoid conflicts.
+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. 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 enviroment.

From ea1108fd59bc7d8ddc803f937cd12968a33c2528 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 11 May 2018 20:22:59 +0300
Subject: [PATCH 043/566] change version parsing logic, old one does not work
 in Docker

---
 find_version.py | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/find_version.py b/find_version.py
index 0d3faa92..438a5411 100644
--- a/find_version.py
+++ b/find_version.py
@@ -24,17 +24,16 @@
 
 # used in local dev releases
 git_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).splitlines()[0].decode()
+# this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
+tag = subprocess.check_output(['git', 'describe', '--tags']).splitlines()[0].decode().split('-')
 
-if os.name == 'posix':
-    version = os.getenv('TRAVIS_TAG', git_hash)
-else:
-    version = os.getenv('APPVEYOR_REPO_TAG_NAME', git_hash)
-
-if version != git_hash:
+if len(tag) == 1:
     # tag identifies the build and should be a sequential revision number
+    version = tag[0]
     opencv_version += ".{}".format(version)
 else:
     # local version identifier, not to be published on PyPI
+    version = git_hash
     opencv_version += "+{}".format(version)
 
 print("Version: ", opencv_version)

From 31f782b3b3022d14519cf56c46088ac7ab498bd0 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 12 May 2018 12:20:57 +0300
Subject: [PATCH 044/566] upload fails on macOS due to too old SSL

---
 .travis.yml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index dff66023..6aed49c8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -428,6 +428,10 @@ after_success: |
         set -x
         pip install twine
 
+        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
+          pip install --upgrade pyOpenSSL
+        fi
+
         if [[ $ENABLE_CONTRIB == 0 ]]; then
             if [[ $ENABLE_HEADLESS == 0 ]]; then
               echo "This is default build. Deployment will be done to to PyPI entry opencv-python."

From 8208e60eb88ed2a24d56af5a41957d984ebef47f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 17 May 2018 19:57:09 +0300
Subject: [PATCH 045/566] bump OpenCV version to 3.4.1

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 6d4f6647..6ffc4876 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 6d4f66472e14b29b8e1623859cfebfdc67f677c3
+Subproject commit 6ffc48769ac60d53c4bd1913eac15117c9b1c9f7
diff --git a/opencv_contrib b/opencv_contrib
index 81ca8dab..ced5aa76 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 81ca8dab8697ae6acc5d8bc45f03b6b10f4d7d24
+Subproject commit ced5aa760688dd2ec867ebf7bd4f0c2341d2fde5

From 21688135b8a35c424bdc97f5629e406a759aa886 Mon Sep 17 00:00:00 2001
From: Brian Zier <zier.brian@gmail.com>
Date: Mon, 11 Jun 2018 06:10:06 -0700
Subject: [PATCH 046/566] Fix OpenCV releases link (#101)

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 16921fcd..0f5cb4dc 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ A: Make sure you have removed old manual installations of OpenCV Python bindings
 [![AppVeyor CI test status (Windows)](https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows)](https://ci.appveyor.com/project/skvark/opencv-python)
 [![Travis CI test status (Linux and OS X)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label=Linux+macOS)](https://travis-ci.org/skvark/opencv-python)
 
-The aim of this repository is to provide means to package each new [OpenCV release](https://github.com/opencv/opencv/releases>) for the most used Python versions and platforms.
+The aim of this repository is to provide means to package each new [OpenCV release](https://github.com/opencv/opencv/releases) for the most used Python versions and platforms.
 
 ### Build process
 

From 7d0ffb7a4c8c4d98f6cea51efb72325ae6b3809f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 24 Jun 2018 18:52:00 +0300
Subject: [PATCH 047/566] update Dockerfiles to match new images

---
 docker/Dockerfile_i686   | 2 +-
 docker/Dockerfile_x86_64 | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
index b788b96f..49c2d32c 100644
--- a/docker/Dockerfile_i686
+++ b/docker/Dockerfile_i686
@@ -3,7 +3,7 @@ FROM quay.io/pypa/manylinux1_i686:latest
 RUN wget --no-check-certificate https://download.qt.io/official_releases/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz && \
 	tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
 	cd qt-everywhere* && \
-	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license && \
+	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license -qtnamespace Qt4 && \
 	gmake && \
 	gmake install && \
 	cd .. && \
diff --git a/docker/Dockerfile_x86_64 b/docker/Dockerfile_x86_64
index 4919f89f..51db79db 100644
--- a/docker/Dockerfile_x86_64
+++ b/docker/Dockerfile_x86_64
@@ -3,7 +3,7 @@ FROM quay.io/pypa/manylinux1_x86_64:latest
 RUN wget --no-check-certificate https://download.qt.io/official_releases/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz && \
 	tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
 	cd qt-everywhere* && \
-	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license && \
+	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license -qtnamespace Qt4 && \
 	gmake && \
 	gmake install && \
 	cd .. && \

From 449366dd9b0659f5877d9ced0a1a70882d4d8368 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 25 Jun 2018 18:31:28 +0300
Subject: [PATCH 048/566] add some linker flags

---
 config.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/config.sh b/config.sh
index ca089dad..1981e60b 100644
--- a/config.sh
+++ b/config.sh
@@ -40,6 +40,7 @@ function pre_build {
     echo '-----------------'
   else
     echo "Running for linux"
+    export LDFLAGS="-Wl,--no-as-needed -Wl,--no-undefined ${LDFLAGS}"
   fi
   qmake -query
 }

From f6e2eea80a312e0909577f9ce05e0e67ada62cc0 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 28 Jun 2018 14:29:02 +0300
Subject: [PATCH 049/566] test OpenCV GUI patches

---
 patches/patch1.patch | 84 ++++++++++++++++++++++++++++++++++++++++++++
 patches/patch2.patch | 55 +++++++++++++++++++++++++++++
 setup.py             |  3 ++
 3 files changed, 142 insertions(+)
 create mode 100644 patches/patch1.patch
 create mode 100644 patches/patch2.patch

diff --git a/patches/patch1.patch b/patches/patch1.patch
new file mode 100644
index 00000000..ae2f63e4
--- /dev/null
+++ b/patches/patch1.patch
@@ -0,0 +1,84 @@
+--- opencv/modules/highgui/src/window_QT.h	2018-06-28 13:13:55.119434000 +0300
++++ opencv/modules/highgui/src/window_QT_patched.h	2018-06-28 13:21:30.934272400 +0300
+@@ -46,43 +46,47 @@
+ #define QT_NO_DEBUG_OUTPUT
+ #endif
+ 
++QT_BEGIN_NAMESPACE
++
+ #if defined( HAVE_QT_OPENGL )
+-#include <QtOpenGL>
+-#include <QGLWidget>
++class QtOpenGL;
++class QGLWidget;
+ #endif
+ 
+-#include <QAbstractEventDispatcher>
+-#include <QApplication>
+-#include <QFile>
+-#include <QPushButton>
+-#include <QGraphicsView>
+-#include <QSizePolicy>
+-#include <QInputDialog>
+-#include <QBoxLayout>
+-#include <QSettings>
+-#include <qtimer.h>
+-#include <QtConcurrentRun>
+-#include <QWaitCondition>
+-#include <QKeyEvent>
+-#include <QMetaObject>
+-#include <QPointer>
+-#include <QSlider>
+-#include <QLabel>
+-#include <QIODevice>
+-#include <QShortcut>
+-#include <QStatusBar>
+-#include <QVarLengthArray>
+-#include <QFileInfo>
+-#include <QDate>
+-#include <QFileDialog>
+-#include <QToolBar>
+-
+-#include <QAction>
+-#include <QCheckBox>
+-#include <QRadioButton>
+-#include <QButtonGroup>
+-#include <QMenu>
+-#include <QTest>
++class QAbstractEventDispatcher;
++class QApplication;
++class QFile;
++class QPushButton;
++class QGraphicsView;
++class QSizePolicy;
++class QInputDialog;
++class QBoxLayout;
++class QSettings;
++class QTimer;
++class QtConcurrentRun;
++class QWaitCondition;
++class QKeyEvent;
++class QMetaObject;
++class QPointer;
++class QSlider;
++class QLabel;
++class QIODevice;
++class QShortcut;
++class QStatusBar;
++class QVarLengthArray;
++class QFileInfo;
++class QDate;
++class QFileDialog;
++class QToolBar;
++
++class QAction;
++class QCheckBox;
++class QRadioButton;
++class QButtonGroup;
++class QMenu;
++class QTest;
++
++QT_END_NAMESPACE
+ 
+ //start private enum
+ enum { CV_MODE_NORMAL = 0, CV_MODE_OPENGL = 1 };
diff --git a/patches/patch2.patch b/patches/patch2.patch
new file mode 100644
index 00000000..f08e085d
--- /dev/null
+++ b/patches/patch2.patch
@@ -0,0 +1,55 @@
+--- opencv/modules/highgui/src/window_QT.cpp	2018-06-28 13:13:52.234096700 +0300
++++ opencv/modules/highgui/src/window_QT_patched.cpp	2018-06-28 13:20:54.896046500 +0300
+@@ -46,6 +46,44 @@
+ 
+ #include <window_QT.h>
+ 
++#if defined( HAVE_QT_OPENGL )
++#include <QtOpenGL>
++#include <QGLWidget>
++#endif
++
++#include <QAbstractEventDispatcher>
++#include <QApplication>
++#include <QFile>
++#include <QPushButton>
++#include <QGraphicsView>
++#include <QSizePolicy>
++#include <QInputDialog>
++#include <QBoxLayout>
++#include <QSettings>
++#include <QTimer>
++#include <QtConcurrentRun>
++#include <QWaitCondition>
++#include <QKeyEvent>
++#include <QMetaObject>
++#include <QPointer>
++#include <QSlider>
++#include <QLabel>
++#include <QIODevice>
++#include <QShortcut>
++#include <QStatusBar>
++#include <QVarLengthArray>
++#include <QFileInfo>
++#include <QDate>
++#include <QFileDialog>
++#include <QToolBar>
++
++#include <QAction>
++#include <QCheckBox>
++#include <QRadioButton>
++#include <QButtonGroup>
++#include <QMenu>
++#include <QTest>
++
+ #include <math.h>
+ 
+ #ifdef _WIN32
+@@ -60,7 +98,6 @@
+     #endif
+ #endif
+ 
+-
+ //Static and global first
+ static GuiReceiver *guiMainThread = NULL;
+ static int parameterSystemC = 1;
diff --git a/setup.py b/setup.py
index 6874e290..cacfdac7 100644
--- a/setup.py
+++ b/setup.py
@@ -109,6 +109,9 @@ def main():
     # OS-specific components
     if (sys.platform == 'darwin' or sys.platform.startswith('linux')) and not build_headless:
         cmake_args.append("-DWITH_QT=4")
+        # Apply Qt namespace patches to OpenCV GUI code
+        subprocess.check_call(["patch", "-p0", "<", "patches/patch1.patch"])
+        subprocess.check_call(["patch", "-p0", "<", "patches/patch2.patch"])
 
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless

From b31049d9fdf91e87e45772c8927b8ed9ff91a127 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 28 Jun 2018 15:02:54 +0300
Subject: [PATCH 050/566] use subprocess.run

---
 setup.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index cacfdac7..25cbecac 100644
--- a/setup.py
+++ b/setup.py
@@ -110,8 +110,8 @@ def main():
     if (sys.platform == 'darwin' or sys.platform.startswith('linux')) and not build_headless:
         cmake_args.append("-DWITH_QT=4")
         # Apply Qt namespace patches to OpenCV GUI code
-        subprocess.check_call(["patch", "-p0", "<", "patches/patch1.patch"])
-        subprocess.check_call(["patch", "-p0", "<", "patches/patch2.patch"])
+        subprocess.run("patch -p0 < patches/patch1.patch", shell=True, check=True)
+        subprocess.run("patch -p0 < patches/patch2.patch", shell=True, check=True)
 
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless

From 80a5e50c712a62f887621ba39356d49294acf846 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 28 Jun 2018 15:13:48 +0300
Subject: [PATCH 051/566] change back to check_call

---
 setup.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index 25cbecac..d7385ff1 100644
--- a/setup.py
+++ b/setup.py
@@ -110,8 +110,8 @@ def main():
     if (sys.platform == 'darwin' or sys.platform.startswith('linux')) and not build_headless:
         cmake_args.append("-DWITH_QT=4")
         # Apply Qt namespace patches to OpenCV GUI code
-        subprocess.run("patch -p0 < patches/patch1.patch", shell=True, check=True)
-        subprocess.run("patch -p0 < patches/patch2.patch", shell=True, check=True)
+        subprocess.check_call("patch -p0 < patches/patch1.patch", shell=True)
+        subprocess.check_call("patch -p0 < patches/patch2.patch", shell=True)
 
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless

From bf89f012c1a46ade16733fc66d6972ede74cdafb Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 30 Jun 2018 01:11:39 +0300
Subject: [PATCH 052/566] fix patch files

---
 patches/patch1.patch | 15 +++++++--------
 patches/patch2.patch | 14 ++++----------
 2 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/patches/patch1.patch b/patches/patch1.patch
index ae2f63e4..10daf514 100644
--- a/patches/patch1.patch
+++ b/patches/patch1.patch
@@ -1,16 +1,14 @@
 --- opencv/modules/highgui/src/window_QT.h	2018-06-28 13:13:55.119434000 +0300
-+++ opencv/modules/highgui/src/window_QT_patched.h	2018-06-28 13:21:30.934272400 +0300
-@@ -46,43 +46,47 @@
++++ opencv/modules/highgui/src/window_QT_patched.h	2018-06-30 01:10:16.135894200 +0300
+@@ -46,43 +46,48 @@
  #define QT_NO_DEBUG_OUTPUT
  #endif
  
-+QT_BEGIN_NAMESPACE
++#include <QApplication>
 +
  #if defined( HAVE_QT_OPENGL )
--#include <QtOpenGL>
--#include <QGLWidget>
-+class QtOpenGL;
-+class QGLWidget;
+ #include <QtOpenGL>
+ #include <QGLWidget>
  #endif
  
 -#include <QAbstractEventDispatcher>
@@ -45,8 +43,9 @@
 -#include <QButtonGroup>
 -#include <QMenu>
 -#include <QTest>
++QT_BEGIN_NAMESPACE
++
 +class QAbstractEventDispatcher;
-+class QApplication;
 +class QFile;
 +class QPushButton;
 +class QGraphicsView;
diff --git a/patches/patch2.patch b/patches/patch2.patch
index f08e085d..018b8290 100644
--- a/patches/patch2.patch
+++ b/patches/patch2.patch
@@ -1,16 +1,10 @@
---- opencv/modules/highgui/src/window_QT.cpp	2018-06-28 13:13:52.234096700 +0300
-+++ opencv/modules/highgui/src/window_QT_patched.cpp	2018-06-28 13:20:54.896046500 +0300
-@@ -46,6 +46,44 @@
+--- opencv/modules/highgui/src/window_QT.cpp	2018-06-30 01:04:51.649121800 +0300
++++ opencv/modules/highgui/src/window_QT_patched.cpp	2018-06-30 01:10:09.448939500 +0300
+@@ -46,6 +46,38 @@
  
  #include <window_QT.h>
  
-+#if defined( HAVE_QT_OPENGL )
-+#include <QtOpenGL>
-+#include <QGLWidget>
-+#endif
-+
 +#include <QAbstractEventDispatcher>
-+#include <QApplication>
 +#include <QFile>
 +#include <QPushButton>
 +#include <QGraphicsView>
@@ -45,7 +39,7 @@
  #include <math.h>
  
  #ifdef _WIN32
-@@ -60,7 +98,6 @@
+@@ -60,7 +92,6 @@
      #endif
  #endif
  

From 72f3e5dd8e1dd18f9f2f096fa903c0d3d9144df4 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 30 Jun 2018 16:19:27 +0300
Subject: [PATCH 053/566] another test...

---
 patches/patch1.patch |  71 ++++---
 patches/patch2.patch | 433 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 470 insertions(+), 34 deletions(-)

diff --git a/patches/patch1.patch b/patches/patch1.patch
index 10daf514..6ad4cd8d 100644
--- a/patches/patch1.patch
+++ b/patches/patch1.patch
@@ -1,20 +1,18 @@
 --- opencv/modules/highgui/src/window_QT.h	2018-06-28 13:13:55.119434000 +0300
-+++ opencv/modules/highgui/src/window_QT_patched.h	2018-06-30 01:10:16.135894200 +0300
-@@ -46,43 +46,48 @@
++++ opencv/modules/highgui/src/window_QT_patched.h	2018-06-30 16:11:10.233722700 +0300
+@@ -46,58 +46,64 @@
  #define QT_NO_DEBUG_OUTPUT
  #endif
  
-+#include <QApplication>
-+
- #if defined( HAVE_QT_OPENGL )
- #include <QtOpenGL>
- #include <QGLWidget>
- #endif
- 
+-#if defined( HAVE_QT_OPENGL )
+-#include <QtOpenGL>
+-#include <QGLWidget>
+-#endif
+-
 -#include <QAbstractEventDispatcher>
--#include <QApplication>
+ #include <QApplication>
 -#include <QFile>
--#include <QPushButton>
+ #include <QPushButton>
 -#include <QGraphicsView>
 -#include <QSizePolicy>
 -#include <QInputDialog>
@@ -25,7 +23,7 @@
 -#include <QWaitCondition>
 -#include <QKeyEvent>
 -#include <QMetaObject>
--#include <QPointer>
+ #include <QPointer>
 -#include <QSlider>
 -#include <QLabel>
 -#include <QIODevice>
@@ -38,17 +36,25 @@
 -#include <QToolBar>
 -
 -#include <QAction>
--#include <QCheckBox>
--#include <QRadioButton>
+ #include <QCheckBox>
++#include <QSlider>
+ #include <QRadioButton>
 -#include <QButtonGroup>
 -#include <QMenu>
--#include <QTest>
++#include <QWidget>
++#include <QGraphicsView>
+ #include <QTest>
++#include <QVarLengthArray>
++
++#if defined( HAVE_QT_OPENGL )
++#include <QtOpenGL>
++#include <QGLWidget>
++#endif
++
 +QT_BEGIN_NAMESPACE
 +
 +class QAbstractEventDispatcher;
 +class QFile;
-+class QPushButton;
-+class QGraphicsView;
 +class QSizePolicy;
 +class QInputDialog;
 +class QBoxLayout;
@@ -58,26 +64,45 @@
 +class QWaitCondition;
 +class QKeyEvent;
 +class QMetaObject;
-+class QPointer;
-+class QSlider;
 +class QLabel;
 +class QIODevice;
 +class QShortcut;
 +class QStatusBar;
-+class QVarLengthArray;
 +class QFileInfo;
 +class QDate;
 +class QFileDialog;
 +class QToolBar;
 +
 +class QAction;
-+class QCheckBox;
-+class QRadioButton;
 +class QButtonGroup;
 +class QMenu;
-+class QTest;
 +
 +QT_END_NAMESPACE
  
  //start private enum
  enum { CV_MODE_NORMAL = 0, CV_MODE_OPENGL = 1 };
+ 
+ //we can change the keyboard shortcuts from here !
+-enum {	shortcut_zoom_normal 	= Qt::CTRL + Qt::Key_Z,
+-        shortcut_zoom_imgRegion = Qt::CTRL + Qt::Key_X,
+-        shortcut_save_img		= Qt::CTRL + Qt::Key_S,
+-        shortcut_properties_win	= Qt::CTRL + Qt::Key_P,
+-        shortcut_zoom_in 		= Qt::CTRL + Qt::Key_Plus,//QKeySequence(QKeySequence::ZoomIn),
+-        shortcut_zoom_out		= Qt::CTRL + Qt::Key_Minus,//QKeySequence(QKeySequence::ZoomOut),
+-        shortcut_panning_left 	= Qt::CTRL + Qt::Key_Left,
+-        shortcut_panning_right 	= Qt::CTRL + Qt::Key_Right,
+-        shortcut_panning_up 	= Qt::CTRL + Qt::Key_Up,
+-        shortcut_panning_down 	= Qt::CTRL + Qt::Key_Down
++enum {	shortcut_zoom_normal 	= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Z,
++        shortcut_zoom_imgRegion = QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_X,
++        shortcut_save_img		= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_S,
++        shortcut_properties_win	= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_P,
++        shortcut_zoom_in 		= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Plus,//QKeySequence(QKeySequence::ZoomIn),
++        shortcut_zoom_out		= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Minus,//QKeySequence(QKeySequence::ZoomOut),
++        shortcut_panning_left 	= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Left,
++        shortcut_panning_right 	= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Right,
++        shortcut_panning_up 	= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Up,
++        shortcut_panning_down 	= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Down
+     };
+ //end enum
+ 
diff --git a/patches/patch2.patch b/patches/patch2.patch
index 018b8290..1f26f585 100644
--- a/patches/patch2.patch
+++ b/patches/patch2.patch
@@ -1,13 +1,11 @@
 --- opencv/modules/highgui/src/window_QT.cpp	2018-06-30 01:04:51.649121800 +0300
-+++ opencv/modules/highgui/src/window_QT_patched.cpp	2018-06-30 01:10:09.448939500 +0300
-@@ -46,6 +46,38 @@
++++ opencv/modules/highgui/src/window_QT_patched.cpp	2018-06-30 16:11:11.360600400 +0300
+@@ -46,6 +46,30 @@
  
  #include <window_QT.h>
  
 +#include <QAbstractEventDispatcher>
 +#include <QFile>
-+#include <QPushButton>
-+#include <QGraphicsView>
 +#include <QSizePolicy>
 +#include <QInputDialog>
 +#include <QBoxLayout>
@@ -17,29 +15,23 @@
 +#include <QWaitCondition>
 +#include <QKeyEvent>
 +#include <QMetaObject>
-+#include <QPointer>
-+#include <QSlider>
 +#include <QLabel>
 +#include <QIODevice>
 +#include <QShortcut>
 +#include <QStatusBar>
-+#include <QVarLengthArray>
 +#include <QFileInfo>
 +#include <QDate>
 +#include <QFileDialog>
 +#include <QToolBar>
 +
 +#include <QAction>
-+#include <QCheckBox>
-+#include <QRadioButton>
 +#include <QButtonGroup>
 +#include <QMenu>
-+#include <QTest>
 +
  #include <math.h>
  
  #ifdef _WIN32
-@@ -60,7 +92,6 @@
+@@ -60,7 +84,6 @@
      #endif
  #endif
  
@@ -47,3 +39,422 @@
  //Static and global first
  static GuiReceiver *guiMainThread = NULL;
  static int parameterSystemC = 1;
+@@ -77,15 +100,15 @@
+ //end static and global
+ 
+ // Declaration
+-Qt::ConnectionType autoBlockingConnection();
++QT_NAMESPACE::ConnectionType autoBlockingConnection();
+ 
+ // Implementation - this allows us to do blocking whilst automatically selecting the right
+ // behaviour for in-thread and out-of-thread launches of cv windows. Qt strangely doesn't
+ // cater for this, but does for strictly queued connections.
+-Qt::ConnectionType autoBlockingConnection() {
++QT_NAMESPACE::ConnectionType autoBlockingConnection() {
+   return (QThread::currentThread() != QApplication::instance()->thread())
+-      ? Qt::BlockingQueuedConnection
+-      : Qt::DirectConnection;
++      ? QT_NAMESPACE::BlockingQueuedConnection
++      : QT_NAMESPACE::DirectConnection;
+ }
+ 
+ CV_IMPL CvFont cvFontQt(const char* nameFont, int pointSize,CvScalar color,int weight,int style, int spacing)
+@@ -522,7 +545,7 @@
+         multiThreads = true;
+         QMetaObject::invokeMethod(guiMainThread,
+         "createWindow",
+-        Qt::BlockingQueuedConnection,  // block so that we can do useful stuff once we confirm it is created
++        QT_NAMESPACE::BlockingQueuedConnection,  // block so that we can do useful stuff once we confirm it is created
+         Q_ARG(QString, QString(name)),
+         Q_ARG(int, flags));
+      } else {
+@@ -540,7 +563,7 @@
+ 
+     QMetaObject::invokeMethod(guiMainThread,
+         "destroyWindow",
+-        Qt::AutoConnection,  // if another thread is controlling, let it handle it without blocking ourselves here
++        QT_NAMESPACE::AutoConnection,  // if another thread is controlling, let it handle it without blocking ourselves here
+         Q_ARG(QString, QString(name)));
+ }
+ 
+@@ -551,7 +574,7 @@
+         return;
+     QMetaObject::invokeMethod(guiMainThread,
+         "destroyAllWindow",
+-        Qt::AutoConnection  // if another thread is controlling, let it handle it without blocking ourselves here
++        QT_NAMESPACE::AutoConnection  // if another thread is controlling, let it handle it without blocking ourselves here
+         );
+ }
+ 
+@@ -1334,8 +1357,8 @@
+     setObjectName(name_bar);
+     dataSlider = value;
+ 
+-    slider = new QSlider(Qt::Horizontal);
+-    slider->setFocusPolicy(Qt::StrongFocus);
++    slider = new QSlider(QT_NAMESPACE::Horizontal);
++    slider->setFocusPolicy(QT_NAMESPACE::StrongFocus);
+     slider->setMinimum(0);
+     slider->setMaximum(_count);
+     slider->setPageStep(5);
+@@ -1367,8 +1390,8 @@
+ 
+     //label->setStyleSheet("QPushButton:disabled {color: black}");
+ 
+-    addWidget(label, Qt::AlignLeft);//name + value
+-    addWidget(slider, Qt::AlignCenter);//slider
++    addWidget(label, QT_NAMESPACE::AlignLeft);//name + value
++    addWidget(slider, QT_NAMESPACE::AlignCenter);//slider
+ }
+ 
+ 
+@@ -1481,7 +1504,7 @@
+         else
+             QObject::connect(button, SIGNAL(toggled(bool)), button, SLOT(callCallBack(bool)));
+ 
+-        addWidget(button, Qt::AlignCenter);
++        addWidget(button, QT_NAMESPACE::AlignCenter);
+     }
+ }
+ 
+@@ -1521,7 +1544,7 @@
+     userdata = arg4;
+ 
+     setObjectName(button_name);
+-    setCheckState((initial_button_state == 1 ? Qt::Checked : Qt::Unchecked));
++    setCheckState((initial_button_state == 1 ? QT_NAMESPACE::Checked : QT_NAMESPACE::Unchecked));
+     setText(button_name);
+ 
+     if (isChecked())
+@@ -1567,7 +1590,7 @@
+ {
+     //setParent(parent);
+     type = type_CvWinProperties;
+-    setWindowFlags(Qt::Tool);
++    setWindowFlags(QT_NAMESPACE::Tool);
+     setContentsMargins(0, 0, 0, 0);
+     setWindowTitle(name_paraWindow);
+     setObjectName(name_paraWindow);
+@@ -1641,12 +1664,12 @@
+     param_gui_mode = arg2 & 0x000000F0;
+     param_ratio_mode =  arg2 & 0x00000F00;
+ 
+-    //setAttribute(Qt::WA_DeleteOnClose); //in other case, does not release memory
++    //setAttribute(QT_NAMESPACE::WA_DeleteOnClose); //in other case, does not release memory
+     setContentsMargins(0, 0, 0, 0);
+     setWindowTitle(name);
+     setObjectName(name);
+ 
+-    setFocus( Qt::PopupFocusReason ); //#1695 arrow keys are not received without the explicit focus
++    setFocus( QT_NAMESPACE::PopupFocusReason ); //#1695 arrow keys are not received without the explicit focus
+ 
+     resize(400, 300);
+     setMinimumSize(1, 1);
+@@ -1684,14 +1707,14 @@
+ 
+     //Now attach everything
+     if (myToolBar)
+-        myGlobalLayout->addWidget(myToolBar, Qt::AlignCenter);
++        myGlobalLayout->addWidget(myToolBar, QT_NAMESPACE::AlignCenter);
+ 
+-    myGlobalLayout->addWidget(myView->getWidget(), Qt::AlignCenter);
++    myGlobalLayout->addWidget(myView->getWidget(), QT_NAMESPACE::AlignCenter);
+ 
+-    myGlobalLayout->addLayout(myBarLayout, Qt::AlignCenter);
++    myGlobalLayout->addLayout(myBarLayout, QT_NAMESPACE::AlignCenter);
+ 
+     if (myStatusBar)
+-        myGlobalLayout->addWidget(myStatusBar, Qt::AlignCenter);
++        myGlobalLayout->addWidget(myStatusBar, QT_NAMESPACE::AlignCenter);
+ 
+     setLayout(myGlobalLayout);
+     show();
+@@ -1860,7 +1883,7 @@
+ CvButtonbar* CvWindow::createButtonBar(QString name_bar)
+ {
+     QPointer<CvButtonbar> t = new CvButtonbar(global_control_panel, name_bar);
+-    t->setAlignment(Qt::AlignHCenter);
++    t->setAlignment(QT_NAMESPACE::AlignHCenter);
+ 
+     QPointer<QBoxLayout> myLayout = global_control_panel->myLayout;
+ 
+@@ -1873,7 +1896,7 @@
+ void CvWindow::addSlider(CvWindow* w, QString name, int* value, int count, CvTrackbarCallback on_change)
+ {
+     QPointer<CvTrackbar> t = new CvTrackbar(w, name, value, count, on_change);
+-    t->setAlignment(Qt::AlignHCenter);
++    t->setAlignment(QT_NAMESPACE::AlignHCenter);
+ 
+     QPointer<QBoxLayout> myLayout;
+ 
+@@ -1897,7 +1920,7 @@
+ void CvWindow::addSlider2(CvWindow* w, QString name, int* value, int count, CvTrackbarCallback2 on_change, void* userdata)
+ {
+     QPointer<CvTrackbar> t = new CvTrackbar(w, name, value, count, on_change, userdata);
+-    t->setAlignment(Qt::AlignHCenter);
++    t->setAlignment(QT_NAMESPACE::AlignHCenter);
+ 
+     QPointer<QBoxLayout> myLayout;
+ 
+@@ -2101,7 +2124,7 @@
+ 
+     //myStatusBar_msg->setFrameStyle(QFrame::Raised);
+ 
+-    myStatusBar_msg->setAlignment(Qt::AlignHCenter);
++    myStatusBar_msg->setAlignment(QT_NAMESPACE::AlignHCenter);
+     myStatusBar->addWidget(myStatusBar_msg);
+ }
+ 
+@@ -2154,7 +2177,7 @@
+     //see http://doc.trolltech.com/4.6/qt.html#Key-enum
+     int key = evnt->key();
+ 
+-        Qt::Key qtkey = static_cast<Qt::Key>(key);
++        QT_NAMESPACE::Key qtkey = static_cast<QT_NAMESPACE::Key>(key);
+         char asciiCode = QTest::keyToAscii(qtkey);
+         if (asciiCode != 0)
+             key = static_cast<int>(asciiCode);
+@@ -2162,7 +2185,7 @@
+             key = evnt->nativeVirtualKey(); //same codes as returned by GTK-based backend
+ 
+     //control plus (Z, +, -, up, down, left, right) are used for zoom/panning functions
+-        if (evnt->modifiers() != Qt::ControlModifier)
++        if (evnt->modifiers() != QT_NAMESPACE::ControlModifier)
+         {
+         mutexKey.lock();
+         last_key = key;
+@@ -2370,44 +2393,44 @@
+ 
+ void OCVViewPort::icvmouseHandler(QMouseEvent* evnt, type_mouse_event category, int& cv_event, int& flags)
+ {
+-    Qt::KeyboardModifiers modifiers = evnt->modifiers();
+-    Qt::MouseButtons buttons = evnt->buttons();
++    QT_NAMESPACE::KeyboardModifiers modifiers = evnt->modifiers();
++    QT_NAMESPACE::MouseButtons buttons = evnt->buttons();
+ 
+     // This line gives excess flags flushing, with it you cannot predefine flags value.
+     // icvmouseHandler called with flags == 0 where it really need.
+     //flags = 0;
+-    if(modifiers & Qt::ShiftModifier)
++    if(modifiers & QT_NAMESPACE::ShiftModifier)
+         flags |= CV_EVENT_FLAG_SHIFTKEY;
+-    if(modifiers & Qt::ControlModifier)
++    if(modifiers & QT_NAMESPACE::ControlModifier)
+         flags |= CV_EVENT_FLAG_CTRLKEY;
+-    if(modifiers & Qt::AltModifier)
++    if(modifiers & QT_NAMESPACE::AltModifier)
+         flags |= CV_EVENT_FLAG_ALTKEY;
+ 
+-    if(buttons & Qt::LeftButton)
++    if(buttons & QT_NAMESPACE::LeftButton)
+         flags |= CV_EVENT_FLAG_LBUTTON;
+-    if(buttons & Qt::RightButton)
++    if(buttons & QT_NAMESPACE::RightButton)
+         flags |= CV_EVENT_FLAG_RBUTTON;
+-    if(buttons & Qt::MidButton)
++    if(buttons & QT_NAMESPACE::MidButton)
+         flags |= CV_EVENT_FLAG_MBUTTON;
+ 
+     if (cv_event == -1) {
+         if (category == mouse_wheel) {
+             QWheelEvent *we = (QWheelEvent *) evnt;
+-            cv_event = ((we->orientation() == Qt::Vertical) ? CV_EVENT_MOUSEWHEEL : CV_EVENT_MOUSEHWHEEL);
++            cv_event = ((we->orientation() == QT_NAMESPACE::Vertical) ? CV_EVENT_MOUSEWHEEL : CV_EVENT_MOUSEHWHEEL);
+             flags |= (we->delta() & 0xffff)<<16;
+             return;
+         }
+         switch(evnt->button())
+         {
+-        case Qt::LeftButton:
++        case QT_NAMESPACE::LeftButton:
+             cv_event = tableMouseButtons[category][0];
+             flags |= CV_EVENT_FLAG_LBUTTON;
+             break;
+-        case Qt::RightButton:
++        case QT_NAMESPACE::RightButton:
+             cv_event = tableMouseButtons[category][1];
+             flags |= CV_EVENT_FLAG_RBUTTON;
+             break;
+-        case Qt::MidButton:
++        case QT_NAMESPACE::MidButton:
+             cv_event = tableMouseButtons[category][2];
+             flags |= CV_EVENT_FLAG_MBUTTON;
+             break;
+@@ -2435,7 +2458,7 @@
+ 
+     setContentsMargins(0, 0, 0, 0);
+     setMinimumSize(1, 1);
+-    setAlignment(Qt::AlignHCenter);
++    setAlignment(QT_NAMESPACE::AlignHCenter);
+ 
+     setObjectName(QString::fromUtf8("graphicsView"));
+ 
+@@ -2666,25 +2689,25 @@
+         viewport()->render(&viewportPixmap);
+ 
+         // Save it..
+-        if (QString::compare(extension, "png", Qt::CaseInsensitive) == 0)
++        if (QString::compare(extension, "png", QT_NAMESPACE::CaseInsensitive) == 0)
+         {
+             viewportPixmap.save(fileName, "PNG");
+             return;
+         }
+ 
+-        if (QString::compare(extension, "jpg", Qt::CaseInsensitive) == 0)
++        if (QString::compare(extension, "jpg", QT_NAMESPACE::CaseInsensitive) == 0)
+         {
+             viewportPixmap.save(fileName, "JPG");
+             return;
+         }
+ 
+-        if (QString::compare(extension, "bmp", Qt::CaseInsensitive) == 0)
++        if (QString::compare(extension, "bmp", QT_NAMESPACE::CaseInsensitive) == 0)
+         {
+             viewportPixmap.save(fileName, "BMP");
+             return;
+         }
+ 
+-        if (QString::compare(extension, "jpeg", Qt::CaseInsensitive) == 0)
++        if (QString::compare(extension, "jpeg", QT_NAMESPACE::CaseInsensitive) == 0)
+         {
+             viewportPixmap.save(fileName, "JPEG");
+             return;
+@@ -2720,7 +2743,7 @@
+     if (param_keepRatio == CV_WINDOW_KEEPRATIO)//to keep the same aspect ratio
+     {
+         QSize newSize = QSize(image2Draw_mat->cols, image2Draw_mat->rows);
+-        newSize.scale(evnt->size(), Qt::KeepAspectRatio);
++        newSize.scale(evnt->size(), QT_NAMESPACE::KeepAspectRatio);
+ 
+         //imageWidth/imageHeight = newWidth/newHeight +/- epsilon
+         //ratioX = ratioY +/- epsilon
+@@ -2764,7 +2787,7 @@
+ 
+     if (param_matrixWorld.m11()>1)
+     {
+-        setCursor(Qt::ClosedHandCursor);
++        setCursor(QT_NAMESPACE::ClosedHandCursor);
+         positionGrabbing = evnt->pos();
+     }
+ 
+@@ -2777,7 +2800,7 @@
+     icvmouseEvent(evnt, mouse_up);
+ 
+     if (param_matrixWorld.m11()>1)
+-        setCursor(Qt::OpenHandCursor);
++        setCursor(QT_NAMESPACE::OpenHandCursor);
+ 
+     QWidget::mouseReleaseEvent(evnt);
+ }
+@@ -2794,7 +2817,7 @@
+ {
+     icvmouseEvent(evnt, mouse_move);
+ 
+-    if (param_matrixWorld.m11() > 1 && evnt->buttons() == Qt::LeftButton)
++    if (param_matrixWorld.m11() > 1 && evnt->buttons() == QT_NAMESPACE::LeftButton)
+     {
+         QPoint pt = evnt->pos();
+         QPointF dxy = (pt - positionGrabbing)/param_matrixWorld.m11();
+@@ -2939,7 +2962,7 @@
+         centralWidget->displayStatusBar(tr("Zoom: %1%").arg(param_matrixWorld.m11()*100),1000);
+ 
+     if (param_matrixWorld.m11()>1)
+-        setCursor(Qt::OpenHandCursor);
++        setCursor(QT_NAMESPACE::OpenHandCursor);
+     else
+         unsetCursor();
+ }
+@@ -3068,26 +3091,26 @@
+                 //for debug
+                 /*
+                 val = tr("%1 %2").arg(point2.x()).arg(point2.y());
+-                painter->setPen(QPen(Qt::black, 1));
++                painter->setPen(QPen(QT_NAMESPACE::black, 1));
+                 painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/2),
+-                    Qt::AlignCenter, val);
++                    QT_NAMESPACE::AlignCenter, val);
+                 */
+                 QString val;
+ 
+                 val = tr("%1").arg(qRed(rgbValue));
+-                painter->setPen(QPen(Qt::red, 1));
++                painter->setPen(QPen(QT_NAMESPACE::red, 1));
+                 painter->drawText(QRect(pos_in_view.x(),pos_in_view.y(),pixel_width,pixel_height/3),
+-                    Qt::AlignCenter, val);
++                    QT_NAMESPACE::AlignCenter, val);
+ 
+                 val = tr("%1").arg(qGreen(rgbValue));
+-                painter->setPen(QPen(Qt::green, 1));
++                painter->setPen(QPen(QT_NAMESPACE::green, 1));
+                 painter->drawText(QRect(pos_in_view.x(),pos_in_view.y()+pixel_height/3,pixel_width,pixel_height/3),
+-                    Qt::AlignCenter, val);
++                    QT_NAMESPACE::AlignCenter, val);
+ 
+                 val = tr("%1").arg(qBlue(rgbValue));
+-                painter->setPen(QPen(Qt::blue, 1));
++                painter->setPen(QPen(QT_NAMESPACE::blue, 1));
+                 painter->drawText(QRect(pos_in_view.x(),pos_in_view.y()+2*pixel_height/3,pixel_width,pixel_height/3),
+-                    Qt::AlignCenter, val);
++                    QT_NAMESPACE::AlignCenter, val);
+ 
+             }
+ 
+@@ -3095,12 +3118,12 @@
+             {
+                 QString val = tr("%1").arg(qRed(rgbValue));
+                 painter->drawText(QRect(pos_in_view.x(),pos_in_view.y(),pixel_width,pixel_height),
+-                    Qt::AlignCenter, val);
++                    QT_NAMESPACE::AlignCenter, val);
+             }
+         }
+     }
+ 
+-    painter->setPen(QPen(Qt::black, 1));
++    painter->setPen(QPen(QT_NAMESPACE::black, 1));
+     painter->drawLines(linesX.data(), linesX.size());
+     painter->drawLines(linesY.data(), linesY.size());
+ 
+@@ -3112,19 +3135,19 @@
+ void DefaultViewPort::drawViewOverview(QPainter *painter)
+ {
+     QSize viewSize = size();
+-    viewSize.scale ( 100, 100,Qt::KeepAspectRatio );
++    viewSize.scale ( 100, 100,QT_NAMESPACE::KeepAspectRatio );
+ 
+     const int margin = 5;
+ 
+     //draw the image's location
+     painter->setBrush(QColor(0, 0, 0, 127));
+-    painter->setPen(Qt::darkGreen);
++    painter->setPen(QT_NAMESPACE::darkGreen);
+     painter->drawRect(QRect(width()-viewSize.width()-margin, 0,viewSize.width(),viewSize.height()));
+ 
+     //daw the view's location inside the image
+     qreal ratioSize = 1/param_matrixWorld.m11();
+     qreal ratioWindow = (qreal)(viewSize.height())/(qreal)(size().height());
+-    painter->setPen(Qt::darkBlue);
++    painter->setPen(QT_NAMESPACE::darkBlue);
+     painter->drawRect(QRectF(width()-viewSize.width()-positionCorners.left()*ratioSize*ratioWindow-margin,
+         -positionCorners.top()*ratioSize*ratioWindow,
+         (viewSize.width()-1)*ratioSize,
+@@ -3138,17 +3161,17 @@
+     int border = qMax(4, metrics.leading());
+ 
+     QRect qrect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125),
+-        Qt::AlignCenter | Qt::TextWordWrap, infoText);
++        QT_NAMESPACE::AlignCenter | QT_NAMESPACE::TextWordWrap, infoText);
+     painter->setRenderHint(QPainter::TextAntialiasing);
+     painter->fillRect(QRect(0, 0, width(), qrect.height() + 2*border),
+         QColor(0, 0, 0, 127));
+-    painter->setPen(Qt::white);
++    painter->setPen(QT_NAMESPACE::white);
+     painter->fillRect(QRect(0, 0, width(), qrect.height() + 2*border),
+         QColor(0, 0, 0, 127));
+ 
+     painter->drawText((width() - qrect.width())/2, border,
+         qrect.width(), qrect.height(),
+-        Qt::AlignCenter | Qt::TextWordWrap, infoText);
++        QT_NAMESPACE::AlignCenter | QT_NAMESPACE::TextWordWrap, infoText);
+ }
+ 
+ 

From f3ad7d09e61bd84508c12f6d5a5d46c1c7fbea55 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 30 Jun 2018 16:47:53 +0300
Subject: [PATCH 054/566] remove QT_NAMESPACE

---
 patches/patch1.patch |  30 +--
 patches/patch2.patch | 421 +------------------------------------------
 2 files changed, 4 insertions(+), 447 deletions(-)

diff --git a/patches/patch1.patch b/patches/patch1.patch
index 6ad4cd8d..ad4f4123 100644
--- a/patches/patch1.patch
+++ b/patches/patch1.patch
@@ -1,6 +1,6 @@
 --- opencv/modules/highgui/src/window_QT.h	2018-06-28 13:13:55.119434000 +0300
-+++ opencv/modules/highgui/src/window_QT_patched.h	2018-06-30 16:11:10.233722700 +0300
-@@ -46,58 +46,64 @@
++++ opencv/modules/highgui/src/window_QT_patched.h	2018-06-30 16:46:55.848126700 +0300
+@@ -46,43 +46,50 @@
  #define QT_NO_DEBUG_OUTPUT
  #endif
  
@@ -72,6 +72,7 @@
 +class QDate;
 +class QFileDialog;
 +class QToolBar;
++class QHBoxLayout;
 +
 +class QAction;
 +class QButtonGroup;
@@ -81,28 +82,3 @@
  
  //start private enum
  enum { CV_MODE_NORMAL = 0, CV_MODE_OPENGL = 1 };
- 
- //we can change the keyboard shortcuts from here !
--enum {	shortcut_zoom_normal 	= Qt::CTRL + Qt::Key_Z,
--        shortcut_zoom_imgRegion = Qt::CTRL + Qt::Key_X,
--        shortcut_save_img		= Qt::CTRL + Qt::Key_S,
--        shortcut_properties_win	= Qt::CTRL + Qt::Key_P,
--        shortcut_zoom_in 		= Qt::CTRL + Qt::Key_Plus,//QKeySequence(QKeySequence::ZoomIn),
--        shortcut_zoom_out		= Qt::CTRL + Qt::Key_Minus,//QKeySequence(QKeySequence::ZoomOut),
--        shortcut_panning_left 	= Qt::CTRL + Qt::Key_Left,
--        shortcut_panning_right 	= Qt::CTRL + Qt::Key_Right,
--        shortcut_panning_up 	= Qt::CTRL + Qt::Key_Up,
--        shortcut_panning_down 	= Qt::CTRL + Qt::Key_Down
-+enum {	shortcut_zoom_normal 	= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Z,
-+        shortcut_zoom_imgRegion = QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_X,
-+        shortcut_save_img		= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_S,
-+        shortcut_properties_win	= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_P,
-+        shortcut_zoom_in 		= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Plus,//QKeySequence(QKeySequence::ZoomIn),
-+        shortcut_zoom_out		= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Minus,//QKeySequence(QKeySequence::ZoomOut),
-+        shortcut_panning_left 	= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Left,
-+        shortcut_panning_right 	= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Right,
-+        shortcut_panning_up 	= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Up,
-+        shortcut_panning_down 	= QT_NAMESPACE::CTRL + QT_NAMESPACE::Key_Down
-     };
- //end enum
- 
diff --git a/patches/patch2.patch b/patches/patch2.patch
index 1f26f585..9ccf3f5b 100644
--- a/patches/patch2.patch
+++ b/patches/patch2.patch
@@ -1,5 +1,5 @@
 --- opencv/modules/highgui/src/window_QT.cpp	2018-06-30 01:04:51.649121800 +0300
-+++ opencv/modules/highgui/src/window_QT_patched.cpp	2018-06-30 16:11:11.360600400 +0300
++++ opencv/modules/highgui/src/window_QT_patched.cpp	2018-06-30 16:46:56.630661000 +0300
 @@ -46,6 +46,30 @@
  
  #include <window_QT.h>
@@ -39,422 +39,3 @@
  //Static and global first
  static GuiReceiver *guiMainThread = NULL;
  static int parameterSystemC = 1;
-@@ -77,15 +100,15 @@
- //end static and global
- 
- // Declaration
--Qt::ConnectionType autoBlockingConnection();
-+QT_NAMESPACE::ConnectionType autoBlockingConnection();
- 
- // Implementation - this allows us to do blocking whilst automatically selecting the right
- // behaviour for in-thread and out-of-thread launches of cv windows. Qt strangely doesn't
- // cater for this, but does for strictly queued connections.
--Qt::ConnectionType autoBlockingConnection() {
-+QT_NAMESPACE::ConnectionType autoBlockingConnection() {
-   return (QThread::currentThread() != QApplication::instance()->thread())
--      ? Qt::BlockingQueuedConnection
--      : Qt::DirectConnection;
-+      ? QT_NAMESPACE::BlockingQueuedConnection
-+      : QT_NAMESPACE::DirectConnection;
- }
- 
- CV_IMPL CvFont cvFontQt(const char* nameFont, int pointSize,CvScalar color,int weight,int style, int spacing)
-@@ -522,7 +545,7 @@
-         multiThreads = true;
-         QMetaObject::invokeMethod(guiMainThread,
-         "createWindow",
--        Qt::BlockingQueuedConnection,  // block so that we can do useful stuff once we confirm it is created
-+        QT_NAMESPACE::BlockingQueuedConnection,  // block so that we can do useful stuff once we confirm it is created
-         Q_ARG(QString, QString(name)),
-         Q_ARG(int, flags));
-      } else {
-@@ -540,7 +563,7 @@
- 
-     QMetaObject::invokeMethod(guiMainThread,
-         "destroyWindow",
--        Qt::AutoConnection,  // if another thread is controlling, let it handle it without blocking ourselves here
-+        QT_NAMESPACE::AutoConnection,  // if another thread is controlling, let it handle it without blocking ourselves here
-         Q_ARG(QString, QString(name)));
- }
- 
-@@ -551,7 +574,7 @@
-         return;
-     QMetaObject::invokeMethod(guiMainThread,
-         "destroyAllWindow",
--        Qt::AutoConnection  // if another thread is controlling, let it handle it without blocking ourselves here
-+        QT_NAMESPACE::AutoConnection  // if another thread is controlling, let it handle it without blocking ourselves here
-         );
- }
- 
-@@ -1334,8 +1357,8 @@
-     setObjectName(name_bar);
-     dataSlider = value;
- 
--    slider = new QSlider(Qt::Horizontal);
--    slider->setFocusPolicy(Qt::StrongFocus);
-+    slider = new QSlider(QT_NAMESPACE::Horizontal);
-+    slider->setFocusPolicy(QT_NAMESPACE::StrongFocus);
-     slider->setMinimum(0);
-     slider->setMaximum(_count);
-     slider->setPageStep(5);
-@@ -1367,8 +1390,8 @@
- 
-     //label->setStyleSheet("QPushButton:disabled {color: black}");
- 
--    addWidget(label, Qt::AlignLeft);//name + value
--    addWidget(slider, Qt::AlignCenter);//slider
-+    addWidget(label, QT_NAMESPACE::AlignLeft);//name + value
-+    addWidget(slider, QT_NAMESPACE::AlignCenter);//slider
- }
- 
- 
-@@ -1481,7 +1504,7 @@
-         else
-             QObject::connect(button, SIGNAL(toggled(bool)), button, SLOT(callCallBack(bool)));
- 
--        addWidget(button, Qt::AlignCenter);
-+        addWidget(button, QT_NAMESPACE::AlignCenter);
-     }
- }
- 
-@@ -1521,7 +1544,7 @@
-     userdata = arg4;
- 
-     setObjectName(button_name);
--    setCheckState((initial_button_state == 1 ? Qt::Checked : Qt::Unchecked));
-+    setCheckState((initial_button_state == 1 ? QT_NAMESPACE::Checked : QT_NAMESPACE::Unchecked));
-     setText(button_name);
- 
-     if (isChecked())
-@@ -1567,7 +1590,7 @@
- {
-     //setParent(parent);
-     type = type_CvWinProperties;
--    setWindowFlags(Qt::Tool);
-+    setWindowFlags(QT_NAMESPACE::Tool);
-     setContentsMargins(0, 0, 0, 0);
-     setWindowTitle(name_paraWindow);
-     setObjectName(name_paraWindow);
-@@ -1641,12 +1664,12 @@
-     param_gui_mode = arg2 & 0x000000F0;
-     param_ratio_mode =  arg2 & 0x00000F00;
- 
--    //setAttribute(Qt::WA_DeleteOnClose); //in other case, does not release memory
-+    //setAttribute(QT_NAMESPACE::WA_DeleteOnClose); //in other case, does not release memory
-     setContentsMargins(0, 0, 0, 0);
-     setWindowTitle(name);
-     setObjectName(name);
- 
--    setFocus( Qt::PopupFocusReason ); //#1695 arrow keys are not received without the explicit focus
-+    setFocus( QT_NAMESPACE::PopupFocusReason ); //#1695 arrow keys are not received without the explicit focus
- 
-     resize(400, 300);
-     setMinimumSize(1, 1);
-@@ -1684,14 +1707,14 @@
- 
-     //Now attach everything
-     if (myToolBar)
--        myGlobalLayout->addWidget(myToolBar, Qt::AlignCenter);
-+        myGlobalLayout->addWidget(myToolBar, QT_NAMESPACE::AlignCenter);
- 
--    myGlobalLayout->addWidget(myView->getWidget(), Qt::AlignCenter);
-+    myGlobalLayout->addWidget(myView->getWidget(), QT_NAMESPACE::AlignCenter);
- 
--    myGlobalLayout->addLayout(myBarLayout, Qt::AlignCenter);
-+    myGlobalLayout->addLayout(myBarLayout, QT_NAMESPACE::AlignCenter);
- 
-     if (myStatusBar)
--        myGlobalLayout->addWidget(myStatusBar, Qt::AlignCenter);
-+        myGlobalLayout->addWidget(myStatusBar, QT_NAMESPACE::AlignCenter);
- 
-     setLayout(myGlobalLayout);
-     show();
-@@ -1860,7 +1883,7 @@
- CvButtonbar* CvWindow::createButtonBar(QString name_bar)
- {
-     QPointer<CvButtonbar> t = new CvButtonbar(global_control_panel, name_bar);
--    t->setAlignment(Qt::AlignHCenter);
-+    t->setAlignment(QT_NAMESPACE::AlignHCenter);
- 
-     QPointer<QBoxLayout> myLayout = global_control_panel->myLayout;
- 
-@@ -1873,7 +1896,7 @@
- void CvWindow::addSlider(CvWindow* w, QString name, int* value, int count, CvTrackbarCallback on_change)
- {
-     QPointer<CvTrackbar> t = new CvTrackbar(w, name, value, count, on_change);
--    t->setAlignment(Qt::AlignHCenter);
-+    t->setAlignment(QT_NAMESPACE::AlignHCenter);
- 
-     QPointer<QBoxLayout> myLayout;
- 
-@@ -1897,7 +1920,7 @@
- void CvWindow::addSlider2(CvWindow* w, QString name, int* value, int count, CvTrackbarCallback2 on_change, void* userdata)
- {
-     QPointer<CvTrackbar> t = new CvTrackbar(w, name, value, count, on_change, userdata);
--    t->setAlignment(Qt::AlignHCenter);
-+    t->setAlignment(QT_NAMESPACE::AlignHCenter);
- 
-     QPointer<QBoxLayout> myLayout;
- 
-@@ -2101,7 +2124,7 @@
- 
-     //myStatusBar_msg->setFrameStyle(QFrame::Raised);
- 
--    myStatusBar_msg->setAlignment(Qt::AlignHCenter);
-+    myStatusBar_msg->setAlignment(QT_NAMESPACE::AlignHCenter);
-     myStatusBar->addWidget(myStatusBar_msg);
- }
- 
-@@ -2154,7 +2177,7 @@
-     //see http://doc.trolltech.com/4.6/qt.html#Key-enum
-     int key = evnt->key();
- 
--        Qt::Key qtkey = static_cast<Qt::Key>(key);
-+        QT_NAMESPACE::Key qtkey = static_cast<QT_NAMESPACE::Key>(key);
-         char asciiCode = QTest::keyToAscii(qtkey);
-         if (asciiCode != 0)
-             key = static_cast<int>(asciiCode);
-@@ -2162,7 +2185,7 @@
-             key = evnt->nativeVirtualKey(); //same codes as returned by GTK-based backend
- 
-     //control plus (Z, +, -, up, down, left, right) are used for zoom/panning functions
--        if (evnt->modifiers() != Qt::ControlModifier)
-+        if (evnt->modifiers() != QT_NAMESPACE::ControlModifier)
-         {
-         mutexKey.lock();
-         last_key = key;
-@@ -2370,44 +2393,44 @@
- 
- void OCVViewPort::icvmouseHandler(QMouseEvent* evnt, type_mouse_event category, int& cv_event, int& flags)
- {
--    Qt::KeyboardModifiers modifiers = evnt->modifiers();
--    Qt::MouseButtons buttons = evnt->buttons();
-+    QT_NAMESPACE::KeyboardModifiers modifiers = evnt->modifiers();
-+    QT_NAMESPACE::MouseButtons buttons = evnt->buttons();
- 
-     // This line gives excess flags flushing, with it you cannot predefine flags value.
-     // icvmouseHandler called with flags == 0 where it really need.
-     //flags = 0;
--    if(modifiers & Qt::ShiftModifier)
-+    if(modifiers & QT_NAMESPACE::ShiftModifier)
-         flags |= CV_EVENT_FLAG_SHIFTKEY;
--    if(modifiers & Qt::ControlModifier)
-+    if(modifiers & QT_NAMESPACE::ControlModifier)
-         flags |= CV_EVENT_FLAG_CTRLKEY;
--    if(modifiers & Qt::AltModifier)
-+    if(modifiers & QT_NAMESPACE::AltModifier)
-         flags |= CV_EVENT_FLAG_ALTKEY;
- 
--    if(buttons & Qt::LeftButton)
-+    if(buttons & QT_NAMESPACE::LeftButton)
-         flags |= CV_EVENT_FLAG_LBUTTON;
--    if(buttons & Qt::RightButton)
-+    if(buttons & QT_NAMESPACE::RightButton)
-         flags |= CV_EVENT_FLAG_RBUTTON;
--    if(buttons & Qt::MidButton)
-+    if(buttons & QT_NAMESPACE::MidButton)
-         flags |= CV_EVENT_FLAG_MBUTTON;
- 
-     if (cv_event == -1) {
-         if (category == mouse_wheel) {
-             QWheelEvent *we = (QWheelEvent *) evnt;
--            cv_event = ((we->orientation() == Qt::Vertical) ? CV_EVENT_MOUSEWHEEL : CV_EVENT_MOUSEHWHEEL);
-+            cv_event = ((we->orientation() == QT_NAMESPACE::Vertical) ? CV_EVENT_MOUSEWHEEL : CV_EVENT_MOUSEHWHEEL);
-             flags |= (we->delta() & 0xffff)<<16;
-             return;
-         }
-         switch(evnt->button())
-         {
--        case Qt::LeftButton:
-+        case QT_NAMESPACE::LeftButton:
-             cv_event = tableMouseButtons[category][0];
-             flags |= CV_EVENT_FLAG_LBUTTON;
-             break;
--        case Qt::RightButton:
-+        case QT_NAMESPACE::RightButton:
-             cv_event = tableMouseButtons[category][1];
-             flags |= CV_EVENT_FLAG_RBUTTON;
-             break;
--        case Qt::MidButton:
-+        case QT_NAMESPACE::MidButton:
-             cv_event = tableMouseButtons[category][2];
-             flags |= CV_EVENT_FLAG_MBUTTON;
-             break;
-@@ -2435,7 +2458,7 @@
- 
-     setContentsMargins(0, 0, 0, 0);
-     setMinimumSize(1, 1);
--    setAlignment(Qt::AlignHCenter);
-+    setAlignment(QT_NAMESPACE::AlignHCenter);
- 
-     setObjectName(QString::fromUtf8("graphicsView"));
- 
-@@ -2666,25 +2689,25 @@
-         viewport()->render(&viewportPixmap);
- 
-         // Save it..
--        if (QString::compare(extension, "png", Qt::CaseInsensitive) == 0)
-+        if (QString::compare(extension, "png", QT_NAMESPACE::CaseInsensitive) == 0)
-         {
-             viewportPixmap.save(fileName, "PNG");
-             return;
-         }
- 
--        if (QString::compare(extension, "jpg", Qt::CaseInsensitive) == 0)
-+        if (QString::compare(extension, "jpg", QT_NAMESPACE::CaseInsensitive) == 0)
-         {
-             viewportPixmap.save(fileName, "JPG");
-             return;
-         }
- 
--        if (QString::compare(extension, "bmp", Qt::CaseInsensitive) == 0)
-+        if (QString::compare(extension, "bmp", QT_NAMESPACE::CaseInsensitive) == 0)
-         {
-             viewportPixmap.save(fileName, "BMP");
-             return;
-         }
- 
--        if (QString::compare(extension, "jpeg", Qt::CaseInsensitive) == 0)
-+        if (QString::compare(extension, "jpeg", QT_NAMESPACE::CaseInsensitive) == 0)
-         {
-             viewportPixmap.save(fileName, "JPEG");
-             return;
-@@ -2720,7 +2743,7 @@
-     if (param_keepRatio == CV_WINDOW_KEEPRATIO)//to keep the same aspect ratio
-     {
-         QSize newSize = QSize(image2Draw_mat->cols, image2Draw_mat->rows);
--        newSize.scale(evnt->size(), Qt::KeepAspectRatio);
-+        newSize.scale(evnt->size(), QT_NAMESPACE::KeepAspectRatio);
- 
-         //imageWidth/imageHeight = newWidth/newHeight +/- epsilon
-         //ratioX = ratioY +/- epsilon
-@@ -2764,7 +2787,7 @@
- 
-     if (param_matrixWorld.m11()>1)
-     {
--        setCursor(Qt::ClosedHandCursor);
-+        setCursor(QT_NAMESPACE::ClosedHandCursor);
-         positionGrabbing = evnt->pos();
-     }
- 
-@@ -2777,7 +2800,7 @@
-     icvmouseEvent(evnt, mouse_up);
- 
-     if (param_matrixWorld.m11()>1)
--        setCursor(Qt::OpenHandCursor);
-+        setCursor(QT_NAMESPACE::OpenHandCursor);
- 
-     QWidget::mouseReleaseEvent(evnt);
- }
-@@ -2794,7 +2817,7 @@
- {
-     icvmouseEvent(evnt, mouse_move);
- 
--    if (param_matrixWorld.m11() > 1 && evnt->buttons() == Qt::LeftButton)
-+    if (param_matrixWorld.m11() > 1 && evnt->buttons() == QT_NAMESPACE::LeftButton)
-     {
-         QPoint pt = evnt->pos();
-         QPointF dxy = (pt - positionGrabbing)/param_matrixWorld.m11();
-@@ -2939,7 +2962,7 @@
-         centralWidget->displayStatusBar(tr("Zoom: %1%").arg(param_matrixWorld.m11()*100),1000);
- 
-     if (param_matrixWorld.m11()>1)
--        setCursor(Qt::OpenHandCursor);
-+        setCursor(QT_NAMESPACE::OpenHandCursor);
-     else
-         unsetCursor();
- }
-@@ -3068,26 +3091,26 @@
-                 //for debug
-                 /*
-                 val = tr("%1 %2").arg(point2.x()).arg(point2.y());
--                painter->setPen(QPen(Qt::black, 1));
-+                painter->setPen(QPen(QT_NAMESPACE::black, 1));
-                 painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/2),
--                    Qt::AlignCenter, val);
-+                    QT_NAMESPACE::AlignCenter, val);
-                 */
-                 QString val;
- 
-                 val = tr("%1").arg(qRed(rgbValue));
--                painter->setPen(QPen(Qt::red, 1));
-+                painter->setPen(QPen(QT_NAMESPACE::red, 1));
-                 painter->drawText(QRect(pos_in_view.x(),pos_in_view.y(),pixel_width,pixel_height/3),
--                    Qt::AlignCenter, val);
-+                    QT_NAMESPACE::AlignCenter, val);
- 
-                 val = tr("%1").arg(qGreen(rgbValue));
--                painter->setPen(QPen(Qt::green, 1));
-+                painter->setPen(QPen(QT_NAMESPACE::green, 1));
-                 painter->drawText(QRect(pos_in_view.x(),pos_in_view.y()+pixel_height/3,pixel_width,pixel_height/3),
--                    Qt::AlignCenter, val);
-+                    QT_NAMESPACE::AlignCenter, val);
- 
-                 val = tr("%1").arg(qBlue(rgbValue));
--                painter->setPen(QPen(Qt::blue, 1));
-+                painter->setPen(QPen(QT_NAMESPACE::blue, 1));
-                 painter->drawText(QRect(pos_in_view.x(),pos_in_view.y()+2*pixel_height/3,pixel_width,pixel_height/3),
--                    Qt::AlignCenter, val);
-+                    QT_NAMESPACE::AlignCenter, val);
- 
-             }
- 
-@@ -3095,12 +3118,12 @@
-             {
-                 QString val = tr("%1").arg(qRed(rgbValue));
-                 painter->drawText(QRect(pos_in_view.x(),pos_in_view.y(),pixel_width,pixel_height),
--                    Qt::AlignCenter, val);
-+                    QT_NAMESPACE::AlignCenter, val);
-             }
-         }
-     }
- 
--    painter->setPen(QPen(Qt::black, 1));
-+    painter->setPen(QPen(QT_NAMESPACE::black, 1));
-     painter->drawLines(linesX.data(), linesX.size());
-     painter->drawLines(linesY.data(), linesY.size());
- 
-@@ -3112,19 +3135,19 @@
- void DefaultViewPort::drawViewOverview(QPainter *painter)
- {
-     QSize viewSize = size();
--    viewSize.scale ( 100, 100,Qt::KeepAspectRatio );
-+    viewSize.scale ( 100, 100,QT_NAMESPACE::KeepAspectRatio );
- 
-     const int margin = 5;
- 
-     //draw the image's location
-     painter->setBrush(QColor(0, 0, 0, 127));
--    painter->setPen(Qt::darkGreen);
-+    painter->setPen(QT_NAMESPACE::darkGreen);
-     painter->drawRect(QRect(width()-viewSize.width()-margin, 0,viewSize.width(),viewSize.height()));
- 
-     //daw the view's location inside the image
-     qreal ratioSize = 1/param_matrixWorld.m11();
-     qreal ratioWindow = (qreal)(viewSize.height())/(qreal)(size().height());
--    painter->setPen(Qt::darkBlue);
-+    painter->setPen(QT_NAMESPACE::darkBlue);
-     painter->drawRect(QRectF(width()-viewSize.width()-positionCorners.left()*ratioSize*ratioWindow-margin,
-         -positionCorners.top()*ratioSize*ratioWindow,
-         (viewSize.width()-1)*ratioSize,
-@@ -3138,17 +3161,17 @@
-     int border = qMax(4, metrics.leading());
- 
-     QRect qrect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125),
--        Qt::AlignCenter | Qt::TextWordWrap, infoText);
-+        QT_NAMESPACE::AlignCenter | QT_NAMESPACE::TextWordWrap, infoText);
-     painter->setRenderHint(QPainter::TextAntialiasing);
-     painter->fillRect(QRect(0, 0, width(), qrect.height() + 2*border),
-         QColor(0, 0, 0, 127));
--    painter->setPen(Qt::white);
-+    painter->setPen(QT_NAMESPACE::white);
-     painter->fillRect(QRect(0, 0, width(), qrect.height() + 2*border),
-         QColor(0, 0, 0, 127));
- 
-     painter->drawText((width() - qrect.width())/2, border,
-         qrect.width(), qrect.height(),
--        Qt::AlignCenter | Qt::TextWordWrap, infoText);
-+        QT_NAMESPACE::AlignCenter | QT_NAMESPACE::TextWordWrap, infoText);
- }
- 
- 

From 09d00b0dadb8bdaad60cbe11a99196c021e6a1b4 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 30 Jun 2018 17:10:49 +0300
Subject: [PATCH 055/566] add missing include

---
 patches/patch1.patch | 4 ++--
 patches/patch2.patch | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/patches/patch1.patch b/patches/patch1.patch
index ad4f4123..c22c8172 100644
--- a/patches/patch1.patch
+++ b/patches/patch1.patch
@@ -1,5 +1,5 @@
 --- opencv/modules/highgui/src/window_QT.h	2018-06-28 13:13:55.119434000 +0300
-+++ opencv/modules/highgui/src/window_QT_patched.h	2018-06-30 16:46:55.848126700 +0300
++++ opencv/modules/highgui/src/window_QT_patched.h	2018-06-30 17:10:09.916999500 +0300
 @@ -46,43 +46,50 @@
  #define QT_NO_DEBUG_OUTPUT
  #endif
@@ -45,6 +45,7 @@
 +#include <QGraphicsView>
  #include <QTest>
 +#include <QVarLengthArray>
++#include <QHBoxLayout>
 +
 +#if defined( HAVE_QT_OPENGL )
 +#include <QtOpenGL>
@@ -72,7 +73,6 @@
 +class QDate;
 +class QFileDialog;
 +class QToolBar;
-+class QHBoxLayout;
 +
 +class QAction;
 +class QButtonGroup;
diff --git a/patches/patch2.patch b/patches/patch2.patch
index 9ccf3f5b..8ca8fbb3 100644
--- a/patches/patch2.patch
+++ b/patches/patch2.patch
@@ -1,5 +1,5 @@
 --- opencv/modules/highgui/src/window_QT.cpp	2018-06-30 01:04:51.649121800 +0300
-+++ opencv/modules/highgui/src/window_QT_patched.cpp	2018-06-30 16:46:56.630661000 +0300
++++ opencv/modules/highgui/src/window_QT_patched.cpp	2018-06-30 17:09:28.697256300 +0300
 @@ -46,6 +46,30 @@
  
  #include <window_QT.h>

From bf58f7ab9d6e7b074c3b597bacaf83397925c272 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 30 Jun 2018 17:36:40 +0300
Subject: [PATCH 056/566] forward declare

---
 patches/patch1.patch | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/patches/patch1.patch b/patches/patch1.patch
index c22c8172..63fc128d 100644
--- a/patches/patch1.patch
+++ b/patches/patch1.patch
@@ -1,6 +1,6 @@
 --- opencv/modules/highgui/src/window_QT.h	2018-06-28 13:13:55.119434000 +0300
-+++ opencv/modules/highgui/src/window_QT_patched.h	2018-06-30 17:10:09.916999500 +0300
-@@ -46,43 +46,50 @@
++++ opencv/modules/highgui/src/window_QT_patched.h	2018-06-30 17:35:55.145192900 +0300
+@@ -46,43 +46,51 @@
  #define QT_NO_DEBUG_OUTPUT
  #endif
  
@@ -73,6 +73,7 @@
 +class QDate;
 +class QFileDialog;
 +class QToolBar;
++class QHBoxLayout;
 +
 +class QAction;
 +class QButtonGroup;

From deafb670ff4ed0c61820f98cff15febb87a0f853 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 14 Jul 2018 12:19:03 +0300
Subject: [PATCH 057/566] remove opencv patches for now

---
 config.sh                |  1 -
 docker/Dockerfile_i686   |  8 ++--
 docker/Dockerfile_x86_64 |  8 ++--
 patches/patch1.patch     | 85 ----------------------------------------
 patches/patch2.patch     | 41 -------------------
 setup.py                 |  3 --
 6 files changed, 8 insertions(+), 138 deletions(-)
 delete mode 100644 patches/patch1.patch
 delete mode 100644 patches/patch2.patch

diff --git a/config.sh b/config.sh
index 1981e60b..ca089dad 100644
--- a/config.sh
+++ b/config.sh
@@ -40,7 +40,6 @@ function pre_build {
     echo '-----------------'
   else
     echo "Running for linux"
-    export LDFLAGS="-Wl,--no-as-needed -Wl,--no-undefined ${LDFLAGS}"
   fi
   qmake -query
 }
diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
index 49c2d32c..c39331d0 100644
--- a/docker/Dockerfile_i686
+++ b/docker/Dockerfile_i686
@@ -1,10 +1,10 @@
 FROM quay.io/pypa/manylinux1_i686:latest
 
-RUN wget --no-check-certificate https://download.qt.io/official_releases/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz && \
+RUN curl -O -L https://download.qt.io/archive/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz && \
 	tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
 	cd qt-everywhere* && \
-	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license -qtnamespace Qt4 && \
-	gmake && \
+	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license && \
+	gmake -j5 && \
 	gmake install && \
 	cd .. && \
 	rm -rf qt-everywhere-opensource-src-4.8.7 && \
@@ -13,7 +13,7 @@ RUN wget --no-check-certificate https://download.qt.io/official_releases/qt/4.8/
 ENV QTDIR /opt/Qt4.8.7
 ENV PATH "$QTDIR/bin:$PATH"
 
-RUN wget --no-check-certificate https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
+RUN curl -O -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
 	tar -zxf cmake-3.9.0.tar.gz && \
 	cd cmake-3.9.0 && \
 	yum -y install curl-devel zlib-devel && \
diff --git a/docker/Dockerfile_x86_64 b/docker/Dockerfile_x86_64
index 51db79db..b855a73b 100644
--- a/docker/Dockerfile_x86_64
+++ b/docker/Dockerfile_x86_64
@@ -1,10 +1,10 @@
 FROM quay.io/pypa/manylinux1_x86_64:latest
 
-RUN wget --no-check-certificate https://download.qt.io/official_releases/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz && \
+RUN curl -O -L https://download.qt.io/archive/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz && \
 	tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
 	cd qt-everywhere* && \
-	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license -qtnamespace Qt4 && \
-	gmake && \
+	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license && \
+	gmake -j5 && \
 	gmake install && \
 	cd .. && \
 	rm -rf qt-everywhere-opensource-src-4.8.7 && \
@@ -13,7 +13,7 @@ RUN wget --no-check-certificate https://download.qt.io/official_releases/qt/4.8/
 ENV QTDIR /opt/Qt4.8.7
 ENV PATH "$QTDIR/bin:$PATH"
 
-RUN wget --no-check-certificate https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
+RUN curl -O -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
 	tar -zxf cmake-3.9.0.tar.gz && \
 	cd cmake-3.9.0 && \
 	yum -y install curl-devel zlib-devel && \
diff --git a/patches/patch1.patch b/patches/patch1.patch
deleted file mode 100644
index 63fc128d..00000000
--- a/patches/patch1.patch
+++ /dev/null
@@ -1,85 +0,0 @@
---- opencv/modules/highgui/src/window_QT.h	2018-06-28 13:13:55.119434000 +0300
-+++ opencv/modules/highgui/src/window_QT_patched.h	2018-06-30 17:35:55.145192900 +0300
-@@ -46,43 +46,51 @@
- #define QT_NO_DEBUG_OUTPUT
- #endif
- 
--#if defined( HAVE_QT_OPENGL )
--#include <QtOpenGL>
--#include <QGLWidget>
--#endif
--
--#include <QAbstractEventDispatcher>
- #include <QApplication>
--#include <QFile>
- #include <QPushButton>
--#include <QGraphicsView>
--#include <QSizePolicy>
--#include <QInputDialog>
--#include <QBoxLayout>
--#include <QSettings>
--#include <qtimer.h>
--#include <QtConcurrentRun>
--#include <QWaitCondition>
--#include <QKeyEvent>
--#include <QMetaObject>
- #include <QPointer>
--#include <QSlider>
--#include <QLabel>
--#include <QIODevice>
--#include <QShortcut>
--#include <QStatusBar>
--#include <QVarLengthArray>
--#include <QFileInfo>
--#include <QDate>
--#include <QFileDialog>
--#include <QToolBar>
--
--#include <QAction>
- #include <QCheckBox>
-+#include <QSlider>
- #include <QRadioButton>
--#include <QButtonGroup>
--#include <QMenu>
-+#include <QWidget>
-+#include <QGraphicsView>
- #include <QTest>
-+#include <QVarLengthArray>
-+#include <QHBoxLayout>
-+
-+#if defined( HAVE_QT_OPENGL )
-+#include <QtOpenGL>
-+#include <QGLWidget>
-+#endif
-+
-+QT_BEGIN_NAMESPACE
-+
-+class QAbstractEventDispatcher;
-+class QFile;
-+class QSizePolicy;
-+class QInputDialog;
-+class QBoxLayout;
-+class QSettings;
-+class QTimer;
-+class QtConcurrentRun;
-+class QWaitCondition;
-+class QKeyEvent;
-+class QMetaObject;
-+class QLabel;
-+class QIODevice;
-+class QShortcut;
-+class QStatusBar;
-+class QFileInfo;
-+class QDate;
-+class QFileDialog;
-+class QToolBar;
-+class QHBoxLayout;
-+
-+class QAction;
-+class QButtonGroup;
-+class QMenu;
-+
-+QT_END_NAMESPACE
- 
- //start private enum
- enum { CV_MODE_NORMAL = 0, CV_MODE_OPENGL = 1 };
diff --git a/patches/patch2.patch b/patches/patch2.patch
deleted file mode 100644
index 8ca8fbb3..00000000
--- a/patches/patch2.patch
+++ /dev/null
@@ -1,41 +0,0 @@
---- opencv/modules/highgui/src/window_QT.cpp	2018-06-30 01:04:51.649121800 +0300
-+++ opencv/modules/highgui/src/window_QT_patched.cpp	2018-06-30 17:09:28.697256300 +0300
-@@ -46,6 +46,30 @@
- 
- #include <window_QT.h>
- 
-+#include <QAbstractEventDispatcher>
-+#include <QFile>
-+#include <QSizePolicy>
-+#include <QInputDialog>
-+#include <QBoxLayout>
-+#include <QSettings>
-+#include <QTimer>
-+#include <QtConcurrentRun>
-+#include <QWaitCondition>
-+#include <QKeyEvent>
-+#include <QMetaObject>
-+#include <QLabel>
-+#include <QIODevice>
-+#include <QShortcut>
-+#include <QStatusBar>
-+#include <QFileInfo>
-+#include <QDate>
-+#include <QFileDialog>
-+#include <QToolBar>
-+
-+#include <QAction>
-+#include <QButtonGroup>
-+#include <QMenu>
-+
- #include <math.h>
- 
- #ifdef _WIN32
-@@ -60,7 +84,6 @@
-     #endif
- #endif
- 
--
- //Static and global first
- static GuiReceiver *guiMainThread = NULL;
- static int parameterSystemC = 1;
diff --git a/setup.py b/setup.py
index d7385ff1..6874e290 100644
--- a/setup.py
+++ b/setup.py
@@ -109,9 +109,6 @@ def main():
     # OS-specific components
     if (sys.platform == 'darwin' or sys.platform.startswith('linux')) and not build_headless:
         cmake_args.append("-DWITH_QT=4")
-        # Apply Qt namespace patches to OpenCV GUI code
-        subprocess.check_call("patch -p0 < patches/patch1.patch", shell=True)
-        subprocess.check_call("patch -p0 < patches/patch2.patch", shell=True)
 
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless

From b38fff04f585391211285107e7f8e8661c3dc126 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 14 Jul 2018 12:30:22 +0300
Subject: [PATCH 058/566] bump OpenCV version to 3.4.2, udpate multibuild, add
 Python 3.7 support, update Dockerfiles

---
 .travis.yml    | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++
 appveyor.yml   | 32 ++++++++++++++++++++++++++++
 multibuild     |  2 +-
 opencv         |  2 +-
 opencv_contrib |  2 +-
 setup.py       |  9 +++++++-
 6 files changed, 100 insertions(+), 4 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 6aed49c8..fc6c526a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -56,6 +56,13 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+    - os: osx
+      language: generic
+      osx_image: xcode7.3
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
 
     # headless builds for MacOS
     - os: osx
@@ -86,6 +93,13 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+    - os: osx
+      language: generic
+      osx_image: xcode7.3
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
 
     # Contrib builds for MacOS
     - os: osx
@@ -116,6 +130,13 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+    - os: osx
+      language: generic
+      osx_image: xcode7.3
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
 
     # headless contrib builds for MacOS
     - os: osx
@@ -146,6 +167,13 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+    - os: osx
+      language: generic
+      osx_image: xcode7.3
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
 
     # default builds for Linux
     - os: linux
@@ -207,6 +235,13 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.11.3
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - PLAT=i686
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.14.5
 
     # headless builds for Linux
     - os: linux
@@ -268,6 +303,13 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.11.3
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - PLAT=i686
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.14.5
 
     # contrib builds for Linux
     - os: linux
@@ -329,6 +371,14 @@ matrix:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - PLAT=i686
+        - TEST_DEPENDS=numpy==1.14.5
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+
 
     # headless contrib builds for Linux
     - os: linux
@@ -390,6 +440,13 @@ matrix:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - PLAT=i686
+        - TEST_DEPENDS=numpy==1.14.5
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
 
 # The first line is printed in the folding header in Travis output
 before_install: |
diff --git a/appveyor.yml b/appveyor.yml
index c7a8b319..53a3938e 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -38,6 +38,14 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
+    - PYTHON: "C:/Python37"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python37-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
     - PYTHON: "C:/Python27"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
@@ -70,6 +78,14 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
+    - PYTHON: "C:/Python37"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python37-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
     - PYTHON: "C:/Python27"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
@@ -102,6 +118,14 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
+    - PYTHON: "C:/Python37"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python37-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
     - PYTHON: "C:/Python27"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
@@ -134,6 +158,14 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
+    - PYTHON: "C:/Python37"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python37-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
 matrix:
     fast_finish: true
 
diff --git a/multibuild b/multibuild
index ae3e5598..afbff539 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit ae3e559829d34a74c706baa9389a101e52d8e2d0
+Subproject commit afbff539ea815f3dafcd68f1bf1e87c4381bcbda
diff --git a/opencv b/opencv
index 6ffc4876..9e1b1e53 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 6ffc48769ac60d53c4bd1913eac15117c9b1c9f7
+Subproject commit 9e1b1e5389237c2b9f6c7b9d7715d9836c0a5de1
diff --git a/opencv_contrib b/opencv_contrib
index ced5aa76..d4e02869 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit ced5aa760688dd2ec867ebf7bd4f0c2341d2fde5
+Subproject commit d4e02869454998c9af5af1a5c3392cdc0c31dd22
diff --git a/setup.py b/setup.py
index 6874e290..aadc307e 100644
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,14 @@ def main():
     # Only import 3rd-party modules after having installed all the build dependencies:
     # any of them, or their dependencies, can be updated during that process,
     # leading to version conflicts
-    numpy_version = get_or_install("numpy", "1.11.3" if sys.version_info[:2] >= (3, 6) else "1.11.1")
+    minimum_supported_numpy = "1.11.1"
+
+    if sys.version_info[:2] >= (3, 6):
+        minimum_supported_numpy = "1.11.3"
+    if sys.version_info[:2] >= (3, 7):
+        minimum_supported_numpy = "1.14.5"
+
+    numpy_version = get_or_install("numpy", minimum_supported_numpy)
     get_or_install("scikit-build")
     import skbuild
 

From 5b2b1e86a224224a03f13c370a019531eeb0294d Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 14 Jul 2018 12:40:05 +0300
Subject: [PATCH 059/566] fix skbuild usage

---
 setup.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/setup.py b/setup.py
index aadc307e..12e5be83 100644
--- a/setup.py
+++ b/setup.py
@@ -207,7 +207,7 @@ class RearrangeCMakeOutput(object):
     # Have to wrap a function reference, or it's converted
     # into an instance method on attr assignment
     import argparse
-    wraps = argparse.Namespace(_classify_files=None)
+    wraps = argparse.Namespace(_classify_installed_files=None)
     del argparse
 
     package_paths_re = None
@@ -216,12 +216,12 @@ class RearrangeCMakeOutput(object):
 
     def __init__(self, package_paths_re, files_outside_package, packages):
         cls = self.__class__
-        assert not cls.wraps._classify_files, "Singleton object"
+        assert not cls.wraps._classify_installed_files, "Singleton object"
         import skbuild.setuptools_wrap
 
         cls._setuptools_wrap = skbuild.setuptools_wrap
-        cls.wraps._classify_files = cls._setuptools_wrap._classify_files
-        cls._setuptools_wrap._classify_files = self._classify_files_override
+        cls.wraps._classify_installed_files = cls._setuptools_wrap._classify_installed_files
+        cls._setuptools_wrap._classify_installed_files = self._classify_installed_files_override
 
         cls.package_paths_re = package_paths_re
         cls.files_outside_package = files_outside_package
@@ -229,11 +229,11 @@ def __init__(self, package_paths_re, files_outside_package, packages):
 
     def __del__(self):
         cls = self.__class__
-        cls._setuptools_wrap._classify_files = cls.wraps._classify_files
-        cls.wraps._classify_files = None
+        cls._setuptools_wrap._classify_installed_files = cls.wraps._classify_installed_files
+        cls.wraps._classify_installed_files = None
         cls._setuptools_wrap = None
 
-    def _classify_files_override(self, install_paths,
+    def _classify_installed_files_override(self, install_paths,
             package_data, package_prefixes,
             py_modules, new_py_modules,
             scripts, new_scripts,
@@ -306,7 +306,7 @@ def _classify_files_override(self, install_paths,
 
         final_install_paths = [os.path.join(cmake_install_dir, p) for p in final_install_relpaths]
 
-        return (cls.wraps._classify_files)(
+        return (cls.wraps._classify_installed_files)(
             final_install_paths,
             package_data, package_prefixes,
             py_modules, new_py_modules,

From 63deb1f170c3887ee34e9b3d26240f0512f50e4b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 15 Jul 2018 16:37:36 +0300
Subject: [PATCH 060/566] xcode7.3 image has too old clang which does not
 support thread-local storage -> update to xcode8 image

---
 .travis.yml | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index fc6c526a..1d366ee3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -30,35 +30,35 @@ matrix:
     # default builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -67,35 +67,35 @@ matrix:
     # headless builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -104,35 +104,35 @@ matrix:
     # Contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -141,35 +141,35 @@ matrix:
     # headless contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1

From d75ac7a0940f72d99555059c874339a7b4262115 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 15 Jul 2018 17:15:32 +0300
Subject: [PATCH 061/566] add -std=c++11

---
 setup.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/setup.py b/setup.py
index 12e5be83..18a63803 100644
--- a/setup.py
+++ b/setup.py
@@ -137,6 +137,8 @@ def main():
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
+        cmake_args.append("-DCMAKE_CXX_FLAGS=-std=c++11")  # enable c++11 explicitly for clang
+
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411
 

From f82efb7f069ff4a7449ce0ff119da4014a0330fc Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 15 Jul 2018 18:26:05 +0300
Subject: [PATCH 062/566] try xcode8.3

---
 .travis.yml | 40 ++++++++++++++++++++--------------------
 setup.py    |  1 -
 2 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 1d366ee3..e6935809 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -30,35 +30,35 @@ matrix:
     # default builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -67,35 +67,35 @@ matrix:
     # headless builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -104,35 +104,35 @@ matrix:
     # Contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -141,35 +141,35 @@ matrix:
     # headless contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
diff --git a/setup.py b/setup.py
index 18a63803..a8730a6c 100644
--- a/setup.py
+++ b/setup.py
@@ -137,7 +137,6 @@ def main():
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
-        cmake_args.append("-DCMAKE_CXX_FLAGS=-std=c++11")  # enable c++11 explicitly for clang
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411

From 0ef8126f847a93f49c7ab23fde1c5ef925a9081f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 15 Jul 2018 19:00:41 +0300
Subject: [PATCH 063/566] try setting cmake macos deployoment target

---
 .travis.yml | 40 ++++++++++++++++++++--------------------
 setup.py    |  1 +
 2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index e6935809..fc6c526a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -30,35 +30,35 @@ matrix:
     # default builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -67,35 +67,35 @@ matrix:
     # headless builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -104,35 +104,35 @@ matrix:
     # Contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -141,35 +141,35 @@ matrix:
     # headless contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode7.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
diff --git a/setup.py b/setup.py
index a8730a6c..2388dd9d 100644
--- a/setup.py
+++ b/setup.py
@@ -137,6 +137,7 @@ def main():
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
+        cmake_args.append("-DMACOSX_DEPLOYMENT_TARGET=10.10")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411

From a62380b389af5bd6096c5a11dc633aedac730934 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 15 Jul 2018 19:35:26 +0300
Subject: [PATCH 064/566] xcode9.3

---
 .travis.yml | 40 ++++++++++++++++++++--------------------
 config.sh   |  2 ++
 setup.py    |  1 -
 3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index fc6c526a..91c8a065 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -30,35 +30,35 @@ matrix:
     # default builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -67,35 +67,35 @@ matrix:
     # headless builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -104,35 +104,35 @@ matrix:
     # Contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -141,35 +141,35 @@ matrix:
     # headless contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode7.3
+      osx_image: xcode9.2
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
diff --git a/config.sh b/config.sh
index ca089dad..4a30e256 100644
--- a/config.sh
+++ b/config.sh
@@ -25,6 +25,8 @@ function pre_build {
 
     brew update
 
+    export CXXFLAGS=-mmacosx-version-min=10.10
+
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap -v cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin -v cartr/qt4
diff --git a/setup.py b/setup.py
index 2388dd9d..a8730a6c 100644
--- a/setup.py
+++ b/setup.py
@@ -137,7 +137,6 @@ def main():
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
-        cmake_args.append("-DMACOSX_DEPLOYMENT_TARGET=10.10")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411

From 5e58fc3ec8bd35135a8f101775aa4af001cab202 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 15 Jul 2018 20:19:51 +0300
Subject: [PATCH 065/566] add -std=c++11 back and change to Xcode 8

---
 .travis.yml | 40 ++++++++++++++++++++--------------------
 setup.py    |  1 +
 2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 91c8a065..1d366ee3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -30,35 +30,35 @@ matrix:
     # default builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -67,35 +67,35 @@ matrix:
     # headless builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -104,35 +104,35 @@ matrix:
     # Contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -141,35 +141,35 @@ matrix:
     # headless contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
       language: generic
-      osx_image: xcode9.2
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
diff --git a/setup.py b/setup.py
index a8730a6c..18a63803 100644
--- a/setup.py
+++ b/setup.py
@@ -137,6 +137,7 @@ def main():
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
+        cmake_args.append("-DCMAKE_CXX_FLAGS=-std=c++11")  # enable c++11 explicitly for clang
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411

From 9d0c9189bc6570ab8fe2ccde954577ed8d83de50 Mon Sep 17 00:00:00 2001
From: "Michael Hirsch, Ph.D" <scivision@users.noreply.github.com>
Date: Mon, 16 Jul 2018 10:28:56 -0400
Subject: [PATCH 066/566] add PyPi download count badge to README

---
 README.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/README.md b/README.md
index 0f5cb4dc..64ec54de 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
+[![Downloads](http://pepy.tech/badge/opencv-python)](http://pepy.tech/project/opencv-python)
+
 ## OpenCV on Wheels
 
 **Unofficial** pre-built OpenCV packages for Python.

From 0b2d341fe1689ae103b344ce27b0f821cd1acde7 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 16 Jul 2018 20:37:47 +0300
Subject: [PATCH 067/566] try different flag

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 18a63803..5f952c77 100644
--- a/setup.py
+++ b/setup.py
@@ -137,7 +137,7 @@ def main():
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
-        cmake_args.append("-DCMAKE_CXX_FLAGS=-std=c++11")  # enable c++11 explicitly for clang
+        cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411

From 725aa6b1092a8064ce4be894cda51f45125bae38 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 16 Jul 2018 21:44:17 +0300
Subject: [PATCH 068/566] set deployment target

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 5f952c77..c3d48290 100644
--- a/setup.py
+++ b/setup.py
@@ -137,7 +137,7 @@ def main():
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
-        cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
+        cmake_args.append("-DCMAKE_CXX_FLAGS='-mmacosx-version-min=10.7 -stdlib=libc++'")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411

From bf5446fe097f09df5a1852b078e42a3721b2fdff Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 16 Jul 2018 22:06:32 +0300
Subject: [PATCH 069/566] try cmake variable...

---
 setup.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index c3d48290..c172dfe3 100644
--- a/setup.py
+++ b/setup.py
@@ -137,7 +137,8 @@ def main():
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
-        cmake_args.append("-DCMAKE_CXX_FLAGS='-mmacosx-version-min=10.7 -stdlib=libc++'")
+        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=10.7")
+        cmake_args.append("-DCMAKE_CXX_FLAGS='-stdlib=libc++'")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411

From 1ed5991b268767fba15afaaf8db8ee1fb53cc5d1 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Tue, 17 Jul 2018 08:45:53 +0300
Subject: [PATCH 070/566] Remove CXXFLAGS

---
 config.sh | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/config.sh b/config.sh
index 4a30e256..948bc9ca 100644
--- a/config.sh
+++ b/config.sh
@@ -25,8 +25,6 @@ function pre_build {
 
     brew update
 
-    export CXXFLAGS=-mmacosx-version-min=10.10
-
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap -v cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin -v cartr/qt4
@@ -72,4 +70,4 @@ function test_wheels {
 }
 
 export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
-set -x
\ No newline at end of file
+set -x

From f50748292e4d9374dc32baa415e51c0290b026cf Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Tue, 17 Jul 2018 09:25:22 +0300
Subject: [PATCH 071/566] Add MACOSX_DEPLOYMENT_TARGET

---
 config.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/config.sh b/config.sh
index 948bc9ca..d62cc65d 100644
--- a/config.sh
+++ b/config.sh
@@ -22,6 +22,8 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
+    
+    MACOSX_DEPLOYMENT_TARGET=10.7
 
     brew update
 

From 47c5a9fb325fba208c7ac963ccd26108bc7d27e2 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 19 Jul 2018 12:29:01 +0300
Subject: [PATCH 072/566] move the deployment target to .travis.yml

---
 .travis.yml | 20 ++++++++++++++++++++
 config.sh   |  2 --
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 1d366ee3..576059d8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -35,6 +35,7 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -42,6 +43,7 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -49,6 +51,7 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -56,6 +59,7 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -63,6 +67,7 @@ matrix:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - MACOSX_DEPLOYMENT_TARGET=10.7
 
     # headless builds for MacOS
     - os: osx
@@ -72,6 +77,7 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -79,6 +85,7 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -86,6 +93,7 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -93,6 +101,7 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -100,6 +109,7 @@ matrix:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - MACOSX_DEPLOYMENT_TARGET=10.7
 
     # Contrib builds for MacOS
     - os: osx
@@ -109,6 +119,7 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -116,6 +127,7 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -123,6 +135,7 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -130,6 +143,7 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -137,6 +151,7 @@ matrix:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - MACOSX_DEPLOYMENT_TARGET=10.7
 
     # headless contrib builds for MacOS
     - os: osx
@@ -146,6 +161,7 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -153,6 +169,7 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -160,6 +177,7 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -167,6 +185,7 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -174,6 +193,7 @@ matrix:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - MACOSX_DEPLOYMENT_TARGET=10.7
 
     # default builds for Linux
     - os: linux
diff --git a/config.sh b/config.sh
index d62cc65d..948bc9ca 100644
--- a/config.sh
+++ b/config.sh
@@ -22,8 +22,6 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
-    
-    MACOSX_DEPLOYMENT_TARGET=10.7
 
     brew update
 

From 4d7a7c95abb4304db6c605b0a3304d27e59baea8 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 19 Jul 2018 13:05:06 +0300
Subject: [PATCH 073/566] Revert "move the deployment target to .travis.yml"

This reverts commit 47c5a9fb325fba208c7ac963ccd26108bc7d27e2.
---
 .travis.yml | 20 --------------------
 config.sh   |  2 ++
 2 files changed, 2 insertions(+), 20 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 576059d8..1d366ee3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -35,7 +35,6 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -43,7 +42,6 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -51,7 +49,6 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -59,7 +56,6 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -67,7 +63,6 @@ matrix:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - MACOSX_DEPLOYMENT_TARGET=10.7
 
     # headless builds for MacOS
     - os: osx
@@ -77,7 +72,6 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -85,7 +79,6 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -93,7 +86,6 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -101,7 +93,6 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -109,7 +100,6 @@ matrix:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - MACOSX_DEPLOYMENT_TARGET=10.7
 
     # Contrib builds for MacOS
     - os: osx
@@ -119,7 +109,6 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -127,7 +116,6 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -135,7 +123,6 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -143,7 +130,6 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -151,7 +137,6 @@ matrix:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - MACOSX_DEPLOYMENT_TARGET=10.7
 
     # headless contrib builds for MacOS
     - os: osx
@@ -161,7 +146,6 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -169,7 +153,6 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -177,7 +160,6 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -185,7 +167,6 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - MACOSX_DEPLOYMENT_TARGET=10.7
     - os: osx
       language: generic
       osx_image: xcode8
@@ -193,7 +174,6 @@ matrix:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - MACOSX_DEPLOYMENT_TARGET=10.7
 
     # default builds for Linux
     - os: linux
diff --git a/config.sh b/config.sh
index 948bc9ca..d62cc65d 100644
--- a/config.sh
+++ b/config.sh
@@ -22,6 +22,8 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
+    
+    MACOSX_DEPLOYMENT_TARGET=10.7
 
     brew update
 

From 87252ed22c22f132a641717580dac87efb34d99a Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 19 Jul 2018 13:08:41 +0300
Subject: [PATCH 074/566] maybe homebrew overwrites the deployment target...

---
 config.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/config.sh b/config.sh
index d62cc65d..7e69c2b9 100644
--- a/config.sh
+++ b/config.sh
@@ -22,8 +22,6 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
-    
-    MACOSX_DEPLOYMENT_TARGET=10.7
 
     brew update
 
@@ -40,6 +38,9 @@ function pre_build {
     travis_wait brew install -v ffmpeg --without-x264 --without-xvid --without-gpl
     brew info ffmpeg
     echo '-----------------'
+
+    export MACOSX_DEPLOYMENT_TARGET=10.7
+
   else
     echo "Running for linux"
   fi

From c5b34e1f8ece610b3da3572c91921b7430ce7a19 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 19 Jul 2018 13:48:50 +0300
Subject: [PATCH 075/566] remove cmake args

---
 setup.py | 2 --
 1 file changed, 2 deletions(-)

diff --git a/setup.py b/setup.py
index c172dfe3..a8730a6c 100644
--- a/setup.py
+++ b/setup.py
@@ -137,8 +137,6 @@ def main():
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
-        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=10.7")
-        cmake_args.append("-DCMAKE_CXX_FLAGS='-stdlib=libc++'")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411

From 09fecca8e180787ab6127da4d1aed5d2dd14a9fb Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 19 Jul 2018 15:11:52 +0300
Subject: [PATCH 076/566] try another approach

---
 config.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/config.sh b/config.sh
index 7e69c2b9..2ca4fd6b 100644
--- a/config.sh
+++ b/config.sh
@@ -39,7 +39,8 @@ function pre_build {
     brew info ffmpeg
     echo '-----------------'
 
-    export MACOSX_DEPLOYMENT_TARGET=10.7
+    MACOS_SDK_PATH=`xcrun --sdk macosx --show-sdk-path`
+    export CXXFLAGS="-stdlib=libc++ -isysroot ${MACOS_SDK_PATH} -mmacosx-version-min=10.7"
 
   else
     echo "Running for linux"

From bfd9eba03a500b39085a11d15d83ae52357f39e0 Mon Sep 17 00:00:00 2001
From: yonip <yonip@github.com>
Date: Thu, 19 Jul 2018 11:46:27 -0400
Subject: [PATCH 077/566] Add flag to setup.py call so skbuild doesn't default
 to osx 10.6

---
 config.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/config.sh b/config.sh
index 2ca4fd6b..dbc41e5d 100644
--- a/config.sh
+++ b/config.sh
@@ -10,6 +10,14 @@ function build_wheel {
     build_bdist_wheel $@
 }
 
+function bdist_wheel_cmd {
+    # copied from multibuild's common_utils.sh
+    # add osx deployment target so it doesnt default to 10.6
+    local abs_wheelhouse=$1
+    python setup.py bdist_wheel -- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7
+    cp dist/*.whl $abs_wheelhouse
+}
+
 if [ -n "$IS_OSX" ]; then
   echo "    > OSX environment "
 else

From ce8b8cb3d32c34f4b812995d970fe2d483a0dbb6 Mon Sep 17 00:00:00 2001
From: yonip <yonip@github.com>
Date: Thu, 19 Jul 2018 13:05:47 -0400
Subject: [PATCH 078/566] De-pollute parameters to bdist so its only on osx and
 make sure that osx also sets the correct numpy version for python3.7

---
 .travis.yml | 26 ++++++++++++++++++++++++++
 config.sh   |  2 +-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 1d366ee3..732499b2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,6 +3,8 @@ env:
         - "PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'"
         # pip dependencies to _test_ your project
         - TEST_DEPENDS="numpy==1.11.1"
+        # params to bdist_wheel. used to set osx build target.
+        - BDIST_PARAMS=""
 
         - PLAT=x86_64
         - UNICODE_WIDTH=32
@@ -35,6 +37,7 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -42,6 +45,7 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -49,6 +53,7 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -56,6 +61,7 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -63,6 +69,8 @@ matrix:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
+        - TEST_DEPENDS=numpy==1.14.5
 
     # headless builds for MacOS
     - os: osx
@@ -72,6 +80,7 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -79,6 +88,7 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -86,6 +96,7 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -93,6 +104,7 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -100,6 +112,8 @@ matrix:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
+        - TEST_DEPENDS=numpy==1.14.5
 
     # Contrib builds for MacOS
     - os: osx
@@ -109,6 +123,7 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -116,6 +131,7 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -123,6 +139,7 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -130,6 +147,7 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -137,6 +155,8 @@ matrix:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
+        - TEST_DEPENDS=numpy==1.14.5
 
     # headless contrib builds for MacOS
     - os: osx
@@ -146,6 +166,7 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -153,6 +174,7 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -160,6 +182,7 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -167,6 +190,7 @@ matrix:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
       osx_image: xcode8
@@ -174,6 +198,8 @@ matrix:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
+        - TEST_DEPENDS=numpy==1.14.5
 
     # default builds for Linux
     - os: linux
diff --git a/config.sh b/config.sh
index dbc41e5d..9a2831ec 100644
--- a/config.sh
+++ b/config.sh
@@ -14,7 +14,7 @@ function bdist_wheel_cmd {
     # copied from multibuild's common_utils.sh
     # add osx deployment target so it doesnt default to 10.6
     local abs_wheelhouse=$1
-    python setup.py bdist_wheel -- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7
+    python setup.py bdist_wheel $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
 }
 

From ba3547c928f7dd8074616977e78c22d428dfb2b4 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 19 Jul 2018 20:49:17 +0300
Subject: [PATCH 079/566] maybe this works

---
 config.sh | 4 ++--
 setup.py  | 5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/config.sh b/config.sh
index 2ca4fd6b..125d9942 100644
--- a/config.sh
+++ b/config.sh
@@ -39,8 +39,8 @@ function pre_build {
     brew info ffmpeg
     echo '-----------------'
 
-    MACOS_SDK_PATH=`xcrun --sdk macosx --show-sdk-path`
-    export CXXFLAGS="-stdlib=libc++ -isysroot ${MACOS_SDK_PATH} -mmacosx-version-min=10.7"
+    export MACOS_SDK_PATH=`xcrun --sdk macosx --show-sdk-path`
+    export MIN_MACOS_VERSION="10.7"
 
   else
     echo "Running for linux"
diff --git a/setup.py b/setup.py
index a8730a6c..cc7c1102 100644
--- a/setup.py
+++ b/setup.py
@@ -133,10 +133,13 @@ def main():
                 "-DJPEG_LIBRARY=%s" % os.environ['JPEG_LIBRARY']
             ]
 
-    # Turn off broken components
+    # Fixes for macOS builds
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
+        cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
+        cmake_args.append("-DCMAKE_OSX_SYSROOT=%s" % os.environ['MACOS_SDK_PATH'])
+        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % os.environ['MIN_MACOS_VERSION'])
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411

From 41496145e4e46651bfb1802dd0cddc2fc92c1dec Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 20 Jul 2018 12:03:35 +0300
Subject: [PATCH 080/566] cleanup and add 3.7 to the README

---
 README.md | 1 +
 config.sh | 3 ---
 setup.py  | 2 --
 3 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 64ec54de..7fcda483 100644
--- a/README.md
+++ b/README.md
@@ -140,3 +140,4 @@ Currently, builds for following Python versions are provided:
 - 3.4
 - 3.5
 - 3.6
+- 3.7
\ No newline at end of file
diff --git a/config.sh b/config.sh
index a1ef12b3..86d238e0 100644
--- a/config.sh
+++ b/config.sh
@@ -47,9 +47,6 @@ function pre_build {
     brew info ffmpeg
     echo '-----------------'
 
-    export MACOS_SDK_PATH=`xcrun --sdk macosx --show-sdk-path`
-    export MIN_MACOS_VERSION="10.7"
-
   else
     echo "Running for linux"
   fi
diff --git a/setup.py b/setup.py
index cc7c1102..24ef2d38 100644
--- a/setup.py
+++ b/setup.py
@@ -138,8 +138,6 @@ def main():
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
         cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
-        cmake_args.append("-DCMAKE_OSX_SYSROOT=%s" % os.environ['MACOS_SDK_PATH'])
-        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % os.environ['MIN_MACOS_VERSION'])
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411

From 4b156057ec7240bde30882990fd5183bc534e430 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 20 Jul 2018 13:01:08 +0300
Subject: [PATCH 081/566] add missing identifier for 3.7

---
 setup.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index 24ef2d38..7acb0270 100644
--- a/setup.py
+++ b/setup.py
@@ -188,6 +188,7 @@ def main():
           'Programming Language :: Python :: 3.4',
           'Programming Language :: Python :: 3.5',
           'Programming Language :: Python :: 3.6',
+          'Programming Language :: Python :: 3.7',
           'Programming Language :: C++',
           'Programming Language :: Python :: Implementation :: CPython',
           'Topic :: Scientific/Engineering',

From a1179e13de05bf026971f95c024837e4267abfa1 Mon Sep 17 00:00:00 2001
From: Krassimir Valev <krassimir_valev@yahoo.com>
Date: Sun, 22 Jul 2018 23:22:42 +0200
Subject: [PATCH 082/566] Create x86_64 Linux wheels for Python 3.7

---
 .travis.yml | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index 732499b2..93aea0c3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -261,6 +261,12 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.11.3
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.14.5
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.7
@@ -329,6 +335,12 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.11.3
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.14.5
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.7
@@ -397,6 +409,12 @@ matrix:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - TEST_DEPENDS=numpy==1.14.5
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.7
@@ -466,6 +484,12 @@ matrix:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - TEST_DEPENDS=numpy==1.14.5
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.7

From 5b36c37a86524a20b38b0965a7f996a7a5fcf293 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Mon, 30 Jul 2018 19:37:57 +0300
Subject: [PATCH 083/566] Add note about piwheels, other fixes and notes

---
 README.md | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 7fcda483..0264fa43 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
 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. 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 enviroment.
+    There are four different packages and you should **select only one of them**. Do not install multiple different packages in the same enviroment. 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)
 
@@ -44,7 +44,7 @@ A: No, the packages are special wheel binary packages and they already contain s
 
 **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 PyPI does not currently support ARM architecture so you can't install these packages for example on Raspberry Pi.
+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.``?**
 
@@ -56,6 +56,10 @@ If the above does not help, check if you are using Anaconda. Old Anaconda versio
 
 A: Make sure you have removed old manual installations of OpenCV Python bindings (cv2.so or cv2.pyd in site-packages).
 
+**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
 
 [![AppVeyor CI test status (Windows)](https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows)](https://ci.appveyor.com/project/skvark/opencv-python)
@@ -140,4 +144,4 @@ Currently, builds for following Python versions are provided:
 - 3.4
 - 3.5
 - 3.6
-- 3.7
\ No newline at end of file
+- 3.7

From f0b072d71509af75d8a22a860e212f3df90e0384 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 8 Sep 2018 14:08:18 +0300
Subject: [PATCH 084/566] bump OpenCV to 3.4.3

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 9e1b1e53..b38c50b3 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 9e1b1e5389237c2b9f6c7b9d7715d9836c0a5de1
+Subproject commit b38c50b3d0c31e82294315ec44b54b7ef559ef12
diff --git a/opencv_contrib b/opencv_contrib
index d4e02869..1f6d6f06 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit d4e02869454998c9af5af1a5c3392cdc0c31dd22
+Subproject commit 1f6d6f06266e1ef336437ae5404bee1c65d42cda

From 608a5e2fa178475bb32bf4f2818f58349c23c137 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sun, 28 Oct 2018 20:54:42 +0300
Subject: [PATCH 085/566] Fix "ImportError: No module named install" at test
 stage with the current matthewbrett/trusty

---
 multibuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multibuild b/multibuild
index afbff539..951b6c64 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit afbff539ea815f3dafcd68f1bf1e87c4381bcbda
+Subproject commit 951b6c64f01853cf2569000bb30ecd01a16bba0b

From 7e5a3802ba3ecb77bf482ee82e6df34536a19589 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 27 Oct 2018 22:48:03 +0300
Subject: [PATCH 086/566] git describe --tags produces "fatal: No names found,
 cannot describe anything." on topic branches

---
 find_version.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/find_version.py b/find_version.py
index 438a5411..519542e4 100644
--- a/find_version.py
+++ b/find_version.py
@@ -25,7 +25,15 @@
 # used in local dev releases
 git_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).splitlines()[0].decode()
 # this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
-tag = subprocess.check_output(['git', 'describe', '--tags']).splitlines()[0].decode().split('-')
+try:
+    tag = subprocess.check_output(['git', 'describe', '--tags'], stderr = subprocess.STDOUT).splitlines()[0].decode().split('-')
+except subprocess.CalledProcessError as e:
+    # no tags reachable (e.g. on a topic branch in a fork), see
+    # https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
+    if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
+        tag=[]
+    else:
+        print(e.output); raise
 
 if len(tag) == 1:
     # tag identifies the build and should be a sequential revision number

From 21cb7f1f06ebe0f2f455e673a79796bb2ddbdee3 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 8 Nov 2018 07:07:10 +0300
Subject: [PATCH 087/566] update linux IPP breakage note

---
 setup.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 7acb0270..bc405e00 100644
--- a/setup.py
+++ b/setup.py
@@ -140,7 +140,9 @@ def main():
         cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
 
     if sys.platform.startswith('linux'):
-        cmake_args.append("-DWITH_IPP=OFF")   # https://github.com/opencv/opencv/issues/10411
+        cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with
+                                              # devtoolset-2 GCC 4.8.2 or vanilla GCC 4.9.4
+                                              # see https://github.com/skvark/opencv-python/issues/138
 
     # ABI config variables are introduced in PEP 425
     if sys.version_info[:2] < (3, 2):

From 85364d388ff8b8df4f7402e92c774179f6c596c2 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Mon, 12 Nov 2018 08:56:04 +0300
Subject: [PATCH 088/566] remove secure variables

---
 .travis.yml | 2 --
 1 file changed, 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 93aea0c3..532bed90 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,8 +8,6 @@ env:
 
         - PLAT=x86_64
         - UNICODE_WIDTH=32
-        - secure: "mU040XIYWtDjRms27deQy5fNg9HBFF9fiLfSteBaMjopZKXFUBsdMTKYGEVvX8DA879guMdjG8Prw1aCFhTTYlWgJ0Afm4YucRC0vAD4HLNhqLJ2lIpRceR3+2qPX+Oz5ATVVRi3ghBeJ20LLtNgOgf6esQVjdrYNC+YqmguClHKEYAxS7ngW42iQP8HX2anRcz9q9H7exZ9fX/D1PJfMNka/mNaB5KXZu5zdLuk/E0VbWU2tMWVIDUvx4uBlpE1d8HixEV5LHnuVE/QI36BcyucYxstTNKW6pGYgrhkYf+0PX4BphZXwY7EUBwzXsYLmyge6yH8W6NfvTW0ZasFF6xzQc9bsj+gAZN7H+hN2a42VQqIpkoJw9sU0hqzCOQf6ZvWUQgwFdAHJRHqe/zk4456WxnF0kAgbZdKaGOl0/n0WvgHNqD5bgO8Zzb1XyJTKoR+eAtYKXuz3KgpxKvZMMQVr8wMlI1cFEuGjIm+7ZrYB5jPvQrVzV/DgOq4gkPHOjjhu478UFlhGA9/XWwcyidC3b7zuBN2E7xVuTMlKdk7URB3AHXfG5bZgUG80vllQDGXQDpHVnv4Qi8bGCzI4iKTpp4fCibbqxFLxW1jhjmgePseGcie7Avpe+zXznkbmM2BqMCu3QRmtmFL3eCifwMf3rCNlAs0Sd3iLmEvyos="
-        - secure: "omn6B+H6s0g1p9rhLGhFtFN1bSB80HCsNUUD9ROEpUirk7Sj7Wxms4CDi1f7aACANsZPXD7YZ72oNpWDJ6hSfTBf2yN1/d1iPILs7F5jt0yeratkDEOXkys1QpfMNO7r3DZ17X3IwvUGy9Mm+Sv15k+DaBdQ/65qwQ4ORIbHZRv3/lwkQ7Z88utjx6DLa9Jwc8fnEjjzIry51lO3OGJoWrjOZlOi2HV9MZ69PuuBdEEuicwfeLnV64QWRle++B51TQZC/3HF5+BBvYXm0LdvV4nSQVa9nTXaOWYcBROPNZizktJI91G6vG6gghWmI1cDR53n9LgCbA3YkPTJm/5Gjn9D+gfU5F16WQ4PFOHfzPZD8nTVmlUDUiuQ30W9QZ+O2ct7wi/xF4/Ff7V+0RIqGSnjhX6SGWk7UziQyGgCjBvYiRIQzfUyGu+86vrqNVXCyBlKOz6rWStTyq/Z0KEIXZFqop+ddeYdsEem5ZxCQ51uTpRMynVgEdKj++1Hn5411Rhntw0Am7RWdDEbFJ65OUyIpNtvlcHVM7ur03oz0hGcZIIkxWHJrCdr80Nw9r/s6KXYvidCNsu4SPx0XYo8KiTA6E2lkIAa5Ct6dZR6m5gjG2vmvlKzRmoD/7byJZN66usNxBh2LuKlgNFuHfG6iR+I6f3XCNmSUOJfm7KZYVI="
 
 
 # Host Python is never used

From c148de210fa4c640547774c3093944c054b03a49 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Mon, 12 Nov 2018 10:16:33 +0300
Subject: [PATCH 089/566] Make library for auto building and caching Homebrew
 bottles

cache Homebrew
---
 .travis.yml              |  38 +++-
 config.sh                |  40 ++--
 travis_osx_brew_cache.sh | 381 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 447 insertions(+), 12 deletions(-)
 create mode 100644 travis_osx_brew_cache.sh

diff --git a/.travis.yml b/.travis.yml
index 93aea0c3..b281544f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,6 +25,15 @@ dist: trusty
 git:
     submodules: false
 
+# https://docs.travis-ci.com/user/caching
+cache:
+  directories:
+    # https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
+    - $HOME/Library/Caches/Homebrew
+    - /usr/local/Homebrew/
+    # used in OSX custom build script dealing with local bottle caching
+    - $HOME/local_bottle_metadata
+    
 matrix:
   fast_finish: true
   include:
@@ -526,9 +535,36 @@ install: |
 script: |
     # Install and run tests
     set -x
-    install_run $PLAT
+    install_run $PLAT && rc=$? || rc=$?
     set +x
 
+    #otherwise, Travis logic terminates prematurely
+    #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
+    trap ERR
+    
+    test "$rc" -eq 0
+
+before_cache: |
+    # Cleanup dirs to be cached
+    set -x
+    if [ -n "$IS_OSX" ]; then
+
+        # When Taps is cached, this dir causes "Error: file exists" on `brew update`
+        rm -rf "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask"
+        find "$(brew --repository)/Library/Taps" -type d -name .git -exec \
+            bash -xec '
+                cd $(dirname '\''{}'\'')
+                git status
+                # https://stackoverflow.com/questions/8296710/how-to-ignore-xargs-commands-if-stdin-input-is-empty/19038748#19038748
+                git ls-files --other -z | xargs -0 -n100 git add
+                git commit -a -m "Travis auto changes"
+                [[ -n $(git stash list) ]] && git stash drop' \;
+
+        brew_cache_cleanup
+        
+    fi
+    set +x
+    
 after_success: |
     # Upload wheels to pypi if requested
     if [ -n "$TRAVIS_TAG" ]; then
diff --git a/config.sh b/config.sh
index 86d238e0..1534c1dc 100644
--- a/config.sh
+++ b/config.sh
@@ -24,28 +24,46 @@ else
   echo "    > Linux environment "
 fi
 
+if [ -n "$IS_OSX" ]; then
+
+    source travis_osx_brew_cache.sh
+    
+    BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
+        "x265 20"  \
+        "cmake 15" \
+        "ffmpeg 10" \
+    )
+    
+    #Contrib adds significantly to project's build time
+    if [ "$ENABLE_CONTRIB" -eq 1 ]; then
+        BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
+    fi
+        
+fi
+
 function pre_build {
   echo "Starting pre-build"
-  set -e
+  set -e -o pipefail
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
+    
+    brew update --merge
+    brew_add_local_bottles
 
-    brew update
+    # Don't query analytical info online on `brew info`,
+    #  this takes several seconds and we don't need it
+    # see https://docs.brew.sh/Manpage , "info formula" section
+    export HOMEBREW_NO_GITHUB_API=1
 
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap -v cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin -v cartr/qt4
-    brew list --versions qt@4 || brew install -v qt@4
-    echo '-----------------'
-    echo '-----------------'
+    brew_install_and_cache_within_time_limit qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
+
     echo 'Installing FFmpeg'
-    # brew install does produce output regularly on a regular MacOS,
-    # but Travis doesn't see it for some reason
-    brew list --versions ffmpeg || \
-    travis_wait brew install -v ffmpeg --without-x264 --without-xvid --without-gpl
-    brew info ffmpeg
-    echo '-----------------'
+
+    brew_install_and_cache_within_time_limit ffmpeg || { [ $? -gt 1 ] && return 2 || return 0; }
 
   else
     echo "Running for linux"
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
new file mode 100644
index 00000000..c5f26190
--- /dev/null
+++ b/travis_osx_brew_cache.sh
@@ -0,0 +1,381 @@
+# Library to cache downloaded and locally-built Homebrew bottles in Travis OSX build.
+
+trap '{ sleep 1;    #if we terminale too abruptly, Travis will lose some log output
+        exit 2;     #The trap isn''t called in the parent function, so can''t use `return` here.
+                    #`exit` will terminate the entire build but it seems we have no choice.
+}' ERR
+set -E
+
+#Should be in Travis' cache
+BREW_LOCAL_BOTTLE_METADATA="$HOME/local_bottle_metadata"
+
+# Starting reference point for elapsed build time; seconds since the epoch.
+#TRAVIS_TIMER_START_TIME is set at the start of a log fold, in nanoseconds since the epoch
+BREW_TIME_START=$(($TRAVIS_TIMER_START_TIME/10**9))
+
+# If after a package is built, elapsed time is more than this many seconds, fail the build but save Travis cache
+# The cutoff moment should leave enough time till Travis' job time limit to process the main project.
+BREW_TIME_LIMIT=$((30*60))
+# If a slow-building package is about to be built and the projected build end moment is beyond this many seconds,
+# skip that build, fail the Travis job and save Travis cache.
+# This cutoff should leave enough time for before_cache and cache save.
+BREW_TIME_HARD_LIMIT=$((40*60))
+
+
+
+#Public functions
+
+function brew_install_and_cache_within_time_limit {
+    # Install the package and its dependencies one by one;
+    # use bottle if available, build and cache bottle if not.
+    # Terminate and exit with status 1 if this takes too long.
+    # Exit with status 2 on any other error.
+    
+    local PACKAGE; PACKAGE="${1:?}"
+    local TIME_LIMIT;TIME_LIMIT=${2:-$BREW_TIME_LIMIT}
+    local TIME_HARD_LIMIT;TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT}
+    local TIME_START;TIME_START=${4:-$BREW_TIME_START}
+
+    local BUILD_FROM_SOURCE INCLUDE_BUILD
+    
+    _brew_is_bottle_available "$PACKAGE" || BUILD_FROM_SOURCE=1
+    [ -n "$BUILD_FROM_SOURCE" ] && INCLUDE_BUILD="--include-build" || true
+
+    # Whitespace is illegal in package names so converting all whitespace into single spaces due to no quotes is okay.
+    DEPS=`brew deps "$PACKAGE" $INCLUDE_BUILD`
+    for dep in $DEPS; do
+        #TIME_LIMIT only has to be met if we'll be actually building the main project this iteration, i.e. after the "root" module installation
+        #While we don't know that yet, we can make better use of Travis-given time with a laxer limit
+        #We still can't overrun TIME_HARD_LIMIT as that would't leave time to save the cache
+        brew_install_and_cache_within_time_limit "$dep" $(((TIME_LIMIT+TIME_HARD_LIMIT)/2)) "$TIME_HARD_LIMIT" "$TIME_START" || return $?
+    done
+
+    _brew_check_slow_building_ahead "$PACKAGE" "$TIME_START" "$TIME_HARD_LIMIT" || return $?
+    _brew_install_and_cache "$PACKAGE" "$([[ -z "$INCLUDE_BUILD" ]] && echo 1 || echo 0)"
+    _brew_check_elapsed_build_time "$TIME_START" "$TIME_LIMIT" || return $?
+}
+
+function brew_add_local_bottles {
+    # Should be called after `brew update` at startup.
+    # Adds metadata for cached locally-built bottles to local formulas
+    #  so that `brew` commands can find them.
+    # If the package was updated, removes the corresponding files
+    #  and the bottle's entry in the formula, if any.
+    
+    # Bottle entry in formula: 
+    #   bottle do
+    #     <...>
+    #     sha256 "<sha256>" => :<os_codename>
+    #     <...>
+    #   end 
+    
+    echo "Cached bottles:"
+    ls "$(brew --cache)/downloads" || true  #may not exist initially since it's "$(brew --cache)" that is in Travis cache
+    echo "Saved .json's and links:"
+    ls "$BREW_LOCAL_BOTTLE_METADATA"
+    
+    for JSON in "$BREW_LOCAL_BOTTLE_METADATA"/*.json; do
+        [ -e "$JSON" ] || break    # OSX 10.11 bash has no nullglob
+        local PACKAGE JSON_VERSION JSON_REBUILD OS_CODENAME BOTTLE_HASH
+        
+        _brew_parse_bottle_json "$JSON" PACKAGE JSON_VERSION JSON_REBUILD OS_CODENAME BOTTLE_HASH
+
+        echo "Adding local bottle: $PACKAGE ${JSON_VERSION}_${JSON_REBUILD}"
+        
+        local FORMULA_VERSION FORMULA_REBUILD FORMULA_BOTTLE_HASH
+        
+        _brew_parse_package_info "$PACKAGE" "$OS_CODENAME" FORMULA_VERSION FORMULA_REBUILD FORMULA_BOTTLE_HASH
+
+        local FORMULA_HAS_BOTTLE; [ -n "$FORMULA_BOTTLE_HASH" ] && FORMULA_HAS_BOTTLE=1 || true
+        
+
+        local BOTTLE_LINK BOTTLE; BOTTLE_LINK="${JSON}.bottle.lnk";
+        local BOTTLE_EXISTS BOTTLE_MISMATCH VERSION_MISMATCH
+
+
+        # Check that the bottle file exists and is still appropriate for the formula
+        if [[ "$FORMULA_VERSION" != "$JSON_VERSION" || "$JSON_REBUILD" != "$FORMULA_REBUILD" ]]; then
+            VERSION_MISMATCH=1;
+            echo "The cached bottle is obsolete: formula ${FORMULA_VERSION}_${FORMULA_REBUILD}"
+        fi
+        if [ -f "$BOTTLE_LINK" ]; then
+            BOTTLE=$(cat "$BOTTLE_LINK");
+            BOTTLE=$(cd "$(dirname "$BOTTLE")"; pwd)/$(basename "$BOTTLE")
+            
+            if [ -e "$BOTTLE" ]; then
+                BOTTLE_EXISTS=1;
+                
+                # The hash in `brew --cache $PACKAGE` entry is generated from download URL,
+                #  which itself is generated from base URL and version
+                # (see Homebrew/Library/Homebrew/download_strategy.rb:cached_location).
+                # So if version changes, hashes will always mismatch anyway
+                #  and we don't need a separate message about this.
+                # XXX: OSX doesn't have `realpath` so can't compare the entire paths
+                if [ -n "$FORMULA_HAS_BOTTLE" -a -z "$VERSION_MISMATCH" -a \
+                    "$(basename "$(brew --cache "$PACKAGE")")" != "$(basename "$BOTTLE")" ]; then
+                        BOTTLE_MISMATCH=1;
+                        echo "Cached bottle file doesn't correspond to formula's cache entry!" \
+                             "This can happen if download URL has changed." >&2
+                fi
+            else
+                echo "Cached bottle file is missing!" >&2
+            fi
+        else
+            echo "Link file is missing or of invalid type!" >&2
+        fi
+                    
+        # Delete cached bottle and all metadata if invalid
+        if [[ -z "$BOTTLE_EXISTS" || -n "$VERSION_MISMATCH" || -n "$BOTTLE_MISMATCH" ]]; then
+            echo "Deleting the cached bottle and all metadata"
+
+            if [ "$FORMULA_BOTTLE_HASH" == "$BOTTLE_HASH" ]; then
+                echo "A bottle block for the cached bottle was merged into the updated formula. Removing..."
+                local FORMULA; FORMULA=$(brew formula "$PACKAGE")
+                perl -wpe 'BEGIN { our $IN_BLOCK=0; }
+                    if ( ($IN_BLOCK==0) && /^\s*bottle\s+do\s*$/ ) { $IN_BLOCK=1; next; }
+                    if ( ($IN_BLOCK==1) && /^\s*end\s*$/ )         { $IN_BLOCK=-1; next; }
+                    if ( ($IN_BLOCK==1) && /^\s*sha256\s+"(\w+)"\s+=>\s+:\w+\s*$/ )
+                                                 { if ( $1 eq "'"$BOTTLE_HASH"'" ) {$_="";}; next; }
+                '  <"$FORMULA" >"${FORMULA}.new"
+                # Depending on diff version, 1 may mean differences found
+                # https://stackoverflow.com/questions/6971284/what-are-the-error-exit-values-for-diff
+                diff -u "$FORMULA" "${FORMULA}.new" || test $? -le 1
+                (   cd $(dirname "$FORMULA")
+                    FORMULA=$(basename "$FORMULA")
+                    mv -v "${FORMULA}.new" "$FORMULA"
+                    git commit -m "Removed obsolete local bottle ${JSON_VERSION}_${JSON_REBUILD} :${OS_CODENAME}" "$FORMULA"
+                )
+            fi
+            
+            if [ -n "$BOTTLE" ]; then rm "$BOTTLE"; fi
+            rm -f "$BOTTLE_LINK"
+            rm "$JSON"
+            
+        #(Re)add metadata to the formula otherwise
+        else
+            if [ "$FORMULA_BOTTLE_HASH" == "$BOTTLE_HASH" ]; then
+                echo "The cached bottle is already present in the formula"
+            else
+                brew bottle --merge --write "$JSON"
+            fi
+        fi
+    done
+}
+
+
+function brew_cache_cleanup {
+    #Cleanup caching directories
+    # Is supposed to be called in before_cache
+
+    #Lefovers from some failure probably
+    rm -f "$BREW_LOCAL_BOTTLE_METADATA"/*.tar.gz
+    
+    #`brew cleanup` may delete locally-built bottles that weren't needed this time
+    # so we're saving and restoring them
+    local BOTTLE_LINK BOTTLE
+    for BOTTLE_LINK in "$BREW_LOCAL_BOTTLE_METADATA"/*.lnk; do
+        BOTTLE=$(cat "$BOTTLE_LINK")
+        ln "$BOTTLE" "$BREW_LOCAL_BOTTLE_METADATA/"
+    done
+    brew cleanup
+    local BOTTLE_BASENAME
+    for BOTTLE_LINK in "$BREW_LOCAL_BOTTLE_METADATA"/*.lnk; do
+        BOTTLE=$(cat "$BOTTLE_LINK")
+        BOTTLE_BASENAME=$(basename "$BOTTLE")
+        if test ! -e "$BOTTLE"; then
+            echo "Restoring: $BOTTLE_BASENAME"
+            mv "$BREW_LOCAL_BOTTLE_METADATA/$BOTTLE_BASENAME" "$BOTTLE"
+        else
+            rm "$BREW_LOCAL_BOTTLE_METADATA/$BOTTLE_BASENAME"
+        fi
+    done
+}
+
+
+function brew_go_bootstrap_mode {
+# Can be overridden
+# Terminate the build but ensure saving the cache
+
+    echo "Going into cache bootstrap mode"
+        
+    #Can't just `exit` because that would terminate the build without saving the cache
+    #Have to replace further actions with no-ops
+    
+    eval '
+    function '"$cmd"' { return 0; }
+    function repair_wheelhouse { return 0; }
+    function install_run {
+        echo -e "\nBuilding dependencies took too long. Restart the build in Travis UI to continue from cache.\n"
+        
+        # Travis runs user scripts via `eval` i.e. in the same shell process.
+        # So have to unset errexit in order to get to cache save stage
+        set +e; return 1
+    }'    
+}
+
+
+
+#Internal functions
+
+function _brew_parse_bottle_json {
+    # Parse JSON info about a package
+    # from `brew info --json=v1` input or a JSON file on stdin
+    # and save it into bash global variables specified in arguments
+
+    local JSON; JSON="${1:?}"; shift
+
+    local JSON_DATA; JSON_DATA=$(python2.7 -c 'if True:
+    import sys,json; j=json.load(open(sys.argv[1],"rb")); [name]=j.keys(); [pdata]=j.values()
+    print name
+    print pdata["formula"]["pkg_version"]
+    print pdata["bottle"]["rebuild"]
+    [(tag_name, tag_dict)]=pdata["bottle"]["tags"].items()
+    print tag_name
+    print tag_dict["sha256"]
+    ' "$JSON")
+    
+    unset JSON
+    
+    { local i v; for i in {1..5}; do
+        read -r v
+        eval "${1:?}=\"$v\""
+        shift
+    done } <<< "$JSON_DATA"
+}
+
+function _brew_parse_package_info {
+    # Get and parse `brew info --json` about a package
+    # and save it into bash variables specified in arguments
+    
+    local PACKAGE; PACKAGE="${1:?}"; shift
+    local OS_CODENAME;OS_CODENAME="${1:?}"; shift
+
+    local JSON_DATA; JSON_DATA=$(python2.7 -c 'if True:
+    import sys, json, subprocess; j=json.loads(subprocess.check_output(("brew","info","--json=v1",sys.argv[1])))
+    data=j[0]
+    print data["versions"]["stable"]
+    bottle_data=data["bottle"]["stable"]
+    print bottle_data["rebuild"]
+    print bottle_data["files"].get(sys.argv[2],{"sha256":""})["sha256"]
+    ' \
+    "$PACKAGE" "$OS_CODENAME")
+    
+    unset PACKAGE OS_CODENAME
+    
+    { local i v; for i in {1..3}; do
+        read -r v
+        eval "${1:?}=\"$v\""
+        shift
+    done } <<< "$JSON_DATA"
+}
+
+
+
+function _brew_is_bottle_available {
+
+    local PACKAGE;PACKAGE="${1:?}"
+    
+    local INFO="$(brew info "$PACKAGE" | head -n 1)"
+    if grep -qwF '(bottled)' <<<"$INFO"; then
+        echo "Bottle available: $INFO"
+        return 0
+    else
+        echo "Bottle not available: $INFO"
+        return 1
+    fi
+}
+
+function _brew_install_and_cache {
+    # Install bottle or make and cache bottle.
+    # assumes that deps were already installed.
+    
+    local PACKAGE;PACKAGE="${1:?}"
+    local USE_BOTTLE;USE_BOTTLE="${2:?}"
+    local VERB
+    
+    if brew list --versions "$PACKAGE"; then
+        if ! (brew outdated | grep -qx "$PACKAGE"); then
+            echo "Already the latest version: $PACKAGE"
+            return 0
+        fi
+        VERB=upgrade
+    else
+        VERB=install
+    fi
+    
+    if [[ "$USE_BOTTLE" -gt 0 ]]; then
+        echo "Installing bottle for: $PACKAGE"
+        brew $VERB "$PACKAGE"
+    else
+        echo "Building bottle for: $PACKAGE"
+        brew $VERB --build-bottle "$PACKAGE"
+        exec 3>&1
+        local OUT=$(brew bottle --json "$PACKAGE" | tee /dev/fd/3)
+        exec 3>&-
+
+        ls "$PACKAGE"*
+        # doesn't seem to be a documented way to get file names
+        local BOTTLE; BOTTLE=$(grep -Ee '^./' <<<"$OUT")
+        #proper procedure as per https://discourse.brew.sh/t/how-are-bottle-and-postinstall-related-is-it-safe-to-run-bottle-after-postinstall/3410/4
+        brew uninstall "$PACKAGE"
+        brew install "$BOTTLE"
+        
+        local JSON; JSON=$(sed -E 's/bottle(.[[:digit:]]+)?\.tar\.gz$/bottle.json/' <<<"$BOTTLE")
+        
+        #`brew bottle --merge` doesn't return nonzero on nonexisting json file
+        test -f "$JSON" -a -f "$BOTTLE"
+        
+        brew bottle --merge --write "$JSON"
+        local CACHED_BOTTLE; CACHED_BOTTLE="$(brew --cache "$PACKAGE")"
+        mv "$BOTTLE" "$CACHED_BOTTLE";
+        local CACHED_JSON; CACHED_JSON="${BREW_LOCAL_BOTTLE_METADATA}/$(basename "$JSON")"
+        mv "$JSON" "$CACHED_JSON"
+        #Symlinks aren't cached by Travis. Will just save paths in files then.
+        local BOTTLE_LINK; BOTTLE_LINK="${CACHED_JSON}.bottle.lnk"
+        echo "$CACHED_BOTTLE" >"$BOTTLE_LINK"
+        
+    fi
+}
+
+
+
+
+function _brew_check_elapsed_build_time {
+    # If time limit has been reached,
+    # arrange for further build to be skipped and return 1
+
+    local TIME_START;TIME_START="${1:?}"
+    local TIME_LIMIT;TIME_LIMIT="${2:?}"
+    
+    local ELAPSED_TIME;ELAPSED_TIME=$(($(date +%s) - $TIME_START))
+    echo "Elapsed time: "$(($ELAPSED_TIME/60))"m (${ELAPSED_TIME}s)"
+    
+    if [[ "$ELAPSED_TIME" -gt $TIME_LIMIT ]]; then 
+        brew_go_bootstrap_mode
+        return 1
+    fi
+    return 0
+}
+
+function _brew_check_slow_building_ahead {
+
+    #If the package's projected build completion is higher than hard limit,
+    # skip it and arrange for further build to be skipped and return 1
+    
+    local PACKAGE="${1:?}"
+    local TIME_START="${2:?}"
+    local TIME_HARD_LIMIT="${3:?}"
+    
+    PROJECTED_BUILD_TIME=$(echo "$BREW_SLOW_BUILIDING_PACKAGES" | awk '$1=="'"$PACKAGE"'"{print $2}')
+    [ -z "$PROJECTED_BUILD_TIME" ] && return 0 || true
+    
+    local PROJECTED_BUILD_END_ELAPSED_TIME
+    PROJECTED_BUILD_END_ELAPSED_TIME=$(( $(date +%s) - TIME_START + PROJECTED_BUILD_TIME * 60))
+    
+    if [[ "$PROJECTED_BUILD_END_ELAPSED_TIME" -ge "$TIME_HARD_LIMIT" ]]; then
+        echo -e "\nProjected build end elapsed time for $PACKAGE: $((PROJECTED_BUILD_END_ELAPSED_TIME/60))m ($PROJECTED_BUILD_END_ELAPSED_TIMEs)"
+        brew_go_bootstrap_mode
+        return 1
+    fi
+    return 0
+}

From 200f0da0e24e51c79176d655bf4da25a4a736119 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Mon, 12 Nov 2018 10:29:47 +0300
Subject: [PATCH 090/566] cache ccache

---
 .travis.yml | 2 ++
 config.sh   | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index b281544f..fe9bf97f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,6 +33,8 @@ cache:
     - /usr/local/Homebrew/
     # used in OSX custom build script dealing with local bottle caching
     - $HOME/local_bottle_metadata
+    # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
+    - $HOME/.ccache
     
 matrix:
   fast_finish: true
diff --git a/config.sh b/config.sh
index 1534c1dc..88255c9d 100644
--- a/config.sh
+++ b/config.sh
@@ -56,6 +56,12 @@ function pre_build {
     # see https://docs.brew.sh/Manpage , "info formula" section
     export HOMEBREW_NO_GITHUB_API=1
 
+    # https://docs.travis-ci.com/user/caching/#ccache-cache
+    # No need to allow rc 1 -- if this triggers a timeout,
+    #  something is clearly wrong
+    brew_install_and_cache_within_time_limit ccache
+    export PATH="/usr/local/opt/ccache/libexec:$PATH"
+
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap -v cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin -v cartr/qt4

From cf601a1a3866fac52bde2381a7448663acc5a128 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Wed, 14 Nov 2018 01:56:15 +0300
Subject: [PATCH 091/566] take advantage of multiple CPUs

---
 config.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/config.sh b/config.sh
index 88255c9d..559b0a65 100644
--- a/config.sh
+++ b/config.sh
@@ -20,8 +20,10 @@ function bdist_wheel_cmd {
 
 if [ -n "$IS_OSX" ]; then
   echo "    > OSX environment "
+  export MAKEFLAGS="-j$(sysctl -n hw.ncpu)"
 else
   echo "    > Linux environment "
+  export MAKEFLAGS="-j$(grep -E '^processor[[:space:]]*:' /proc/cpuinfo | wc -l)"
 fi
 
 if [ -n "$IS_OSX" ]; then

From 01df5ed7f717230f1ad07370531783190ef17700 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Fri, 16 Nov 2018 05:47:37 +0300
Subject: [PATCH 092/566] more accurate cleaning of Homebrew dirs

---
 .travis.yml              | 27 ++++++++++++++++++---------
 travis_osx_brew_cache.sh |  2 ++
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index fe9bf97f..8c54615e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -524,6 +524,21 @@ before_install: |
     source multibuild_customize.sh
     echo $ENABLE_CONTRIB > contrib.enabled
     echo $ENABLE_HEADLESS > headless.enabled
+    
+    if [ -n "$IS_OSX" ]; then
+        TAPS="$(brew --repository)/Library/Taps"
+        if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
+            rm -rf "$TAPS/caskroom/homebrew-cask"
+        fi
+        find "$TAPS" -type d -name .git -exec \
+                bash -xec '
+                    cd $(dirname '\''{}'\'')
+                    git clean -fxd
+                    git status' \;
+                    
+        brew_cache_cleanup
+    fi
+    
     before_install
     # Not interested in travis internal scripts' output
     set +x
@@ -552,15 +567,9 @@ before_cache: |
     if [ -n "$IS_OSX" ]; then
 
         # When Taps is cached, this dir causes "Error: file exists" on `brew update`
-        rm -rf "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask"
-        find "$(brew --repository)/Library/Taps" -type d -name .git -exec \
-            bash -xec '
-                cd $(dirname '\''{}'\'')
-                git status
-                # https://stackoverflow.com/questions/8296710/how-to-ignore-xargs-commands-if-stdin-input-is-empty/19038748#19038748
-                git ls-files --other -z | xargs -0 -n100 git add
-                git commit -a -m "Travis auto changes"
-                [[ -n $(git stash list) ]] && git stash drop' \;
+        if [ -e "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask" ]; then
+            rm -rf "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask"
+        fi
 
         brew_cache_cleanup
         
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index c5f26190..2b4407ed 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -174,12 +174,14 @@ function brew_cache_cleanup {
     # so we're saving and restoring them
     local BOTTLE_LINK BOTTLE
     for BOTTLE_LINK in "$BREW_LOCAL_BOTTLE_METADATA"/*.lnk; do
+        [ -e "$BOTTLE_LINK" ] || break
         BOTTLE=$(cat "$BOTTLE_LINK")
         ln "$BOTTLE" "$BREW_LOCAL_BOTTLE_METADATA/"
     done
     brew cleanup
     local BOTTLE_BASENAME
     for BOTTLE_LINK in "$BREW_LOCAL_BOTTLE_METADATA"/*.lnk; do
+        [ -e "$BOTTLE_LINK" ] || break
         BOTTLE=$(cat "$BOTTLE_LINK")
         BOTTLE_BASENAME=$(basename "$BOTTLE")
         if test ! -e "$BOTTLE"; then

From c744b5af2e037f3c26a6a2c4d9fb9bc18cf1d4b9 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Tue, 20 Nov 2018 08:17:16 +0300
Subject: [PATCH 093/566] brew tap -v is no longer supported

---
 config.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/config.sh b/config.sh
index 559b0a65..c9bf656a 100644
--- a/config.sh
+++ b/config.sh
@@ -65,8 +65,8 @@ function pre_build {
     export PATH="/usr/local/opt/ccache/libexec:$PATH"
 
     echo 'Installing QT4'
-    brew tap | grep -qxF cartr/qt4 || brew tap -v cartr/qt4
-    brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin -v cartr/qt4
+    brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
+    brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
     brew_install_and_cache_within_time_limit qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
 
     echo 'Installing FFmpeg'

From d364ab36e7190bec5712c9f9b4dc55ddcf460c34 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Tue, 20 Nov 2018 09:57:59 +0300
Subject: [PATCH 094/566] harden the source

---
 travis_osx_brew_cache.sh | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 2b4407ed..47d37326 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -1,10 +1,12 @@
 # Library to cache downloaded and locally-built Homebrew bottles in Travis OSX build.
 
-trap '{ sleep 1;    #if we terminale too abruptly, Travis will lose some log output
+_BREW_ERREXIT='
+set -e -o pipefail
+trap '\''{ sleep 3;    #if we terminale too abruptly, Travis will lose some log output
         exit 2;     #The trap isn''t called in the parent function, so can''t use `return` here.
                     #`exit` will terminate the entire build but it seems we have no choice.
-}' ERR
-set -E
+}'\'' ERR
+set -E'
 
 #Should be in Travis' cache
 BREW_LOCAL_BOTTLE_METADATA="$HOME/local_bottle_metadata"
@@ -30,11 +32,12 @@ function brew_install_and_cache_within_time_limit {
     # use bottle if available, build and cache bottle if not.
     # Terminate and exit with status 1 if this takes too long.
     # Exit with status 2 on any other error.
+    ( eval "$_BREW_ERREXIT"
     
-    local PACKAGE; PACKAGE="${1:?}"
-    local TIME_LIMIT;TIME_LIMIT=${2:-$BREW_TIME_LIMIT}
-    local TIME_HARD_LIMIT;TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT}
-    local TIME_START;TIME_START=${4:-$BREW_TIME_START}
+    local PACKAGE; PACKAGE="${1:?}" || return 2
+    local TIME_LIMIT;TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || return 2
+    local TIME_HARD_LIMIT;TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || return 2
+    local TIME_START;TIME_START=${4:-$BREW_TIME_START} || return 2
 
     local BUILD_FROM_SOURCE INCLUDE_BUILD
     
@@ -42,7 +45,7 @@ function brew_install_and_cache_within_time_limit {
     [ -n "$BUILD_FROM_SOURCE" ] && INCLUDE_BUILD="--include-build" || true
 
     # Whitespace is illegal in package names so converting all whitespace into single spaces due to no quotes is okay.
-    DEPS=`brew deps "$PACKAGE" $INCLUDE_BUILD`
+    DEPS=`brew deps "$PACKAGE" $INCLUDE_BUILD` || return 2
     for dep in $DEPS; do
         #TIME_LIMIT only has to be met if we'll be actually building the main project this iteration, i.e. after the "root" module installation
         #While we don't know that yet, we can make better use of Travis-given time with a laxer limit
@@ -51,8 +54,10 @@ function brew_install_and_cache_within_time_limit {
     done
 
     _brew_check_slow_building_ahead "$PACKAGE" "$TIME_START" "$TIME_HARD_LIMIT" || return $?
-    _brew_install_and_cache "$PACKAGE" "$([[ -z "$INCLUDE_BUILD" ]] && echo 1 || echo 0)"
+    _brew_install_and_cache "$PACKAGE" "$([[ -z "$INCLUDE_BUILD" ]] && echo 1 || echo 0)" || return 2
     _brew_check_elapsed_build_time "$TIME_START" "$TIME_LIMIT" || return $?
+    ) \
+    || if test $? -eq 1; then brew_go_bootstrap_mode; return 1; else return 2; fi      #must run this in current process
 }
 
 function brew_add_local_bottles {
@@ -220,9 +225,8 @@ function brew_go_bootstrap_mode {
 #Internal functions
 
 function _brew_parse_bottle_json {
-    # Parse JSON info about a package
-    # from `brew info --json=v1` input or a JSON file on stdin
-    # and save it into bash global variables specified in arguments
+    # Parse JSON file resulting from `brew bottle --json`
+    # and save data into specified variables
 
     local JSON; JSON="${1:?}"; shift
 
@@ -247,7 +251,7 @@ function _brew_parse_bottle_json {
 
 function _brew_parse_package_info {
     # Get and parse `brew info --json` about a package
-    # and save it into bash variables specified in arguments
+    # and save data into specified variables
     
     local PACKAGE; PACKAGE="${1:?}"; shift
     local OS_CODENAME;OS_CODENAME="${1:?}"; shift
@@ -255,12 +259,14 @@ function _brew_parse_package_info {
     local JSON_DATA; JSON_DATA=$(python2.7 -c 'if True:
     import sys, json, subprocess; j=json.loads(subprocess.check_output(("brew","info","--json=v1",sys.argv[1])))
     data=j[0]
-    print data["versions"]["stable"]
+    revision=data["revision"]
+    # in bottle''s json, revision is included into version; here, they are separate
+    print data["versions"]["stable"]+("_"+str(revision) if revision else "")
     bottle_data=data["bottle"]["stable"]
     print bottle_data["rebuild"]
-    print bottle_data["files"].get(sys.argv[2],{"sha256":""})["sha256"]
+    print bottle_data["files"].get(sys.argv[2],{"sha256":"!?"})["sha256"]     #prevent losing trailing blank line to command substitution
     ' \
-    "$PACKAGE" "$OS_CODENAME")
+    "$PACKAGE" "$OS_CODENAME"); JSON_DATA="${JSON_DATA%\!\?}"  #!? can't occur in a hash
     
     unset PACKAGE OS_CODENAME
     

From c416449fc46eb5a66bd115265d8ee6392ebd4fad Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 17 Nov 2018 01:31:28 +0300
Subject: [PATCH 095/566] use patched ffmpeg

---
 config.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/config.sh b/config.sh
index c9bf656a..53c5ff2f 100644
--- a/config.sh
+++ b/config.sh
@@ -33,13 +33,55 @@ if [ -n "$IS_OSX" ]; then
     BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
         "x265 20"  \
         "cmake 15" \
-        "ffmpeg 10" \
+        "ffmpeg_opencv 10" \
     )
     
     #Contrib adds significantly to project's build time
     if [ "$ENABLE_CONTRIB" -eq 1 ]; then
         BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
     fi
+    
+    function generate_ffmpeg_formula {
+        local FF="ffmpeg"
+        local LFF="ffmpeg_opencv"
+        local FF_FORMULA; FF_FORMULA=$(brew formula "$FF")
+        local LFF_FORMULA; LFF_FORMULA="$(dirname "$FF_FORMULA")/${LFF}.rb"
+        
+        local REGENERATE
+        if [ -f "$LFF_FORMULA" ]; then
+            local UPSTREAM_VERSION VERSION
+            _brew_parse_package_info "$FF" " " UPSTREAM_VERSION _ _
+            _brew_parse_package_info "$LFF" " " VERSION _ _   || REGENERATE=1
+            #`rebuild` clause is ignored on `brew bottle` and deleted
+            # from newly-generated formula on `brew bottle --merge` for some reason
+            # so can't compare rebuild numbers
+            if [ "$UPSTREAM_VERSION" != "$VERSION" ]; then
+                REGENERATE=1
+            fi
+        else
+            REGENERATE=1
+        fi
+        if [ -n "$REGENERATE" ]; then
+            echo "Regenerating custom ffmpeg formula"
+            # Bottle block syntax: https://docs.brew.sh/Bottles#bottle-dsl-domain-specific-language
+            perl -wpe 'BEGIN {our ($found_blank, $bottle_block);}
+                if (/(^class )(Ffmpeg)(\s.*)/) {$_=$1.$2."Opencv".$3."\n"; next;}
+                if (!$found_blank && /^$/) {$_.="conflicts_with \"ffmpeg\"\n\n"; $found_blank=1; next;}
+                if (!$bottle_block && /^\s*bottle do$/) { $bottle_block=1; next; }
+                if ($bottle_block) { if (/^\s*end\s*$/) { $bottle_block=0} elsif (/^\s*sha256\s/) {$_=""} next; }
+if (/^\s*depends_on "(x264|x265|xvid)"$/) {$_=""; next;}
+                if (/^\s*--enable-(gpl|libx264|libx265|libxvid)$/) {$_=""; next;}
+                ' <"$FF_FORMULA" >"$LFF_FORMULA"
+            diff -u "$FF_FORMULA" "$LFF_FORMULA" || test $? -le 1
+
+            (   cd "$(dirname "$LFF_FORMULA")"
+                # This is the official way to add a formula
+                # https://docs.brew.sh/Formula-Cookbook#commit
+                git add "$(basename "$LFF_FORMULA")"
+                git commit -m "add/update custom ffmpeg ${VERSION}"
+            )
+        fi
+    }
         
 fi
 
@@ -71,7 +113,8 @@ function pre_build {
 
     echo 'Installing FFmpeg'
 
-    brew_install_and_cache_within_time_limit ffmpeg || { [ $? -gt 1 ] && return 2 || return 0; }
+    generate_ffmpeg_formula
+    brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
 
   else
     echo "Running for linux"

From 16e4cd1fcb53383b9cc43c8c3d312aca7c1536bf Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Wed, 21 Nov 2018 02:23:05 +0300
Subject: [PATCH 096/566] Eliminate entry duplication and tilde in PATH [skip
 ci]

---
 docker/Dockerfile_i686   | 2 +-
 docker/Dockerfile_x86_64 | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
index c39331d0..c297e0e9 100644
--- a/docker/Dockerfile_i686
+++ b/docker/Dockerfile_i686
@@ -84,4 +84,4 @@ RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
 	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
 
-ENV PATH "$PATH=~/bin:$PATH"
\ No newline at end of file
+ENV PATH "$HOME/bin:$PATH"
\ No newline at end of file
diff --git a/docker/Dockerfile_x86_64 b/docker/Dockerfile_x86_64
index b855a73b..e9de76e8 100644
--- a/docker/Dockerfile_x86_64
+++ b/docker/Dockerfile_x86_64
@@ -84,4 +84,4 @@ RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
 	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
 
-ENV PATH "$PATH=~/bin:$PATH"
\ No newline at end of file
+ENV PATH "$HOME/bin:$PATH"
\ No newline at end of file

From 4e59499843251e0ed1ef17acd81360502006647a Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 17 Nov 2018 01:31:28 +0300
Subject: [PATCH 097/566] use patched ffmpeg

---
 config.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/config.sh b/config.sh
index c9bf656a..53c5ff2f 100644
--- a/config.sh
+++ b/config.sh
@@ -33,13 +33,55 @@ if [ -n "$IS_OSX" ]; then
     BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
         "x265 20"  \
         "cmake 15" \
-        "ffmpeg 10" \
+        "ffmpeg_opencv 10" \
     )
     
     #Contrib adds significantly to project's build time
     if [ "$ENABLE_CONTRIB" -eq 1 ]; then
         BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
     fi
+    
+    function generate_ffmpeg_formula {
+        local FF="ffmpeg"
+        local LFF="ffmpeg_opencv"
+        local FF_FORMULA; FF_FORMULA=$(brew formula "$FF")
+        local LFF_FORMULA; LFF_FORMULA="$(dirname "$FF_FORMULA")/${LFF}.rb"
+        
+        local REGENERATE
+        if [ -f "$LFF_FORMULA" ]; then
+            local UPSTREAM_VERSION VERSION
+            _brew_parse_package_info "$FF" " " UPSTREAM_VERSION _ _
+            _brew_parse_package_info "$LFF" " " VERSION _ _   || REGENERATE=1
+            #`rebuild` clause is ignored on `brew bottle` and deleted
+            # from newly-generated formula on `brew bottle --merge` for some reason
+            # so can't compare rebuild numbers
+            if [ "$UPSTREAM_VERSION" != "$VERSION" ]; then
+                REGENERATE=1
+            fi
+        else
+            REGENERATE=1
+        fi
+        if [ -n "$REGENERATE" ]; then
+            echo "Regenerating custom ffmpeg formula"
+            # Bottle block syntax: https://docs.brew.sh/Bottles#bottle-dsl-domain-specific-language
+            perl -wpe 'BEGIN {our ($found_blank, $bottle_block);}
+                if (/(^class )(Ffmpeg)(\s.*)/) {$_=$1.$2."Opencv".$3."\n"; next;}
+                if (!$found_blank && /^$/) {$_.="conflicts_with \"ffmpeg\"\n\n"; $found_blank=1; next;}
+                if (!$bottle_block && /^\s*bottle do$/) { $bottle_block=1; next; }
+                if ($bottle_block) { if (/^\s*end\s*$/) { $bottle_block=0} elsif (/^\s*sha256\s/) {$_=""} next; }
+if (/^\s*depends_on "(x264|x265|xvid)"$/) {$_=""; next;}
+                if (/^\s*--enable-(gpl|libx264|libx265|libxvid)$/) {$_=""; next;}
+                ' <"$FF_FORMULA" >"$LFF_FORMULA"
+            diff -u "$FF_FORMULA" "$LFF_FORMULA" || test $? -le 1
+
+            (   cd "$(dirname "$LFF_FORMULA")"
+                # This is the official way to add a formula
+                # https://docs.brew.sh/Formula-Cookbook#commit
+                git add "$(basename "$LFF_FORMULA")"
+                git commit -m "add/update custom ffmpeg ${VERSION}"
+            )
+        fi
+    }
         
 fi
 
@@ -71,7 +113,8 @@ function pre_build {
 
     echo 'Installing FFmpeg'
 
-    brew_install_and_cache_within_time_limit ffmpeg || { [ $? -gt 1 ] && return 2 || return 0; }
+    generate_ffmpeg_formula
+    brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
 
   else
     echo "Running for linux"

From 313e09d2c9f5bd9bcbf7a5143e4246a646023694 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Tue, 20 Nov 2018 11:28:29 +0300
Subject: [PATCH 098/566] use ccache in Linux

fix: cache
---
 .travis.yml | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index 8c54615e..c231aab2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -218,18 +218,24 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
@@ -237,34 +243,46 @@ matrix:
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.11.3
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
@@ -272,12 +290,16 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.11.3
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.7
@@ -285,6 +307,8 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
+      cache:
+        directories: $HOME/.ccache
 
     # headless builds for Linux
     - os: linux
@@ -292,18 +316,24 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
@@ -311,34 +341,46 @@ matrix:
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.11.3
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
@@ -346,12 +388,16 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.11.3
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.7
@@ -359,6 +405,8 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
+      cache:
+        directories: $HOME/.ccache
 
     # contrib builds for Linux
     - os: linux
@@ -366,18 +414,24 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - PLAT=i686
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
@@ -385,34 +439,46 @@ matrix:
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
         - PLAT=i686
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
@@ -420,12 +486,16 @@ matrix:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.7
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.7
@@ -433,6 +503,8 @@ matrix:
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
 
 
     # headless contrib builds for Linux
@@ -441,18 +513,24 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
         - PLAT=i686
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=2.7
@@ -460,34 +538,46 @@ matrix:
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.4
         - PLAT=i686
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.6
@@ -495,12 +585,16 @@ matrix:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.7
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.7
@@ -508,6 +602,8 @@ matrix:
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
 
 # The first line is printed in the folding header in Travis output
 before_install: |

From a27f9d565f56231663d95f64b55f2ad0519e51b1 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Tue, 20 Nov 2018 11:31:08 +0300
Subject: [PATCH 099/566] use multibuild facilities for ccache

---
 .travis.yml | 2 +-
 config.sh   | 6 ------
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index c231aab2..d23b7c3c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,7 +5,7 @@ env:
         - TEST_DEPENDS="numpy==1.11.1"
         # params to bdist_wheel. used to set osx build target.
         - BDIST_PARAMS=""
-
+        - USE_CCACHE=1
         - PLAT=x86_64
         - UNICODE_WIDTH=32
         - secure: "mU040XIYWtDjRms27deQy5fNg9HBFF9fiLfSteBaMjopZKXFUBsdMTKYGEVvX8DA879guMdjG8Prw1aCFhTTYlWgJ0Afm4YucRC0vAD4HLNhqLJ2lIpRceR3+2qPX+Oz5ATVVRi3ghBeJ20LLtNgOgf6esQVjdrYNC+YqmguClHKEYAxS7ngW42iQP8HX2anRcz9q9H7exZ9fX/D1PJfMNka/mNaB5KXZu5zdLuk/E0VbWU2tMWVIDUvx4uBlpE1d8HixEV5LHnuVE/QI36BcyucYxstTNKW6pGYgrhkYf+0PX4BphZXwY7EUBwzXsYLmyge6yH8W6NfvTW0ZasFF6xzQc9bsj+gAZN7H+hN2a42VQqIpkoJw9sU0hqzCOQf6ZvWUQgwFdAHJRHqe/zk4456WxnF0kAgbZdKaGOl0/n0WvgHNqD5bgO8Zzb1XyJTKoR+eAtYKXuz3KgpxKvZMMQVr8wMlI1cFEuGjIm+7ZrYB5jPvQrVzV/DgOq4gkPHOjjhu478UFlhGA9/XWwcyidC3b7zuBN2E7xVuTMlKdk7URB3AHXfG5bZgUG80vllQDGXQDpHVnv4Qi8bGCzI4iKTpp4fCibbqxFLxW1jhjmgePseGcie7Avpe+zXznkbmM2BqMCu3QRmtmFL3eCifwMf3rCNlAs0Sd3iLmEvyos="
diff --git a/config.sh b/config.sh
index 53c5ff2f..3bdacd2f 100644
--- a/config.sh
+++ b/config.sh
@@ -100,12 +100,6 @@ function pre_build {
     # see https://docs.brew.sh/Manpage , "info formula" section
     export HOMEBREW_NO_GITHUB_API=1
 
-    # https://docs.travis-ci.com/user/caching/#ccache-cache
-    # No need to allow rc 1 -- if this triggers a timeout,
-    #  something is clearly wrong
-    brew_install_and_cache_within_time_limit ccache
-    export PATH="/usr/local/opt/ccache/libexec:$PATH"
-
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4

From 23f0ec06f5b728776ff42ad9311a6406c0e33803 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Tue, 20 Nov 2018 12:06:20 +0300
Subject: [PATCH 100/566] show ccache stats

---
 .travis.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.travis.yml b/.travis.yml
index d23b7c3c..b4d114b1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -643,6 +643,7 @@ install: |
     # Build and package
     set -x
     build_wheel $REPO_DIR $PLAT
+    if [ -n "$USE_CCACHE" ]; then ccache --show-stats; fi
     set +x
 
 script: |

From 8aaff83a74175efbd697c287035350295d6e5b92 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Wed, 21 Nov 2018 03:38:22 +0300
Subject: [PATCH 101/566] fix "Not using downloaded repomd.xml because it is
 older than what we have"

---
 env_vars.sh | 5 +++++
 1 file changed, 5 insertions(+)
 create mode 100644 env_vars.sh

diff --git a/env_vars.sh b/env_vars.sh
new file mode 100644
index 00000000..d67c3523
--- /dev/null
+++ b/env_vars.sh
@@ -0,0 +1,5 @@
+if [ -n "$IS_OSX" ]; then
+    :
+else
+    yum clean metadata
+fi
\ No newline at end of file

From 45f0d791e0fab315aa98293f22a10512d52b4b2e Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: Sun, 25 Nov 2018 07:31:49 +0300
Subject: [PATCH 102/566] Clear yum metadata in x32 docker

Fixes ccache not found in yum
[skip ci]
---
 docker/Dockerfile_i686 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
index c297e0e9..62366543 100644
--- a/docker/Dockerfile_i686
+++ b/docker/Dockerfile_i686
@@ -84,4 +84,6 @@ RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
 	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
 
-ENV PATH "$HOME/bin:$PATH"
\ No newline at end of file
+RUN yum clean all
+
+ENV PATH "$HOME/bin:$PATH"

From 53ad6c435cdb8469f1fa410d42b11cd9758d7fd1 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 25 Nov 2018 13:04:33 +0200
Subject: [PATCH 103/566] Revert "fix "Not using downloaded repomd.xml because
 it is older than what we have"" See:
 https://github.com/skvark/opencv-python/pull/150

This reverts commit 8aaff83a74175efbd697c287035350295d6e5b92.
---
 env_vars.sh | 5 -----
 1 file changed, 5 deletions(-)
 delete mode 100644 env_vars.sh

diff --git a/env_vars.sh b/env_vars.sh
deleted file mode 100644
index d67c3523..00000000
--- a/env_vars.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-if [ -n "$IS_OSX" ]; then
-    :
-else
-    yum clean metadata
-fi
\ No newline at end of file

From 513656469489941bee4840ef95a64300822fc385 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 26 Nov 2018 17:37:33 +0200
Subject: [PATCH 104/566] bump OpenCV version to 3.4.4

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index b38c50b3..a1fe8f75 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit b38c50b3d0c31e82294315ec44b54b7ef559ef12
+Subproject commit a1fe8f754fbfe20c20d4ca4e6972d453e5eea925
diff --git a/opencv_contrib b/opencv_contrib
index 1f6d6f06..f0ecc092 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 1f6d6f06266e1ef336437ae5404bee1c65d42cda
+Subproject commit f0ecc092ce2a55956578b6088f6b9b2fe8c19847

From 2df4d3ace7569c94c002bb09dd1a5a3e441419a4 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 27 Nov 2018 17:17:06 +0200
Subject: [PATCH 105/566] update variable value

---
 appveyor.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/appveyor.yml b/appveyor.yml
index 53a3938e..a7a3eb17 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -3,7 +3,7 @@ environment:
     secure: fXgF9uyy6sT0JoVOR7BoqA==
 
   PASS:
-    secure: HHNjmjxQSvgSY9Zde0qh6A==
+    secure: 0bXSOVjf9x8L7nErTivu92TF1FwNosTjFJQPmxp8Dys=
 
   matrix:
     - PYTHON: "C:/Python27"

From 01b702e508f6e98b543dce25861894caa6f83868 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 13 Dec 2018 20:01:20 +0200
Subject: [PATCH 106/566] bump opencv version

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index a1fe8f75..75ed282b 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit a1fe8f754fbfe20c20d4ca4e6972d453e5eea925
+Subproject commit 75ed282b20770a7a9b490102fd2e0b4fa26223e5
diff --git a/opencv_contrib b/opencv_contrib
index f0ecc092..d511587c 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit f0ecc092ce2a55956578b6088f6b9b2fe8c19847
+Subproject commit d511587cf0bc782022db215d20d960afb2e9efe2

From 6d654f95bf27f99e29acc8c2b5bf6a4601262c43 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 20 Dec 2018 17:47:39 +0200
Subject: [PATCH 107/566] force old install behaviour

---
 setup.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index bc405e00..43d8db60 100644
--- a/setup.py
+++ b/setup.py
@@ -123,6 +123,7 @@ def main():
         cmake_args.append("-DWITH_QT=OFF")
 
     if sys.platform.startswith('linux'):
+        cmake_args.append("-DOPENCV_SKIP_PYTHON_LOADER=ON")
         cmake_args.append("-DWITH_V4L=ON")
         cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 

From 1f2328a075f96ec3e97812287a8c41e2920f8712 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 20 Dec 2018 22:42:43 +0200
Subject: [PATCH 108/566] fix haarcascades path

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 43d8db60..145137f1 100644
--- a/setup.py
+++ b/setup.py
@@ -83,7 +83,7 @@ def main():
         ['python/([^/]+/){1,2}cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
 
         'cv2.data': [  # OPENCV_OTHER_INSTALL_PATH
-            ('etc' if os.name == 'nt' else 'share/OpenCV') +
+            ('etc' if os.name == 'nt' else 'share/opencv4/') +
             r'/haarcascades/.*\.xml'
         ]
     }

From 766c9923a08283fab521844472f4eaff8de52345 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Fri, 21 Dec 2018 13:31:12 +0200
Subject: [PATCH 109/566] Remove trailing slash

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 145137f1..bc11430d 100644
--- a/setup.py
+++ b/setup.py
@@ -83,7 +83,7 @@ def main():
         ['python/([^/]+/){1,2}cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
 
         'cv2.data': [  # OPENCV_OTHER_INSTALL_PATH
-            ('etc' if os.name == 'nt' else 'share/opencv4/') +
+            ('etc' if os.name == 'nt' else 'share/opencv4') +
             r'/haarcascades/.*\.xml'
         ]
     }

From 9438f5a8fc11d651268946cd1990b24edb081b9f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 27 Dec 2018 17:14:46 +0200
Subject: [PATCH 110/566] test 3.4.5 release

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 75ed282b..8f1356c3 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 75ed282b20770a7a9b490102fd2e0b4fa26223e5
+Subproject commit 8f1356c3c5b16721349582db461a2051653059e8
diff --git a/opencv_contrib b/opencv_contrib
index d511587c..7292df62 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit d511587cf0bc782022db215d20d960afb2e9efe2
+Subproject commit 7292df62624ded8af8035231435dfd17c93e1a80

From 99aa2f9437b5c9a3d13144bae75cc5583aefb794 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 27 Dec 2018 17:32:52 +0200
Subject: [PATCH 111/566] move flag

---
 setup.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index bc11430d..7c09c139 100644
--- a/setup.py
+++ b/setup.py
@@ -110,7 +110,8 @@ def main():
         "-DBUILD_SHARED_LIBS=OFF",
         "-DBUILD_TESTS=OFF",
         "-DBUILD_PERF_TESTS=OFF",
-        "-DBUILD_DOCS=OFF"
+        "-DBUILD_DOCS=OFF",
+        "-DOPENCV_SKIP_PYTHON_LOADER=ON"
     ] + (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
 
     # OS-specific components
@@ -123,7 +124,6 @@ def main():
         cmake_args.append("-DWITH_QT=OFF")
 
     if sys.platform.startswith('linux'):
-        cmake_args.append("-DOPENCV_SKIP_PYTHON_LOADER=ON")
         cmake_args.append("-DWITH_V4L=ON")
         cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 

From 182ebb54d773fd3eb30af623d2e4e38c1646f894 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 27 Dec 2018 17:59:05 +0200
Subject: [PATCH 112/566] update setuptools

---
 appveyor.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/appveyor.yml b/appveyor.yml
index a7a3eb17..19645421 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -172,6 +172,7 @@ matrix:
 build_script:
 - cmd: |
     "%PYTHON%/python.exe" -m pip install --upgrade pip
+    "%PYTHON%/python.exe" -m pip install --upgrade setuptools
     "%PYTHON%/python.exe" setup.py bdist_wheel
 
 before_test:

From 5111fa415f7039bceeb5ed8d6c9ff20250066cdb Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 27 Dec 2018 18:16:38 +0200
Subject: [PATCH 113/566] reset to old behaviour

---
 setup.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/setup.py b/setup.py
index 7c09c139..43d8db60 100644
--- a/setup.py
+++ b/setup.py
@@ -83,7 +83,7 @@ def main():
         ['python/([^/]+/){1,2}cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
 
         'cv2.data': [  # OPENCV_OTHER_INSTALL_PATH
-            ('etc' if os.name == 'nt' else 'share/opencv4') +
+            ('etc' if os.name == 'nt' else 'share/OpenCV') +
             r'/haarcascades/.*\.xml'
         ]
     }
@@ -110,8 +110,7 @@ def main():
         "-DBUILD_SHARED_LIBS=OFF",
         "-DBUILD_TESTS=OFF",
         "-DBUILD_PERF_TESTS=OFF",
-        "-DBUILD_DOCS=OFF",
-        "-DOPENCV_SKIP_PYTHON_LOADER=ON"
+        "-DBUILD_DOCS=OFF"
     ] + (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
 
     # OS-specific components
@@ -124,6 +123,7 @@ def main():
         cmake_args.append("-DWITH_QT=OFF")
 
     if sys.platform.startswith('linux'):
+        cmake_args.append("-DOPENCV_SKIP_PYTHON_LOADER=ON")
         cmake_args.append("-DWITH_V4L=ON")
         cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 

From 6b6b8fe05de85d53420cab66c29036b82ee25d83 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 27 Dec 2018 18:39:55 +0200
Subject: [PATCH 114/566] move flag again

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 43d8db60..2b013018 100644
--- a/setup.py
+++ b/setup.py
@@ -105,6 +105,7 @@ def main():
         # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
         # and skbuild bails out on seeing that
         "-DINSTALL_CREATE_DISTRIB=ON",
+        "-DOPENCV_SKIP_PYTHON_LOADER=ON",
         # See opencv/CMakeLists.txt for options and defaults
         "-DBUILD_opencv_apps=OFF",
         "-DBUILD_SHARED_LIBS=OFF",
@@ -123,7 +124,6 @@ def main():
         cmake_args.append("-DWITH_QT=OFF")
 
     if sys.platform.startswith('linux'):
-        cmake_args.append("-DOPENCV_SKIP_PYTHON_LOADER=ON")
         cmake_args.append("-DWITH_V4L=ON")
         cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 

From abcd9442bb1a0921120640fc19a2bafb56d72068 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 27 Dec 2018 19:59:21 +0200
Subject: [PATCH 115/566] set python install path to mimic 3.4.4 behaviour

---
 setup.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 2b013018..a57fe805 100644
--- a/setup.py
+++ b/setup.py
@@ -102,10 +102,11 @@ def main():
         # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
         "-DPYTHON%d_EXECUTABLE=%s" % (sys.version_info[0], sys.executable),
         "-DBUILD_opencv_python%d=ON" % sys.version_info[0],
+        "-DOPENCV_SKIP_PYTHON_LOADER=ON",
+        "-DOPENCV_PYTHON_INSTALL_PATH=python",
         # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
         # and skbuild bails out on seeing that
         "-DINSTALL_CREATE_DISTRIB=ON",
-        "-DOPENCV_SKIP_PYTHON_LOADER=ON",
         # See opencv/CMakeLists.txt for options and defaults
         "-DBUILD_opencv_apps=OFF",
         "-DBUILD_SHARED_LIBS=OFF",

From 441e52c1a7efadac26a5bcbcfcbaa33d07eb530e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 27 Dec 2018 20:23:38 +0200
Subject: [PATCH 116/566] fix the param name

---
 setup.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index a57fe805..0e0bbbf1 100644
--- a/setup.py
+++ b/setup.py
@@ -103,7 +103,8 @@ def main():
         "-DPYTHON%d_EXECUTABLE=%s" % (sys.version_info[0], sys.executable),
         "-DBUILD_opencv_python%d=ON" % sys.version_info[0],
         "-DOPENCV_SKIP_PYTHON_LOADER=ON",
-        "-DOPENCV_PYTHON_INSTALL_PATH=python",
+        "-DOPENCV_PYTHON2_INSTALL_PATH=python",
+        "-DOPENCV_PYTHON3_INSTALL_PATH=python",
         # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
         # and skbuild bails out on seeing that
         "-DINSTALL_CREATE_DISTRIB=ON",

From 29f0466187b20982eaadfc5d834bae672c98200f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 27 Dec 2018 20:55:58 +0200
Subject: [PATCH 117/566] simplify regex

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 0e0bbbf1..423a0ef2 100644
--- a/setup.py
+++ b/setup.py
@@ -80,7 +80,7 @@ def main():
         # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
         # Naming conventions vary so widely between versions and OSes
         # had to give up on checking them.
-        ['python/([^/]+/){1,2}cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
+        ['python/cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
 
         'cv2.data': [  # OPENCV_OTHER_INSTALL_PATH
             ('etc' if os.name == 'nt' else 'share/OpenCV') +

From 11e30d505fd83f4a9be0058772a3f2f33b1e32a9 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 7 Jan 2019 21:32:53 +0200
Subject: [PATCH 118/566] try 4.0.1 release

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 8f1356c3..c9ad5779 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 8f1356c3c5b16721349582db461a2051653059e8
+Subproject commit c9ad5779f2803dcc91a9938142209128d30b22d1
diff --git a/opencv_contrib b/opencv_contrib
index 7292df62..25221244 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 7292df62624ded8af8035231435dfd17c93e1a80
+Subproject commit 25221244732dcf44c1450d0f93edc2529a61c0e1

From 6851d5695815bb6cef3c41b8435ce1b77fa1640e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 8 Jan 2019 17:35:53 +0200
Subject: [PATCH 119/566] back to 4.0.0, fix haarcascades path

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 setup.py       | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/opencv b/opencv
index c9ad5779..75ed282b 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit c9ad5779f2803dcc91a9938142209128d30b22d1
+Subproject commit 75ed282b20770a7a9b490102fd2e0b4fa26223e5
diff --git a/opencv_contrib b/opencv_contrib
index 25221244..d511587c 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 25221244732dcf44c1450d0f93edc2529a61c0e1
+Subproject commit d511587cf0bc782022db215d20d960afb2e9efe2
diff --git a/setup.py b/setup.py
index 423a0ef2..669305c7 100644
--- a/setup.py
+++ b/setup.py
@@ -83,7 +83,7 @@ def main():
         ['python/cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
 
         'cv2.data': [  # OPENCV_OTHER_INSTALL_PATH
-            ('etc' if os.name == 'nt' else 'share/OpenCV') +
+            ('etc' if os.name == 'nt' else 'share/opencv4') +
             r'/haarcascades/.*\.xml'
         ]
     }

From b05f919964f9c09cb43dd8933f732b603894189b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 8 Jan 2019 19:12:16 +0200
Subject: [PATCH 120/566] try to disable __STRICT_ANSI__ on 32-bit linux

---
 setup.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/setup.py b/setup.py
index 669305c7..68bede4f 100644
--- a/setup.py
+++ b/setup.py
@@ -146,6 +146,8 @@ def main():
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with
                                               # devtoolset-2 GCC 4.8.2 or vanilla GCC 4.9.4
                                               # see https://github.com/skvark/opencv-python/issues/138
+    if sys.platform.startswith('linux') and not x64:
+        cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
 
     # ABI config variables are introduced in PEP 425
     if sys.version_info[:2] < (3, 2):

From d11efd4eccbe9163c3100d60ab3474d85145d801 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 25 Jan 2019 19:21:28 +0200
Subject: [PATCH 121/566] bump OpenCV version to 4.0.1

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 75ed282b..c9ad5779 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 75ed282b20770a7a9b490102fd2e0b4fa26223e5
+Subproject commit c9ad5779f2803dcc91a9938142209128d30b22d1
diff --git a/opencv_contrib b/opencv_contrib
index d511587c..25221244 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit d511587cf0bc782022db215d20d960afb2e9efe2
+Subproject commit 25221244732dcf44c1450d0f93edc2529a61c0e1

From 5e193e36bd52e9f488e87bc8eabf03e68f4eb512 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 25 Jan 2019 20:17:50 +0200
Subject: [PATCH 122/566] ignore py2.7 deprecation warning

---
 appveyor.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/appveyor.yml b/appveyor.yml
index 19645421..3e755db9 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -179,6 +179,7 @@ before_test:
 - ps: |
 
     cd ${Env:APPVEYOR_BUILD_FOLDER}\tests
+    $env:PYTHONWARNINGS = "ignore:::pip._internal.cli.base_command"
     &"${Env:PYTHON}/python.exe" -m pip install --user (ls "../dist/opencv_*.whl")
     if ($LastExitCode -ne 0) {throw $LastExitCode}
 

From 5288ba5fa2603975d1ee36544b11c2a45b7adc1e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 26 Jan 2019 13:28:17 +0200
Subject: [PATCH 123/566] update travis xcode 8 to 8.3

---
 .travis.yml | 54 ++++++++++++++++++++++++++---------------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index a6fb537d..7e775d04 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,7 +33,7 @@ cache:
     - $HOME/local_bottle_metadata
     # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
     - $HOME/.ccache
-    
+
 matrix:
   fast_finish: true
   include:
@@ -41,7 +41,7 @@ matrix:
     # default builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
@@ -49,7 +49,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
@@ -57,7 +57,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -65,7 +65,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -73,7 +73,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -84,7 +84,7 @@ matrix:
     # headless builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
@@ -92,7 +92,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
@@ -100,7 +100,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -108,7 +108,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -116,7 +116,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -127,7 +127,7 @@ matrix:
     # Contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
@@ -135,7 +135,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
@@ -143,7 +143,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -151,7 +151,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
@@ -159,7 +159,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -170,7 +170,7 @@ matrix:
     # headless contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
@@ -178,7 +178,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
@@ -186,7 +186,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -194,7 +194,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
@@ -202,7 +202,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -618,7 +618,7 @@ before_install: |
     source multibuild_customize.sh
     echo $ENABLE_CONTRIB > contrib.enabled
     echo $ENABLE_HEADLESS > headless.enabled
-    
+
     if [ -n "$IS_OSX" ]; then
         TAPS="$(brew --repository)/Library/Taps"
         if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
@@ -629,10 +629,10 @@ before_install: |
                     cd $(dirname '\''{}'\'')
                     git clean -fxd
                     git status' \;
-                    
+
         brew_cache_cleanup
     fi
-    
+
     before_install
     # Not interested in travis internal scripts' output
     set +x
@@ -653,7 +653,7 @@ script: |
     #otherwise, Travis logic terminates prematurely
     #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
     trap ERR
-    
+
     test "$rc" -eq 0
 
 before_cache: |
@@ -667,10 +667,10 @@ before_cache: |
         fi
 
         brew_cache_cleanup
-        
+
     fi
     set +x
-    
+
 after_success: |
     # Upload wheels to pypi if requested
     if [ -n "$TRAVIS_TAG" ]; then

From c3e703f9ccb91ba209f8fefbd1f0f77c7d985f89 Mon Sep 17 00:00:00 2001
From: Christian Vallentin <vallentinsource@gmail.com>
Date: Thu, 31 Jan 2019 15:33:41 +0100
Subject: [PATCH 124/566] Fixed typo

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 0264fa43..32e5687b 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
 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. 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 enviroment. 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.
+    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 with ``pip uninstall`` and reinstall only one package.
 
     **a.** Packages for standard desktop environments (Windows, macOS, almost any GNU/Linux distribution)
 

From 7e756bfabcfdfa669fc39502cc535d6afd789dca Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 17 Feb 2019 21:51:31 +0200
Subject: [PATCH 125/566] Revert "update travis xcode 8 to 8.3"

This reverts commit 5288ba5fa2603975d1ee36544b11c2a45b7adc1e.
---
 .travis.yml | 54 ++++++++++++++++++++++++++---------------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 7e775d04..a6fb537d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,7 +33,7 @@ cache:
     - $HOME/local_bottle_metadata
     # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
     - $HOME/.ccache
-
+    
 matrix:
   fast_finish: true
   include:
@@ -41,7 +41,7 @@ matrix:
     # default builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
@@ -49,7 +49,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
@@ -57,7 +57,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -65,7 +65,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -73,7 +73,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -84,7 +84,7 @@ matrix:
     # headless builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
@@ -92,7 +92,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
@@ -100,7 +100,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -108,7 +108,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -116,7 +116,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -127,7 +127,7 @@ matrix:
     # Contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
@@ -135,7 +135,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
@@ -143,7 +143,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -151,7 +151,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
@@ -159,7 +159,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -170,7 +170,7 @@ matrix:
     # headless contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
@@ -178,7 +178,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
@@ -186,7 +186,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -194,7 +194,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
@@ -202,7 +202,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -618,7 +618,7 @@ before_install: |
     source multibuild_customize.sh
     echo $ENABLE_CONTRIB > contrib.enabled
     echo $ENABLE_HEADLESS > headless.enabled
-
+    
     if [ -n "$IS_OSX" ]; then
         TAPS="$(brew --repository)/Library/Taps"
         if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
@@ -629,10 +629,10 @@ before_install: |
                     cd $(dirname '\''{}'\'')
                     git clean -fxd
                     git status' \;
-
+                    
         brew_cache_cleanup
     fi
-
+    
     before_install
     # Not interested in travis internal scripts' output
     set +x
@@ -653,7 +653,7 @@ script: |
     #otherwise, Travis logic terminates prematurely
     #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
     trap ERR
-
+    
     test "$rc" -eq 0
 
 before_cache: |
@@ -667,10 +667,10 @@ before_cache: |
         fi
 
         brew_cache_cleanup
-
+        
     fi
     set +x
-
+    
 after_success: |
     # Upload wheels to pypi if requested
     if [ -n "$TRAVIS_TAG" ]; then

From 0e788e25f4a205832dac6c09dccc9180acd29b73 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 17 Feb 2019 22:16:54 +0200
Subject: [PATCH 126/566] remove --merge

---
 config.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/config.sh b/config.sh
index 3bdacd2f..94eaf051 100644
--- a/config.sh
+++ b/config.sh
@@ -29,24 +29,24 @@ fi
 if [ -n "$IS_OSX" ]; then
 
     source travis_osx_brew_cache.sh
-    
+
     BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
         "x265 20"  \
         "cmake 15" \
         "ffmpeg_opencv 10" \
     )
-    
+
     #Contrib adds significantly to project's build time
     if [ "$ENABLE_CONTRIB" -eq 1 ]; then
         BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
     fi
-    
+
     function generate_ffmpeg_formula {
         local FF="ffmpeg"
         local LFF="ffmpeg_opencv"
         local FF_FORMULA; FF_FORMULA=$(brew formula "$FF")
         local LFF_FORMULA; LFF_FORMULA="$(dirname "$FF_FORMULA")/${LFF}.rb"
-        
+
         local REGENERATE
         if [ -f "$LFF_FORMULA" ]; then
             local UPSTREAM_VERSION VERSION
@@ -82,7 +82,7 @@ if (/^\s*depends_on "(x264|x265|xvid)"$/) {$_=""; next;}
             )
         fi
     }
-        
+
 fi
 
 function pre_build {
@@ -91,8 +91,8 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
-    
-    brew update --merge
+
+    brew update
     brew_add_local_bottles
 
     # Don't query analytical info online on `brew info`,

From 3ccee5a48440df7961c0769c344a3c2b5cdc580e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 19 Feb 2019 19:33:17 +0200
Subject: [PATCH 127/566] Revert "remove --merge"

This reverts commit 0e788e25f4a205832dac6c09dccc9180acd29b73.
---
 config.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/config.sh b/config.sh
index 94eaf051..3bdacd2f 100644
--- a/config.sh
+++ b/config.sh
@@ -29,24 +29,24 @@ fi
 if [ -n "$IS_OSX" ]; then
 
     source travis_osx_brew_cache.sh
-
+    
     BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
         "x265 20"  \
         "cmake 15" \
         "ffmpeg_opencv 10" \
     )
-
+    
     #Contrib adds significantly to project's build time
     if [ "$ENABLE_CONTRIB" -eq 1 ]; then
         BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
     fi
-
+    
     function generate_ffmpeg_formula {
         local FF="ffmpeg"
         local LFF="ffmpeg_opencv"
         local FF_FORMULA; FF_FORMULA=$(brew formula "$FF")
         local LFF_FORMULA; LFF_FORMULA="$(dirname "$FF_FORMULA")/${LFF}.rb"
-
+        
         local REGENERATE
         if [ -f "$LFF_FORMULA" ]; then
             local UPSTREAM_VERSION VERSION
@@ -82,7 +82,7 @@ if (/^\s*depends_on "(x264|x265|xvid)"$/) {$_=""; next;}
             )
         fi
     }
-
+        
 fi
 
 function pre_build {
@@ -91,8 +91,8 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
-
-    brew update
+    
+    brew update --merge
     brew_add_local_bottles
 
     # Don't query analytical info online on `brew info`,

From 54110e3a1cb4d012873f1e3adcb840863173b7d5 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 19 Feb 2019 19:56:42 +0200
Subject: [PATCH 128/566] try --force

---
 config.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/config.sh b/config.sh
index 3bdacd2f..fee87537 100644
--- a/config.sh
+++ b/config.sh
@@ -29,24 +29,24 @@ fi
 if [ -n "$IS_OSX" ]; then
 
     source travis_osx_brew_cache.sh
-    
+
     BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
         "x265 20"  \
         "cmake 15" \
         "ffmpeg_opencv 10" \
     )
-    
+
     #Contrib adds significantly to project's build time
     if [ "$ENABLE_CONTRIB" -eq 1 ]; then
         BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
     fi
-    
+
     function generate_ffmpeg_formula {
         local FF="ffmpeg"
         local LFF="ffmpeg_opencv"
         local FF_FORMULA; FF_FORMULA=$(brew formula "$FF")
         local LFF_FORMULA; LFF_FORMULA="$(dirname "$FF_FORMULA")/${LFF}.rb"
-        
+
         local REGENERATE
         if [ -f "$LFF_FORMULA" ]; then
             local UPSTREAM_VERSION VERSION
@@ -82,7 +82,7 @@ if (/^\s*depends_on "(x264|x265|xvid)"$/) {$_=""; next;}
             )
         fi
     }
-        
+
 fi
 
 function pre_build {
@@ -91,8 +91,8 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
-    
-    brew update --merge
+
+    brew update --force
     brew_add_local_bottles
 
     # Don't query analytical info online on `brew info`,

From 7dee26cbc87445d60cbb846e751e377c2d1aebf5 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 23 Mar 2019 20:53:41 +0300
Subject: [PATCH 129/566] Remove redundant language:generic

---
 .travis.yml | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index a6fb537d..16b6025f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -40,7 +40,6 @@ matrix:
 
     # default builds for MacOS
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
@@ -48,7 +47,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
@@ -56,7 +54,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
@@ -64,7 +61,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
@@ -72,7 +68,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
@@ -83,7 +78,6 @@ matrix:
 
     # headless builds for MacOS
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
@@ -91,7 +85,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
@@ -99,7 +92,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
@@ -107,7 +99,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
@@ -115,7 +106,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
@@ -126,7 +116,6 @@ matrix:
 
     # Contrib builds for MacOS
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
@@ -134,7 +123,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
@@ -142,7 +130,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
@@ -150,7 +137,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
@@ -158,7 +144,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
@@ -169,7 +154,6 @@ matrix:
 
     # headless contrib builds for MacOS
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
@@ -177,7 +161,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
@@ -185,7 +168,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
@@ -193,7 +175,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
@@ -201,7 +182,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7

From 59daed260ecba41deadc4c1bde9d51695fd90930 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Fri, 22 Mar 2019 00:44:02 +0300
Subject: [PATCH 130/566] Move CMAKE_OSX_DEPLOYMENT_TARGET to setup.py

---
 .travis.yml | 20 --------------------
 setup.py    |  1 +
 2 files changed, 1 insertion(+), 20 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 16b6025f..5945c9d5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -45,35 +45,30 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
         - TEST_DEPENDS=numpy==1.14.5
 
     # headless builds for MacOS
@@ -83,35 +78,30 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
         - TEST_DEPENDS=numpy==1.14.5
 
     # Contrib builds for MacOS
@@ -121,35 +111,30 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
         - TEST_DEPENDS=numpy==1.14.5
 
     # headless contrib builds for MacOS
@@ -159,35 +144,30 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
         - TEST_DEPENDS=numpy==1.14.5
 
     # default builds for Linux
diff --git a/setup.py b/setup.py
index 68bede4f..06dfe273 100644
--- a/setup.py
+++ b/setup.py
@@ -141,6 +141,7 @@ def main():
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
         cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
+        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with

From f08d11d7bd86ef0d4a1be727f5912c7b61a8c9a8 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Fri, 22 Mar 2019 01:16:35 +0300
Subject: [PATCH 131/566] * No need for both OPENCV_PYTHON{2,3}_INSTALL_PATH in
 cmake args * Add explanation to more obscure cmake args

---
 setup.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index 06dfe273..4cf0e733 100644
--- a/setup.py
+++ b/setup.py
@@ -102,12 +102,16 @@ def main():
         # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
         "-DPYTHON%d_EXECUTABLE=%s" % (sys.version_info[0], sys.executable),
         "-DBUILD_opencv_python%d=ON" % sys.version_info[0],
+        
+        # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
         "-DOPENCV_SKIP_PYTHON_LOADER=ON",
-        "-DOPENCV_PYTHON2_INSTALL_PATH=python",
-        "-DOPENCV_PYTHON3_INSTALL_PATH=python",
+        # Relative dir to install the built module to in the build tree.
+        # The default is generated from sysconfig, we'd rather have a constant for simplicity
+        "-DOPENCV_PYTHON%d_INSTALL_PATH=python" % sys.version_info[0],
         # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
         # and skbuild bails out on seeing that
         "-DINSTALL_CREATE_DISTRIB=ON",
+        
         # See opencv/CMakeLists.txt for options and defaults
         "-DBUILD_opencv_apps=OFF",
         "-DBUILD_SHARED_LIBS=OFF",

From c04617a2c0db330420d379b7d323c91fc4657648 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 21 Mar 2019 16:43:05 +0300
Subject: [PATCH 132/566] Upgrade to Xcode 8.3

---
 .travis.yml | 54 ++++++++++++++++++++++++++---------------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 5945c9d5..e7e9a5f0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,38 +33,38 @@ cache:
     - $HOME/local_bottle_metadata
     # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
     - $HOME/.ccache
-    
+
 matrix:
   fast_finish: true
   include:
 
     # default builds for MacOS
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -73,31 +73,31 @@ matrix:
 
     # headless builds for MacOS
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -106,31 +106,31 @@ matrix:
 
     # Contrib builds for MacOS
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -139,31 +139,31 @@ matrix:
 
     # headless contrib builds for MacOS
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -578,7 +578,7 @@ before_install: |
     source multibuild_customize.sh
     echo $ENABLE_CONTRIB > contrib.enabled
     echo $ENABLE_HEADLESS > headless.enabled
-    
+
     if [ -n "$IS_OSX" ]; then
         TAPS="$(brew --repository)/Library/Taps"
         if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
@@ -589,10 +589,10 @@ before_install: |
                     cd $(dirname '\''{}'\'')
                     git clean -fxd
                     git status' \;
-                    
+
         brew_cache_cleanup
     fi
-    
+
     before_install
     # Not interested in travis internal scripts' output
     set +x
@@ -613,7 +613,7 @@ script: |
     #otherwise, Travis logic terminates prematurely
     #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
     trap ERR
-    
+
     test "$rc" -eq 0
 
 before_cache: |
@@ -627,10 +627,10 @@ before_cache: |
         fi
 
         brew_cache_cleanup
-        
+
     fi
     set +x
-    
+
 after_success: |
     # Upload wheels to pypi if requested
     if [ -n "$TRAVIS_TAG" ]; then

From 4f4727106c00db39a67106f9083cb9d1eb3f689e Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Tue, 19 Mar 2019 15:41:56 +0300
Subject: [PATCH 133/566] Diagnostics for a `find -exec git clean` failure

---
 .travis.yml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index e7e9a5f0..130df767 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -586,9 +586,10 @@ before_install: |
         fi
         find "$TAPS" -type d -name .git -exec \
                 bash -xec '
-                    cd $(dirname '\''{}'\'')
-                    git clean -fxd
-                    git status' \;
+                    cd $(dirname '\''{}'\'') || echo "status: $?"
+                    git clean -fxd || echo "status: $?"
+                    sleep 1 || echo "status: $?"
+                    git status || echo "status: $?"' \; || echo "status: $?"
 
         brew_cache_cleanup
     fi

From 61c4172a4d95e2f96f1a06d4473f83e24d9db151 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Tue, 19 Mar 2019 12:51:03 +0300
Subject: [PATCH 134/566] Fix/improve travis_osx_brew_cache & caching logic

* fix built bottle & metadata cleanup when bottle is missing
* -e mode for before_cache step
* faster finish when already the latest version
---
 .travis.yml              |  4 ++--
 travis_osx_brew_cache.sh | 15 +++++++++------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 130df767..8772517e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -619,7 +619,7 @@ script: |
 
 before_cache: |
     # Cleanup dirs to be cached
-    set -x
+    set -e; set -x
     if [ -n "$IS_OSX" ]; then
 
         # When Taps is cached, this dir causes "Error: file exists" on `brew update`
@@ -630,7 +630,7 @@ before_cache: |
         brew_cache_cleanup
 
     fi
-    set +x
+    set +x; set +e
 
 after_success: |
     # Upload wheels to pypi if requested
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 47d37326..8d2401b2 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -41,6 +41,12 @@ function brew_install_and_cache_within_time_limit {
 
     local BUILD_FROM_SOURCE INCLUDE_BUILD
     
+    if brew list --versions "$PACKAGE" && ! (brew outdated | grep -qx "$PACKAGE"); then
+        echo "Already installed and the latest version: $PACKAGE"
+        return 0
+    fi
+
+    
     _brew_is_bottle_available "$PACKAGE" || BUILD_FROM_SOURCE=1
     [ -n "$BUILD_FROM_SOURCE" ] && INCLUDE_BUILD="--include-build" || true
 
@@ -152,7 +158,7 @@ function brew_add_local_bottles {
                 )
             fi
             
-            if [ -n "$BOTTLE" ]; then rm "$BOTTLE"; fi
+            if [ -n "$BOTTLE" -a -n "$BOTTLE_EXISTS" ]; then rm "$BOTTLE"; fi
             rm -f "$BOTTLE_LINK"
             rm "$JSON"
             
@@ -295,17 +301,14 @@ function _brew_is_bottle_available {
 
 function _brew_install_and_cache {
     # Install bottle or make and cache bottle.
-    # assumes that deps were already installed.
+    # assumes that deps were already installed
+    # and not already the latest version
     
     local PACKAGE;PACKAGE="${1:?}"
     local USE_BOTTLE;USE_BOTTLE="${2:?}"
     local VERB
     
     if brew list --versions "$PACKAGE"; then
-        if ! (brew outdated | grep -qx "$PACKAGE"); then
-            echo "Already the latest version: $PACKAGE"
-            return 0
-        fi
         VERB=upgrade
     else
         VERB=install

From 573480899c9c79f3d6303cd6c4167f5c76e61c0e Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Tue, 19 Mar 2019 13:10:38 +0300
Subject: [PATCH 135/566] Update caching logic to support new Homebrew in OSX
 10.12

* disable auto `brew cleanup`
* support formulae with disabled bottles
* install alongside to avoid "runtime dependents" update
  https://discourse.brew.sh/t/can-i-install-a-new-version-without-having-to-upgrade-runtime-dependents/4443
---
 config.sh                |  4 +--
 travis_osx_brew_cache.sh | 59 ++++++++++++++++++++++++++++------------
 2 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/config.sh b/config.sh
index fee87537..ead68645 100644
--- a/config.sh
+++ b/config.sh
@@ -92,14 +92,14 @@ function pre_build {
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
 
-    brew update --force
+    brew update
     brew_add_local_bottles
 
     # Don't query analytical info online on `brew info`,
     #  this takes several seconds and we don't need it
     # see https://docs.brew.sh/Manpage , "info formula" section
     export HOMEBREW_NO_GITHUB_API=1
-
+    
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 8d2401b2..c62a6235 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -24,6 +24,11 @@ BREW_TIME_LIMIT=$((30*60))
 BREW_TIME_HARD_LIMIT=$((40*60))
 
 
+# Auto cleanup can delete locally-built bottles
+# when the caching logic isn't prepared for that
+export HOMEBREW_NO_INSTALL_CLEANUP=1
+
+
 
 #Public functions
 
@@ -34,12 +39,12 @@ function brew_install_and_cache_within_time_limit {
     # Exit with status 2 on any other error.
     ( eval "$_BREW_ERREXIT"
     
-    local PACKAGE; PACKAGE="${1:?}" || return 2
-    local TIME_LIMIT;TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || return 2
-    local TIME_HARD_LIMIT;TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || return 2
-    local TIME_START;TIME_START=${4:-$BREW_TIME_START} || return 2
+    local PACKAGE; PACKAGE="${1:?}" || exit 2
+    local TIME_LIMIT;TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || exit 2
+    local TIME_HARD_LIMIT;TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || exit 2
+    local TIME_START;TIME_START=${4:-$BREW_TIME_START} || exit 2
 
-    local BUILD_FROM_SOURCE INCLUDE_BUILD
+    local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
     
     if brew list --versions "$PACKAGE" && ! (brew outdated | grep -qx "$PACKAGE"); then
         echo "Already installed and the latest version: $PACKAGE"
@@ -47,21 +52,21 @@ function brew_install_and_cache_within_time_limit {
     fi
 
     
-    _brew_is_bottle_available "$PACKAGE" || BUILD_FROM_SOURCE=1
+    _brew_is_bottle_available "$PACKAGE" KEG_ONLY || BUILD_FROM_SOURCE=1
     [ -n "$BUILD_FROM_SOURCE" ] && INCLUDE_BUILD="--include-build" || true
 
     # Whitespace is illegal in package names so converting all whitespace into single spaces due to no quotes is okay.
-    DEPS=`brew deps "$PACKAGE" $INCLUDE_BUILD` || return 2
+    DEPS=`brew deps "$PACKAGE" $INCLUDE_BUILD` || exit 2
     for dep in $DEPS; do
         #TIME_LIMIT only has to be met if we'll be actually building the main project this iteration, i.e. after the "root" module installation
         #While we don't know that yet, we can make better use of Travis-given time with a laxer limit
         #We still can't overrun TIME_HARD_LIMIT as that would't leave time to save the cache
-        brew_install_and_cache_within_time_limit "$dep" $(((TIME_LIMIT+TIME_HARD_LIMIT)/2)) "$TIME_HARD_LIMIT" "$TIME_START" || return $?
+        brew_install_and_cache_within_time_limit "$dep" $(((TIME_LIMIT+TIME_HARD_LIMIT)/2)) "$TIME_HARD_LIMIT" "$TIME_START" || exit $?
     done
 
-    _brew_check_slow_building_ahead "$PACKAGE" "$TIME_START" "$TIME_HARD_LIMIT" || return $?
-    _brew_install_and_cache "$PACKAGE" "$([[ -z "$INCLUDE_BUILD" ]] && echo 1 || echo 0)" || return 2
-    _brew_check_elapsed_build_time "$TIME_START" "$TIME_LIMIT" || return $?
+    _brew_check_slow_building_ahead "$PACKAGE" "$TIME_START" "$TIME_HARD_LIMIT" || exit $?
+    _brew_install_and_cache "$PACKAGE" "$([[ -z "$BUILD_FROM_SOURCE" ]] && echo 1 || echo 0)" "$KEG_ONLY" || exit 2
+    _brew_check_elapsed_build_time "$TIME_START" "$TIME_LIMIT" || exit $?
     ) \
     || if test $? -eq 1; then brew_go_bootstrap_mode; return 1; else return 2; fi      #must run this in current process
 }
@@ -288,8 +293,22 @@ function _brew_parse_package_info {
 function _brew_is_bottle_available {
 
     local PACKAGE;PACKAGE="${1:?}"
-    
-    local INFO="$(brew info "$PACKAGE" | head -n 1)"
+    local VAR_KEG_ONLY="$2"
+
+    local INFO;INFO="$(brew info "$PACKAGE" | head -n 1)"
+    if [ -n "$VAR_KEG_ONLY" ]; then
+        if grep -qwF '[keg-only]' <<<"$INFO"; then
+            eval "${VAR_KEG_ONLY}=1"
+        else
+            eval "${VAR_KEG_ONLY}=0"
+        fi
+    fi
+
+    if grep -qxEe '[[:space:]]*bottle :unneeded' $(brew formula "$PACKAGE"); then
+        echo "Bottle disabled: $PACKAGE"
+        return 0
+    fi
+
     if grep -qwF '(bottled)' <<<"$INFO"; then
         echo "Bottle available: $INFO"
         return 0
@@ -306,10 +325,16 @@ function _brew_install_and_cache {
     
     local PACKAGE;PACKAGE="${1:?}"
     local USE_BOTTLE;USE_BOTTLE="${2:?}"
+    local KEG_ONLY;KEG_ONLY="${3:?}"
     local VERB
     
-    if brew list --versions "$PACKAGE"; then
-        VERB=upgrade
+    if brew list --versions "$PACKAGE" >/dev/null; then
+        # Install alongside the old version to avoid to have to update "runtime dependents"
+        # https://discourse.brew.sh/t/can-i-install-a-new-version-without-having-to-upgrade-runtime-dependents/4443
+        VERB="install --force"
+        if [ "$KEG_ONLY" -eq 0 ]; then
+            brew unlink "$PACKAGE"
+        fi
     else
         VERB=install
     fi
@@ -328,8 +353,8 @@ function _brew_install_and_cache {
         # doesn't seem to be a documented way to get file names
         local BOTTLE; BOTTLE=$(grep -Ee '^./' <<<"$OUT")
         #proper procedure as per https://discourse.brew.sh/t/how-are-bottle-and-postinstall-related-is-it-safe-to-run-bottle-after-postinstall/3410/4
-        brew uninstall "$PACKAGE"
-        brew install "$BOTTLE"
+        brew uninstall --ignore-dependencies "$PACKAGE"
+        brew $VERB "$BOTTLE"
         
         local JSON; JSON=$(sed -E 's/bottle(.[[:digit:]]+)?\.tar\.gz$/bottle.json/' <<<"$BOTTLE")
         

From b5bd66108e606222e64c14048de95681d9a97978 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 21 Mar 2019 12:33:04 +0300
Subject: [PATCH 136/566] Install macpython late to avoid conflict with
 Homebrew python upgrade

---
 .travis.yml              |  2 --
 config.sh                | 12 +++++++++---
 travis_osx_brew_cache.sh |  2 ++
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 8772517e..632af248 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -594,7 +594,6 @@ before_install: |
         brew_cache_cleanup
     fi
 
-    before_install
     # Not interested in travis internal scripts' output
     set +x
 
@@ -602,7 +601,6 @@ install: |
     # Build and package
     set -x
     build_wheel $REPO_DIR $PLAT
-    if [ -n "$USE_CCACHE" ]; then ccache --show-stats; fi
     set +x
 
 script: |
diff --git a/config.sh b/config.sh
index ead68645..22d16066 100644
--- a/config.sh
+++ b/config.sh
@@ -16,6 +16,7 @@ function bdist_wheel_cmd {
     local abs_wheelhouse=$1
     python setup.py bdist_wheel $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
+    if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache --show-stats; fi
 }
 
 if [ -n "$IS_OSX" ]; then
@@ -99,7 +100,7 @@ function pre_build {
     #  this takes several seconds and we don't need it
     # see https://docs.brew.sh/Manpage , "info formula" section
     export HOMEBREW_NO_GITHUB_API=1
-    
+
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
@@ -108,8 +109,13 @@ function pre_build {
     echo 'Installing FFmpeg'
 
     generate_ffmpeg_formula
-    brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
-
+    local IS_BOTTLE_AVAILABLE; _brew_is_bottle_available ffmpeg_opencv && IS_BOTTLE_AVAILABLE=1 || IS_BOTTLE_AVAILABLE=0
+    _brew_install_and_cache ffmpeg_opencv "$IS_BOTTLE_AVAILABLE"
+    #brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
+    
+    # Have to install macpython late to avoid conflict with Homebrew Python update
+    before_install
+    
   else
     echo "Running for linux"
   fi
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index c62a6235..261e1d00 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -215,6 +215,8 @@ function brew_go_bootstrap_mode {
 # Terminate the build but ensure saving the cache
 
     echo "Going into cache bootstrap mode"
+    
+    BREW_BOOTSTRAP_MODE=1
         
     #Can't just `exit` because that would terminate the build without saving the cache
     #Have to replace further actions with no-ops

From 7d87741ebb41e560d0246308c6f6a5416e286da5 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 21 Mar 2019 22:11:08 +0300
Subject: [PATCH 137/566] OSX custom ffmpeg formula: disable GPLed frei0r,
 librubberband

---
 config.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/config.sh b/config.sh
index 22d16066..59c40ee3 100644
--- a/config.sh
+++ b/config.sh
@@ -70,8 +70,8 @@ if [ -n "$IS_OSX" ]; then
                 if (!$found_blank && /^$/) {$_.="conflicts_with \"ffmpeg\"\n\n"; $found_blank=1; next;}
                 if (!$bottle_block && /^\s*bottle do$/) { $bottle_block=1; next; }
                 if ($bottle_block) { if (/^\s*end\s*$/) { $bottle_block=0} elsif (/^\s*sha256\s/) {$_=""} next; }
-if (/^\s*depends_on "(x264|x265|xvid)"$/) {$_=""; next;}
-                if (/^\s*--enable-(gpl|libx264|libx265|libxvid)$/) {$_=""; next;}
+if (/^\s*depends_on "(x264|x265|xvid|frei0r|rubberband)"$/) {$_=""; next;}
+                if (/^\s*--enable-(gpl|libx264|libx265|libxvid|frei0r|librubberband)$/) {$_=""; next;}
                 ' <"$FF_FORMULA" >"$LFF_FORMULA"
             diff -u "$FF_FORMULA" "$LFF_FORMULA" || test $? -le 1
 

From b5b4e8473918349e1f3dfeb9fc3922056684d894 Mon Sep 17 00:00:00 2001
From: Admin <admin@Mac-Admin.local>
Date: Fri, 22 Mar 2019 02:34:10 +0300
Subject: [PATCH 138/566] Adapt setup.py hook for skbuild 0.9.0

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 4cf0e733..65322dbc 100644
--- a/setup.py
+++ b/setup.py
@@ -268,7 +268,7 @@ def _classify_installed_files_override(self, install_paths,
 
         # 'relpath'/'reldir' = relative to CMAKE_INSTALL_DIR/cmake_install_dir
         # 'path'/'dir' = relative to sourcetree root
-        cmake_install_dir = os.path.join(cls._setuptools_wrap.CMAKE_INSTALL_DIR,
+        cmake_install_dir = os.path.join(cls._setuptools_wrap.CMAKE_INSTALL_DIR(),
                                          cmake_install_reldir)
         install_relpaths = [os.path.relpath(p, cmake_install_dir) for p in install_paths]
         fslash_install_relpaths = [p.replace(os.path.sep, '/') for p in install_relpaths]

From e93bb9376fdcda572151653a8110e60667b239e5 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Fri, 22 Mar 2019 23:04:51 +0300
Subject: [PATCH 139/566] Reduce the amount of trace output

* Reduce the number of command lines executed in most used functions
* List existing versions only when installing
---
 travis_osx_brew_cache.sh | 51 ++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 261e1d00..69dbf729 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -1,12 +1,5 @@
 # Library to cache downloaded and locally-built Homebrew bottles in Travis OSX build.
 
-_BREW_ERREXIT='
-set -e -o pipefail
-trap '\''{ sleep 3;    #if we terminale too abruptly, Travis will lose some log output
-        exit 2;     #The trap isn''t called in the parent function, so can''t use `return` here.
-                    #`exit` will terminate the entire build but it seems we have no choice.
-}'\'' ERR
-set -E'
 
 #Should be in Travis' cache
 BREW_LOCAL_BOTTLE_METADATA="$HOME/local_bottle_metadata"
@@ -37,16 +30,17 @@ function brew_install_and_cache_within_time_limit {
     # use bottle if available, build and cache bottle if not.
     # Terminate and exit with status 1 if this takes too long.
     # Exit with status 2 on any other error.
-    ( eval "$_BREW_ERREXIT"
-    
-    local PACKAGE; PACKAGE="${1:?}" || exit 2
-    local TIME_LIMIT;TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || exit 2
-    local TIME_HARD_LIMIT;TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || exit 2
-    local TIME_START;TIME_START=${4:-$BREW_TIME_START} || exit 2
+    ( set -eE -o pipefail; trap '{ sleep 3; exit 2; }' ERR
+
+    local PACKAGE TIME_LIMIT TIME_HARD_LIMIT TIME_START
+    PACKAGE="${1:?}" || exit 2
+    TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || exit 2
+    TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || exit 2
+    TIME_START=${4:-$BREW_TIME_START} || exit 2
 
     local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
     
-    if brew list --versions "$PACKAGE" && ! (brew outdated | grep -qx "$PACKAGE"); then
+    if brew list --versions "$PACKAGE" >/dev/null && ! (brew outdated | grep -qxF "$PACKAGE"); then
         echo "Already installed and the latest version: $PACKAGE"
         return 0
     fi
@@ -266,8 +260,9 @@ function _brew_parse_package_info {
     # Get and parse `brew info --json` about a package
     # and save data into specified variables
     
-    local PACKAGE; PACKAGE="${1:?}"; shift
-    local OS_CODENAME;OS_CODENAME="${1:?}"; shift
+    local PACKAGE OS_CODENAME
+    PACKAGE="${1:?}"; shift
+    OS_CODENAME="${1:?}"; shift
 
     local JSON_DATA; JSON_DATA=$(python2.7 -c 'if True:
     import sys, json, subprocess; j=json.loads(subprocess.check_output(("brew","info","--json=v1",sys.argv[1])))
@@ -325,12 +320,13 @@ function _brew_install_and_cache {
     # assumes that deps were already installed
     # and not already the latest version
     
-    local PACKAGE;PACKAGE="${1:?}"
-    local USE_BOTTLE;USE_BOTTLE="${2:?}"
-    local KEG_ONLY;KEG_ONLY="${3:?}"
+    local PACKAGE USE_BOTTLE KEG_ONLY
+    PACKAGE="${1:?}"
+    USE_BOTTLE="${2:?}"
+    KEG_ONLY="${3:?}"
     local VERB
     
-    if brew list --versions "$PACKAGE" >/dev/null; then
+    if brew list --versions "$PACKAGE"; then
         # Install alongside the old version to avoid to have to update "runtime dependents"
         # https://discourse.brew.sh/t/can-i-install-a-new-version-without-having-to-upgrade-runtime-dependents/4443
         VERB="install --force"
@@ -382,10 +378,11 @@ function _brew_check_elapsed_build_time {
     # If time limit has been reached,
     # arrange for further build to be skipped and return 1
 
-    local TIME_START;TIME_START="${1:?}"
-    local TIME_LIMIT;TIME_LIMIT="${2:?}"
+    local TIME_START TIME_LIMIT ELAPSED_TIME
+    TIME_START="${1:?}"
+    TIME_LIMIT="${2:?}"
     
-    local ELAPSED_TIME;ELAPSED_TIME=$(($(date +%s) - $TIME_START))
+    ELAPSED_TIME=$(($(date +%s) - $TIME_START))
     echo "Elapsed time: "$(($ELAPSED_TIME/60))"m (${ELAPSED_TIME}s)"
     
     if [[ "$ELAPSED_TIME" -gt $TIME_LIMIT ]]; then 
@@ -400,10 +397,12 @@ function _brew_check_slow_building_ahead {
     #If the package's projected build completion is higher than hard limit,
     # skip it and arrange for further build to be skipped and return 1
     
-    local PACKAGE="${1:?}"
-    local TIME_START="${2:?}"
-    local TIME_HARD_LIMIT="${3:?}"
+    local PACKAGE TIME_START TIME_HARD_LIMIT
+    PACKAGE="${1:?}"
+    TIME_START="${2:?}"
+    TIME_HARD_LIMIT="${3:?}"
     
+    local PROJECTED_BUILD_TIME 
     PROJECTED_BUILD_TIME=$(echo "$BREW_SLOW_BUILIDING_PACKAGES" | awk '$1=="'"$PACKAGE"'"{print $2}')
     [ -z "$PROJECTED_BUILD_TIME" ] && return 0 || true
     

From 9d020bc045f893eb500de86722f912d74caef2a5 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 23 Mar 2019 02:08:15 +0300
Subject: [PATCH 140/566] Use 2 stages for MacOS builds

* Add a dedicated stage to each OSX build to download/build brew packages
* Remove bottle building logic and the corresponding trace output from the project build stage
---
 .travis.yml              | 128 +++++++++++++++++++++++++++++++++------
 config.sh                |  35 +++++++----
 travis_osx_brew_cache.sh |   6 +-
 3 files changed, 135 insertions(+), 34 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 632af248..07febd6e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -34,144 +34,232 @@ cache:
     # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
     - $HOME/.ccache
 
+# Add more cache stages (s2 etc) and corresponding OSX jobs like s1
+# if brew builds start to take longer than one Travis time limit
+stages:
+  - s1
+  - final
+    
 matrix:
   fast_finish: true
   include:
 
     # default builds for MacOS
-    - os: osx
+    - &osx-10
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-10
+      stage: s1
+    - &osx-30
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-30
+      stage: s1
+    - &osx-40
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-40
+      stage: s1
+    - &osx-50
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-50
+      stage: s1
+    - &osx-60
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
+      stage: final
+    - <<: *osx-60
+      stage: s1
 
     # headless builds for MacOS
-    - os: osx
+    - &osx-70
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-70
+      stage: s1
+    - &osx-80
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-80
+      stage: s1
+    - &osx-90
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-90
+      stage: s1
+    - &osx-100
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-100
+      stage: s1
+    - &osx-110
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
+      stage: final
+    - <<: *osx-110
+      stage: s1
 
     # Contrib builds for MacOS
-    - os: osx
+    - &osx-120
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-120
+      stage: s1
+    - &osx-130
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-130
+      stage: s1
+    - &osx-140
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-140
+      stage: s1
+    - &osx-150
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-150
+      stage: s1
+    - &osx-160
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
+      stage: final
+    - <<: *osx-160
+      stage: s1
 
     # headless contrib builds for MacOS
-    - os: osx
+    - &osx-170
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-170
+      stage: s1
+    - &osx-180
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-180
+      stage: s1
+    - &osx-190
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-190
+      stage: s1
+    - &osx-200
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-200
+      stage: s1
+    - &osx-210
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
+      stage: final
+    - <<: *osx-210
+      stage: s1
 
     # default builds for Linux
     - os: linux
+      # the following jobs will use the same stage name by default
+      stage: s1
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
diff --git a/config.sh b/config.sh
index 59c40ee3..16a5ad68 100644
--- a/config.sh
+++ b/config.sh
@@ -37,11 +37,6 @@ if [ -n "$IS_OSX" ]; then
         "ffmpeg_opencv 10" \
     )
 
-    #Contrib adds significantly to project's build time
-    if [ "$ENABLE_CONTRIB" -eq 1 ]; then
-        BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
-    fi
-
     function generate_ffmpeg_formula {
         local FF="ffmpeg"
         local LFF="ffmpeg_opencv"
@@ -92,9 +87,14 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
+    
+    local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
 
-    brew update
-    brew_add_local_bottles
+    #after the cache stage, all bottles and Homebrew metadata should be already cached locally
+    if [ -n "$CACHE_STAGE" ]; then
+        brew update
+        brew_add_local_bottles
+    fi
 
     # Don't query analytical info online on `brew info`,
     #  this takes several seconds and we don't need it
@@ -104,14 +104,25 @@ function pre_build {
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
-    brew_install_and_cache_within_time_limit qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
+    if [ -n "$CACHE_STAGE" ]; then
+        brew_install_and_cache_within_time_limit qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
+    else
+        brew install qt@4
+    fi
 
     echo 'Installing FFmpeg'
 
-    generate_ffmpeg_formula
-    local IS_BOTTLE_AVAILABLE; _brew_is_bottle_available ffmpeg_opencv && IS_BOTTLE_AVAILABLE=1 || IS_BOTTLE_AVAILABLE=0
-    _brew_install_and_cache ffmpeg_opencv "$IS_BOTTLE_AVAILABLE"
-    #brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
+    if [ -n "$CACHE_STAGE" ]; then
+        generate_ffmpeg_formula
+        brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
+    else
+        brew install ffmpeg_opencv
+    fi
+
+    if [ -n "$CACHE_STAGE" ]; then
+        brew_go_bootstrap_mode 0
+        return 0
+    fi
     
     # Have to install macpython late to avoid conflict with Homebrew Python update
     before_install
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 69dbf729..3eba10f6 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -10,7 +10,8 @@ BREW_TIME_START=$(($TRAVIS_TIMER_START_TIME/10**9))
 
 # If after a package is built, elapsed time is more than this many seconds, fail the build but save Travis cache
 # The cutoff moment should leave enough time till Travis' job time limit to process the main project.
-BREW_TIME_LIMIT=$((30*60))
+#  Since we have moved deps into a separate stage, we don't need to leave time for the project any more
+BREW_TIME_LIMIT=$((38*60))
 # If a slow-building package is about to be built and the projected build end moment is beyond this many seconds,
 # skip that build, fail the Travis job and save Travis cache.
 # This cutoff should leave enough time for before_cache and cache save.
@@ -207,6 +208,7 @@ function brew_cache_cleanup {
 function brew_go_bootstrap_mode {
 # Can be overridden
 # Terminate the build but ensure saving the cache
+    local EXIT_CODE=${1:-1}
 
     echo "Going into cache bootstrap mode"
     
@@ -223,7 +225,7 @@ function brew_go_bootstrap_mode {
         
         # Travis runs user scripts via `eval` i.e. in the same shell process.
         # So have to unset errexit in order to get to cache save stage
-        set +e; return 1
+        set +e; return '"$EXIT_CODE"'
     }'    
 }
 

From 509e5cbc75178f92d5d084b1c0e38b294471d3cd Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 23 Mar 2019 22:16:33 +0300
Subject: [PATCH 141/566] Further increase time limits for the cache jobs

---
 travis_osx_brew_cache.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 3eba10f6..87de4c78 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -11,11 +11,11 @@ BREW_TIME_START=$(($TRAVIS_TIMER_START_TIME/10**9))
 # If after a package is built, elapsed time is more than this many seconds, fail the build but save Travis cache
 # The cutoff moment should leave enough time till Travis' job time limit to process the main project.
 #  Since we have moved deps into a separate stage, we don't need to leave time for the project any more
-BREW_TIME_LIMIT=$((38*60))
+BREW_TIME_LIMIT=$((42*60))
 # If a slow-building package is about to be built and the projected build end moment is beyond this many seconds,
 # skip that build, fail the Travis job and save Travis cache.
 # This cutoff should leave enough time for before_cache and cache save.
-BREW_TIME_HARD_LIMIT=$((40*60))
+BREW_TIME_HARD_LIMIT=$((43*60))
 
 
 # Auto cleanup can delete locally-built bottles

From c1edb270867f0fb87689e3bbc1b11331c250f677 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 23 Mar 2019 22:17:44 +0300
Subject: [PATCH 142/566] x265 is not among the custom formula dependencies

---
 config.sh | 1 -
 1 file changed, 1 deletion(-)

diff --git a/config.sh b/config.sh
index 16a5ad68..c6aae3db 100644
--- a/config.sh
+++ b/config.sh
@@ -32,7 +32,6 @@ if [ -n "$IS_OSX" ]; then
     source travis_osx_brew_cache.sh
 
     BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
-        "x265 20"  \
         "cmake 15" \
         "ffmpeg_opencv 10" \
     )

From f2e6647a2ade5a297b23ccab24a0a02344c0cc46 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 23 Mar 2019 22:20:33 +0300
Subject: [PATCH 143/566] HOMEBREW_NO_GITHUB_API is more relevant to the lib
 rather than main logic

---
 config.sh                | 5 -----
 travis_osx_brew_cache.sh | 6 ++++++
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/config.sh b/config.sh
index c6aae3db..c31def77 100644
--- a/config.sh
+++ b/config.sh
@@ -95,11 +95,6 @@ function pre_build {
         brew_add_local_bottles
     fi
 
-    # Don't query analytical info online on `brew info`,
-    #  this takes several seconds and we don't need it
-    # see https://docs.brew.sh/Manpage , "info formula" section
-    export HOMEBREW_NO_GITHUB_API=1
-
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 87de4c78..43625c41 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -22,6 +22,12 @@ BREW_TIME_HARD_LIMIT=$((43*60))
 # when the caching logic isn't prepared for that
 export HOMEBREW_NO_INSTALL_CLEANUP=1
 
+# Don't query analytical info online on `brew info`,
+#  this takes several seconds and we don't need it
+# see https://docs.brew.sh/Manpage , "info formula" section
+export HOMEBREW_NO_GITHUB_API=1
+
+
 
 
 #Public functions

From 23100a71d5e8797a7e3abf13d4a0c18e970599c1 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Mon, 25 Mar 2019 11:41:41 +0300
Subject: [PATCH 144/566] Fix contrib failures due to
 https://github.com/opencv/opencv_contrib/issues/920

---
 opencv_contrib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/opencv_contrib b/opencv_contrib
index 25221244..b7e78523 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 25221244732dcf44c1450d0f93edc2529a61c0e1
+Subproject commit b7e785233c1722c31530b59434b7d8bdcb0422f3

From 11b97628cbdc178ea576dfb046b0c93f0f45df39 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 5 Apr 2019 19:43:01 +0300
Subject: [PATCH 145/566] update README

---
 README.md | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/README.md b/README.md
index 32e5687b..a8556f98 100644
--- a/README.md
+++ b/README.md
@@ -50,12 +50,20 @@ A: Most likely the issue is related to too old pip and can be fixed by running `
 
 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.
 
+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](https://support.microsoft.com/en-us/help/3145500/media-feature-pack-list-for-windows-n-editions).
+
 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](https://github.com/skvark/opencv-python/issues/36) for a manual fix.
 
+If you still encounter the error after you have checked all the previous solutions, download [Dependencies](https://github.com/lucasg/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 SIFT and SURF are not included in these packages because they are patented and therefore cannot be distributed as built binaries. 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``.

From 9358fea620969fb02796291b8371f420bfcd3e3b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 8 Apr 2019 18:43:59 +0300
Subject: [PATCH 146/566] add --user flag to pip install

---
 .travis.yml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 07febd6e..22822de6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -39,7 +39,7 @@ cache:
 stages:
   - s1
   - final
-    
+
 matrix:
   fast_finish: true
   include:
@@ -722,10 +722,10 @@ after_success: |
     # Upload wheels to pypi if requested
     if [ -n "$TRAVIS_TAG" ]; then
         set -x
-        pip install twine
+        pip install --user twine
 
         if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
-          pip install --upgrade pyOpenSSL
+          pip install --user --upgrade pyOpenSSL
         fi
 
         if [[ $ENABLE_CONTRIB == 0 ]]; then

From 005d00184338edc5e40f00546371b2ffda456f0e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 8 Apr 2019 19:02:02 +0300
Subject: [PATCH 147/566] upgrade six...

---
 .travis.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.travis.yml b/.travis.yml
index 22822de6..c63fdbbb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -723,6 +723,7 @@ after_success: |
     if [ -n "$TRAVIS_TAG" ]; then
         set -x
         pip install --user twine
+        pip install --user --upgrade six
 
         if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
           pip install --user --upgrade pyOpenSSL

From eb0b33c953b7447f6a9c2b24fd57fea04542c550 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 8 Apr 2019 19:33:26 +0300
Subject: [PATCH 148/566] update README

---
 README.md | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index a8556f98..10229096 100644
--- a/README.md
+++ b/README.md
@@ -144,7 +144,9 @@ The default ``manylinux`` images have been extended with some OpenCV dependencie
 
 ### Supported Python versions
 
-Python 2.7 is the only supported version in 2.x series. Python 3.x releases follow Numpy releases. For example Python 3.3 is no longer supported by Numpy so support for it has been dropped in ``opencv-python``, too.
+Python 2.7 is the only supported version in 2.x series. Python 2.7 support will be dropped in the end of 2019.
+
+Python 3.x releases follow Numpy releases. For example Python 3.3 is no longer supported by Numpy so support for it has been dropped in ``opencv-python``, too.
 
 Currently, builds for following Python versions are provided:
 

From c21d9e039318a2eb71c34d2e422fb8539fb8c533 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 8 Apr 2019 23:26:50 +0300
Subject: [PATCH 149/566] fix macOS deployment phase

---
 .travis.yml | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index c63fdbbb..34d989f8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -722,11 +722,15 @@ after_success: |
     # Upload wheels to pypi if requested
     if [ -n "$TRAVIS_TAG" ]; then
         set -x
-        pip install --user twine
-        pip install --user --upgrade six
+
+        if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
+          pip install --user twine
+          pip install --user --upgrade six
+        fi
 
         if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
-          pip install --user --upgrade pyOpenSSL
+          pip install twine
+          pip install --upgrade pyOpenSSL
         fi
 
         if [[ $ENABLE_CONTRIB == 0 ]]; then

From 7f9aa262371a6c16fde24a7925ee77c71ace1c20 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 10 Apr 2019 11:27:37 +0300
Subject: [PATCH 150/566] bump OpenCV version to 4.1.0

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index c9ad5779..371bba8f 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit c9ad5779f2803dcc91a9938142209128d30b22d1
+Subproject commit 371bba8f54560b374fbcd47e7e02f015ac4969ad
diff --git a/opencv_contrib b/opencv_contrib
index b7e78523..2c32791a 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit b7e785233c1722c31530b59434b7d8bdcb0422f3
+Subproject commit 2c32791a9c500343568a21ea34bf2daeac2adae7

From a49c1b1187b3f25d714986b5e0d7c415bd429937 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 00:35:34 +0300
Subject: [PATCH 151/566] Fix values of mismatch detection variables carrying
 over to the next iteration

Happened in https://travis-ci.org/skvark/opencv-python/builds/518836739 S1 jobs
---
 travis_osx_brew_cache.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 43625c41..6a270678 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -106,8 +106,8 @@ function brew_add_local_bottles {
         local FORMULA_HAS_BOTTLE; [ -n "$FORMULA_BOTTLE_HASH" ] && FORMULA_HAS_BOTTLE=1 || true
         
 
-        local BOTTLE_LINK BOTTLE; BOTTLE_LINK="${JSON}.bottle.lnk";
-        local BOTTLE_EXISTS BOTTLE_MISMATCH VERSION_MISMATCH
+        local BOTTLE_LINK BOTTLE=""; BOTTLE_LINK="${JSON}.bottle.lnk";
+        local BOTTLE_EXISTS= BOTTLE_MISMATCH= VERSION_MISMATCH=
 
 
         # Check that the bottle file exists and is still appropriate for the formula

From 3844f7aa834518c2eb2a7b3cde357b220ac1adda Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 00:46:02 +0300
Subject: [PATCH 152/566] Fix removing old built opencv_ffmpeg when a new
 upstream formula is available

Happened in https://travis-ci.org/skvark/opencv-python/builds/518179810 S1 jobs
---
 config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config.sh b/config.sh
index c31def77..2a7e8ec1 100644
--- a/config.sh
+++ b/config.sh
@@ -92,6 +92,7 @@ function pre_build {
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then
         brew update
+        generate_ffmpeg_formula
         brew_add_local_bottles
     fi
 
@@ -107,7 +108,6 @@ function pre_build {
     echo 'Installing FFmpeg'
 
     if [ -n "$CACHE_STAGE" ]; then
-        generate_ffmpeg_formula
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew install ffmpeg_opencv

From 144e61c15251c09f596f842e5d25825aa100670d Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 01:19:18 +0300
Subject: [PATCH 153/566] Don't print bogus error message when cache warmup is
 complete

---
 travis_osx_brew_cache.sh | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 6a270678..eb15618c 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -223,12 +223,19 @@ function brew_go_bootstrap_mode {
     #Can't just `exit` because that would terminate the build without saving the cache
     #Have to replace further actions with no-ops
     
+    local MESSAGE=""; if [ "$EXIT_CODE" -ne 0 ]; then
+        MESSAGE='Building dependencies took too long. Restart the build in Travis UI to continue from cache.';
+    fi
+    
     eval '
     function '"$cmd"' { return 0; }
     function repair_wheelhouse { return 0; }
-    function install_run {
-        echo -e "\nBuilding dependencies took too long. Restart the build in Travis UI to continue from cache.\n"
-        
+    function install_run {'\
+        "$(if [ -n "$MESSAGE" ]; then
+            echo \
+        '        echo -e "\n'"$MESSAGE"'\n"'
+        fi)"\
+    '    
         # Travis runs user scripts via `eval` i.e. in the same shell process.
         # So have to unset errexit in order to get to cache save stage
         set +e; return '"$EXIT_CODE"'

From 583d1266b47ac5527ba34d9118add325577a333e Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 04:12:14 +0300
Subject: [PATCH 154/566] Fix "Error: broken pipe" if `brew info` gives lots of
 output

---
 travis_osx_brew_cache.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index eb15618c..65d4f0a9 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -307,7 +307,9 @@ function _brew_is_bottle_available {
     local PACKAGE;PACKAGE="${1:?}"
     local VAR_KEG_ONLY="$2"
 
-    local INFO;INFO="$(brew info "$PACKAGE" | head -n 1)"
+    # `brew info` prints "Error: Broken pipe" if piped directly to `head` and the info is long
+    # 141 = 128 + SIGPIPE
+    local INFO;INFO="$((brew info "$PACKAGE" | cat || test $? -eq 141) | head -n 1)"
     if [ -n "$VAR_KEG_ONLY" ]; then
         if grep -qwF '[keg-only]' <<<"$INFO"; then
             eval "${VAR_KEG_ONLY}=1"

From d0dbb0513b28122fc6cfdf126e344064f2077de8 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 05:22:08 +0300
Subject: [PATCH 155/566] CentOS 5 ccache doesn't have --show-stats

---
 config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config.sh b/config.sh
index 2a7e8ec1..af888179 100644
--- a/config.sh
+++ b/config.sh
@@ -16,7 +16,7 @@ function bdist_wheel_cmd {
     local abs_wheelhouse=$1
     python setup.py bdist_wheel $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
-    if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache --show-stats; fi
+    if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }
 
 if [ -n "$IS_OSX" ]; then

From d4a51981676eacd6763fac5b183e6267a4305610 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 02:29:59 +0300
Subject: [PATCH 156/566] Use latest cmake for the main build, too, with better
 Python support

---
 config.sh | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/config.sh b/config.sh
index af888179..3370d221 100644
--- a/config.sh
+++ b/config.sh
@@ -111,6 +111,10 @@ function pre_build {
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew install ffmpeg_opencv
+        #cmake is a build dependency of ffmpeg so a bottle should be present in cache
+        if (brew outdated | grep -qxF cmake) || ! (brew list | grep -qxF cmake); then
+            _brew_install_and_cache cmake 1 0
+        fi
     fi
 
     if [ -n "$CACHE_STAGE" ]; then

From e1523c845ed4f17029d7a97671ca49b630d3c6c7 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 23:55:12 +0300
Subject: [PATCH 157/566] JSON format change for formula without any bottles

---
 travis_osx_brew_cache.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 65d4f0a9..5eaefe42 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -285,7 +285,7 @@ function _brew_parse_package_info {
     revision=data["revision"]
     # in bottle''s json, revision is included into version; here, they are separate
     print data["versions"]["stable"]+("_"+str(revision) if revision else "")
-    bottle_data=data["bottle"]["stable"]
+    bottle_data=data["bottle"].get("stable",{"rebuild":"","files":{}})
     print bottle_data["rebuild"]
     print bottle_data["files"].get(sys.argv[2],{"sha256":"!?"})["sha256"]     #prevent losing trailing blank line to command substitution
     ' \

From c4286d26c3f9763a502e17c852855a4303e4c771 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Fri, 3 May 2019 22:34:38 +0300
Subject: [PATCH 158/566] Speed up repeat checks for the same deps

---
 travis_osx_brew_cache.sh | 85 +++++++++++++++++++++++-----------------
 1 file changed, 49 insertions(+), 36 deletions(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 5eaefe42..e3a69cc3 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -27,7 +27,8 @@ export HOMEBREW_NO_INSTALL_CLEANUP=1
 # see https://docs.brew.sh/Manpage , "info formula" section
 export HOMEBREW_NO_GITHUB_API=1
 
-
+#Packages already installed in the current session to avoid checking them again
+_BREW_ALREADY_INSTALLED='$'     #$ = illegal package name; a blank line would cause macos grep to swallow everything
 
 
 #Public functions
@@ -37,39 +38,8 @@ function brew_install_and_cache_within_time_limit {
     # use bottle if available, build and cache bottle if not.
     # Terminate and exit with status 1 if this takes too long.
     # Exit with status 2 on any other error.
-    ( set -eE -o pipefail; trap '{ sleep 3; exit 2; }' ERR
-
-    local PACKAGE TIME_LIMIT TIME_HARD_LIMIT TIME_START
-    PACKAGE="${1:?}" || exit 2
-    TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || exit 2
-    TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || exit 2
-    TIME_START=${4:-$BREW_TIME_START} || exit 2
-
-    local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
-    
-    if brew list --versions "$PACKAGE" >/dev/null && ! (brew outdated | grep -qxF "$PACKAGE"); then
-        echo "Already installed and the latest version: $PACKAGE"
-        return 0
-    fi
-
-    
-    _brew_is_bottle_available "$PACKAGE" KEG_ONLY || BUILD_FROM_SOURCE=1
-    [ -n "$BUILD_FROM_SOURCE" ] && INCLUDE_BUILD="--include-build" || true
-
-    # Whitespace is illegal in package names so converting all whitespace into single spaces due to no quotes is okay.
-    DEPS=`brew deps "$PACKAGE" $INCLUDE_BUILD` || exit 2
-    for dep in $DEPS; do
-        #TIME_LIMIT only has to be met if we'll be actually building the main project this iteration, i.e. after the "root" module installation
-        #While we don't know that yet, we can make better use of Travis-given time with a laxer limit
-        #We still can't overrun TIME_HARD_LIMIT as that would't leave time to save the cache
-        brew_install_and_cache_within_time_limit "$dep" $(((TIME_LIMIT+TIME_HARD_LIMIT)/2)) "$TIME_HARD_LIMIT" "$TIME_START" || exit $?
-    done
-
-    _brew_check_slow_building_ahead "$PACKAGE" "$TIME_START" "$TIME_HARD_LIMIT" || exit $?
-    _brew_install_and_cache "$PACKAGE" "$([[ -z "$BUILD_FROM_SOURCE" ]] && echo 1 || echo 0)" "$KEG_ONLY" || exit 2
-    _brew_check_elapsed_build_time "$TIME_START" "$TIME_LIMIT" || exit $?
-    ) \
-    || if test $? -eq 1; then brew_go_bootstrap_mode; return 1; else return 2; fi      #must run this in current process
+    _brew_install_and_cache_within_time_limit $@ \
+    || if test $? -eq 1; then brew_go_bootstrap_mode; return 1; else return 2; fi
 }
 
 function brew_add_local_bottles {
@@ -246,6 +216,46 @@ function brew_go_bootstrap_mode {
 
 #Internal functions
 
+function _brew_install_and_cache_within_time_limit {
+    # This fn is run with || so errexit can't be enabled
+
+    local PACKAGE TIME_LIMIT TIME_HARD_LIMIT TIME_START MARKED_INSTALLED
+    PACKAGE="${1:?}" || return 2
+    TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || return 2
+    TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || return 2
+    TIME_START=${4:-$BREW_TIME_START} || return 2
+
+    if grep -qxFf <(cat <<<"$_BREW_ALREADY_INSTALLED") <<<"$PACKAGE"; then
+        MARKED_INSTALLED=1
+    fi
+        
+    if [ -n "$MARKED_INSTALLED" ] || (brew list --versions "$PACKAGE" >/dev/null && ! (brew outdated | grep -qxF "$PACKAGE")); then
+        echo "Already installed and the latest version: $PACKAGE"
+        if [ -z "$MARKED_INSTALLED" ]; then _brew_mark_installed "$PACKAGE"; fi
+        return 0
+    fi
+    
+    local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
+    
+    _brew_is_bottle_available "$PACKAGE" KEG_ONLY || BUILD_FROM_SOURCE=1
+    [ -n "$BUILD_FROM_SOURCE" ] && INCLUDE_BUILD="--include-build" || true
+
+    # Whitespace is illegal in package names so converting all whitespace into single spaces due to no quotes is okay.
+    DEPS=`brew deps "$PACKAGE" $INCLUDE_BUILD` || return 2
+    DEPS=`grep -vxF <(cat <<<"$_BREW_ALREADY_INSTALLED") <<<"$DEPS"` || test $? -eq 1 || return 2
+    for dep in $DEPS; do
+        #TIME_LIMIT only has to be met if we'll be actually building the main project this iteration, i.e. after the "root" module installation
+        #While we don't know that yet, we can make better use of Travis-given time with a laxer limit
+        #We still can't overrun TIME_HARD_LIMIT as that would't leave time to save the cache
+        _brew_install_and_cache_within_time_limit "$dep" $(((TIME_LIMIT+TIME_HARD_LIMIT)/2)) "$TIME_HARD_LIMIT" "$TIME_START" || return $?
+    done
+
+    _brew_check_slow_building_ahead "$PACKAGE" "$TIME_START" "$TIME_HARD_LIMIT" || return $?
+    _brew_install_and_cache "$PACKAGE" "$([[ -z "$BUILD_FROM_SOURCE" ]] && echo 1 || echo 0)" "$KEG_ONLY" || return 2
+    _brew_check_elapsed_build_time "$TIME_START" "$TIME_LIMIT" || return $?
+}
+    
+
 function _brew_parse_bottle_json {
     # Parse JSON file resulting from `brew bottle --json`
     # and save data into specified variables
@@ -386,10 +396,13 @@ function _brew_install_and_cache {
         echo "$CACHED_BOTTLE" >"$BOTTLE_LINK"
         
     fi
+    
+    _brew_mark_installed "$PACKAGE"
 }
 
-
-
+function _brew_mark_installed {
+    _BREW_ALREADY_INSTALLED="$_BREW_ALREADY_INSTALLED"$'\n'"${1:?}"
+}
 
 function _brew_check_elapsed_build_time {
     # If time limit has been reached,

From 42b35191fae5c41cf028ae627ca47033e06ff1ea Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 4 May 2019 11:02:49 +0300
Subject: [PATCH 159/566] Add prefix to all files related to CI rather than
 project

---
 .travis.yml                                               | 3 ++-
 config.sh => travis_config.sh                             | 0
 multibuild_customize.sh => travis_multibuild_customize.sh | 0
 3 files changed, 2 insertions(+), 1 deletion(-)
 rename config.sh => travis_config.sh (100%)
 rename multibuild_customize.sh => travis_multibuild_customize.sh (100%)

diff --git a/.travis.yml b/.travis.yml
index 34d989f8..81d2331e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,6 +5,7 @@ env:
         - TEST_DEPENDS="numpy==1.11.1"
         # params to bdist_wheel. used to set osx build target.
         - BDIST_PARAMS=""
+        - CONFIG_PATH="travis_config.sh"
         - USE_CCACHE=1
         - PLAT=x86_64
         - UNICODE_WIDTH=32
@@ -663,7 +664,7 @@ before_install: |
     if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
     source multibuild/travis_steps.sh
     # This sets -x
-    source multibuild_customize.sh
+    source travis_multibuild_customize.sh
     echo $ENABLE_CONTRIB > contrib.enabled
     echo $ENABLE_HEADLESS > headless.enabled
 
diff --git a/config.sh b/travis_config.sh
similarity index 100%
rename from config.sh
rename to travis_config.sh
diff --git a/multibuild_customize.sh b/travis_multibuild_customize.sh
similarity index 100%
rename from multibuild_customize.sh
rename to travis_multibuild_customize.sh

From d6a45ba2ae322562e8731c27695b6e00528862f7 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 9 May 2019 01:14:29 +0300
Subject: [PATCH 160/566] (dummy commit to rerun checks)


From fac2703ffcc7ad810ce9a0af119d95bd03048fb9 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 13 Jun 2019 19:57:44 +0300
Subject: [PATCH 161/566] Revert "Use latest cmake for the main build, too,
 with better Python support

This reverts commit d4a51981676eacd6763fac5b183e6267a4305610.

cmake 3.14 can't find py3 installation when "python" points to Python 3 while cmake 3.9 can
---
 travis_config.sh | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index 3370d221..af888179 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -111,10 +111,6 @@ function pre_build {
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew install ffmpeg_opencv
-        #cmake is a build dependency of ffmpeg so a bottle should be present in cache
-        if (brew outdated | grep -qxF cmake) || ! (brew list | grep -qxF cmake); then
-            _brew_install_and_cache cmake 1 0
-        fi
     fi
 
     if [ -n "$CACHE_STAGE" ]; then

From f3c731aefa65be7dfebda4e887c345bbe41ede72 Mon Sep 17 00:00:00 2001
From: Christian Clauss <cclauss@me.com>
Date: Tue, 30 Jul 2019 08:27:45 +0200
Subject: [PATCH 162/566] Travis CI: Xenial is now the default Ubuntu in Travis

https://blog.travis-ci.com/2019-04-15-xenial-default-build-environment

Also: __sudo: required__ no longer is [Travis are now recommending removing the __sudo__ tag](https://blog.travis-ci.com/2018-11-19-required-linux-infrastructure-migration) because the sudo command is always available in Travis CI and there is no longer any way to turn it off.
---
 .travis.yml | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 81d2331e..d1efa36a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,11 +13,9 @@ env:
 
 # Host Python is never used
 language: generic
-# Required to invoke docker ourselves as per https://docs.travis-ci.com/user/docker/
-sudo: required
 services: docker
-# https://docs.travis-ci.com/user/reference/trusty/
-dist: trusty
+# https://docs.travis-ci.com/user/reference/xenial
+dist: xenial
 
 # Save some time, we and setup check them out on demand instead
 # https://docs.travis-ci.com/user/customizing-the-build/#Git-Clone-Depth

From 4b191f860257297be04e57213b0d981bcfb9a841 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 17 Aug 2019 16:08:13 +0300
Subject: [PATCH 163/566] Allow passing custom CMake arguments

---
 README.md | 30 ++++++++++++++++++++----------
 setup.py  |  6 ++++++
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md
index 10229096..0db6eb08 100644
--- a/README.md
+++ b/README.md
@@ -77,7 +77,10 @@ The aim of this repository is to provide means to package each new [OpenCV relea
 
 ### 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):
+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):
+
+0. In Linux and MacOS build: get OpenCV's optional C dependencies that we compile against
 
 1. Checkout repository and submodules
 
@@ -86,25 +89,32 @@ The project is structured like a normal Python package with a standard ``setup.p
    -  Contrib modules are also included as a submodule
 
 2. Find OpenCV version from the sources
-3. Install dependencies (numpy)
+3. Install Python dependencies
+
+   - ``setup.py`` installs the dependencies itself, so you need to run it in an environment
+     where you have the rights to install modules with Pip for the running Python
+
 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)
 
-5. Copy each ``.pyd/.so`` file to cv2 folder of this project and
-   generate wheel
+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
 
-   - Linux and macOS wheels are checked with auditwheel and delocate
+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)
 
-6. Install the generated wheel
-7. Test that Python can import the library and run some sanity checks
-8. Use twine to upload the generated wheel to PyPI (only in release builds)
+Steps 1--5 are handled by ``setup.py bdist_wheel``.
 
-The ``cv2.pyd/.so`` file is normally copied to site-packages. To avoid polluting the root folder this package wraps the statically built binary into cv2 package and ``__init__.py`` file in the package handles the import logic correctly.
+The build can be customized with environment variables.
+In addition to any variables that OpenCV's build accepts, we recognize:
 
-Since all packages use the same ``cv2`` namespace explained above, uninstall the other package before switching for example from ``opencv-python`` to ``opencv-contrib-python``.
+- ``ENABLE_CONTRIB`` and ``ENABLE_HEADLESS``. Set to ``1`` to build the contrib and/or headless version
+- ``CMAKE_ARGS``. Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build.
 
 ### Licensing
 
diff --git a/setup.py b/setup.py
index 65322dbc..1fbffa72 100644
--- a/setup.py
+++ b/setup.py
@@ -154,6 +154,12 @@ def main():
     if sys.platform.startswith('linux') and not x64:
         cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
 
+        
+    if 'CMAKE_ARGS' in os.environ:
+        import shlex
+        cmake_args.extend(shlex.split(os.environ['CMAKE_ARGS']))
+        del shlex
+        
     # ABI config variables are introduced in PEP 425
     if sys.version_info[:2] < (3, 2):
         import warnings

From eed0f0d1c7572e3cb69d9c45d14b2b2acbbe4bd6 Mon Sep 17 00:00:00 2001
From: Abhishek Thakur <abhi.una12@gmail.com>
Date: Sun, 18 Aug 2019 16:22:07 +0530
Subject: [PATCH 164/566] Added OpenSSL & various protocol support to FFmpeg
 backend (#229)

* Added OpenSSL & different protocol support to FFmpeg backend
- Fixed Docker dependencies (both x86 & x86-64)
- Fixes bug #204

* Additional Fixes
- updates to OpenSSL build from scratch
- removed specific protocol
- Added neccessary dependency

* Fixed ./Configure command

* Updates for docker images:
- Added perl build from scratch
- Fixed wrong/redundant dependencies/paths
- Fixed & updated openssl installation

* Fixed Empty continuation lines bug & added comments

* fix inconsitent spacing

* Don't add perl 5.10 to PATH

* fix syntax error

* Fixed OpenSSL build fails in i686 Dockerfile due to buggy perl source

* Fixing manylinux docker entrypoint for i686 in 32 bit images

* ENTRYPOINT not needed, it only affects "docker run" invocations

* manylinux1 provides better libcurl for cmake

* manylinux1 provides the toolchain and git

git install fails in i686, too

* cleanup tar invocations

* nasm is not installed in manylinux1

* detect i686 in openssl configure

* move perl to a separate subtree as it's a private dependency

* rm it after library build

* comment unusual openssl build step

* avoid redundant work in perl build

* build each library in a separate dockerfile command for easier debugging

* comment custom i686 step

* update dockerfile README

* opencv now bundles libjpeg-turbo

and the separate's onre buid fails dueto expired certificate at https://kent.dl.sourceforge.net
---
 docker/Dockerfile_i686   | 86 ++++++++++++++++++++++++----------------
 docker/Dockerfile_x86_64 | 83 +++++++++++++++++++++-----------------
 docker/README.md         |  3 +-
 3 files changed, 99 insertions(+), 73 deletions(-)

diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
index 62366543..98d70324 100644
--- a/docker/Dockerfile_i686
+++ b/docker/Dockerfile_i686
@@ -14,43 +14,74 @@ ENV QTDIR /opt/Qt4.8.7
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN curl -O -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
-	tar -zxf cmake-3.9.0.tar.gz && \
+	tar -xf cmake-3.9.0.tar.gz && \
 	cd cmake-3.9.0 && \
-	yum -y install curl-devel zlib-devel && \
+    true '#manylinux1 provides curl-devel equivalent and libcurl statically linked \
+         against the same newer OpenSSL as other source-built tools \
+         (1.0.2s as of this writing)' && \
+	yum -y install zlib-devel && \
 	./configure --system-curl && \
-	make && \
+	make -j4 && \
 	make install && \
 	cd .. && \
 	rm -rf cmake-3.9.0*
 
-RUN yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ libtool make mercurial pkgconfig zlib-devel -y && \
-	yum remove nasm -y && \
-	mkdir ~/ffmpeg_sources && \
-	cd ~/ffmpeg_sources && \
+# https://trac.ffmpeg.org/wiki/CompilationGuide/Centos#GettheDependencies
+# manylinux provides the toolchain and git; we provide cmake
+RUN yum install freetype-devel bzip2-devel zlib-devel -y && \
+    mkdir ~/ffmpeg_sources
+
+# Newer openssl configure requires newer perl
+RUN curl -O -L https://www.cpan.org/src/5.0/perl-5.20.1.tar.gz && \
+	tar -xf perl-5.20.1.tar.gz && \
+	cd perl-5.20.1 && \
+	./Configure -des -Dprefix="$HOME/openssl_build" && \
+	true '#perl build scripts do much redundant work \
+	     if running "make install" separately' && \
+	make install -j4 && \
+	cd .. && \
+	rm -rf perl-5.20.1*
+
+RUN cd ~/ffmpeg_sources && \
+	curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
+	tar -xf OpenSSL_1_1_1c.tar.gz && \
+	cd openssl-OpenSSL_1_1_1c && \
+    true '#in i686, ./config detects x64 in i686 without linux32 \
+         when run from "docker build"' && \
+	PERL="$HOME/openssl_build/bin/perl" linux32 ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+	make -j4 && \
+    true '#skip installing documentation' && \
+	make install_sw && \
+    rm -rf ~/openssl_build
+
+RUN cd ~/ffmpeg_sources && \
 	curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
-	tar xjvf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+	tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
 	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
 	make -j4 && \
-	make install && \
-	cd ~/ffmpeg_sources && \
+	make install
+
+RUN cd ~/ffmpeg_sources && \
 	curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
-	tar xzvf yasm-1.3.0.tar.gz && \
+	tar -xf yasm-1.3.0.tar.gz && \
 	cd yasm-1.3.0 && \
 	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
 	make -j4 && \
-	make install && \
-	cd ~/ffmpeg_sources && \
+	make install
+
+RUN cd ~/ffmpeg_sources && \
 	git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
 	cd libvpx && \
 	./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
 	make -j4 && \
-	make install && \
-	cd ~/ffmpeg_sources && \
+	make install
+
+RUN cd ~/ffmpeg_sources && \
 	curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
-	tar xjvf ffmpeg-snapshot.tar.bz2 && \
+	tar -xf ffmpeg-snapshot.tar.bz2 && \
 	cd ffmpeg && \
 	PATH=~/bin:$PATH && \
-	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
 	make -j4 && \
 	make install && \
 	echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
@@ -60,30 +91,15 @@ RUN yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ libtool
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 
-RUN mkdir libjpeg-turbo && \
-	cd libjpeg-turbo && \
-	export PATH=~/bin:$PATH && \
-	curl -L https://kent.dl.sourceforge.net/project/libjpeg-turbo/1.5.3/libjpeg-turbo-1.5.3.tar.gz > libjpeg-turbo-1.5.3.tar.gz && \
-	tar xzvf libjpeg-turbo-1.5.3.tar.gz && \
-	cd libjpeg-turbo-1.5.3 && \
-	export CFLAGS="-fPIC" && \
-	export CXXFLAGS="-fPIC" && \
-	autoreconf -fiv && \
-	./configure --host=i686-pc-linux-gnu && \
-	make && \
-	make install && \
-	cd ../../ && \
-	rm -rf libjpeg-turbo
-
-ENV JPEG_LIBRARY /opt/libjpeg-turbo/lib32/libjpeg.a
-ENV JPEG_INCLUDE_DIR /opt/libjpeg-turbo/include
-
 RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/videodev2.h && \
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
 	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
 
+#in i686, yum metadata ends up with slightly wrong timestamps
+#which inhibits its update
+#https://github.com/skvark/opencv-python/issues/148
 RUN yum clean all
 
 ENV PATH "$HOME/bin:$PATH"
diff --git a/docker/Dockerfile_x86_64 b/docker/Dockerfile_x86_64
index e9de76e8..81b59974 100644
--- a/docker/Dockerfile_x86_64
+++ b/docker/Dockerfile_x86_64
@@ -14,43 +14,72 @@ ENV QTDIR /opt/Qt4.8.7
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN curl -O -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
-	tar -zxf cmake-3.9.0.tar.gz && \
+	tar -xf cmake-3.9.0.tar.gz && \
 	cd cmake-3.9.0 && \
-	yum -y install curl-devel zlib-devel && \
+    true '#manylinux1 provides curl-devel equivalent and libcurl statically linked \
+         against the same newer OpenSSL as other source-built tools \
+         (1.0.2s as of this writing)' && \
+	yum -y install zlib-devel && \
 	./configure --system-curl && \
-	make && \
+	make -j4 && \
 	make install && \
 	cd .. && \
 	rm -rf cmake-3.9.0*
 
-RUN yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ libtool make mercurial pkgconfig zlib-devel -y && \
-	yum remove nasm -y && \
-	mkdir ~/ffmpeg_sources && \
-	cd ~/ffmpeg_sources && \
+# https://trac.ffmpeg.org/wiki/CompilationGuide/Centos#GettheDependencies
+# manylinux provides the toolchain and git; we provide cmake
+RUN yum install freetype-devel bzip2-devel zlib-devel -y && \
+    mkdir ~/ffmpeg_sources
+
+# Newer openssl configure requires newer perl
+RUN curl -O -L https://www.cpan.org/src/5.0/perl-5.20.1.tar.gz && \
+	tar -xf perl-5.20.1.tar.gz && \
+	cd perl-5.20.1 && \
+	./Configure -des -Dprefix="$HOME/openssl_build" && \
+	true '#perl build scripts do much redundant work \
+	     if running "make install" separately' && \
+	make install -j4 && \
+	cd .. && \
+	rm -rf perl-5.20.1*
+
+RUN cd ~/ffmpeg_sources && \
+	curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
+	tar -xf OpenSSL_1_1_1c.tar.gz && \
+	cd openssl-OpenSSL_1_1_1c && \
+	PERL="$HOME/openssl_build/bin/perl" ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+	make -j4 && \
+    true '#skip installing documentation' && \
+	make install_sw && \
+    rm -rf ~/openssl_build
+
+RUN cd ~/ffmpeg_sources && \
 	curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
-	tar xjvf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+	tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
 	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
 	make -j4 && \
-	make install && \
-	cd ~/ffmpeg_sources && \
+	make install
+
+RUN cd ~/ffmpeg_sources && \
 	curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
-	tar xzvf yasm-1.3.0.tar.gz && \
+	tar -xf yasm-1.3.0.tar.gz && \
 	cd yasm-1.3.0 && \
 	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
 	make -j4 && \
-	make install && \
-	cd ~/ffmpeg_sources && \
+	make install
+
+RUN cd ~/ffmpeg_sources && \
 	git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
 	cd libvpx && \
 	./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
 	make -j4 && \
-	make install && \
-	cd ~/ffmpeg_sources && \
+	make install
+
+RUN cd ~/ffmpeg_sources && \
 	curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
-	tar xjvf ffmpeg-snapshot.tar.bz2 && \
+	tar -xf ffmpeg-snapshot.tar.bz2 && \
 	cd ffmpeg && \
 	PATH=~/bin:$PATH && \
-	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
 	make -j4 && \
 	make install && \
 	echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
@@ -60,28 +89,10 @@ RUN yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ libtool
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 
-RUN mkdir libjpeg-turbo && \
-	cd libjpeg-turbo && \
-	export PATH=~/bin:$PATH && \
-	curl -L https://kent.dl.sourceforge.net/project/libjpeg-turbo/1.5.3/libjpeg-turbo-1.5.3.tar.gz > libjpeg-turbo-1.5.3.tar.gz && \
-	tar xzvf libjpeg-turbo-1.5.3.tar.gz && \
-	cd libjpeg-turbo-1.5.3 && \
-	export CFLAGS="-fPIC" && \
-	export CXXFLAGS="-fPIC" && \
-	autoreconf -fiv && \
-	./configure && \
-	make && \
-	make install && \
-	cd ../../ && \
-	rm -rf libjpeg-turbo
-
-ENV JPEG_LIBRARY /opt/libjpeg-turbo/lib64/libjpeg.a
-ENV JPEG_INCLUDE_DIR /opt/libjpeg-turbo/include
-
 RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/videodev2.h && \
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
 	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
 
-ENV PATH "$HOME/bin:$PATH"
\ No newline at end of file
+ENV PATH "$HOME/bin:$PATH"
diff --git a/docker/README.md b/docker/README.md
index 2e8602bf..e31d7a07 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -10,6 +10,5 @@ The images have following extra software installed:
 
 - Qt 4.8.7
 - Cmake 3.9.0
-- FFmpeg with libvpx (latest snapshots at the build time)
-- libjpeg-turbo 1.5.3
+- FFmpeg with libvpx (latest snapshots at the build time) and recent openssl
 - Some missing headers included from more recent Linux to be able to enable V4L / V4L2 support in OpenCV
\ No newline at end of file

From 5a2f82ec73ca9f473437f45197f6bfac264cf20e Mon Sep 17 00:00:00 2001
From: native-api <vano@mail.mipt.ru>
Date: Sun, 18 Aug 2019 13:53:51 +0300
Subject: [PATCH 165/566] Including a custom libjpeg is no longer needed (#231)

* Including a custom libjpeg is no longer needed

Since https://github.com/opencv/opencv/pull/11497, OpenCV bundles its own

* (dummy commit to trigger rebuild)
---
 setup.py | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/setup.py b/setup.py
index 65322dbc..e5d43a34 100644
--- a/setup.py
+++ b/setup.py
@@ -133,13 +133,6 @@ def main():
         cmake_args.append("-DWITH_V4L=ON")
         cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 
-        if all(v in os.environ for v in ('JPEG_INCLUDE_DIR', 'JPEG_LIBRARY')):
-            cmake_args += [
-                "-DBUILD_JPEG=OFF",
-                "-DJPEG_INCLUDE_DIR=%s" % os.environ['JPEG_INCLUDE_DIR'],
-                "-DJPEG_LIBRARY=%s" % os.environ['JPEG_LIBRARY']
-            ]
-
     # Fixes for macOS builds
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see

From 4ca11a2cae92ac28fd78411601ceba98834c95c1 Mon Sep 17 00:00:00 2001
From: native-api <vano@mail.mipt.ru>
Date: Sun, 18 Aug 2019 14:03:02 +0300
Subject: [PATCH 166/566] Use Travis workspaces (#228)

* Use one job for MacOS Homebrew builds cache with Travis workspaces

* Brew build job needs to both feed to other jobs and cache between builds

* Move Linux jobs to the Final stage

With only 1 OSX job in S1, the Linux part is now the critical path and holds the build time back
---
 .travis.yml | 190 +++++++++++++++++++++++-----------------------------
 1 file changed, 84 insertions(+), 106 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index d1efa36a..e6213b1c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,11 +25,6 @@ git:
 # https://docs.travis-ci.com/user/caching
 cache:
   directories:
-    # https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
-    - $HOME/Library/Caches/Homebrew
-    - /usr/local/Homebrew/
-    # used in OSX custom build script dealing with local bottle caching
-    - $HOME/local_bottle_metadata
     # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
     - $HOME/.ccache
 
@@ -43,222 +38,205 @@ matrix:
   fast_finish: true
   include:
 
+    - os: osx
+      osx_image: xcode8.3
+      stage: s1
+      workspaces:
+        create:
+          name: brew_cache
+          paths:
+            # https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
+            - $HOME/Library/Caches/Homebrew
+            - /usr/local/Homebrew/
+            # used in OSX custom build script dealing with local bottle caching
+            - $HOME/local_bottle_metadata
+      #workspaces share within the same build, cache shares between builds
+      cache:
+        directories:
+          # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
+          - $HOME/.ccache
+          # https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
+          - $HOME/Library/Caches/Homebrew
+          - /usr/local/Homebrew/
+          # used in OSX custom build script dealing with local bottle caching
+          - $HOME/local_bottle_metadata
+
     # default builds for MacOS
-    - &osx-10
+      #further jobs in the list will use the same stage until the next assignment
+    - stage: final
       os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-10
-      stage: s1
-    - &osx-30
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-30
-      stage: s1
-    - &osx-40
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-40
-      stage: s1
-    - &osx-50
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-50
-      stage: s1
-    - &osx-60
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
-      stage: final
-    - <<: *osx-60
-      stage: s1
+      workspaces:
+        use: brew_cache
 
     # headless builds for MacOS
-    - &osx-70
-      os: osx
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-70
-      stage: s1
-    - &osx-80
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-80
-      stage: s1
-    - &osx-90
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-90
-      stage: s1
-    - &osx-100
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-100
-      stage: s1
-    - &osx-110
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
-      stage: final
-    - <<: *osx-110
-      stage: s1
+      workspaces:
+        use: brew_cache
 
     # Contrib builds for MacOS
-    - &osx-120
-      os: osx
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-120
-      stage: s1
-    - &osx-130
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-130
-      stage: s1
-    - &osx-140
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-140
-      stage: s1
-    - &osx-150
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-150
-      stage: s1
-    - &osx-160
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
-      stage: final
-    - <<: *osx-160
-      stage: s1
+      workspaces:
+        use: brew_cache
 
     # headless contrib builds for MacOS
-    - &osx-170
-      os: osx
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-170
-      stage: s1
-    - &osx-180
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-180
-      stage: s1
-    - &osx-190
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-190
-      stage: s1
-    - &osx-200
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-200
-      stage: s1
-    - &osx-210
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
-      stage: final
-    - <<: *osx-210
-      stage: s1
+      workspaces:
+        use: brew_cache
 
     # default builds for Linux
     - os: linux
-      # the following jobs will use the same stage name by default
-      stage: s1
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0

From 87fbd5685a35b38cc25f1329c7ae8ccd1e689c71 Mon Sep 17 00:00:00 2001
From: native-api <vano@mail.mipt.ru>
Date: Tue, 20 Aug 2019 19:54:45 +0300
Subject: [PATCH 167/566] Don't build unused Qt features; use all cores (#236)

* Don't build unused Qt features; use all cores

* cmake does bootstrapping, too; comment unclear steps

* Use Docker comment syntax

* tab to space
---
 docker/Dockerfile_i686   | 140 +++++++++++++++++++++------------------
 docker/Dockerfile_x86_64 | 136 +++++++++++++++++++------------------
 2 files changed, 146 insertions(+), 130 deletions(-)

diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
index 98d70324..cc97e661 100644
--- a/docker/Dockerfile_i686
+++ b/docker/Dockerfile_i686
@@ -1,30 +1,38 @@
 FROM quay.io/pypa/manylinux1_i686:latest
 
 RUN curl -O -L https://download.qt.io/archive/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz && \
-	tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
-	cd qt-everywhere* && \
-	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license && \
-	gmake -j5 && \
-	gmake install && \
-	cd .. && \
-	rm -rf qt-everywhere-opensource-src-4.8.7 && \
-	rm qt-everywhere-opensource-src-4.8.7.tar.gz
+    tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
+    cd qt-everywhere* && \
+    #configure does a bootstrap make under the hood
+    #manylinux1 is too old to have `nproc`
+    export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
+    #OpenCV only links against QtCore, QtGui, QtTest
+    ./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license \
+    -no-sql-sqlite -no-qt3support -no-xmlpatterns -no-multimedia \
+    -no-webkit -no-script -no-declarative -no-dbus -make libs && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf qt-everywhere-opensource-src-4.8.7 && \
+    rm qt-everywhere-opensource-src-4.8.7.tar.gz
 
 ENV QTDIR /opt/Qt4.8.7
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN curl -O -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
-	tar -xf cmake-3.9.0.tar.gz && \
-	cd cmake-3.9.0 && \
-    true '#manylinux1 provides curl-devel equivalent and libcurl statically linked \
-         against the same newer OpenSSL as other source-built tools \
-         (1.0.2s as of this writing)' && \
-	yum -y install zlib-devel && \
-	./configure --system-curl && \
-	make -j4 && \
-	make install && \
-	cd .. && \
-	rm -rf cmake-3.9.0*
+    tar -xf cmake-3.9.0.tar.gz && \
+    cd cmake-3.9.0 && \
+    #manylinux1 provides curl-devel equivalent and libcurl statically linked
+    # against the same newer OpenSSL as other source-built tools
+    # (1.0.2s as of this writing)
+    yum -y install zlib-devel && \
+    #configure does a bootstrap make under the hood
+    export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
+    ./configure --system-curl && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf cmake-3.9.0*
 
 # https://trac.ffmpeg.org/wiki/CompilationGuide/Centos#GettheDependencies
 # manylinux provides the toolchain and git; we provide cmake
@@ -33,69 +41,69 @@ RUN yum install freetype-devel bzip2-devel zlib-devel -y && \
 
 # Newer openssl configure requires newer perl
 RUN curl -O -L https://www.cpan.org/src/5.0/perl-5.20.1.tar.gz && \
-	tar -xf perl-5.20.1.tar.gz && \
-	cd perl-5.20.1 && \
-	./Configure -des -Dprefix="$HOME/openssl_build" && \
-	true '#perl build scripts do much redundant work \
-	     if running "make install" separately' && \
-	make install -j4 && \
-	cd .. && \
-	rm -rf perl-5.20.1*
+    tar -xf perl-5.20.1.tar.gz && \
+    cd perl-5.20.1 && \
+    ./Configure -des -Dprefix="$HOME/openssl_build" && \
+    #perl build scripts do much redundant work
+    # if running "make install" separately
+    make install -j$(getconf _NPROCESSORS_ONLN) && \
+    cd .. && \
+    rm -rf perl-5.20.1*
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
-	tar -xf OpenSSL_1_1_1c.tar.gz && \
-	cd openssl-OpenSSL_1_1_1c && \
-    true '#in i686, ./config detects x64 in i686 without linux32 \
-         when run from "docker build"' && \
-	PERL="$HOME/openssl_build/bin/perl" linux32 ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
-	make -j4 && \
-    true '#skip installing documentation' && \
-	make install_sw && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
+    tar -xf OpenSSL_1_1_1c.tar.gz && \
+    cd openssl-OpenSSL_1_1_1c && \
+    #in i686, ./config detects x64 in i686 container without linux32
+    # when run from "docker build"
+    PERL="$HOME/openssl_build/bin/perl" linux32 ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    #skip installing documentation
+    make install_sw && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
-	tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
-	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
-	make -j4 && \
-	make install
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
+    tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
-	tar -xf yasm-1.3.0.tar.gz && \
-	cd yasm-1.3.0 && \
-	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
-	make -j4 && \
-	make install
+    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
+    tar -xf yasm-1.3.0.tar.gz && \
+    cd yasm-1.3.0 && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
 
 RUN cd ~/ffmpeg_sources && \
-	git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
-	cd libvpx && \
-	./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
-	make -j4 && \
-	make install
+    git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
+    cd libvpx && \
+    ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
-	tar -xf ffmpeg-snapshot.tar.bz2 && \
-	cd ffmpeg && \
-	PATH=~/bin:$PATH && \
-	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
-	make -j4 && \
-	make install && \
-	echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
-	ldconfig && \
-	rm -rf ~/ffmpeg_sources
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
+    tar -xf ffmpeg-snapshot.tar.bz2 && \
+    cd ffmpeg && \
+    PATH=~/bin:$PATH && \
+    PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install && \
+    echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
+    ldconfig && \
+    rm -rf ~/ffmpeg_sources
 
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 
 RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/videodev2.h && \
-	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
-	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
-	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
-	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
+    curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
+    curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
+    curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
+    mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
 
 #in i686, yum metadata ends up with slightly wrong timestamps
 #which inhibits its update
diff --git a/docker/Dockerfile_x86_64 b/docker/Dockerfile_x86_64
index 81b59974..f7b0b081 100644
--- a/docker/Dockerfile_x86_64
+++ b/docker/Dockerfile_x86_64
@@ -1,30 +1,38 @@
 FROM quay.io/pypa/manylinux1_x86_64:latest
 
 RUN curl -O -L https://download.qt.io/archive/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz && \
-	tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
-	cd qt-everywhere* && \
-	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license && \
-	gmake -j5 && \
-	gmake install && \
-	cd .. && \
-	rm -rf qt-everywhere-opensource-src-4.8.7 && \
-	rm qt-everywhere-opensource-src-4.8.7.tar.gz
+    tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
+    cd qt-everywhere* && \
+    #configure does a bootstrap make under the hood
+    #manylinux1 is too old to have `nproc`
+    export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
+    #OpenCV only links against QtCore, QtGui, QtTest
+    ./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license \
+    -no-sql-sqlite -no-qt3support -no-xmlpatterns -no-multimedia \
+    -no-webkit -no-script -no-declarative -no-dbus -make libs && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf qt-everywhere-opensource-src-4.8.7 && \
+    rm qt-everywhere-opensource-src-4.8.7.tar.gz
 
 ENV QTDIR /opt/Qt4.8.7
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN curl -O -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
-	tar -xf cmake-3.9.0.tar.gz && \
-	cd cmake-3.9.0 && \
-    true '#manylinux1 provides curl-devel equivalent and libcurl statically linked \
-         against the same newer OpenSSL as other source-built tools \
-         (1.0.2s as of this writing)' && \
-	yum -y install zlib-devel && \
-	./configure --system-curl && \
-	make -j4 && \
-	make install && \
-	cd .. && \
-	rm -rf cmake-3.9.0*
+    tar -xf cmake-3.9.0.tar.gz && \
+    cd cmake-3.9.0 && \
+    #manylinux1 provides curl-devel equivalent and libcurl statically linked
+    # against the same newer OpenSSL as other source-built tools
+    # (1.0.2s as of this writing)
+    yum -y install zlib-devel && \
+    #configure does a bootstrap make under the hood
+    export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
+    ./configure --system-curl && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf cmake-3.9.0*
 
 # https://trac.ffmpeg.org/wiki/CompilationGuide/Centos#GettheDependencies
 # manylinux provides the toolchain and git; we provide cmake
@@ -33,66 +41,66 @@ RUN yum install freetype-devel bzip2-devel zlib-devel -y && \
 
 # Newer openssl configure requires newer perl
 RUN curl -O -L https://www.cpan.org/src/5.0/perl-5.20.1.tar.gz && \
-	tar -xf perl-5.20.1.tar.gz && \
-	cd perl-5.20.1 && \
-	./Configure -des -Dprefix="$HOME/openssl_build" && \
-	true '#perl build scripts do much redundant work \
-	     if running "make install" separately' && \
-	make install -j4 && \
-	cd .. && \
-	rm -rf perl-5.20.1*
+    tar -xf perl-5.20.1.tar.gz && \
+    cd perl-5.20.1 && \
+    ./Configure -des -Dprefix="$HOME/openssl_build" && \
+    #perl build scripts do much redundant work
+    # if running "make install" separately
+    make install -j$(getconf _NPROCESSORS_ONLN) && \
+    cd .. && \
+    rm -rf perl-5.20.1*
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
-	tar -xf OpenSSL_1_1_1c.tar.gz && \
-	cd openssl-OpenSSL_1_1_1c && \
-	PERL="$HOME/openssl_build/bin/perl" ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
-	make -j4 && \
-    true '#skip installing documentation' && \
-	make install_sw && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
+    tar -xf OpenSSL_1_1_1c.tar.gz && \
+    cd openssl-OpenSSL_1_1_1c && \
+    PERL="$HOME/openssl_build/bin/perl" ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    #skip installing documentation
+    make install_sw && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
-	tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
-	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
-	make -j4 && \
-	make install
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
+    tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
-	tar -xf yasm-1.3.0.tar.gz && \
-	cd yasm-1.3.0 && \
-	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
-	make -j4 && \
-	make install
+    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
+    tar -xf yasm-1.3.0.tar.gz && \
+    cd yasm-1.3.0 && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
 
 RUN cd ~/ffmpeg_sources && \
-	git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
-	cd libvpx && \
-	./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
-	make -j4 && \
-	make install
+    git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
+    cd libvpx && \
+    ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
-	tar -xf ffmpeg-snapshot.tar.bz2 && \
-	cd ffmpeg && \
-	PATH=~/bin:$PATH && \
-	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
-	make -j4 && \
-	make install && \
-	echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
-	ldconfig && \
-	rm -rf ~/ffmpeg_sources
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
+    tar -xf ffmpeg-snapshot.tar.bz2 && \
+    cd ffmpeg && \
+    PATH=~/bin:$PATH && \
+    PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install && \
+    echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
+    ldconfig && \
+    rm -rf ~/ffmpeg_sources
 
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 
 RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/videodev2.h && \
-	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
-	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
-	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
-	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
+    curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
+    curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
+    curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
+    mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
 
 ENV PATH "$HOME/bin:$PATH"

From 288a9d3454f55d8ef0ca0dd6b6382d1f9f2abb01 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 22 Aug 2019 20:04:24 +0300
Subject: [PATCH 168/566] bump OpenCV version to 4.1.1 (manylinux images have
 been rebuilt with updated Dockerfiles)

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 371bba8f..ddbd10c0 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 371bba8f54560b374fbcd47e7e02f015ac4969ad
+Subproject commit ddbd10c0019f3ee5f43b7902d47e7fc4303a6574
diff --git a/opencv_contrib b/opencv_contrib
index 2c32791a..0915b7ea 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 2c32791a9c500343568a21ea34bf2daeac2adae7
+Subproject commit 0915b7eaddba3c06d83e201c9a7595e73801f417

From a145e59b879f3e4e5bcf735ed78178785ae67710 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 22 Aug 2019 21:25:37 +0300
Subject: [PATCH 169/566] update ffmpeg dll name

---
 setup.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/setup.py b/setup.py
index 13fcd5b9..09950002 100644
--- a/setup.py
+++ b/setup.py
@@ -76,7 +76,7 @@ def main():
     # Path regexes with forward slashes relative to CMake install dir.
     rearrange_cmake_output_data = {
 
-        'cv2': ([r'bin/opencv_ffmpeg\d{3}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else []) +
+        'cv2': ([r'bin/opencv_videoio_ffmpeg\d{3}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else []) +
         # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
         # Naming conventions vary so widely between versions and OSes
         # had to give up on checking them.
@@ -102,7 +102,7 @@ def main():
         # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
         "-DPYTHON%d_EXECUTABLE=%s" % (sys.version_info[0], sys.executable),
         "-DBUILD_opencv_python%d=ON" % sys.version_info[0],
-        
+
         # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
         "-DOPENCV_SKIP_PYTHON_LOADER=ON",
         # Relative dir to install the built module to in the build tree.
@@ -111,7 +111,7 @@ def main():
         # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
         # and skbuild bails out on seeing that
         "-DINSTALL_CREATE_DISTRIB=ON",
-        
+
         # See opencv/CMakeLists.txt for options and defaults
         "-DBUILD_opencv_apps=OFF",
         "-DBUILD_SHARED_LIBS=OFF",
@@ -147,12 +147,12 @@ def main():
     if sys.platform.startswith('linux') and not x64:
         cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
 
-        
+
     if 'CMAKE_ARGS' in os.environ:
         import shlex
         cmake_args.extend(shlex.split(os.environ['CMAKE_ARGS']))
         del shlex
-        
+
     # ABI config variables are introduced in PEP 425
     if sys.version_info[:2] < (3, 2):
         import warnings

From 2700ec938f998210add5eb65f9387a332db29cc9 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 22 Aug 2019 21:49:00 +0300
Subject: [PATCH 170/566] opencv 4.1.1 does not seem to support macOS 10.7
 anymore, bump to 10.8

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 09950002..ddf46c56 100644
--- a/setup.py
+++ b/setup.py
@@ -138,7 +138,7 @@ def main():
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
         cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
-        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7")
+        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.8")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with

From 510a5a4de0b4817aa52644c7a7cd26f522885d2c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 23 Aug 2019 14:43:20 +0300
Subject: [PATCH 171/566] patch OpenEXR on 32-bit Linux

---
 patches/patchOpenEXR | 288 +++++++++++++++++++++++++++++++++++++++++++
 setup.py             |   2 +
 2 files changed, 290 insertions(+)
 create mode 100644 patches/patchOpenEXR

diff --git a/patches/patchOpenEXR b/patches/patchOpenEXR
new file mode 100644
index 00000000..52dba087
--- /dev/null
+++ b/patches/patchOpenEXR
@@ -0,0 +1,288 @@
+diff -ruN opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp
+--- opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-22 20:02:54.769176800 +0300
++++ opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-23 14:31:17.103949100 +0300
+@@ -1,138 +1,146 @@
+-///////////////////////////////////////////////////////////////////////////
+-//
+-// Copyright (c) 2009-2014 DreamWorks Animation LLC. 
+-//
+-// All rights reserved.
+-//
+-// Redistribution and use in source and binary forms, with or without
+-// modification, are permitted provided that the following conditions are
+-// met:
+-// *       Redistributions of source code must retain the above copyright
+-// notice, this list of conditions and the following disclaimer.
+-// *       Redistributions in binary form must reproduce the above
+-// copyright notice, this list of conditions and the following disclaimer
+-// in the documentation and/or other materials provided with the
+-// distribution.
+-// *       Neither the name of DreamWorks Animation nor the names of
+-// its contributors may be used to endorse or promote products derived
+-// from this software without specific prior written permission.
+-//
+-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-//
+-///////////////////////////////////////////////////////////////////////////
+-
+-#include "ImfSimd.h"
+-#include "ImfSystemSpecific.h"
+-#include "ImfNamespace.h"
+-#include "OpenEXRConfig.h"
+-
+-OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
+-
+-namespace {
+-#if defined(IMF_HAVE_SSE2) && defined(__GNUC__) && !defined(__ANDROID__)
+-
+-    // Helper functions for gcc + SSE enabled
+-    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
+-    {
+-        __asm__ __volatile__ (
+-            "cpuid"
+-            : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) 
+-            : /* Input   */ "a"(n)
+-            : /* Clobber */);
+-    }
+-
+-#else // IMF_HAVE_SSE2 && __GNUC__
+-
+-    // Helper functions for generic compiler - all disabled
+-    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
+-    {
+-        eax = ebx = ecx = edx = 0;
+-    }
+-
+-#endif // IMF_HAVE_SSE2 && __GNUC__
+-
+-
+-#ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
+-
+-    void xgetbv(int n, int &eax, int &edx)
+-    {
+-        __asm__ __volatile__ (
+-            "xgetbv"
+-            : /* Output  */ "=a"(eax), "=d"(edx) 
+-            : /* Input   */ "c"(n)
+-            : /* Clobber */);
+-    }
+-
+-#else //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
+-
+-    void xgetbv(int n, int &eax, int &edx)
+-    {
+-        eax = edx = 0;
+-    }
+-
+-#endif //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
+-
+-} // namespace 
+-
+-CpuId::CpuId():
+-    sse2(false), 
+-    sse3(false), 
+-    ssse3(false),
+-    sse4_1(false), 
+-    sse4_2(false), 
+-    avx(false), 
+-    f16c(false)
+-{
+-    bool osxsave = false;
+-    int  max     = 0;
+-    int  eax, ebx, ecx, edx;
+-
+-    cpuid(0, max, ebx, ecx, edx);
+-    if (max > 0)
+-    {
+-        cpuid(1, eax, ebx, ecx, edx);
+-        sse2    = ( edx & (1<<26) );
+-        sse3    = ( ecx & (1<< 0) );
+-        ssse3   = ( ecx & (1<< 9) );
+-        sse4_1  = ( ecx & (1<<19) );
+-        sse4_2  = ( ecx & (1<<20) );
+-        osxsave = ( ecx & (1<<27) );
+-        avx     = ( ecx & (1<<28) );
+-        f16c    = ( ecx & (1<<29) );
+-
+-        if (!osxsave)
+-        {
+-            avx = f16c = false;
+-        }
+-        else
+-        {
+-            xgetbv(0, eax, edx);
+-            // eax bit 1 - SSE managed, bit 2 - AVX managed
+-            if ((eax & 6) != 6)
+-            {
+-                avx = f16c = false;
+-            }
+-        }
+-    }
+-
+-#if defined(IMF_HAVE_SSE2) && defined(__ANDROID__)
+-    sse2 = true;
+-    sse3 = true;
+-#ifdef __x86_64__
+-    ssse3 = true;
+-    sse4_1 = true;
+-#endif
+-#endif
+-}
+-
+-OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
++///////////////////////////////////////////////////////////////////////////
++//
++// Copyright (c) 2009-2014 DreamWorks Animation LLC.
++//
++// All rights reserved.
++//
++// Redistribution and use in source and binary forms, with or without
++// modification, are permitted provided that the following conditions are
++// met:
++// *       Redistributions of source code must retain the above copyright
++// notice, this list of conditions and the following disclaimer.
++// *       Redistributions in binary form must reproduce the above
++// copyright notice, this list of conditions and the following disclaimer
++// in the documentation and/or other materials provided with the
++// distribution.
++// *       Neither the name of DreamWorks Animation nor the names of
++// its contributors may be used to endorse or promote products derived
++// from this software without specific prior written permission.
++//
++// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
++// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
++// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
++// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
++// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
++// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
++// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
++// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
++// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
++// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
++//
++///////////////////////////////////////////////////////////////////////////
++
++#include "ImfSimd.h"
++#include "ImfSystemSpecific.h"
++#include "ImfNamespace.h"
++#include "OpenEXRConfig.h"
++
++OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
++
++namespace {
++#if defined(IMF_HAVE_SSE2) && defined(__GNUC__) && !defined(__ANDROID__)
++
++    // Helper functions for gcc + SSE enabled
++    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
++    {
++		#ifdef __i386__
++	        __asm__ __volatile__ (
++	            "pushl %%ebx; cpuid; movl %%ebx, %0; popl %%ebx"
++	            : /* Output  */ "=m"(ebx), "=a"(eax), "=c"(ecx), "=d"(edx)
++	            : /* Input   */ "a"(n)
++	            : /* Clobber */);
++		#else
++	         __asm__ __volatile__ (
++	             "cpuid"
++	             : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
++	             : /* Input   */ "a"(n)
++	             : /* Clobber */);
++		#endif
++    }
++
++#else // IMF_HAVE_SSE2 && __GNUC__
++
++    // Helper functions for generic compiler - all disabled
++    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
++    {
++        eax = ebx = ecx = edx = 0;
++    }
++
++#endif // IMF_HAVE_SSE2 && __GNUC__
++
++
++#ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
++
++    void xgetbv(int n, int &eax, int &edx)
++    {
++        __asm__ __volatile__ (
++            "xgetbv"
++            : /* Output  */ "=a"(eax), "=d"(edx)
++            : /* Input   */ "c"(n)
++            : /* Clobber */);
++    }
++
++#else //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
++
++    void xgetbv(int n, int &eax, int &edx)
++    {
++        eax = edx = 0;
++    }
++
++#endif //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
++
++} // namespace
++
++CpuId::CpuId():
++    sse2(false),
++    sse3(false),
++    ssse3(false),
++    sse4_1(false),
++    sse4_2(false),
++    avx(false),
++    f16c(false)
++{
++    bool osxsave = false;
++    int  max     = 0;
++    int  eax, ebx, ecx, edx;
++
++    cpuid(0, max, ebx, ecx, edx);
++    if (max > 0)
++    {
++        cpuid(1, eax, ebx, ecx, edx);
++        sse2    = ( edx & (1<<26) );
++        sse3    = ( ecx & (1<< 0) );
++        ssse3   = ( ecx & (1<< 9) );
++        sse4_1  = ( ecx & (1<<19) );
++        sse4_2  = ( ecx & (1<<20) );
++        osxsave = ( ecx & (1<<27) );
++        avx     = ( ecx & (1<<28) );
++        f16c    = ( ecx & (1<<29) );
++
++        if (!osxsave)
++        {
++            avx = f16c = false;
++        }
++        else
++        {
++            xgetbv(0, eax, edx);
++            // eax bit 1 - SSE managed, bit 2 - AVX managed
++            if ((eax & 6) != 6)
++            {
++                avx = f16c = false;
++            }
++        }
++    }
++
++#if defined(IMF_HAVE_SSE2) && defined(__ANDROID__)
++    sse2 = true;
++    sse3 = true;
++#ifdef __x86_64__
++    ssse3 = true;
++    sse4_1 = true;
++#endif
++#endif
++}
++
++OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
diff --git a/setup.py b/setup.py
index ddf46c56..1c132318 100644
--- a/setup.py
+++ b/setup.py
@@ -146,6 +146,8 @@ def main():
                                               # see https://github.com/skvark/opencv-python/issues/138
     if sys.platform.startswith('linux') and not x64:
         cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
+        # patch openEXR when building on i386, see: https://github.com/openexr/openexr/issues/128
+        subprocess.check_call(["patch", "-p0", "<", "patches/patchOpenEXR"])
 
 
     if 'CMAKE_ARGS' in os.environ:

From 0dedf84d688fd55a267e8f32833109bfcd1f81e5 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 23 Aug 2019 08:20:11 -0400
Subject: [PATCH 172/566] fix patch file

---
 patches/patchOpenEXR | 304 ++++---------------------------------------
 1 file changed, 22 insertions(+), 282 deletions(-)

diff --git a/patches/patchOpenEXR b/patches/patchOpenEXR
index 52dba087..6633e844 100644
--- a/patches/patchOpenEXR
+++ b/patches/patchOpenEXR
@@ -1,288 +1,28 @@
 diff -ruN opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp
---- opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-22 20:02:54.769176800 +0300
-+++ opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-23 14:31:17.103949100 +0300
-@@ -1,138 +1,146 @@
--///////////////////////////////////////////////////////////////////////////
--//
--// Copyright (c) 2009-2014 DreamWorks Animation LLC. 
--//
--// All rights reserved.
--//
--// Redistribution and use in source and binary forms, with or without
--// modification, are permitted provided that the following conditions are
--// met:
--// *       Redistributions of source code must retain the above copyright
--// notice, this list of conditions and the following disclaimer.
--// *       Redistributions in binary form must reproduce the above
--// copyright notice, this list of conditions and the following disclaimer
--// in the documentation and/or other materials provided with the
--// distribution.
--// *       Neither the name of DreamWorks Animation nor the names of
--// its contributors may be used to endorse or promote products derived
--// from this software without specific prior written permission.
--//
--// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
--// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
--// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
--// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
--// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
--// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
--// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
--// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
--// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
--// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
--// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--//
--///////////////////////////////////////////////////////////////////////////
--
--#include "ImfSimd.h"
--#include "ImfSystemSpecific.h"
--#include "ImfNamespace.h"
--#include "OpenEXRConfig.h"
--
--OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
--
--namespace {
--#if defined(IMF_HAVE_SSE2) && defined(__GNUC__) && !defined(__ANDROID__)
--
--    // Helper functions for gcc + SSE enabled
--    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
--    {
+--- opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-23 08:11:43.536117200 -0400
++++ opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-23 08:16:58.337879800 -0400
+@@ -44,11 +44,19 @@
+     // Helper functions for gcc + SSE enabled
+     void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
+     {
 -        __asm__ __volatile__ (
 -            "cpuid"
 -            : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) 
 -            : /* Input   */ "a"(n)
 -            : /* Clobber */);
--    }
--
--#else // IMF_HAVE_SSE2 && __GNUC__
--
--    // Helper functions for generic compiler - all disabled
--    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
--    {
--        eax = ebx = ecx = edx = 0;
--    }
--
--#endif // IMF_HAVE_SSE2 && __GNUC__
--
--
--#ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
--
--    void xgetbv(int n, int &eax, int &edx)
--    {
--        __asm__ __volatile__ (
--            "xgetbv"
--            : /* Output  */ "=a"(eax), "=d"(edx) 
--            : /* Input   */ "c"(n)
--            : /* Clobber */);
--    }
--
--#else //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
--
--    void xgetbv(int n, int &eax, int &edx)
--    {
--        eax = edx = 0;
--    }
--
--#endif //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
--
--} // namespace 
--
--CpuId::CpuId():
--    sse2(false), 
--    sse3(false), 
--    ssse3(false),
--    sse4_1(false), 
--    sse4_2(false), 
--    avx(false), 
--    f16c(false)
--{
--    bool osxsave = false;
--    int  max     = 0;
--    int  eax, ebx, ecx, edx;
--
--    cpuid(0, max, ebx, ecx, edx);
--    if (max > 0)
--    {
--        cpuid(1, eax, ebx, ecx, edx);
--        sse2    = ( edx & (1<<26) );
--        sse3    = ( ecx & (1<< 0) );
--        ssse3   = ( ecx & (1<< 9) );
--        sse4_1  = ( ecx & (1<<19) );
--        sse4_2  = ( ecx & (1<<20) );
--        osxsave = ( ecx & (1<<27) );
--        avx     = ( ecx & (1<<28) );
--        f16c    = ( ecx & (1<<29) );
--
--        if (!osxsave)
--        {
--            avx = f16c = false;
--        }
--        else
--        {
--            xgetbv(0, eax, edx);
--            // eax bit 1 - SSE managed, bit 2 - AVX managed
--            if ((eax & 6) != 6)
--            {
--                avx = f16c = false;
--            }
--        }
--    }
--
--#if defined(IMF_HAVE_SSE2) && defined(__ANDROID__)
--    sse2 = true;
--    sse3 = true;
--#ifdef __x86_64__
--    ssse3 = true;
--    sse4_1 = true;
--#endif
--#endif
--}
--
--OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
-+///////////////////////////////////////////////////////////////////////////
-+//
-+// Copyright (c) 2009-2014 DreamWorks Animation LLC.
-+//
-+// All rights reserved.
-+//
-+// Redistribution and use in source and binary forms, with or without
-+// modification, are permitted provided that the following conditions are
-+// met:
-+// *       Redistributions of source code must retain the above copyright
-+// notice, this list of conditions and the following disclaimer.
-+// *       Redistributions in binary form must reproduce the above
-+// copyright notice, this list of conditions and the following disclaimer
-+// in the documentation and/or other materials provided with the
-+// distribution.
-+// *       Neither the name of DreamWorks Animation nor the names of
-+// its contributors may be used to endorse or promote products derived
-+// from this software without specific prior written permission.
-+//
-+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-+//
-+///////////////////////////////////////////////////////////////////////////
-+
-+#include "ImfSimd.h"
-+#include "ImfSystemSpecific.h"
-+#include "ImfNamespace.h"
-+#include "OpenEXRConfig.h"
-+
-+OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
-+
-+namespace {
-+#if defined(IMF_HAVE_SSE2) && defined(__GNUC__) && !defined(__ANDROID__)
-+
-+    // Helper functions for gcc + SSE enabled
-+    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
-+    {
-+		#ifdef __i386__
-+	        __asm__ __volatile__ (
-+	            "pushl %%ebx; cpuid; movl %%ebx, %0; popl %%ebx"
-+	            : /* Output  */ "=m"(ebx), "=a"(eax), "=c"(ecx), "=d"(edx)
-+	            : /* Input   */ "a"(n)
-+	            : /* Clobber */);
-+		#else
-+	         __asm__ __volatile__ (
-+	             "cpuid"
-+	             : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
-+	             : /* Input   */ "a"(n)
-+	             : /* Clobber */);
-+		#endif
-+    }
-+
-+#else // IMF_HAVE_SSE2 && __GNUC__
-+
-+    // Helper functions for generic compiler - all disabled
-+    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
-+    {
-+        eax = ebx = ecx = edx = 0;
-+    }
-+
-+#endif // IMF_HAVE_SSE2 && __GNUC__
-+
-+
-+#ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
-+
-+    void xgetbv(int n, int &eax, int &edx)
-+    {
-+        __asm__ __volatile__ (
-+            "xgetbv"
-+            : /* Output  */ "=a"(eax), "=d"(edx)
-+            : /* Input   */ "c"(n)
-+            : /* Clobber */);
-+    }
-+
-+#else //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
-+
-+    void xgetbv(int n, int &eax, int &edx)
-+    {
-+        eax = edx = 0;
-+    }
-+
-+#endif //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
-+
-+} // namespace
-+
-+CpuId::CpuId():
-+    sse2(false),
-+    sse3(false),
-+    ssse3(false),
-+    sse4_1(false),
-+    sse4_2(false),
-+    avx(false),
-+    f16c(false)
-+{
-+    bool osxsave = false;
-+    int  max     = 0;
-+    int  eax, ebx, ecx, edx;
-+
-+    cpuid(0, max, ebx, ecx, edx);
-+    if (max > 0)
-+    {
-+        cpuid(1, eax, ebx, ecx, edx);
-+        sse2    = ( edx & (1<<26) );
-+        sse3    = ( ecx & (1<< 0) );
-+        ssse3   = ( ecx & (1<< 9) );
-+        sse4_1  = ( ecx & (1<<19) );
-+        sse4_2  = ( ecx & (1<<20) );
-+        osxsave = ( ecx & (1<<27) );
-+        avx     = ( ecx & (1<<28) );
-+        f16c    = ( ecx & (1<<29) );
-+
-+        if (!osxsave)
-+        {
-+            avx = f16c = false;
-+        }
-+        else
-+        {
-+            xgetbv(0, eax, edx);
-+            // eax bit 1 - SSE managed, bit 2 - AVX managed
-+            if ((eax & 6) != 6)
-+            {
-+                avx = f16c = false;
-+            }
-+        }
-+    }
-+
-+#if defined(IMF_HAVE_SSE2) && defined(__ANDROID__)
-+    sse2 = true;
-+    sse3 = true;
-+#ifdef __x86_64__
-+    ssse3 = true;
-+    sse4_1 = true;
-+#endif
-+#endif
-+}
-+
-+OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
++        #ifdef __i386__
++            __asm__ __volatile__ (
++                "pushl %%ebx; cpuid; movl %%ebx, %0; popl %%ebx"
++                : /* Output  */ "=m"(ebx), "=a"(eax), "=c"(ecx), "=d"(edx) 
++                : /* Input   */ "a"(n)
++                : /* Clobber */);
++        #else
++            __asm__ __volatile__ (
++                "cpuid"
++                : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) 
++                : /* Input   */ "a"(n)
++                : /* Clobber */);
++        #endif
+     }
+ 
+ #else // IMF_HAVE_SSE2 && __GNUC__

From 291768c035127d0c11972bef2dd6048631094053 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 25 Aug 2019 15:57:26 +0300
Subject: [PATCH 173/566] fix subprocess call

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 1c132318..6c75a9d4 100644
--- a/setup.py
+++ b/setup.py
@@ -147,7 +147,7 @@ def main():
     if sys.platform.startswith('linux') and not x64:
         cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
         # patch openEXR when building on i386, see: https://github.com/openexr/openexr/issues/128
-        subprocess.check_call(["patch", "-p0", "<", "patches/patchOpenEXR"])
+        subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
 
 
     if 'CMAKE_ARGS' in os.environ:

From 1795159df462bc07fc1a5e9511042f74161b392f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 25 Aug 2019 10:55:31 -0400
Subject: [PATCH 174/566] fix patch

---
 patches/patchOpenEXR | 66 ++++++++++++++++++++++++++++++++------------
 1 file changed, 49 insertions(+), 17 deletions(-)

diff --git a/patches/patchOpenEXR b/patches/patchOpenEXR
index 6633e844..e2a1ffc7 100644
--- a/patches/patchOpenEXR
+++ b/patches/patchOpenEXR
@@ -1,28 +1,60 @@
 diff -ruN opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp
---- opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-23 08:11:43.536117200 -0400
-+++ opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-23 08:16:58.337879800 -0400
-@@ -44,11 +44,19 @@
+--- opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-25 10:40:57.596395000 -0400
++++ opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-25 10:53:15.331689900 -0400
+@@ -40,21 +40,19 @@
+ 
+ namespace {
+ #if defined(IMF_HAVE_SSE2) && defined(__GNUC__) && !defined(__ANDROID__)
+-
++#include <cpuid.h>
      // Helper functions for gcc + SSE enabled
-     void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
+-    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
++    void cpuid(unsigned int n, unsigned int &eax, unsigned int &ebx,
++					unsigned int &ecx, unsigned int &edx)
      {
 -        __asm__ __volatile__ (
 -            "cpuid"
 -            : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) 
 -            : /* Input   */ "a"(n)
 -            : /* Clobber */);
-+        #ifdef __i386__
-+            __asm__ __volatile__ (
-+                "pushl %%ebx; cpuid; movl %%ebx, %0; popl %%ebx"
-+                : /* Output  */ "=m"(ebx), "=a"(eax), "=c"(ecx), "=d"(edx) 
-+                : /* Input   */ "a"(n)
-+                : /* Clobber */);
-+        #else
-+            __asm__ __volatile__ (
-+                "cpuid"
-+                : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) 
-+                : /* Input   */ "a"(n)
-+                : /* Clobber */);
-+        #endif
++        __get_cpuid(n, &eax, &ebx, &ecx, &edx);
      }
  
  #else // IMF_HAVE_SSE2 && __GNUC__
+ 
+     // Helper functions for generic compiler - all disabled
+-    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
++    void cpuid(unsigned int n, unsigned int &eax, unsigned int &ebx,
++					unsigned int &ecx, unsigned int &edx)
+     {
+         eax = ebx = ecx = edx = 0;
+     }
+@@ -64,7 +62,7 @@
+ 
+ #ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
+ 
+-    void xgetbv(int n, int &eax, int &edx)
++    void xgetbv(unsigned int n, unsigned int &eax, unsigned int &edx)
+     {
+         __asm__ __volatile__ (
+             "xgetbv"
+@@ -75,7 +73,7 @@
+ 
+ #else //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
+ 
+-    void xgetbv(int n, int &eax, int &edx)
++    void xgetbv(unsigned int n, unsigned int &eax, unsigned int &edx)
+     {
+         eax = edx = 0;
+     }
+@@ -94,8 +92,8 @@
+     f16c(false)
+ {
+     bool osxsave = false;
+-    int  max     = 0;
+-    int  eax, ebx, ecx, edx;
++    unsigned int  max     = 0;
++    unsigned int  eax, ebx, ecx, edx;
+ 
+     cpuid(0, max, ebx, ecx, edx);
+     if (max > 0)

From fd9fb99f2bdbe6e16c5bf1832bb8db5d0af65249 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 29 Aug 2019 20:23:47 +0300
Subject: [PATCH 175/566] i686 patchelf / auditwheel issue fix (revert back to
 full Qt build)

---
 docker/Dockerfile_i686 | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
index cc97e661..d5b315a2 100644
--- a/docker/Dockerfile_i686
+++ b/docker/Dockerfile_i686
@@ -7,9 +7,7 @@ RUN curl -O -L https://download.qt.io/archive/qt/4.8/4.8.7/qt-everywhere-opensou
     #manylinux1 is too old to have `nproc`
     export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
     #OpenCV only links against QtCore, QtGui, QtTest
-    ./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license \
-    -no-sql-sqlite -no-qt3support -no-xmlpatterns -no-multimedia \
-    -no-webkit -no-script -no-declarative -no-dbus -make libs && \
+    ./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license -make && \
     make && \
     make install && \
     cd .. && \

From 091603176ecb979090f10f1f91883710c0c4bb3a Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 5 Sep 2019 17:32:51 +0300
Subject: [PATCH 176/566] opencv 3.4.6

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 8f1356c3..33b765d7 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 8f1356c3c5b16721349582db461a2051653059e8
+Subproject commit 33b765d7979fd8a6038026aa44f6ff1a9c082b7b
diff --git a/opencv_contrib b/opencv_contrib
index 7292df62..f26c9836 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 7292df62624ded8af8035231435dfd17c93e1a80
+Subproject commit f26c98365da6af93cb5e49397b571190fca7bb55

From 3c8cf39d6cf44aca31220ced65f76778a20fae54 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 8 Jan 2019 19:12:16 +0200
Subject: [PATCH 177/566] try to disable __STRICT_ANSI__ on 32-bit linux

---
 setup.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/setup.py b/setup.py
index 423a0ef2..4f484bef 100644
--- a/setup.py
+++ b/setup.py
@@ -146,6 +146,8 @@ def main():
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with
                                               # devtoolset-2 GCC 4.8.2 or vanilla GCC 4.9.4
                                               # see https://github.com/skvark/opencv-python/issues/138
+    if sys.platform.startswith('linux') and not x64:
+        cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
 
     # ABI config variables are introduced in PEP 425
     if sys.version_info[:2] < (3, 2):

From 29ddb368d4fb8b9178f8b7079b5f7bcc844713b4 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 25 Jan 2019 20:17:50 +0200
Subject: [PATCH 178/566] ignore py2.7 deprecation warning

---
 appveyor.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/appveyor.yml b/appveyor.yml
index 19645421..3e755db9 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -179,6 +179,7 @@ before_test:
 - ps: |
 
     cd ${Env:APPVEYOR_BUILD_FOLDER}\tests
+    $env:PYTHONWARNINGS = "ignore:::pip._internal.cli.base_command"
     &"${Env:PYTHON}/python.exe" -m pip install --user (ls "../dist/opencv_*.whl")
     if ($LastExitCode -ne 0) {throw $LastExitCode}
 

From 22efb62f8f5d99cec05b94b62f4bd0ed2e9a3724 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 26 Jan 2019 13:28:17 +0200
Subject: [PATCH 179/566] update travis xcode 8 to 8.3

---
 .travis.yml | 54 ++++++++++++++++++++++++++---------------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index a6fb537d..7e775d04 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,7 +33,7 @@ cache:
     - $HOME/local_bottle_metadata
     # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
     - $HOME/.ccache
-    
+
 matrix:
   fast_finish: true
   include:
@@ -41,7 +41,7 @@ matrix:
     # default builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
@@ -49,7 +49,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
@@ -57,7 +57,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -65,7 +65,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -73,7 +73,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -84,7 +84,7 @@ matrix:
     # headless builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
@@ -92,7 +92,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
@@ -100,7 +100,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -108,7 +108,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -116,7 +116,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -127,7 +127,7 @@ matrix:
     # Contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
@@ -135,7 +135,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
@@ -143,7 +143,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -151,7 +151,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
@@ -159,7 +159,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -170,7 +170,7 @@ matrix:
     # headless contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
@@ -178,7 +178,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
@@ -186,7 +186,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -194,7 +194,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
@@ -202,7 +202,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -618,7 +618,7 @@ before_install: |
     source multibuild_customize.sh
     echo $ENABLE_CONTRIB > contrib.enabled
     echo $ENABLE_HEADLESS > headless.enabled
-    
+
     if [ -n "$IS_OSX" ]; then
         TAPS="$(brew --repository)/Library/Taps"
         if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
@@ -629,10 +629,10 @@ before_install: |
                     cd $(dirname '\''{}'\'')
                     git clean -fxd
                     git status' \;
-                    
+
         brew_cache_cleanup
     fi
-    
+
     before_install
     # Not interested in travis internal scripts' output
     set +x
@@ -653,7 +653,7 @@ script: |
     #otherwise, Travis logic terminates prematurely
     #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
     trap ERR
-    
+
     test "$rc" -eq 0
 
 before_cache: |
@@ -667,10 +667,10 @@ before_cache: |
         fi
 
         brew_cache_cleanup
-        
+
     fi
     set +x
-    
+
 after_success: |
     # Upload wheels to pypi if requested
     if [ -n "$TRAVIS_TAG" ]; then

From 52ab1f004aa0e3ef3017908039b23773df91f00d Mon Sep 17 00:00:00 2001
From: Christian Vallentin <vallentinsource@gmail.com>
Date: Thu, 31 Jan 2019 15:33:41 +0100
Subject: [PATCH 180/566] Fixed typo

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 0264fa43..32e5687b 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
 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. 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 enviroment. 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.
+    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 with ``pip uninstall`` and reinstall only one package.
 
     **a.** Packages for standard desktop environments (Windows, macOS, almost any GNU/Linux distribution)
 

From 27c23744185c6b95217ae64aba874d77743c4a0b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 17 Feb 2019 21:51:31 +0200
Subject: [PATCH 181/566] Revert "update travis xcode 8 to 8.3"

This reverts commit 5288ba5fa2603975d1ee36544b11c2a45b7adc1e.
---
 .travis.yml | 54 ++++++++++++++++++++++++++---------------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 7e775d04..a6fb537d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,7 +33,7 @@ cache:
     - $HOME/local_bottle_metadata
     # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
     - $HOME/.ccache
-
+    
 matrix:
   fast_finish: true
   include:
@@ -41,7 +41,7 @@ matrix:
     # default builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
@@ -49,7 +49,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
@@ -57,7 +57,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -65,7 +65,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -73,7 +73,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -84,7 +84,7 @@ matrix:
     # headless builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
@@ -92,7 +92,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
@@ -100,7 +100,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -108,7 +108,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -116,7 +116,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -127,7 +127,7 @@ matrix:
     # Contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
@@ -135,7 +135,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
@@ -143,7 +143,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -151,7 +151,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
@@ -159,7 +159,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -170,7 +170,7 @@ matrix:
     # headless contrib builds for MacOS
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
@@ -178,7 +178,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
@@ -186,7 +186,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -194,7 +194,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
@@ -202,7 +202,7 @@ matrix:
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       language: generic
-      osx_image: xcode8.3
+      osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -618,7 +618,7 @@ before_install: |
     source multibuild_customize.sh
     echo $ENABLE_CONTRIB > contrib.enabled
     echo $ENABLE_HEADLESS > headless.enabled
-
+    
     if [ -n "$IS_OSX" ]; then
         TAPS="$(brew --repository)/Library/Taps"
         if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
@@ -629,10 +629,10 @@ before_install: |
                     cd $(dirname '\''{}'\'')
                     git clean -fxd
                     git status' \;
-
+                    
         brew_cache_cleanup
     fi
-
+    
     before_install
     # Not interested in travis internal scripts' output
     set +x
@@ -653,7 +653,7 @@ script: |
     #otherwise, Travis logic terminates prematurely
     #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
     trap ERR
-
+    
     test "$rc" -eq 0
 
 before_cache: |
@@ -667,10 +667,10 @@ before_cache: |
         fi
 
         brew_cache_cleanup
-
+        
     fi
     set +x
-
+    
 after_success: |
     # Upload wheels to pypi if requested
     if [ -n "$TRAVIS_TAG" ]; then

From 356a968aa95a6f6038e6af38504cfe51c525f708 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 17 Feb 2019 22:16:54 +0200
Subject: [PATCH 182/566] remove --merge

---
 config.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/config.sh b/config.sh
index 3bdacd2f..94eaf051 100644
--- a/config.sh
+++ b/config.sh
@@ -29,24 +29,24 @@ fi
 if [ -n "$IS_OSX" ]; then
 
     source travis_osx_brew_cache.sh
-    
+
     BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
         "x265 20"  \
         "cmake 15" \
         "ffmpeg_opencv 10" \
     )
-    
+
     #Contrib adds significantly to project's build time
     if [ "$ENABLE_CONTRIB" -eq 1 ]; then
         BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
     fi
-    
+
     function generate_ffmpeg_formula {
         local FF="ffmpeg"
         local LFF="ffmpeg_opencv"
         local FF_FORMULA; FF_FORMULA=$(brew formula "$FF")
         local LFF_FORMULA; LFF_FORMULA="$(dirname "$FF_FORMULA")/${LFF}.rb"
-        
+
         local REGENERATE
         if [ -f "$LFF_FORMULA" ]; then
             local UPSTREAM_VERSION VERSION
@@ -82,7 +82,7 @@ if (/^\s*depends_on "(x264|x265|xvid)"$/) {$_=""; next;}
             )
         fi
     }
-        
+
 fi
 
 function pre_build {
@@ -91,8 +91,8 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
-    
-    brew update --merge
+
+    brew update
     brew_add_local_bottles
 
     # Don't query analytical info online on `brew info`,

From 10be7e56c0712bb3cc22e3d52766a3f4c1dca3ca Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 19 Feb 2019 19:33:17 +0200
Subject: [PATCH 183/566] Revert "remove --merge"

This reverts commit 0e788e25f4a205832dac6c09dccc9180acd29b73.
---
 config.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/config.sh b/config.sh
index 94eaf051..3bdacd2f 100644
--- a/config.sh
+++ b/config.sh
@@ -29,24 +29,24 @@ fi
 if [ -n "$IS_OSX" ]; then
 
     source travis_osx_brew_cache.sh
-
+    
     BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
         "x265 20"  \
         "cmake 15" \
         "ffmpeg_opencv 10" \
     )
-
+    
     #Contrib adds significantly to project's build time
     if [ "$ENABLE_CONTRIB" -eq 1 ]; then
         BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
     fi
-
+    
     function generate_ffmpeg_formula {
         local FF="ffmpeg"
         local LFF="ffmpeg_opencv"
         local FF_FORMULA; FF_FORMULA=$(brew formula "$FF")
         local LFF_FORMULA; LFF_FORMULA="$(dirname "$FF_FORMULA")/${LFF}.rb"
-
+        
         local REGENERATE
         if [ -f "$LFF_FORMULA" ]; then
             local UPSTREAM_VERSION VERSION
@@ -82,7 +82,7 @@ if (/^\s*depends_on "(x264|x265|xvid)"$/) {$_=""; next;}
             )
         fi
     }
-
+        
 fi
 
 function pre_build {
@@ -91,8 +91,8 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
-
-    brew update
+    
+    brew update --merge
     brew_add_local_bottles
 
     # Don't query analytical info online on `brew info`,

From e78ecbddff746f59d15305469f70447ce910fdb3 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 19 Feb 2019 19:56:42 +0200
Subject: [PATCH 184/566] try --force

---
 config.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/config.sh b/config.sh
index 3bdacd2f..fee87537 100644
--- a/config.sh
+++ b/config.sh
@@ -29,24 +29,24 @@ fi
 if [ -n "$IS_OSX" ]; then
 
     source travis_osx_brew_cache.sh
-    
+
     BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
         "x265 20"  \
         "cmake 15" \
         "ffmpeg_opencv 10" \
     )
-    
+
     #Contrib adds significantly to project's build time
     if [ "$ENABLE_CONTRIB" -eq 1 ]; then
         BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
     fi
-    
+
     function generate_ffmpeg_formula {
         local FF="ffmpeg"
         local LFF="ffmpeg_opencv"
         local FF_FORMULA; FF_FORMULA=$(brew formula "$FF")
         local LFF_FORMULA; LFF_FORMULA="$(dirname "$FF_FORMULA")/${LFF}.rb"
-        
+
         local REGENERATE
         if [ -f "$LFF_FORMULA" ]; then
             local UPSTREAM_VERSION VERSION
@@ -82,7 +82,7 @@ if (/^\s*depends_on "(x264|x265|xvid)"$/) {$_=""; next;}
             )
         fi
     }
-        
+
 fi
 
 function pre_build {
@@ -91,8 +91,8 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
-    
-    brew update --merge
+
+    brew update --force
     brew_add_local_bottles
 
     # Don't query analytical info online on `brew info`,

From c824854d72034a1863a49a72af73988c05cc5e4b Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 23 Mar 2019 20:53:41 +0300
Subject: [PATCH 185/566] Remove redundant language:generic

---
 .travis.yml | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index a6fb537d..16b6025f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -40,7 +40,6 @@ matrix:
 
     # default builds for MacOS
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
@@ -48,7 +47,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
@@ -56,7 +54,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
@@ -64,7 +61,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
@@ -72,7 +68,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
@@ -83,7 +78,6 @@ matrix:
 
     # headless builds for MacOS
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
@@ -91,7 +85,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
@@ -99,7 +92,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
@@ -107,7 +99,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
@@ -115,7 +106,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
@@ -126,7 +116,6 @@ matrix:
 
     # Contrib builds for MacOS
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
@@ -134,7 +123,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
@@ -142,7 +130,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
@@ -150,7 +137,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
@@ -158,7 +144,6 @@ matrix:
         - ENABLE_HEADLESS=0
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
@@ -169,7 +154,6 @@ matrix:
 
     # headless contrib builds for MacOS
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=2.7
@@ -177,7 +161,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
@@ -185,7 +168,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
@@ -193,7 +175,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
@@ -201,7 +182,6 @@ matrix:
         - ENABLE_HEADLESS=1
         - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
-      language: generic
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7

From 008134fed4b9f778d8689763e42246c5de65f20b Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Fri, 22 Mar 2019 00:44:02 +0300
Subject: [PATCH 186/566] Move CMAKE_OSX_DEPLOYMENT_TARGET to setup.py

---
 .travis.yml | 20 --------------------
 setup.py    |  1 +
 2 files changed, 1 insertion(+), 20 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 16b6025f..5945c9d5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -45,35 +45,30 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
         - TEST_DEPENDS=numpy==1.14.5
 
     # headless builds for MacOS
@@ -83,35 +78,30 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
         - TEST_DEPENDS=numpy==1.14.5
 
     # Contrib builds for MacOS
@@ -121,35 +111,30 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
         - TEST_DEPENDS=numpy==1.14.5
 
     # headless contrib builds for MacOS
@@ -159,35 +144,30 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
     - os: osx
       osx_image: xcode8
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - BDIST_PARAMS="-- -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7"
         - TEST_DEPENDS=numpy==1.14.5
 
     # default builds for Linux
diff --git a/setup.py b/setup.py
index 4f484bef..108cdc43 100644
--- a/setup.py
+++ b/setup.py
@@ -141,6 +141,7 @@ def main():
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
         cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
+        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with

From 059fea0437e12e6673523b9cc352dd012a4f526f Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Fri, 22 Mar 2019 01:16:35 +0300
Subject: [PATCH 187/566] * No need for both OPENCV_PYTHON{2,3}_INSTALL_PATH in
 cmake args * Add explanation to more obscure cmake args

---
 setup.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index 108cdc43..fa70f5a3 100644
--- a/setup.py
+++ b/setup.py
@@ -102,12 +102,16 @@ def main():
         # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
         "-DPYTHON%d_EXECUTABLE=%s" % (sys.version_info[0], sys.executable),
         "-DBUILD_opencv_python%d=ON" % sys.version_info[0],
+        
+        # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
         "-DOPENCV_SKIP_PYTHON_LOADER=ON",
-        "-DOPENCV_PYTHON2_INSTALL_PATH=python",
-        "-DOPENCV_PYTHON3_INSTALL_PATH=python",
+        # Relative dir to install the built module to in the build tree.
+        # The default is generated from sysconfig, we'd rather have a constant for simplicity
+        "-DOPENCV_PYTHON%d_INSTALL_PATH=python" % sys.version_info[0],
         # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
         # and skbuild bails out on seeing that
         "-DINSTALL_CREATE_DISTRIB=ON",
+        
         # See opencv/CMakeLists.txt for options and defaults
         "-DBUILD_opencv_apps=OFF",
         "-DBUILD_SHARED_LIBS=OFF",

From 1b6fa44f5d305e7b71d114841cfcc09647030047 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 21 Mar 2019 16:43:05 +0300
Subject: [PATCH 188/566] Upgrade to Xcode 8.3

---
 .travis.yml | 54 ++++++++++++++++++++++++++---------------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 5945c9d5..e7e9a5f0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,38 +33,38 @@ cache:
     - $HOME/local_bottle_metadata
     # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
     - $HOME/.ccache
-    
+
 matrix:
   fast_finish: true
   include:
 
     # default builds for MacOS
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -73,31 +73,31 @@ matrix:
 
     # headless builds for MacOS
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -106,31 +106,31 @@ matrix:
 
     # Contrib builds for MacOS
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -139,31 +139,31 @@ matrix:
 
     # headless contrib builds for MacOS
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
     - os: osx
-      osx_image: xcode8
+      osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -578,7 +578,7 @@ before_install: |
     source multibuild_customize.sh
     echo $ENABLE_CONTRIB > contrib.enabled
     echo $ENABLE_HEADLESS > headless.enabled
-    
+
     if [ -n "$IS_OSX" ]; then
         TAPS="$(brew --repository)/Library/Taps"
         if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
@@ -589,10 +589,10 @@ before_install: |
                     cd $(dirname '\''{}'\'')
                     git clean -fxd
                     git status' \;
-                    
+
         brew_cache_cleanup
     fi
-    
+
     before_install
     # Not interested in travis internal scripts' output
     set +x
@@ -613,7 +613,7 @@ script: |
     #otherwise, Travis logic terminates prematurely
     #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
     trap ERR
-    
+
     test "$rc" -eq 0
 
 before_cache: |
@@ -627,10 +627,10 @@ before_cache: |
         fi
 
         brew_cache_cleanup
-        
+
     fi
     set +x
-    
+
 after_success: |
     # Upload wheels to pypi if requested
     if [ -n "$TRAVIS_TAG" ]; then

From 10c7cfa6fb470b258b0b229bcba03a7824cdcf3b Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Tue, 19 Mar 2019 15:41:56 +0300
Subject: [PATCH 189/566] Diagnostics for a `find -exec git clean` failure

---
 .travis.yml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index e7e9a5f0..130df767 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -586,9 +586,10 @@ before_install: |
         fi
         find "$TAPS" -type d -name .git -exec \
                 bash -xec '
-                    cd $(dirname '\''{}'\'')
-                    git clean -fxd
-                    git status' \;
+                    cd $(dirname '\''{}'\'') || echo "status: $?"
+                    git clean -fxd || echo "status: $?"
+                    sleep 1 || echo "status: $?"
+                    git status || echo "status: $?"' \; || echo "status: $?"
 
         brew_cache_cleanup
     fi

From e7a5b665c4af2ec0ba4bf801d890bce04bb43fc1 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Tue, 19 Mar 2019 12:51:03 +0300
Subject: [PATCH 190/566] Fix/improve travis_osx_brew_cache & caching logic

* fix built bottle & metadata cleanup when bottle is missing
* -e mode for before_cache step
* faster finish when already the latest version
---
 .travis.yml              |  4 ++--
 travis_osx_brew_cache.sh | 15 +++++++++------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 130df767..8772517e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -619,7 +619,7 @@ script: |
 
 before_cache: |
     # Cleanup dirs to be cached
-    set -x
+    set -e; set -x
     if [ -n "$IS_OSX" ]; then
 
         # When Taps is cached, this dir causes "Error: file exists" on `brew update`
@@ -630,7 +630,7 @@ before_cache: |
         brew_cache_cleanup
 
     fi
-    set +x
+    set +x; set +e
 
 after_success: |
     # Upload wheels to pypi if requested
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 47d37326..8d2401b2 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -41,6 +41,12 @@ function brew_install_and_cache_within_time_limit {
 
     local BUILD_FROM_SOURCE INCLUDE_BUILD
     
+    if brew list --versions "$PACKAGE" && ! (brew outdated | grep -qx "$PACKAGE"); then
+        echo "Already installed and the latest version: $PACKAGE"
+        return 0
+    fi
+
+    
     _brew_is_bottle_available "$PACKAGE" || BUILD_FROM_SOURCE=1
     [ -n "$BUILD_FROM_SOURCE" ] && INCLUDE_BUILD="--include-build" || true
 
@@ -152,7 +158,7 @@ function brew_add_local_bottles {
                 )
             fi
             
-            if [ -n "$BOTTLE" ]; then rm "$BOTTLE"; fi
+            if [ -n "$BOTTLE" -a -n "$BOTTLE_EXISTS" ]; then rm "$BOTTLE"; fi
             rm -f "$BOTTLE_LINK"
             rm "$JSON"
             
@@ -295,17 +301,14 @@ function _brew_is_bottle_available {
 
 function _brew_install_and_cache {
     # Install bottle or make and cache bottle.
-    # assumes that deps were already installed.
+    # assumes that deps were already installed
+    # and not already the latest version
     
     local PACKAGE;PACKAGE="${1:?}"
     local USE_BOTTLE;USE_BOTTLE="${2:?}"
     local VERB
     
     if brew list --versions "$PACKAGE"; then
-        if ! (brew outdated | grep -qx "$PACKAGE"); then
-            echo "Already the latest version: $PACKAGE"
-            return 0
-        fi
         VERB=upgrade
     else
         VERB=install

From 5916c66207a8eb50d074f70793aa509e0e7bda07 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Tue, 19 Mar 2019 13:10:38 +0300
Subject: [PATCH 191/566] Update caching logic to support new Homebrew in OSX
 10.12

* disable auto `brew cleanup`
* support formulae with disabled bottles
* install alongside to avoid "runtime dependents" update
  https://discourse.brew.sh/t/can-i-install-a-new-version-without-having-to-upgrade-runtime-dependents/4443
---
 config.sh                |  4 +--
 travis_osx_brew_cache.sh | 59 ++++++++++++++++++++++++++++------------
 2 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/config.sh b/config.sh
index fee87537..ead68645 100644
--- a/config.sh
+++ b/config.sh
@@ -92,14 +92,14 @@ function pre_build {
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
 
-    brew update --force
+    brew update
     brew_add_local_bottles
 
     # Don't query analytical info online on `brew info`,
     #  this takes several seconds and we don't need it
     # see https://docs.brew.sh/Manpage , "info formula" section
     export HOMEBREW_NO_GITHUB_API=1
-
+    
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 8d2401b2..c62a6235 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -24,6 +24,11 @@ BREW_TIME_LIMIT=$((30*60))
 BREW_TIME_HARD_LIMIT=$((40*60))
 
 
+# Auto cleanup can delete locally-built bottles
+# when the caching logic isn't prepared for that
+export HOMEBREW_NO_INSTALL_CLEANUP=1
+
+
 
 #Public functions
 
@@ -34,12 +39,12 @@ function brew_install_and_cache_within_time_limit {
     # Exit with status 2 on any other error.
     ( eval "$_BREW_ERREXIT"
     
-    local PACKAGE; PACKAGE="${1:?}" || return 2
-    local TIME_LIMIT;TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || return 2
-    local TIME_HARD_LIMIT;TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || return 2
-    local TIME_START;TIME_START=${4:-$BREW_TIME_START} || return 2
+    local PACKAGE; PACKAGE="${1:?}" || exit 2
+    local TIME_LIMIT;TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || exit 2
+    local TIME_HARD_LIMIT;TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || exit 2
+    local TIME_START;TIME_START=${4:-$BREW_TIME_START} || exit 2
 
-    local BUILD_FROM_SOURCE INCLUDE_BUILD
+    local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
     
     if brew list --versions "$PACKAGE" && ! (brew outdated | grep -qx "$PACKAGE"); then
         echo "Already installed and the latest version: $PACKAGE"
@@ -47,21 +52,21 @@ function brew_install_and_cache_within_time_limit {
     fi
 
     
-    _brew_is_bottle_available "$PACKAGE" || BUILD_FROM_SOURCE=1
+    _brew_is_bottle_available "$PACKAGE" KEG_ONLY || BUILD_FROM_SOURCE=1
     [ -n "$BUILD_FROM_SOURCE" ] && INCLUDE_BUILD="--include-build" || true
 
     # Whitespace is illegal in package names so converting all whitespace into single spaces due to no quotes is okay.
-    DEPS=`brew deps "$PACKAGE" $INCLUDE_BUILD` || return 2
+    DEPS=`brew deps "$PACKAGE" $INCLUDE_BUILD` || exit 2
     for dep in $DEPS; do
         #TIME_LIMIT only has to be met if we'll be actually building the main project this iteration, i.e. after the "root" module installation
         #While we don't know that yet, we can make better use of Travis-given time with a laxer limit
         #We still can't overrun TIME_HARD_LIMIT as that would't leave time to save the cache
-        brew_install_and_cache_within_time_limit "$dep" $(((TIME_LIMIT+TIME_HARD_LIMIT)/2)) "$TIME_HARD_LIMIT" "$TIME_START" || return $?
+        brew_install_and_cache_within_time_limit "$dep" $(((TIME_LIMIT+TIME_HARD_LIMIT)/2)) "$TIME_HARD_LIMIT" "$TIME_START" || exit $?
     done
 
-    _brew_check_slow_building_ahead "$PACKAGE" "$TIME_START" "$TIME_HARD_LIMIT" || return $?
-    _brew_install_and_cache "$PACKAGE" "$([[ -z "$INCLUDE_BUILD" ]] && echo 1 || echo 0)" || return 2
-    _brew_check_elapsed_build_time "$TIME_START" "$TIME_LIMIT" || return $?
+    _brew_check_slow_building_ahead "$PACKAGE" "$TIME_START" "$TIME_HARD_LIMIT" || exit $?
+    _brew_install_and_cache "$PACKAGE" "$([[ -z "$BUILD_FROM_SOURCE" ]] && echo 1 || echo 0)" "$KEG_ONLY" || exit 2
+    _brew_check_elapsed_build_time "$TIME_START" "$TIME_LIMIT" || exit $?
     ) \
     || if test $? -eq 1; then brew_go_bootstrap_mode; return 1; else return 2; fi      #must run this in current process
 }
@@ -288,8 +293,22 @@ function _brew_parse_package_info {
 function _brew_is_bottle_available {
 
     local PACKAGE;PACKAGE="${1:?}"
-    
-    local INFO="$(brew info "$PACKAGE" | head -n 1)"
+    local VAR_KEG_ONLY="$2"
+
+    local INFO;INFO="$(brew info "$PACKAGE" | head -n 1)"
+    if [ -n "$VAR_KEG_ONLY" ]; then
+        if grep -qwF '[keg-only]' <<<"$INFO"; then
+            eval "${VAR_KEG_ONLY}=1"
+        else
+            eval "${VAR_KEG_ONLY}=0"
+        fi
+    fi
+
+    if grep -qxEe '[[:space:]]*bottle :unneeded' $(brew formula "$PACKAGE"); then
+        echo "Bottle disabled: $PACKAGE"
+        return 0
+    fi
+
     if grep -qwF '(bottled)' <<<"$INFO"; then
         echo "Bottle available: $INFO"
         return 0
@@ -306,10 +325,16 @@ function _brew_install_and_cache {
     
     local PACKAGE;PACKAGE="${1:?}"
     local USE_BOTTLE;USE_BOTTLE="${2:?}"
+    local KEG_ONLY;KEG_ONLY="${3:?}"
     local VERB
     
-    if brew list --versions "$PACKAGE"; then
-        VERB=upgrade
+    if brew list --versions "$PACKAGE" >/dev/null; then
+        # Install alongside the old version to avoid to have to update "runtime dependents"
+        # https://discourse.brew.sh/t/can-i-install-a-new-version-without-having-to-upgrade-runtime-dependents/4443
+        VERB="install --force"
+        if [ "$KEG_ONLY" -eq 0 ]; then
+            brew unlink "$PACKAGE"
+        fi
     else
         VERB=install
     fi
@@ -328,8 +353,8 @@ function _brew_install_and_cache {
         # doesn't seem to be a documented way to get file names
         local BOTTLE; BOTTLE=$(grep -Ee '^./' <<<"$OUT")
         #proper procedure as per https://discourse.brew.sh/t/how-are-bottle-and-postinstall-related-is-it-safe-to-run-bottle-after-postinstall/3410/4
-        brew uninstall "$PACKAGE"
-        brew install "$BOTTLE"
+        brew uninstall --ignore-dependencies "$PACKAGE"
+        brew $VERB "$BOTTLE"
         
         local JSON; JSON=$(sed -E 's/bottle(.[[:digit:]]+)?\.tar\.gz$/bottle.json/' <<<"$BOTTLE")
         

From 6af897d7dfa15be1abf8fa489a66180215e3579e Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 21 Mar 2019 12:33:04 +0300
Subject: [PATCH 192/566] Install macpython late to avoid conflict with
 Homebrew python upgrade

---
 .travis.yml              |  2 --
 config.sh                | 12 +++++++++---
 travis_osx_brew_cache.sh |  2 ++
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 8772517e..632af248 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -594,7 +594,6 @@ before_install: |
         brew_cache_cleanup
     fi
 
-    before_install
     # Not interested in travis internal scripts' output
     set +x
 
@@ -602,7 +601,6 @@ install: |
     # Build and package
     set -x
     build_wheel $REPO_DIR $PLAT
-    if [ -n "$USE_CCACHE" ]; then ccache --show-stats; fi
     set +x
 
 script: |
diff --git a/config.sh b/config.sh
index ead68645..22d16066 100644
--- a/config.sh
+++ b/config.sh
@@ -16,6 +16,7 @@ function bdist_wheel_cmd {
     local abs_wheelhouse=$1
     python setup.py bdist_wheel $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
+    if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache --show-stats; fi
 }
 
 if [ -n "$IS_OSX" ]; then
@@ -99,7 +100,7 @@ function pre_build {
     #  this takes several seconds and we don't need it
     # see https://docs.brew.sh/Manpage , "info formula" section
     export HOMEBREW_NO_GITHUB_API=1
-    
+
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
@@ -108,8 +109,13 @@ function pre_build {
     echo 'Installing FFmpeg'
 
     generate_ffmpeg_formula
-    brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
-
+    local IS_BOTTLE_AVAILABLE; _brew_is_bottle_available ffmpeg_opencv && IS_BOTTLE_AVAILABLE=1 || IS_BOTTLE_AVAILABLE=0
+    _brew_install_and_cache ffmpeg_opencv "$IS_BOTTLE_AVAILABLE"
+    #brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
+    
+    # Have to install macpython late to avoid conflict with Homebrew Python update
+    before_install
+    
   else
     echo "Running for linux"
   fi
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index c62a6235..261e1d00 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -215,6 +215,8 @@ function brew_go_bootstrap_mode {
 # Terminate the build but ensure saving the cache
 
     echo "Going into cache bootstrap mode"
+    
+    BREW_BOOTSTRAP_MODE=1
         
     #Can't just `exit` because that would terminate the build without saving the cache
     #Have to replace further actions with no-ops

From 6e8f51643217805af7cee13cbc148b5356b2284a Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 21 Mar 2019 22:11:08 +0300
Subject: [PATCH 193/566] OSX custom ffmpeg formula: disable GPLed frei0r,
 librubberband

---
 config.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/config.sh b/config.sh
index 22d16066..59c40ee3 100644
--- a/config.sh
+++ b/config.sh
@@ -70,8 +70,8 @@ if [ -n "$IS_OSX" ]; then
                 if (!$found_blank && /^$/) {$_.="conflicts_with \"ffmpeg\"\n\n"; $found_blank=1; next;}
                 if (!$bottle_block && /^\s*bottle do$/) { $bottle_block=1; next; }
                 if ($bottle_block) { if (/^\s*end\s*$/) { $bottle_block=0} elsif (/^\s*sha256\s/) {$_=""} next; }
-if (/^\s*depends_on "(x264|x265|xvid)"$/) {$_=""; next;}
-                if (/^\s*--enable-(gpl|libx264|libx265|libxvid)$/) {$_=""; next;}
+if (/^\s*depends_on "(x264|x265|xvid|frei0r|rubberband)"$/) {$_=""; next;}
+                if (/^\s*--enable-(gpl|libx264|libx265|libxvid|frei0r|librubberband)$/) {$_=""; next;}
                 ' <"$FF_FORMULA" >"$LFF_FORMULA"
             diff -u "$FF_FORMULA" "$LFF_FORMULA" || test $? -le 1
 

From cbfa320e02d0c0545244bd053d05e964cb7dfc32 Mon Sep 17 00:00:00 2001
From: Admin <admin@Mac-Admin.local>
Date: Fri, 22 Mar 2019 02:34:10 +0300
Subject: [PATCH 194/566] Adapt setup.py hook for skbuild 0.9.0

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index fa70f5a3..a6494914 100644
--- a/setup.py
+++ b/setup.py
@@ -268,7 +268,7 @@ def _classify_installed_files_override(self, install_paths,
 
         # 'relpath'/'reldir' = relative to CMAKE_INSTALL_DIR/cmake_install_dir
         # 'path'/'dir' = relative to sourcetree root
-        cmake_install_dir = os.path.join(cls._setuptools_wrap.CMAKE_INSTALL_DIR,
+        cmake_install_dir = os.path.join(cls._setuptools_wrap.CMAKE_INSTALL_DIR(),
                                          cmake_install_reldir)
         install_relpaths = [os.path.relpath(p, cmake_install_dir) for p in install_paths]
         fslash_install_relpaths = [p.replace(os.path.sep, '/') for p in install_relpaths]

From b9350e7d17d96fdcb3dfe36cded2a51412a5f7e2 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Fri, 22 Mar 2019 23:04:51 +0300
Subject: [PATCH 195/566] Reduce the amount of trace output

* Reduce the number of command lines executed in most used functions
* List existing versions only when installing
---
 travis_osx_brew_cache.sh | 51 ++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 261e1d00..69dbf729 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -1,12 +1,5 @@
 # Library to cache downloaded and locally-built Homebrew bottles in Travis OSX build.
 
-_BREW_ERREXIT='
-set -e -o pipefail
-trap '\''{ sleep 3;    #if we terminale too abruptly, Travis will lose some log output
-        exit 2;     #The trap isn''t called in the parent function, so can''t use `return` here.
-                    #`exit` will terminate the entire build but it seems we have no choice.
-}'\'' ERR
-set -E'
 
 #Should be in Travis' cache
 BREW_LOCAL_BOTTLE_METADATA="$HOME/local_bottle_metadata"
@@ -37,16 +30,17 @@ function brew_install_and_cache_within_time_limit {
     # use bottle if available, build and cache bottle if not.
     # Terminate and exit with status 1 if this takes too long.
     # Exit with status 2 on any other error.
-    ( eval "$_BREW_ERREXIT"
-    
-    local PACKAGE; PACKAGE="${1:?}" || exit 2
-    local TIME_LIMIT;TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || exit 2
-    local TIME_HARD_LIMIT;TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || exit 2
-    local TIME_START;TIME_START=${4:-$BREW_TIME_START} || exit 2
+    ( set -eE -o pipefail; trap '{ sleep 3; exit 2; }' ERR
+
+    local PACKAGE TIME_LIMIT TIME_HARD_LIMIT TIME_START
+    PACKAGE="${1:?}" || exit 2
+    TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || exit 2
+    TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || exit 2
+    TIME_START=${4:-$BREW_TIME_START} || exit 2
 
     local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
     
-    if brew list --versions "$PACKAGE" && ! (brew outdated | grep -qx "$PACKAGE"); then
+    if brew list --versions "$PACKAGE" >/dev/null && ! (brew outdated | grep -qxF "$PACKAGE"); then
         echo "Already installed and the latest version: $PACKAGE"
         return 0
     fi
@@ -266,8 +260,9 @@ function _brew_parse_package_info {
     # Get and parse `brew info --json` about a package
     # and save data into specified variables
     
-    local PACKAGE; PACKAGE="${1:?}"; shift
-    local OS_CODENAME;OS_CODENAME="${1:?}"; shift
+    local PACKAGE OS_CODENAME
+    PACKAGE="${1:?}"; shift
+    OS_CODENAME="${1:?}"; shift
 
     local JSON_DATA; JSON_DATA=$(python2.7 -c 'if True:
     import sys, json, subprocess; j=json.loads(subprocess.check_output(("brew","info","--json=v1",sys.argv[1])))
@@ -325,12 +320,13 @@ function _brew_install_and_cache {
     # assumes that deps were already installed
     # and not already the latest version
     
-    local PACKAGE;PACKAGE="${1:?}"
-    local USE_BOTTLE;USE_BOTTLE="${2:?}"
-    local KEG_ONLY;KEG_ONLY="${3:?}"
+    local PACKAGE USE_BOTTLE KEG_ONLY
+    PACKAGE="${1:?}"
+    USE_BOTTLE="${2:?}"
+    KEG_ONLY="${3:?}"
     local VERB
     
-    if brew list --versions "$PACKAGE" >/dev/null; then
+    if brew list --versions "$PACKAGE"; then
         # Install alongside the old version to avoid to have to update "runtime dependents"
         # https://discourse.brew.sh/t/can-i-install-a-new-version-without-having-to-upgrade-runtime-dependents/4443
         VERB="install --force"
@@ -382,10 +378,11 @@ function _brew_check_elapsed_build_time {
     # If time limit has been reached,
     # arrange for further build to be skipped and return 1
 
-    local TIME_START;TIME_START="${1:?}"
-    local TIME_LIMIT;TIME_LIMIT="${2:?}"
+    local TIME_START TIME_LIMIT ELAPSED_TIME
+    TIME_START="${1:?}"
+    TIME_LIMIT="${2:?}"
     
-    local ELAPSED_TIME;ELAPSED_TIME=$(($(date +%s) - $TIME_START))
+    ELAPSED_TIME=$(($(date +%s) - $TIME_START))
     echo "Elapsed time: "$(($ELAPSED_TIME/60))"m (${ELAPSED_TIME}s)"
     
     if [[ "$ELAPSED_TIME" -gt $TIME_LIMIT ]]; then 
@@ -400,10 +397,12 @@ function _brew_check_slow_building_ahead {
     #If the package's projected build completion is higher than hard limit,
     # skip it and arrange for further build to be skipped and return 1
     
-    local PACKAGE="${1:?}"
-    local TIME_START="${2:?}"
-    local TIME_HARD_LIMIT="${3:?}"
+    local PACKAGE TIME_START TIME_HARD_LIMIT
+    PACKAGE="${1:?}"
+    TIME_START="${2:?}"
+    TIME_HARD_LIMIT="${3:?}"
     
+    local PROJECTED_BUILD_TIME 
     PROJECTED_BUILD_TIME=$(echo "$BREW_SLOW_BUILIDING_PACKAGES" | awk '$1=="'"$PACKAGE"'"{print $2}')
     [ -z "$PROJECTED_BUILD_TIME" ] && return 0 || true
     

From 7af6a3545e4497fc6ad148cea232dd5ff04a192a Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 23 Mar 2019 02:08:15 +0300
Subject: [PATCH 196/566] Use 2 stages for MacOS builds

* Add a dedicated stage to each OSX build to download/build brew packages
* Remove bottle building logic and the corresponding trace output from the project build stage
---
 .travis.yml              | 128 +++++++++++++++++++++++++++++++++------
 config.sh                |  35 +++++++----
 travis_osx_brew_cache.sh |   6 +-
 3 files changed, 135 insertions(+), 34 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 632af248..07febd6e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -34,144 +34,232 @@ cache:
     # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
     - $HOME/.ccache
 
+# Add more cache stages (s2 etc) and corresponding OSX jobs like s1
+# if brew builds start to take longer than one Travis time limit
+stages:
+  - s1
+  - final
+    
 matrix:
   fast_finish: true
   include:
 
     # default builds for MacOS
-    - os: osx
+    - &osx-10
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-10
+      stage: s1
+    - &osx-30
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-30
+      stage: s1
+    - &osx-40
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-40
+      stage: s1
+    - &osx-50
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-50
+      stage: s1
+    - &osx-60
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
+      stage: final
+    - <<: *osx-60
+      stage: s1
 
     # headless builds for MacOS
-    - os: osx
+    - &osx-70
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-70
+      stage: s1
+    - &osx-80
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-80
+      stage: s1
+    - &osx-90
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-90
+      stage: s1
+    - &osx-100
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-100
+      stage: s1
+    - &osx-110
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
+      stage: final
+    - <<: *osx-110
+      stage: s1
 
     # Contrib builds for MacOS
-    - os: osx
+    - &osx-120
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-120
+      stage: s1
+    - &osx-130
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-130
+      stage: s1
+    - &osx-140
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-140
+      stage: s1
+    - &osx-150
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-    - os: osx
+      stage: final
+    - <<: *osx-150
+      stage: s1
+    - &osx-160
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
+      stage: final
+    - <<: *osx-160
+      stage: s1
 
     # headless contrib builds for MacOS
-    - os: osx
+    - &osx-170
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-170
+      stage: s1
+    - &osx-180
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-180
+      stage: s1
+    - &osx-190
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-190
+      stage: s1
+    - &osx-200
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-    - os: osx
+      stage: final
+    - <<: *osx-200
+      stage: s1
+    - &osx-210
+      os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
+      stage: final
+    - <<: *osx-210
+      stage: s1
 
     # default builds for Linux
     - os: linux
+      # the following jobs will use the same stage name by default
+      stage: s1
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
diff --git a/config.sh b/config.sh
index 59c40ee3..16a5ad68 100644
--- a/config.sh
+++ b/config.sh
@@ -37,11 +37,6 @@ if [ -n "$IS_OSX" ]; then
         "ffmpeg_opencv 10" \
     )
 
-    #Contrib adds significantly to project's build time
-    if [ "$ENABLE_CONTRIB" -eq 1 ]; then
-        BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
-    fi
-
     function generate_ffmpeg_formula {
         local FF="ffmpeg"
         local LFF="ffmpeg_opencv"
@@ -92,9 +87,14 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
+    
+    local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
 
-    brew update
-    brew_add_local_bottles
+    #after the cache stage, all bottles and Homebrew metadata should be already cached locally
+    if [ -n "$CACHE_STAGE" ]; then
+        brew update
+        brew_add_local_bottles
+    fi
 
     # Don't query analytical info online on `brew info`,
     #  this takes several seconds and we don't need it
@@ -104,14 +104,25 @@ function pre_build {
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
-    brew_install_and_cache_within_time_limit qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
+    if [ -n "$CACHE_STAGE" ]; then
+        brew_install_and_cache_within_time_limit qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
+    else
+        brew install qt@4
+    fi
 
     echo 'Installing FFmpeg'
 
-    generate_ffmpeg_formula
-    local IS_BOTTLE_AVAILABLE; _brew_is_bottle_available ffmpeg_opencv && IS_BOTTLE_AVAILABLE=1 || IS_BOTTLE_AVAILABLE=0
-    _brew_install_and_cache ffmpeg_opencv "$IS_BOTTLE_AVAILABLE"
-    #brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
+    if [ -n "$CACHE_STAGE" ]; then
+        generate_ffmpeg_formula
+        brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
+    else
+        brew install ffmpeg_opencv
+    fi
+
+    if [ -n "$CACHE_STAGE" ]; then
+        brew_go_bootstrap_mode 0
+        return 0
+    fi
     
     # Have to install macpython late to avoid conflict with Homebrew Python update
     before_install
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 69dbf729..3eba10f6 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -10,7 +10,8 @@ BREW_TIME_START=$(($TRAVIS_TIMER_START_TIME/10**9))
 
 # If after a package is built, elapsed time is more than this many seconds, fail the build but save Travis cache
 # The cutoff moment should leave enough time till Travis' job time limit to process the main project.
-BREW_TIME_LIMIT=$((30*60))
+#  Since we have moved deps into a separate stage, we don't need to leave time for the project any more
+BREW_TIME_LIMIT=$((38*60))
 # If a slow-building package is about to be built and the projected build end moment is beyond this many seconds,
 # skip that build, fail the Travis job and save Travis cache.
 # This cutoff should leave enough time for before_cache and cache save.
@@ -207,6 +208,7 @@ function brew_cache_cleanup {
 function brew_go_bootstrap_mode {
 # Can be overridden
 # Terminate the build but ensure saving the cache
+    local EXIT_CODE=${1:-1}
 
     echo "Going into cache bootstrap mode"
     
@@ -223,7 +225,7 @@ function brew_go_bootstrap_mode {
         
         # Travis runs user scripts via `eval` i.e. in the same shell process.
         # So have to unset errexit in order to get to cache save stage
-        set +e; return 1
+        set +e; return '"$EXIT_CODE"'
     }'    
 }
 

From 2c8282f816a125cb7f2f6918f69dd37ec36a6fcf Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 23 Mar 2019 22:16:33 +0300
Subject: [PATCH 197/566] Further increase time limits for the cache jobs

---
 travis_osx_brew_cache.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 3eba10f6..87de4c78 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -11,11 +11,11 @@ BREW_TIME_START=$(($TRAVIS_TIMER_START_TIME/10**9))
 # If after a package is built, elapsed time is more than this many seconds, fail the build but save Travis cache
 # The cutoff moment should leave enough time till Travis' job time limit to process the main project.
 #  Since we have moved deps into a separate stage, we don't need to leave time for the project any more
-BREW_TIME_LIMIT=$((38*60))
+BREW_TIME_LIMIT=$((42*60))
 # If a slow-building package is about to be built and the projected build end moment is beyond this many seconds,
 # skip that build, fail the Travis job and save Travis cache.
 # This cutoff should leave enough time for before_cache and cache save.
-BREW_TIME_HARD_LIMIT=$((40*60))
+BREW_TIME_HARD_LIMIT=$((43*60))
 
 
 # Auto cleanup can delete locally-built bottles

From 81e4987e05536977c808093e740607ea7d4d8ffa Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 23 Mar 2019 22:17:44 +0300
Subject: [PATCH 198/566] x265 is not among the custom formula dependencies

---
 config.sh | 1 -
 1 file changed, 1 deletion(-)

diff --git a/config.sh b/config.sh
index 16a5ad68..c6aae3db 100644
--- a/config.sh
+++ b/config.sh
@@ -32,7 +32,6 @@ if [ -n "$IS_OSX" ]; then
     source travis_osx_brew_cache.sh
 
     BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
-        "x265 20"  \
         "cmake 15" \
         "ffmpeg_opencv 10" \
     )

From 02ab5572128ea5e35b254641906fa899c1da1e0e Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 23 Mar 2019 22:20:33 +0300
Subject: [PATCH 199/566] HOMEBREW_NO_GITHUB_API is more relevant to the lib
 rather than main logic

---
 config.sh                | 5 -----
 travis_osx_brew_cache.sh | 6 ++++++
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/config.sh b/config.sh
index c6aae3db..c31def77 100644
--- a/config.sh
+++ b/config.sh
@@ -95,11 +95,6 @@ function pre_build {
         brew_add_local_bottles
     fi
 
-    # Don't query analytical info online on `brew info`,
-    #  this takes several seconds and we don't need it
-    # see https://docs.brew.sh/Manpage , "info formula" section
-    export HOMEBREW_NO_GITHUB_API=1
-
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
     brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 87de4c78..43625c41 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -22,6 +22,12 @@ BREW_TIME_HARD_LIMIT=$((43*60))
 # when the caching logic isn't prepared for that
 export HOMEBREW_NO_INSTALL_CLEANUP=1
 
+# Don't query analytical info online on `brew info`,
+#  this takes several seconds and we don't need it
+# see https://docs.brew.sh/Manpage , "info formula" section
+export HOMEBREW_NO_GITHUB_API=1
+
+
 
 
 #Public functions

From ae953ca3c1ce08b9787bbdec3b55cf1cb020a412 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 5 Apr 2019 19:43:01 +0300
Subject: [PATCH 200/566] update README

---
 README.md | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/README.md b/README.md
index 32e5687b..a8556f98 100644
--- a/README.md
+++ b/README.md
@@ -50,12 +50,20 @@ A: Most likely the issue is related to too old pip and can be fixed by running `
 
 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.
 
+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](https://support.microsoft.com/en-us/help/3145500/media-feature-pack-list-for-windows-n-editions).
+
 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](https://github.com/skvark/opencv-python/issues/36) for a manual fix.
 
+If you still encounter the error after you have checked all the previous solutions, download [Dependencies](https://github.com/lucasg/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 SIFT and SURF are not included in these packages because they are patented and therefore cannot be distributed as built binaries. 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``.

From 3025220a9724ed7cb9ec6079dbaa24d67e6029d5 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 8 Apr 2019 18:43:59 +0300
Subject: [PATCH 201/566] add --user flag to pip install

---
 .travis.yml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 07febd6e..22822de6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -39,7 +39,7 @@ cache:
 stages:
   - s1
   - final
-    
+
 matrix:
   fast_finish: true
   include:
@@ -722,10 +722,10 @@ after_success: |
     # Upload wheels to pypi if requested
     if [ -n "$TRAVIS_TAG" ]; then
         set -x
-        pip install twine
+        pip install --user twine
 
         if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
-          pip install --upgrade pyOpenSSL
+          pip install --user --upgrade pyOpenSSL
         fi
 
         if [[ $ENABLE_CONTRIB == 0 ]]; then

From 9aa34f7d3b28ffb5aba380d72586cb44b9bab0c2 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 8 Apr 2019 19:02:02 +0300
Subject: [PATCH 202/566] upgrade six...

---
 .travis.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.travis.yml b/.travis.yml
index 22822de6..c63fdbbb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -723,6 +723,7 @@ after_success: |
     if [ -n "$TRAVIS_TAG" ]; then
         set -x
         pip install --user twine
+        pip install --user --upgrade six
 
         if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
           pip install --user --upgrade pyOpenSSL

From 2fa617300642390f2ee4011e0ce177dcfba9c003 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 8 Apr 2019 19:33:26 +0300
Subject: [PATCH 203/566] update README

---
 README.md | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index a8556f98..10229096 100644
--- a/README.md
+++ b/README.md
@@ -144,7 +144,9 @@ The default ``manylinux`` images have been extended with some OpenCV dependencie
 
 ### Supported Python versions
 
-Python 2.7 is the only supported version in 2.x series. Python 3.x releases follow Numpy releases. For example Python 3.3 is no longer supported by Numpy so support for it has been dropped in ``opencv-python``, too.
+Python 2.7 is the only supported version in 2.x series. Python 2.7 support will be dropped in the end of 2019.
+
+Python 3.x releases follow Numpy releases. For example Python 3.3 is no longer supported by Numpy so support for it has been dropped in ``opencv-python``, too.
 
 Currently, builds for following Python versions are provided:
 

From 630df31b430e1b7b06d07e15204978d73323f7bc Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 8 Apr 2019 23:26:50 +0300
Subject: [PATCH 204/566] fix macOS deployment phase

---
 .travis.yml | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index c63fdbbb..34d989f8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -722,11 +722,15 @@ after_success: |
     # Upload wheels to pypi if requested
     if [ -n "$TRAVIS_TAG" ]; then
         set -x
-        pip install --user twine
-        pip install --user --upgrade six
+
+        if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
+          pip install --user twine
+          pip install --user --upgrade six
+        fi
 
         if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
-          pip install --user --upgrade pyOpenSSL
+          pip install twine
+          pip install --upgrade pyOpenSSL
         fi
 
         if [[ $ENABLE_CONTRIB == 0 ]]; then

From 54cbe08ad584b279f1cd250ca286d2de819ef7b5 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 00:35:34 +0300
Subject: [PATCH 205/566] Fix values of mismatch detection variables carrying
 over to the next iteration

Happened in https://travis-ci.org/skvark/opencv-python/builds/518836739 S1 jobs
---
 travis_osx_brew_cache.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 43625c41..6a270678 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -106,8 +106,8 @@ function brew_add_local_bottles {
         local FORMULA_HAS_BOTTLE; [ -n "$FORMULA_BOTTLE_HASH" ] && FORMULA_HAS_BOTTLE=1 || true
         
 
-        local BOTTLE_LINK BOTTLE; BOTTLE_LINK="${JSON}.bottle.lnk";
-        local BOTTLE_EXISTS BOTTLE_MISMATCH VERSION_MISMATCH
+        local BOTTLE_LINK BOTTLE=""; BOTTLE_LINK="${JSON}.bottle.lnk";
+        local BOTTLE_EXISTS= BOTTLE_MISMATCH= VERSION_MISMATCH=
 
 
         # Check that the bottle file exists and is still appropriate for the formula

From d3c3882338c2c624ed6aadb325ded83a386cebfe Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 00:46:02 +0300
Subject: [PATCH 206/566] Fix removing old built opencv_ffmpeg when a new
 upstream formula is available

Happened in https://travis-ci.org/skvark/opencv-python/builds/518179810 S1 jobs
---
 config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config.sh b/config.sh
index c31def77..2a7e8ec1 100644
--- a/config.sh
+++ b/config.sh
@@ -92,6 +92,7 @@ function pre_build {
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then
         brew update
+        generate_ffmpeg_formula
         brew_add_local_bottles
     fi
 
@@ -107,7 +108,6 @@ function pre_build {
     echo 'Installing FFmpeg'
 
     if [ -n "$CACHE_STAGE" ]; then
-        generate_ffmpeg_formula
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew install ffmpeg_opencv

From ea088a936d1596ac31a0ef58303faf6059bb9070 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 01:19:18 +0300
Subject: [PATCH 207/566] Don't print bogus error message when cache warmup is
 complete

---
 travis_osx_brew_cache.sh | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 6a270678..eb15618c 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -223,12 +223,19 @@ function brew_go_bootstrap_mode {
     #Can't just `exit` because that would terminate the build without saving the cache
     #Have to replace further actions with no-ops
     
+    local MESSAGE=""; if [ "$EXIT_CODE" -ne 0 ]; then
+        MESSAGE='Building dependencies took too long. Restart the build in Travis UI to continue from cache.';
+    fi
+    
     eval '
     function '"$cmd"' { return 0; }
     function repair_wheelhouse { return 0; }
-    function install_run {
-        echo -e "\nBuilding dependencies took too long. Restart the build in Travis UI to continue from cache.\n"
-        
+    function install_run {'\
+        "$(if [ -n "$MESSAGE" ]; then
+            echo \
+        '        echo -e "\n'"$MESSAGE"'\n"'
+        fi)"\
+    '    
         # Travis runs user scripts via `eval` i.e. in the same shell process.
         # So have to unset errexit in order to get to cache save stage
         set +e; return '"$EXIT_CODE"'

From bf365e191e33eaabaa362ceeb4e1111a2e9cc417 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 04:12:14 +0300
Subject: [PATCH 208/566] Fix "Error: broken pipe" if `brew info` gives lots of
 output

---
 travis_osx_brew_cache.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index eb15618c..65d4f0a9 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -307,7 +307,9 @@ function _brew_is_bottle_available {
     local PACKAGE;PACKAGE="${1:?}"
     local VAR_KEG_ONLY="$2"
 
-    local INFO;INFO="$(brew info "$PACKAGE" | head -n 1)"
+    # `brew info` prints "Error: Broken pipe" if piped directly to `head` and the info is long
+    # 141 = 128 + SIGPIPE
+    local INFO;INFO="$((brew info "$PACKAGE" | cat || test $? -eq 141) | head -n 1)"
     if [ -n "$VAR_KEG_ONLY" ]; then
         if grep -qwF '[keg-only]' <<<"$INFO"; then
             eval "${VAR_KEG_ONLY}=1"

From df122a018c57a3e3657a538b53710cab3c4b13d4 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 05:22:08 +0300
Subject: [PATCH 209/566] CentOS 5 ccache doesn't have --show-stats

---
 config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config.sh b/config.sh
index 2a7e8ec1..af888179 100644
--- a/config.sh
+++ b/config.sh
@@ -16,7 +16,7 @@ function bdist_wheel_cmd {
     local abs_wheelhouse=$1
     python setup.py bdist_wheel $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
-    if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache --show-stats; fi
+    if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }
 
 if [ -n "$IS_OSX" ]; then

From 8e23e986a83a5c11b0b348073a419d3678927367 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 02:29:59 +0300
Subject: [PATCH 210/566] Use latest cmake for the main build, too, with better
 Python support

---
 config.sh | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/config.sh b/config.sh
index af888179..3370d221 100644
--- a/config.sh
+++ b/config.sh
@@ -111,6 +111,10 @@ function pre_build {
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew install ffmpeg_opencv
+        #cmake is a build dependency of ffmpeg so a bottle should be present in cache
+        if (brew outdated | grep -qxF cmake) || ! (brew list | grep -qxF cmake); then
+            _brew_install_and_cache cmake 1 0
+        fi
     fi
 
     if [ -n "$CACHE_STAGE" ]; then

From a22f8bf9f447f9c9ed8f6c4a4a10024f147bf9c7 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 2 May 2019 23:55:12 +0300
Subject: [PATCH 211/566] JSON format change for formula without any bottles

---
 travis_osx_brew_cache.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 65d4f0a9..5eaefe42 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -285,7 +285,7 @@ function _brew_parse_package_info {
     revision=data["revision"]
     # in bottle''s json, revision is included into version; here, they are separate
     print data["versions"]["stable"]+("_"+str(revision) if revision else "")
-    bottle_data=data["bottle"]["stable"]
+    bottle_data=data["bottle"].get("stable",{"rebuild":"","files":{}})
     print bottle_data["rebuild"]
     print bottle_data["files"].get(sys.argv[2],{"sha256":"!?"})["sha256"]     #prevent losing trailing blank line to command substitution
     ' \

From 676971681d846ad0a82b07afc7ccb7bedc1bfe34 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Fri, 3 May 2019 22:34:38 +0300
Subject: [PATCH 212/566] Speed up repeat checks for the same deps

---
 travis_osx_brew_cache.sh | 85 +++++++++++++++++++++++-----------------
 1 file changed, 49 insertions(+), 36 deletions(-)

diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 5eaefe42..e3a69cc3 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -27,7 +27,8 @@ export HOMEBREW_NO_INSTALL_CLEANUP=1
 # see https://docs.brew.sh/Manpage , "info formula" section
 export HOMEBREW_NO_GITHUB_API=1
 
-
+#Packages already installed in the current session to avoid checking them again
+_BREW_ALREADY_INSTALLED='$'     #$ = illegal package name; a blank line would cause macos grep to swallow everything
 
 
 #Public functions
@@ -37,39 +38,8 @@ function brew_install_and_cache_within_time_limit {
     # use bottle if available, build and cache bottle if not.
     # Terminate and exit with status 1 if this takes too long.
     # Exit with status 2 on any other error.
-    ( set -eE -o pipefail; trap '{ sleep 3; exit 2; }' ERR
-
-    local PACKAGE TIME_LIMIT TIME_HARD_LIMIT TIME_START
-    PACKAGE="${1:?}" || exit 2
-    TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || exit 2
-    TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || exit 2
-    TIME_START=${4:-$BREW_TIME_START} || exit 2
-
-    local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
-    
-    if brew list --versions "$PACKAGE" >/dev/null && ! (brew outdated | grep -qxF "$PACKAGE"); then
-        echo "Already installed and the latest version: $PACKAGE"
-        return 0
-    fi
-
-    
-    _brew_is_bottle_available "$PACKAGE" KEG_ONLY || BUILD_FROM_SOURCE=1
-    [ -n "$BUILD_FROM_SOURCE" ] && INCLUDE_BUILD="--include-build" || true
-
-    # Whitespace is illegal in package names so converting all whitespace into single spaces due to no quotes is okay.
-    DEPS=`brew deps "$PACKAGE" $INCLUDE_BUILD` || exit 2
-    for dep in $DEPS; do
-        #TIME_LIMIT only has to be met if we'll be actually building the main project this iteration, i.e. after the "root" module installation
-        #While we don't know that yet, we can make better use of Travis-given time with a laxer limit
-        #We still can't overrun TIME_HARD_LIMIT as that would't leave time to save the cache
-        brew_install_and_cache_within_time_limit "$dep" $(((TIME_LIMIT+TIME_HARD_LIMIT)/2)) "$TIME_HARD_LIMIT" "$TIME_START" || exit $?
-    done
-
-    _brew_check_slow_building_ahead "$PACKAGE" "$TIME_START" "$TIME_HARD_LIMIT" || exit $?
-    _brew_install_and_cache "$PACKAGE" "$([[ -z "$BUILD_FROM_SOURCE" ]] && echo 1 || echo 0)" "$KEG_ONLY" || exit 2
-    _brew_check_elapsed_build_time "$TIME_START" "$TIME_LIMIT" || exit $?
-    ) \
-    || if test $? -eq 1; then brew_go_bootstrap_mode; return 1; else return 2; fi      #must run this in current process
+    _brew_install_and_cache_within_time_limit $@ \
+    || if test $? -eq 1; then brew_go_bootstrap_mode; return 1; else return 2; fi
 }
 
 function brew_add_local_bottles {
@@ -246,6 +216,46 @@ function brew_go_bootstrap_mode {
 
 #Internal functions
 
+function _brew_install_and_cache_within_time_limit {
+    # This fn is run with || so errexit can't be enabled
+
+    local PACKAGE TIME_LIMIT TIME_HARD_LIMIT TIME_START MARKED_INSTALLED
+    PACKAGE="${1:?}" || return 2
+    TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || return 2
+    TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || return 2
+    TIME_START=${4:-$BREW_TIME_START} || return 2
+
+    if grep -qxFf <(cat <<<"$_BREW_ALREADY_INSTALLED") <<<"$PACKAGE"; then
+        MARKED_INSTALLED=1
+    fi
+        
+    if [ -n "$MARKED_INSTALLED" ] || (brew list --versions "$PACKAGE" >/dev/null && ! (brew outdated | grep -qxF "$PACKAGE")); then
+        echo "Already installed and the latest version: $PACKAGE"
+        if [ -z "$MARKED_INSTALLED" ]; then _brew_mark_installed "$PACKAGE"; fi
+        return 0
+    fi
+    
+    local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
+    
+    _brew_is_bottle_available "$PACKAGE" KEG_ONLY || BUILD_FROM_SOURCE=1
+    [ -n "$BUILD_FROM_SOURCE" ] && INCLUDE_BUILD="--include-build" || true
+
+    # Whitespace is illegal in package names so converting all whitespace into single spaces due to no quotes is okay.
+    DEPS=`brew deps "$PACKAGE" $INCLUDE_BUILD` || return 2
+    DEPS=`grep -vxF <(cat <<<"$_BREW_ALREADY_INSTALLED") <<<"$DEPS"` || test $? -eq 1 || return 2
+    for dep in $DEPS; do
+        #TIME_LIMIT only has to be met if we'll be actually building the main project this iteration, i.e. after the "root" module installation
+        #While we don't know that yet, we can make better use of Travis-given time with a laxer limit
+        #We still can't overrun TIME_HARD_LIMIT as that would't leave time to save the cache
+        _brew_install_and_cache_within_time_limit "$dep" $(((TIME_LIMIT+TIME_HARD_LIMIT)/2)) "$TIME_HARD_LIMIT" "$TIME_START" || return $?
+    done
+
+    _brew_check_slow_building_ahead "$PACKAGE" "$TIME_START" "$TIME_HARD_LIMIT" || return $?
+    _brew_install_and_cache "$PACKAGE" "$([[ -z "$BUILD_FROM_SOURCE" ]] && echo 1 || echo 0)" "$KEG_ONLY" || return 2
+    _brew_check_elapsed_build_time "$TIME_START" "$TIME_LIMIT" || return $?
+}
+    
+
 function _brew_parse_bottle_json {
     # Parse JSON file resulting from `brew bottle --json`
     # and save data into specified variables
@@ -386,10 +396,13 @@ function _brew_install_and_cache {
         echo "$CACHED_BOTTLE" >"$BOTTLE_LINK"
         
     fi
+    
+    _brew_mark_installed "$PACKAGE"
 }
 
-
-
+function _brew_mark_installed {
+    _BREW_ALREADY_INSTALLED="$_BREW_ALREADY_INSTALLED"$'\n'"${1:?}"
+}
 
 function _brew_check_elapsed_build_time {
     # If time limit has been reached,

From 87902b0e40fd04ec47bf4d53d4b6cfa342250ad9 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 4 May 2019 11:02:49 +0300
Subject: [PATCH 213/566] Add prefix to all files related to CI rather than
 project

---
 .travis.yml                                               | 3 ++-
 config.sh => travis_config.sh                             | 0
 multibuild_customize.sh => travis_multibuild_customize.sh | 0
 3 files changed, 2 insertions(+), 1 deletion(-)
 rename config.sh => travis_config.sh (100%)
 rename multibuild_customize.sh => travis_multibuild_customize.sh (100%)

diff --git a/.travis.yml b/.travis.yml
index 34d989f8..81d2331e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,6 +5,7 @@ env:
         - TEST_DEPENDS="numpy==1.11.1"
         # params to bdist_wheel. used to set osx build target.
         - BDIST_PARAMS=""
+        - CONFIG_PATH="travis_config.sh"
         - USE_CCACHE=1
         - PLAT=x86_64
         - UNICODE_WIDTH=32
@@ -663,7 +664,7 @@ before_install: |
     if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
     source multibuild/travis_steps.sh
     # This sets -x
-    source multibuild_customize.sh
+    source travis_multibuild_customize.sh
     echo $ENABLE_CONTRIB > contrib.enabled
     echo $ENABLE_HEADLESS > headless.enabled
 
diff --git a/config.sh b/travis_config.sh
similarity index 100%
rename from config.sh
rename to travis_config.sh
diff --git a/multibuild_customize.sh b/travis_multibuild_customize.sh
similarity index 100%
rename from multibuild_customize.sh
rename to travis_multibuild_customize.sh

From 61ddc1a2fbbf8ca56a22b5feb72b1e6ca7daf050 Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Thu, 13 Jun 2019 19:57:44 +0300
Subject: [PATCH 214/566] Revert "Use latest cmake for the main build, too,
 with better Python support

This reverts commit d4a51981676eacd6763fac5b183e6267a4305610.

cmake 3.14 can't find py3 installation when "python" points to Python 3 while cmake 3.9 can
---
 travis_config.sh | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index 3370d221..af888179 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -111,10 +111,6 @@ function pre_build {
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew install ffmpeg_opencv
-        #cmake is a build dependency of ffmpeg so a bottle should be present in cache
-        if (brew outdated | grep -qxF cmake) || ! (brew list | grep -qxF cmake); then
-            _brew_install_and_cache cmake 1 0
-        fi
     fi
 
     if [ -n "$CACHE_STAGE" ]; then

From 8f08f38ad6d07544b276663a03ae67febc1991d4 Mon Sep 17 00:00:00 2001
From: Christian Clauss <cclauss@me.com>
Date: Tue, 30 Jul 2019 08:27:45 +0200
Subject: [PATCH 215/566] Travis CI: Xenial is now the default Ubuntu in Travis

https://blog.travis-ci.com/2019-04-15-xenial-default-build-environment

Also: __sudo: required__ no longer is [Travis are now recommending removing the __sudo__ tag](https://blog.travis-ci.com/2018-11-19-required-linux-infrastructure-migration) because the sudo command is always available in Travis CI and there is no longer any way to turn it off.
---
 .travis.yml | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 81d2331e..d1efa36a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,11 +13,9 @@ env:
 
 # Host Python is never used
 language: generic
-# Required to invoke docker ourselves as per https://docs.travis-ci.com/user/docker/
-sudo: required
 services: docker
-# https://docs.travis-ci.com/user/reference/trusty/
-dist: trusty
+# https://docs.travis-ci.com/user/reference/xenial
+dist: xenial
 
 # Save some time, we and setup check them out on demand instead
 # https://docs.travis-ci.com/user/customizing-the-build/#Git-Clone-Depth

From a229f278b7fa90e6e0099d90b3d17b0e2cc59d1e Mon Sep 17 00:00:00 2001
From: Ivan Pozdeev <vano@mail.mipt.ru>
Date: Sat, 17 Aug 2019 16:08:13 +0300
Subject: [PATCH 216/566] Allow passing custom CMake arguments

---
 README.md | 30 ++++++++++++++++++++----------
 setup.py  |  6 ++++++
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md
index 10229096..0db6eb08 100644
--- a/README.md
+++ b/README.md
@@ -77,7 +77,10 @@ The aim of this repository is to provide means to package each new [OpenCV relea
 
 ### 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):
+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):
+
+0. In Linux and MacOS build: get OpenCV's optional C dependencies that we compile against
 
 1. Checkout repository and submodules
 
@@ -86,25 +89,32 @@ The project is structured like a normal Python package with a standard ``setup.p
    -  Contrib modules are also included as a submodule
 
 2. Find OpenCV version from the sources
-3. Install dependencies (numpy)
+3. Install Python dependencies
+
+   - ``setup.py`` installs the dependencies itself, so you need to run it in an environment
+     where you have the rights to install modules with Pip for the running Python
+
 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)
 
-5. Copy each ``.pyd/.so`` file to cv2 folder of this project and
-   generate wheel
+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
 
-   - Linux and macOS wheels are checked with auditwheel and delocate
+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)
 
-6. Install the generated wheel
-7. Test that Python can import the library and run some sanity checks
-8. Use twine to upload the generated wheel to PyPI (only in release builds)
+Steps 1--5 are handled by ``setup.py bdist_wheel``.
 
-The ``cv2.pyd/.so`` file is normally copied to site-packages. To avoid polluting the root folder this package wraps the statically built binary into cv2 package and ``__init__.py`` file in the package handles the import logic correctly.
+The build can be customized with environment variables.
+In addition to any variables that OpenCV's build accepts, we recognize:
 
-Since all packages use the same ``cv2`` namespace explained above, uninstall the other package before switching for example from ``opencv-python`` to ``opencv-contrib-python``.
+- ``ENABLE_CONTRIB`` and ``ENABLE_HEADLESS``. Set to ``1`` to build the contrib and/or headless version
+- ``CMAKE_ARGS``. Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build.
 
 ### Licensing
 
diff --git a/setup.py b/setup.py
index a6494914..29dc1efd 100644
--- a/setup.py
+++ b/setup.py
@@ -154,6 +154,12 @@ def main():
     if sys.platform.startswith('linux') and not x64:
         cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
 
+        
+    if 'CMAKE_ARGS' in os.environ:
+        import shlex
+        cmake_args.extend(shlex.split(os.environ['CMAKE_ARGS']))
+        del shlex
+        
     # ABI config variables are introduced in PEP 425
     if sys.version_info[:2] < (3, 2):
         import warnings

From a7019ef748fd3680e844c752fd670e21297da2f0 Mon Sep 17 00:00:00 2001
From: Abhishek Thakur <abhi.una12@gmail.com>
Date: Sun, 18 Aug 2019 16:22:07 +0530
Subject: [PATCH 217/566] Added OpenSSL & various protocol support to FFmpeg
 backend (#229)

* Added OpenSSL & different protocol support to FFmpeg backend
- Fixed Docker dependencies (both x86 & x86-64)
- Fixes bug #204

* Additional Fixes
- updates to OpenSSL build from scratch
- removed specific protocol
- Added neccessary dependency

* Fixed ./Configure command

* Updates for docker images:
- Added perl build from scratch
- Fixed wrong/redundant dependencies/paths
- Fixed & updated openssl installation

* Fixed Empty continuation lines bug & added comments

* fix inconsitent spacing

* Don't add perl 5.10 to PATH

* fix syntax error

* Fixed OpenSSL build fails in i686 Dockerfile due to buggy perl source

* Fixing manylinux docker entrypoint for i686 in 32 bit images

* ENTRYPOINT not needed, it only affects "docker run" invocations

* manylinux1 provides better libcurl for cmake

* manylinux1 provides the toolchain and git

git install fails in i686, too

* cleanup tar invocations

* nasm is not installed in manylinux1

* detect i686 in openssl configure

* move perl to a separate subtree as it's a private dependency

* rm it after library build

* comment unusual openssl build step

* avoid redundant work in perl build

* build each library in a separate dockerfile command for easier debugging

* comment custom i686 step

* update dockerfile README

* opencv now bundles libjpeg-turbo

and the separate's onre buid fails dueto expired certificate at https://kent.dl.sourceforge.net
---
 docker/Dockerfile_i686   | 86 ++++++++++++++++++++++++----------------
 docker/Dockerfile_x86_64 | 83 +++++++++++++++++++++-----------------
 docker/README.md         |  3 +-
 3 files changed, 99 insertions(+), 73 deletions(-)

diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
index 62366543..98d70324 100644
--- a/docker/Dockerfile_i686
+++ b/docker/Dockerfile_i686
@@ -14,43 +14,74 @@ ENV QTDIR /opt/Qt4.8.7
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN curl -O -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
-	tar -zxf cmake-3.9.0.tar.gz && \
+	tar -xf cmake-3.9.0.tar.gz && \
 	cd cmake-3.9.0 && \
-	yum -y install curl-devel zlib-devel && \
+    true '#manylinux1 provides curl-devel equivalent and libcurl statically linked \
+         against the same newer OpenSSL as other source-built tools \
+         (1.0.2s as of this writing)' && \
+	yum -y install zlib-devel && \
 	./configure --system-curl && \
-	make && \
+	make -j4 && \
 	make install && \
 	cd .. && \
 	rm -rf cmake-3.9.0*
 
-RUN yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ libtool make mercurial pkgconfig zlib-devel -y && \
-	yum remove nasm -y && \
-	mkdir ~/ffmpeg_sources && \
-	cd ~/ffmpeg_sources && \
+# https://trac.ffmpeg.org/wiki/CompilationGuide/Centos#GettheDependencies
+# manylinux provides the toolchain and git; we provide cmake
+RUN yum install freetype-devel bzip2-devel zlib-devel -y && \
+    mkdir ~/ffmpeg_sources
+
+# Newer openssl configure requires newer perl
+RUN curl -O -L https://www.cpan.org/src/5.0/perl-5.20.1.tar.gz && \
+	tar -xf perl-5.20.1.tar.gz && \
+	cd perl-5.20.1 && \
+	./Configure -des -Dprefix="$HOME/openssl_build" && \
+	true '#perl build scripts do much redundant work \
+	     if running "make install" separately' && \
+	make install -j4 && \
+	cd .. && \
+	rm -rf perl-5.20.1*
+
+RUN cd ~/ffmpeg_sources && \
+	curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
+	tar -xf OpenSSL_1_1_1c.tar.gz && \
+	cd openssl-OpenSSL_1_1_1c && \
+    true '#in i686, ./config detects x64 in i686 without linux32 \
+         when run from "docker build"' && \
+	PERL="$HOME/openssl_build/bin/perl" linux32 ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+	make -j4 && \
+    true '#skip installing documentation' && \
+	make install_sw && \
+    rm -rf ~/openssl_build
+
+RUN cd ~/ffmpeg_sources && \
 	curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
-	tar xjvf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+	tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
 	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
 	make -j4 && \
-	make install && \
-	cd ~/ffmpeg_sources && \
+	make install
+
+RUN cd ~/ffmpeg_sources && \
 	curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
-	tar xzvf yasm-1.3.0.tar.gz && \
+	tar -xf yasm-1.3.0.tar.gz && \
 	cd yasm-1.3.0 && \
 	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
 	make -j4 && \
-	make install && \
-	cd ~/ffmpeg_sources && \
+	make install
+
+RUN cd ~/ffmpeg_sources && \
 	git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
 	cd libvpx && \
 	./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
 	make -j4 && \
-	make install && \
-	cd ~/ffmpeg_sources && \
+	make install
+
+RUN cd ~/ffmpeg_sources && \
 	curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
-	tar xjvf ffmpeg-snapshot.tar.bz2 && \
+	tar -xf ffmpeg-snapshot.tar.bz2 && \
 	cd ffmpeg && \
 	PATH=~/bin:$PATH && \
-	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
 	make -j4 && \
 	make install && \
 	echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
@@ -60,30 +91,15 @@ RUN yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ libtool
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 
-RUN mkdir libjpeg-turbo && \
-	cd libjpeg-turbo && \
-	export PATH=~/bin:$PATH && \
-	curl -L https://kent.dl.sourceforge.net/project/libjpeg-turbo/1.5.3/libjpeg-turbo-1.5.3.tar.gz > libjpeg-turbo-1.5.3.tar.gz && \
-	tar xzvf libjpeg-turbo-1.5.3.tar.gz && \
-	cd libjpeg-turbo-1.5.3 && \
-	export CFLAGS="-fPIC" && \
-	export CXXFLAGS="-fPIC" && \
-	autoreconf -fiv && \
-	./configure --host=i686-pc-linux-gnu && \
-	make && \
-	make install && \
-	cd ../../ && \
-	rm -rf libjpeg-turbo
-
-ENV JPEG_LIBRARY /opt/libjpeg-turbo/lib32/libjpeg.a
-ENV JPEG_INCLUDE_DIR /opt/libjpeg-turbo/include
-
 RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/videodev2.h && \
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
 	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
 
+#in i686, yum metadata ends up with slightly wrong timestamps
+#which inhibits its update
+#https://github.com/skvark/opencv-python/issues/148
 RUN yum clean all
 
 ENV PATH "$HOME/bin:$PATH"
diff --git a/docker/Dockerfile_x86_64 b/docker/Dockerfile_x86_64
index e9de76e8..81b59974 100644
--- a/docker/Dockerfile_x86_64
+++ b/docker/Dockerfile_x86_64
@@ -14,43 +14,72 @@ ENV QTDIR /opt/Qt4.8.7
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN curl -O -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
-	tar -zxf cmake-3.9.0.tar.gz && \
+	tar -xf cmake-3.9.0.tar.gz && \
 	cd cmake-3.9.0 && \
-	yum -y install curl-devel zlib-devel && \
+    true '#manylinux1 provides curl-devel equivalent and libcurl statically linked \
+         against the same newer OpenSSL as other source-built tools \
+         (1.0.2s as of this writing)' && \
+	yum -y install zlib-devel && \
 	./configure --system-curl && \
-	make && \
+	make -j4 && \
 	make install && \
 	cd .. && \
 	rm -rf cmake-3.9.0*
 
-RUN yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ libtool make mercurial pkgconfig zlib-devel -y && \
-	yum remove nasm -y && \
-	mkdir ~/ffmpeg_sources && \
-	cd ~/ffmpeg_sources && \
+# https://trac.ffmpeg.org/wiki/CompilationGuide/Centos#GettheDependencies
+# manylinux provides the toolchain and git; we provide cmake
+RUN yum install freetype-devel bzip2-devel zlib-devel -y && \
+    mkdir ~/ffmpeg_sources
+
+# Newer openssl configure requires newer perl
+RUN curl -O -L https://www.cpan.org/src/5.0/perl-5.20.1.tar.gz && \
+	tar -xf perl-5.20.1.tar.gz && \
+	cd perl-5.20.1 && \
+	./Configure -des -Dprefix="$HOME/openssl_build" && \
+	true '#perl build scripts do much redundant work \
+	     if running "make install" separately' && \
+	make install -j4 && \
+	cd .. && \
+	rm -rf perl-5.20.1*
+
+RUN cd ~/ffmpeg_sources && \
+	curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
+	tar -xf OpenSSL_1_1_1c.tar.gz && \
+	cd openssl-OpenSSL_1_1_1c && \
+	PERL="$HOME/openssl_build/bin/perl" ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+	make -j4 && \
+    true '#skip installing documentation' && \
+	make install_sw && \
+    rm -rf ~/openssl_build
+
+RUN cd ~/ffmpeg_sources && \
 	curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
-	tar xjvf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+	tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
 	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
 	make -j4 && \
-	make install && \
-	cd ~/ffmpeg_sources && \
+	make install
+
+RUN cd ~/ffmpeg_sources && \
 	curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
-	tar xzvf yasm-1.3.0.tar.gz && \
+	tar -xf yasm-1.3.0.tar.gz && \
 	cd yasm-1.3.0 && \
 	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
 	make -j4 && \
-	make install && \
-	cd ~/ffmpeg_sources && \
+	make install
+
+RUN cd ~/ffmpeg_sources && \
 	git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
 	cd libvpx && \
 	./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
 	make -j4 && \
-	make install && \
-	cd ~/ffmpeg_sources && \
+	make install
+
+RUN cd ~/ffmpeg_sources && \
 	curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
-	tar xjvf ffmpeg-snapshot.tar.bz2 && \
+	tar -xf ffmpeg-snapshot.tar.bz2 && \
 	cd ffmpeg && \
 	PATH=~/bin:$PATH && \
-	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
 	make -j4 && \
 	make install && \
 	echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
@@ -60,28 +89,10 @@ RUN yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ libtool
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 
-RUN mkdir libjpeg-turbo && \
-	cd libjpeg-turbo && \
-	export PATH=~/bin:$PATH && \
-	curl -L https://kent.dl.sourceforge.net/project/libjpeg-turbo/1.5.3/libjpeg-turbo-1.5.3.tar.gz > libjpeg-turbo-1.5.3.tar.gz && \
-	tar xzvf libjpeg-turbo-1.5.3.tar.gz && \
-	cd libjpeg-turbo-1.5.3 && \
-	export CFLAGS="-fPIC" && \
-	export CXXFLAGS="-fPIC" && \
-	autoreconf -fiv && \
-	./configure && \
-	make && \
-	make install && \
-	cd ../../ && \
-	rm -rf libjpeg-turbo
-
-ENV JPEG_LIBRARY /opt/libjpeg-turbo/lib64/libjpeg.a
-ENV JPEG_INCLUDE_DIR /opt/libjpeg-turbo/include
-
 RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/videodev2.h && \
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
 	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
 	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
 
-ENV PATH "$HOME/bin:$PATH"
\ No newline at end of file
+ENV PATH "$HOME/bin:$PATH"
diff --git a/docker/README.md b/docker/README.md
index 2e8602bf..e31d7a07 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -10,6 +10,5 @@ The images have following extra software installed:
 
 - Qt 4.8.7
 - Cmake 3.9.0
-- FFmpeg with libvpx (latest snapshots at the build time)
-- libjpeg-turbo 1.5.3
+- FFmpeg with libvpx (latest snapshots at the build time) and recent openssl
 - Some missing headers included from more recent Linux to be able to enable V4L / V4L2 support in OpenCV
\ No newline at end of file

From 9b41acdc769a9247918c55c1435dd60ae47fcaf8 Mon Sep 17 00:00:00 2001
From: native-api <vano@mail.mipt.ru>
Date: Sun, 18 Aug 2019 13:53:51 +0300
Subject: [PATCH 218/566] Including a custom libjpeg is no longer needed (#231)

* Including a custom libjpeg is no longer needed

Since https://github.com/opencv/opencv/pull/11497, OpenCV bundles its own

* (dummy commit to trigger rebuild)
---
 setup.py | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/setup.py b/setup.py
index 29dc1efd..9fb1e049 100644
--- a/setup.py
+++ b/setup.py
@@ -133,13 +133,6 @@ def main():
         cmake_args.append("-DWITH_V4L=ON")
         cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 
-        if all(v in os.environ for v in ('JPEG_INCLUDE_DIR', 'JPEG_LIBRARY')):
-            cmake_args += [
-                "-DBUILD_JPEG=OFF",
-                "-DJPEG_INCLUDE_DIR=%s" % os.environ['JPEG_INCLUDE_DIR'],
-                "-DJPEG_LIBRARY=%s" % os.environ['JPEG_LIBRARY']
-            ]
-
     # Fixes for macOS builds
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see

From 9f1a4422141babc7bfa244e41cfcde081a4876bf Mon Sep 17 00:00:00 2001
From: native-api <vano@mail.mipt.ru>
Date: Sun, 18 Aug 2019 14:03:02 +0300
Subject: [PATCH 219/566] Use Travis workspaces (#228)

* Use one job for MacOS Homebrew builds cache with Travis workspaces

* Brew build job needs to both feed to other jobs and cache between builds

* Move Linux jobs to the Final stage

With only 1 OSX job in S1, the Linux part is now the critical path and holds the build time back
---
 .travis.yml | 190 +++++++++++++++++++++++-----------------------------
 1 file changed, 84 insertions(+), 106 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index d1efa36a..e6213b1c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,11 +25,6 @@ git:
 # https://docs.travis-ci.com/user/caching
 cache:
   directories:
-    # https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
-    - $HOME/Library/Caches/Homebrew
-    - /usr/local/Homebrew/
-    # used in OSX custom build script dealing with local bottle caching
-    - $HOME/local_bottle_metadata
     # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
     - $HOME/.ccache
 
@@ -43,222 +38,205 @@ matrix:
   fast_finish: true
   include:
 
+    - os: osx
+      osx_image: xcode8.3
+      stage: s1
+      workspaces:
+        create:
+          name: brew_cache
+          paths:
+            # https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
+            - $HOME/Library/Caches/Homebrew
+            - /usr/local/Homebrew/
+            # used in OSX custom build script dealing with local bottle caching
+            - $HOME/local_bottle_metadata
+      #workspaces share within the same build, cache shares between builds
+      cache:
+        directories:
+          # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
+          - $HOME/.ccache
+          # https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
+          - $HOME/Library/Caches/Homebrew
+          - /usr/local/Homebrew/
+          # used in OSX custom build script dealing with local bottle caching
+          - $HOME/local_bottle_metadata
+
     # default builds for MacOS
-    - &osx-10
+      #further jobs in the list will use the same stage until the next assignment
+    - stage: final
       os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-10
-      stage: s1
-    - &osx-30
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-30
-      stage: s1
-    - &osx-40
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-40
-      stage: s1
-    - &osx-50
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-50
-      stage: s1
-    - &osx-60
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
-      stage: final
-    - <<: *osx-60
-      stage: s1
+      workspaces:
+        use: brew_cache
 
     # headless builds for MacOS
-    - &osx-70
-      os: osx
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-70
-      stage: s1
-    - &osx-80
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-80
-      stage: s1
-    - &osx-90
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-90
-      stage: s1
-    - &osx-100
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-100
-      stage: s1
-    - &osx-110
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
-      stage: final
-    - <<: *osx-110
-      stage: s1
+      workspaces:
+        use: brew_cache
 
     # Contrib builds for MacOS
-    - &osx-120
-      os: osx
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-120
-      stage: s1
-    - &osx-130
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-130
-      stage: s1
-    - &osx-140
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-140
-      stage: s1
-    - &osx-150
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-      stage: final
-    - <<: *osx-150
-      stage: s1
-    - &osx-160
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
-      stage: final
-    - <<: *osx-160
-      stage: s1
+      workspaces:
+        use: brew_cache
 
     # headless contrib builds for MacOS
-    - &osx-170
-      os: osx
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-170
-      stage: s1
-    - &osx-180
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-180
-      stage: s1
-    - &osx-190
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-190
-      stage: s1
-    - &osx-200
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-      stage: final
-    - <<: *osx-200
-      stage: s1
-    - &osx-210
-      os: osx
+      workspaces:
+        use: brew_cache
+    - os: osx
       osx_image: xcode8.3
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
-      stage: final
-    - <<: *osx-210
-      stage: s1
+      workspaces:
+        use: brew_cache
 
     # default builds for Linux
     - os: linux
-      # the following jobs will use the same stage name by default
-      stage: s1
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0

From 3126712cc7a42e9e59d1d462109cd8d10451e058 Mon Sep 17 00:00:00 2001
From: native-api <vano@mail.mipt.ru>
Date: Tue, 20 Aug 2019 19:54:45 +0300
Subject: [PATCH 220/566] Don't build unused Qt features; use all cores (#236)

* Don't build unused Qt features; use all cores

* cmake does bootstrapping, too; comment unclear steps

* Use Docker comment syntax

* tab to space
---
 docker/Dockerfile_i686   | 140 +++++++++++++++++++++------------------
 docker/Dockerfile_x86_64 | 136 +++++++++++++++++++------------------
 2 files changed, 146 insertions(+), 130 deletions(-)

diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
index 98d70324..cc97e661 100644
--- a/docker/Dockerfile_i686
+++ b/docker/Dockerfile_i686
@@ -1,30 +1,38 @@
 FROM quay.io/pypa/manylinux1_i686:latest
 
 RUN curl -O -L https://download.qt.io/archive/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz && \
-	tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
-	cd qt-everywhere* && \
-	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license && \
-	gmake -j5 && \
-	gmake install && \
-	cd .. && \
-	rm -rf qt-everywhere-opensource-src-4.8.7 && \
-	rm qt-everywhere-opensource-src-4.8.7.tar.gz
+    tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
+    cd qt-everywhere* && \
+    #configure does a bootstrap make under the hood
+    #manylinux1 is too old to have `nproc`
+    export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
+    #OpenCV only links against QtCore, QtGui, QtTest
+    ./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license \
+    -no-sql-sqlite -no-qt3support -no-xmlpatterns -no-multimedia \
+    -no-webkit -no-script -no-declarative -no-dbus -make libs && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf qt-everywhere-opensource-src-4.8.7 && \
+    rm qt-everywhere-opensource-src-4.8.7.tar.gz
 
 ENV QTDIR /opt/Qt4.8.7
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN curl -O -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
-	tar -xf cmake-3.9.0.tar.gz && \
-	cd cmake-3.9.0 && \
-    true '#manylinux1 provides curl-devel equivalent and libcurl statically linked \
-         against the same newer OpenSSL as other source-built tools \
-         (1.0.2s as of this writing)' && \
-	yum -y install zlib-devel && \
-	./configure --system-curl && \
-	make -j4 && \
-	make install && \
-	cd .. && \
-	rm -rf cmake-3.9.0*
+    tar -xf cmake-3.9.0.tar.gz && \
+    cd cmake-3.9.0 && \
+    #manylinux1 provides curl-devel equivalent and libcurl statically linked
+    # against the same newer OpenSSL as other source-built tools
+    # (1.0.2s as of this writing)
+    yum -y install zlib-devel && \
+    #configure does a bootstrap make under the hood
+    export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
+    ./configure --system-curl && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf cmake-3.9.0*
 
 # https://trac.ffmpeg.org/wiki/CompilationGuide/Centos#GettheDependencies
 # manylinux provides the toolchain and git; we provide cmake
@@ -33,69 +41,69 @@ RUN yum install freetype-devel bzip2-devel zlib-devel -y && \
 
 # Newer openssl configure requires newer perl
 RUN curl -O -L https://www.cpan.org/src/5.0/perl-5.20.1.tar.gz && \
-	tar -xf perl-5.20.1.tar.gz && \
-	cd perl-5.20.1 && \
-	./Configure -des -Dprefix="$HOME/openssl_build" && \
-	true '#perl build scripts do much redundant work \
-	     if running "make install" separately' && \
-	make install -j4 && \
-	cd .. && \
-	rm -rf perl-5.20.1*
+    tar -xf perl-5.20.1.tar.gz && \
+    cd perl-5.20.1 && \
+    ./Configure -des -Dprefix="$HOME/openssl_build" && \
+    #perl build scripts do much redundant work
+    # if running "make install" separately
+    make install -j$(getconf _NPROCESSORS_ONLN) && \
+    cd .. && \
+    rm -rf perl-5.20.1*
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
-	tar -xf OpenSSL_1_1_1c.tar.gz && \
-	cd openssl-OpenSSL_1_1_1c && \
-    true '#in i686, ./config detects x64 in i686 without linux32 \
-         when run from "docker build"' && \
-	PERL="$HOME/openssl_build/bin/perl" linux32 ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
-	make -j4 && \
-    true '#skip installing documentation' && \
-	make install_sw && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
+    tar -xf OpenSSL_1_1_1c.tar.gz && \
+    cd openssl-OpenSSL_1_1_1c && \
+    #in i686, ./config detects x64 in i686 container without linux32
+    # when run from "docker build"
+    PERL="$HOME/openssl_build/bin/perl" linux32 ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    #skip installing documentation
+    make install_sw && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
-	tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
-	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
-	make -j4 && \
-	make install
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
+    tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
-	tar -xf yasm-1.3.0.tar.gz && \
-	cd yasm-1.3.0 && \
-	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
-	make -j4 && \
-	make install
+    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
+    tar -xf yasm-1.3.0.tar.gz && \
+    cd yasm-1.3.0 && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
 
 RUN cd ~/ffmpeg_sources && \
-	git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
-	cd libvpx && \
-	./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
-	make -j4 && \
-	make install
+    git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
+    cd libvpx && \
+    ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
-	tar -xf ffmpeg-snapshot.tar.bz2 && \
-	cd ffmpeg && \
-	PATH=~/bin:$PATH && \
-	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
-	make -j4 && \
-	make install && \
-	echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
-	ldconfig && \
-	rm -rf ~/ffmpeg_sources
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
+    tar -xf ffmpeg-snapshot.tar.bz2 && \
+    cd ffmpeg && \
+    PATH=~/bin:$PATH && \
+    PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install && \
+    echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
+    ldconfig && \
+    rm -rf ~/ffmpeg_sources
 
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 
 RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/videodev2.h && \
-	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
-	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
-	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
-	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
+    curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
+    curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
+    curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
+    mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
 
 #in i686, yum metadata ends up with slightly wrong timestamps
 #which inhibits its update
diff --git a/docker/Dockerfile_x86_64 b/docker/Dockerfile_x86_64
index 81b59974..f7b0b081 100644
--- a/docker/Dockerfile_x86_64
+++ b/docker/Dockerfile_x86_64
@@ -1,30 +1,38 @@
 FROM quay.io/pypa/manylinux1_x86_64:latest
 
 RUN curl -O -L https://download.qt.io/archive/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz && \
-	tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
-	cd qt-everywhere* && \
-	./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license && \
-	gmake -j5 && \
-	gmake install && \
-	cd .. && \
-	rm -rf qt-everywhere-opensource-src-4.8.7 && \
-	rm qt-everywhere-opensource-src-4.8.7.tar.gz
+    tar -xf qt-everywhere-opensource-src-4.8.7.tar.gz && \
+    cd qt-everywhere* && \
+    #configure does a bootstrap make under the hood
+    #manylinux1 is too old to have `nproc`
+    export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
+    #OpenCV only links against QtCore, QtGui, QtTest
+    ./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license \
+    -no-sql-sqlite -no-qt3support -no-xmlpatterns -no-multimedia \
+    -no-webkit -no-script -no-declarative -no-dbus -make libs && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf qt-everywhere-opensource-src-4.8.7 && \
+    rm qt-everywhere-opensource-src-4.8.7.tar.gz
 
 ENV QTDIR /opt/Qt4.8.7
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN curl -O -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \
-	tar -xf cmake-3.9.0.tar.gz && \
-	cd cmake-3.9.0 && \
-    true '#manylinux1 provides curl-devel equivalent and libcurl statically linked \
-         against the same newer OpenSSL as other source-built tools \
-         (1.0.2s as of this writing)' && \
-	yum -y install zlib-devel && \
-	./configure --system-curl && \
-	make -j4 && \
-	make install && \
-	cd .. && \
-	rm -rf cmake-3.9.0*
+    tar -xf cmake-3.9.0.tar.gz && \
+    cd cmake-3.9.0 && \
+    #manylinux1 provides curl-devel equivalent and libcurl statically linked
+    # against the same newer OpenSSL as other source-built tools
+    # (1.0.2s as of this writing)
+    yum -y install zlib-devel && \
+    #configure does a bootstrap make under the hood
+    export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
+    ./configure --system-curl && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf cmake-3.9.0*
 
 # https://trac.ffmpeg.org/wiki/CompilationGuide/Centos#GettheDependencies
 # manylinux provides the toolchain and git; we provide cmake
@@ -33,66 +41,66 @@ RUN yum install freetype-devel bzip2-devel zlib-devel -y && \
 
 # Newer openssl configure requires newer perl
 RUN curl -O -L https://www.cpan.org/src/5.0/perl-5.20.1.tar.gz && \
-	tar -xf perl-5.20.1.tar.gz && \
-	cd perl-5.20.1 && \
-	./Configure -des -Dprefix="$HOME/openssl_build" && \
-	true '#perl build scripts do much redundant work \
-	     if running "make install" separately' && \
-	make install -j4 && \
-	cd .. && \
-	rm -rf perl-5.20.1*
+    tar -xf perl-5.20.1.tar.gz && \
+    cd perl-5.20.1 && \
+    ./Configure -des -Dprefix="$HOME/openssl_build" && \
+    #perl build scripts do much redundant work
+    # if running "make install" separately
+    make install -j$(getconf _NPROCESSORS_ONLN) && \
+    cd .. && \
+    rm -rf perl-5.20.1*
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
-	tar -xf OpenSSL_1_1_1c.tar.gz && \
-	cd openssl-OpenSSL_1_1_1c && \
-	PERL="$HOME/openssl_build/bin/perl" ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
-	make -j4 && \
-    true '#skip installing documentation' && \
-	make install_sw && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
+    tar -xf OpenSSL_1_1_1c.tar.gz && \
+    cd openssl-OpenSSL_1_1_1c && \
+    PERL="$HOME/openssl_build/bin/perl" ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    #skip installing documentation
+    make install_sw && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
-	tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
-	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
-	make -j4 && \
-	make install
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
+    tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
-	tar -xf yasm-1.3.0.tar.gz && \
-	cd yasm-1.3.0 && \
-	./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
-	make -j4 && \
-	make install
+    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
+    tar -xf yasm-1.3.0.tar.gz && \
+    cd yasm-1.3.0 && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
 
 RUN cd ~/ffmpeg_sources && \
-	git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
-	cd libvpx && \
-	./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
-	make -j4 && \
-	make install
+    git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
+    cd libvpx && \
+    ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
 
 RUN cd ~/ffmpeg_sources && \
-	curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
-	tar -xf ffmpeg-snapshot.tar.bz2 && \
-	cd ffmpeg && \
-	PATH=~/bin:$PATH && \
-	PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
-	make -j4 && \
-	make install && \
-	echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
-	ldconfig && \
-	rm -rf ~/ffmpeg_sources
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
+    tar -xf ffmpeg-snapshot.tar.bz2 && \
+    cd ffmpeg && \
+    PATH=~/bin:$PATH && \
+    PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install && \
+    echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
+    ldconfig && \
+    rm -rf ~/ffmpeg_sources
 
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 
 RUN curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/videodev2.h && \
-	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
-	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
-	curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
-	mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
+    curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-common.h && \
+    curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/uapi/linux/v4l2-controls.h && \
+    curl -O https://raw.githubusercontent.com/torvalds/linux/v4.14/include/linux/compiler.h && \
+    mv videodev2.h v4l2-common.h v4l2-controls.h compiler.h /usr/include/linux
 
 ENV PATH "$HOME/bin:$PATH"

From 5582b2e178920743013f985fe97329a4cee9057e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 29 Aug 2019 20:23:47 +0300
Subject: [PATCH 221/566] i686 patchelf / auditwheel issue fix (revert back to
 full Qt build)

---
 docker/Dockerfile_i686 | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
index cc97e661..d5b315a2 100644
--- a/docker/Dockerfile_i686
+++ b/docker/Dockerfile_i686
@@ -7,9 +7,7 @@ RUN curl -O -L https://download.qt.io/archive/qt/4.8/4.8.7/qt-everywhere-opensou
     #manylinux1 is too old to have `nproc`
     export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
     #OpenCV only links against QtCore, QtGui, QtTest
-    ./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license \
-    -no-sql-sqlite -no-qt3support -no-xmlpatterns -no-multimedia \
-    -no-webkit -no-script -no-declarative -no-dbus -make libs && \
+    ./configure -prefix /opt/Qt4.8.7 -release -opensource -confirm-license -make && \
     make && \
     make install && \
     cd .. && \

From ca9a5273175315e6652a610b3572c3afd0321e18 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 5 Sep 2019 18:40:28 +0300
Subject: [PATCH 222/566] add note to the README about branches

---
 README.md | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 0db6eb08..8c2f9306 100644
--- a/README.md
+++ b/README.md
@@ -134,10 +134,12 @@ Linux and MacOS wheels ship with [Qt 4.8.7](http://doc.qt.io/qt-4.8/lgpl.html) l
 
 ### 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:
+A release is made and uploaded to PyPI when a new tag is pushed to the repo. 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:

From efb20ee3de71657726846360395278d7a90d0766 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 7 Sep 2019 14:57:20 +0300
Subject: [PATCH 223/566] add std=c++11

---
 setup.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/setup.py b/setup.py
index 9fb1e049..994b8198 100644
--- a/setup.py
+++ b/setup.py
@@ -102,7 +102,7 @@ def main():
         # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
         "-DPYTHON%d_EXECUTABLE=%s" % (sys.version_info[0], sys.executable),
         "-DBUILD_opencv_python%d=ON" % sys.version_info[0],
-        
+
         # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
         "-DOPENCV_SKIP_PYTHON_LOADER=ON",
         # Relative dir to install the built module to in the build tree.
@@ -111,7 +111,7 @@ def main():
         # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
         # and skbuild bails out on seeing that
         "-DINSTALL_CREATE_DISTRIB=ON",
-        
+
         # See opencv/CMakeLists.txt for options and defaults
         "-DBUILD_opencv_apps=OFF",
         "-DBUILD_SHARED_LIBS=OFF",
@@ -137,8 +137,8 @@ def main():
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
-        cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
-        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7")
+        cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -std=c++11")
+        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.8")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with
@@ -147,12 +147,12 @@ def main():
     if sys.platform.startswith('linux') and not x64:
         cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
 
-        
+
     if 'CMAKE_ARGS' in os.environ:
         import shlex
         cmake_args.extend(shlex.split(os.environ['CMAKE_ARGS']))
         del shlex
-        
+
     # ABI config variables are introduced in PEP 425
     if sys.version_info[:2] < (3, 2):
         import warnings

From 6093cc63cb65431e7d4d8f895dd7e73acd1e5d06 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 7 Sep 2019 16:38:49 +0300
Subject: [PATCH 224/566] remove flag

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 994b8198..e887c74d 100644
--- a/setup.py
+++ b/setup.py
@@ -137,7 +137,7 @@ def main():
     if sys.platform == 'darwin':
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
-        cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -std=c++11")
+        cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
         cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.8")
 
     if sys.platform.startswith('linux'):

From 358097f6e188e4bd443f79ddc404a263300a05b7 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 7 Sep 2019 19:30:06 +0300
Subject: [PATCH 225/566] try another flag

---
 setup.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/setup.py b/setup.py
index e887c74d..2e730bba 100644
--- a/setup.py
+++ b/setup.py
@@ -140,6 +140,10 @@ def main():
         cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
         cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.8")
 
+    if sys.platform == 'darwin' and build_contrib:
+        # see: https://github.com/opencv/opencv_contrib/issues/1388#issuecomment-354403896
+        cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
+
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with
                                               # devtoolset-2 GCC 4.8.2 or vanilla GCC 4.9.4

From c966038b7247c7f47061717128ab41452ad468bf Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 9 Sep 2019 18:12:57 +0300
Subject: [PATCH 226/566] add -std=c++11

---
 setup.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index 2e730bba..bf159995 100644
--- a/setup.py
+++ b/setup.py
@@ -141,8 +141,7 @@ def main():
         cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.8")
 
     if sys.platform == 'darwin' and build_contrib:
-        # see: https://github.com/opencv/opencv_contrib/issues/1388#issuecomment-354403896
-        cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
+        cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -std=c++11")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with

From 3fed34b192f7b3a557d3992d175144e39116957e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 9 Sep 2019 21:17:46 +0300
Subject: [PATCH 227/566] no narrowing

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index bf159995..4589bde8 100644
--- a/setup.py
+++ b/setup.py
@@ -141,7 +141,7 @@ def main():
         cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.8")
 
     if sys.platform == 'darwin' and build_contrib:
-        cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -std=c++11")
+        cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -std=c++11 -Wno-c++11-narrowing")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with

From 91f64abd93611d48367f8c615f8a6f9bd8b954a8 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 11 Sep 2019 17:15:54 +0300
Subject: [PATCH 228/566] bump OpenCV version

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 33b765d7..4a7ca5a2 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 33b765d7979fd8a6038026aa44f6ff1a9c082b7b
+Subproject commit 4a7ca5a291038a773ea0b67eaf6fbed9ad72170b
diff --git a/opencv_contrib b/opencv_contrib
index f26c9836..6d656ca0 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit f26c98365da6af93cb5e49397b571190fca7bb55
+Subproject commit 6d656ca069afb3a3cb43a3484ee3a2d215982997

From 0d24dcca4a138f9f69aee0a5f8230153e3cc8918 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 23 Aug 2019 14:43:20 +0300
Subject: [PATCH 229/566] patch OpenEXR on 32-bit Linux

---
 patches/patchOpenEXR | 288 +++++++++++++++++++++++++++++++++++++++++++
 setup.py             |   2 +
 2 files changed, 290 insertions(+)
 create mode 100644 patches/patchOpenEXR

diff --git a/patches/patchOpenEXR b/patches/patchOpenEXR
new file mode 100644
index 00000000..52dba087
--- /dev/null
+++ b/patches/patchOpenEXR
@@ -0,0 +1,288 @@
+diff -ruN opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp
+--- opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-22 20:02:54.769176800 +0300
++++ opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-23 14:31:17.103949100 +0300
+@@ -1,138 +1,146 @@
+-///////////////////////////////////////////////////////////////////////////
+-//
+-// Copyright (c) 2009-2014 DreamWorks Animation LLC. 
+-//
+-// All rights reserved.
+-//
+-// Redistribution and use in source and binary forms, with or without
+-// modification, are permitted provided that the following conditions are
+-// met:
+-// *       Redistributions of source code must retain the above copyright
+-// notice, this list of conditions and the following disclaimer.
+-// *       Redistributions in binary form must reproduce the above
+-// copyright notice, this list of conditions and the following disclaimer
+-// in the documentation and/or other materials provided with the
+-// distribution.
+-// *       Neither the name of DreamWorks Animation nor the names of
+-// its contributors may be used to endorse or promote products derived
+-// from this software without specific prior written permission.
+-//
+-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-//
+-///////////////////////////////////////////////////////////////////////////
+-
+-#include "ImfSimd.h"
+-#include "ImfSystemSpecific.h"
+-#include "ImfNamespace.h"
+-#include "OpenEXRConfig.h"
+-
+-OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
+-
+-namespace {
+-#if defined(IMF_HAVE_SSE2) && defined(__GNUC__) && !defined(__ANDROID__)
+-
+-    // Helper functions for gcc + SSE enabled
+-    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
+-    {
+-        __asm__ __volatile__ (
+-            "cpuid"
+-            : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) 
+-            : /* Input   */ "a"(n)
+-            : /* Clobber */);
+-    }
+-
+-#else // IMF_HAVE_SSE2 && __GNUC__
+-
+-    // Helper functions for generic compiler - all disabled
+-    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
+-    {
+-        eax = ebx = ecx = edx = 0;
+-    }
+-
+-#endif // IMF_HAVE_SSE2 && __GNUC__
+-
+-
+-#ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
+-
+-    void xgetbv(int n, int &eax, int &edx)
+-    {
+-        __asm__ __volatile__ (
+-            "xgetbv"
+-            : /* Output  */ "=a"(eax), "=d"(edx) 
+-            : /* Input   */ "c"(n)
+-            : /* Clobber */);
+-    }
+-
+-#else //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
+-
+-    void xgetbv(int n, int &eax, int &edx)
+-    {
+-        eax = edx = 0;
+-    }
+-
+-#endif //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
+-
+-} // namespace 
+-
+-CpuId::CpuId():
+-    sse2(false), 
+-    sse3(false), 
+-    ssse3(false),
+-    sse4_1(false), 
+-    sse4_2(false), 
+-    avx(false), 
+-    f16c(false)
+-{
+-    bool osxsave = false;
+-    int  max     = 0;
+-    int  eax, ebx, ecx, edx;
+-
+-    cpuid(0, max, ebx, ecx, edx);
+-    if (max > 0)
+-    {
+-        cpuid(1, eax, ebx, ecx, edx);
+-        sse2    = ( edx & (1<<26) );
+-        sse3    = ( ecx & (1<< 0) );
+-        ssse3   = ( ecx & (1<< 9) );
+-        sse4_1  = ( ecx & (1<<19) );
+-        sse4_2  = ( ecx & (1<<20) );
+-        osxsave = ( ecx & (1<<27) );
+-        avx     = ( ecx & (1<<28) );
+-        f16c    = ( ecx & (1<<29) );
+-
+-        if (!osxsave)
+-        {
+-            avx = f16c = false;
+-        }
+-        else
+-        {
+-            xgetbv(0, eax, edx);
+-            // eax bit 1 - SSE managed, bit 2 - AVX managed
+-            if ((eax & 6) != 6)
+-            {
+-                avx = f16c = false;
+-            }
+-        }
+-    }
+-
+-#if defined(IMF_HAVE_SSE2) && defined(__ANDROID__)
+-    sse2 = true;
+-    sse3 = true;
+-#ifdef __x86_64__
+-    ssse3 = true;
+-    sse4_1 = true;
+-#endif
+-#endif
+-}
+-
+-OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
++///////////////////////////////////////////////////////////////////////////
++//
++// Copyright (c) 2009-2014 DreamWorks Animation LLC.
++//
++// All rights reserved.
++//
++// Redistribution and use in source and binary forms, with or without
++// modification, are permitted provided that the following conditions are
++// met:
++// *       Redistributions of source code must retain the above copyright
++// notice, this list of conditions and the following disclaimer.
++// *       Redistributions in binary form must reproduce the above
++// copyright notice, this list of conditions and the following disclaimer
++// in the documentation and/or other materials provided with the
++// distribution.
++// *       Neither the name of DreamWorks Animation nor the names of
++// its contributors may be used to endorse or promote products derived
++// from this software without specific prior written permission.
++//
++// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
++// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
++// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
++// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
++// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
++// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
++// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
++// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
++// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
++// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
++//
++///////////////////////////////////////////////////////////////////////////
++
++#include "ImfSimd.h"
++#include "ImfSystemSpecific.h"
++#include "ImfNamespace.h"
++#include "OpenEXRConfig.h"
++
++OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
++
++namespace {
++#if defined(IMF_HAVE_SSE2) && defined(__GNUC__) && !defined(__ANDROID__)
++
++    // Helper functions for gcc + SSE enabled
++    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
++    {
++		#ifdef __i386__
++	        __asm__ __volatile__ (
++	            "pushl %%ebx; cpuid; movl %%ebx, %0; popl %%ebx"
++	            : /* Output  */ "=m"(ebx), "=a"(eax), "=c"(ecx), "=d"(edx)
++	            : /* Input   */ "a"(n)
++	            : /* Clobber */);
++		#else
++	         __asm__ __volatile__ (
++	             "cpuid"
++	             : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
++	             : /* Input   */ "a"(n)
++	             : /* Clobber */);
++		#endif
++    }
++
++#else // IMF_HAVE_SSE2 && __GNUC__
++
++    // Helper functions for generic compiler - all disabled
++    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
++    {
++        eax = ebx = ecx = edx = 0;
++    }
++
++#endif // IMF_HAVE_SSE2 && __GNUC__
++
++
++#ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
++
++    void xgetbv(int n, int &eax, int &edx)
++    {
++        __asm__ __volatile__ (
++            "xgetbv"
++            : /* Output  */ "=a"(eax), "=d"(edx)
++            : /* Input   */ "c"(n)
++            : /* Clobber */);
++    }
++
++#else //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
++
++    void xgetbv(int n, int &eax, int &edx)
++    {
++        eax = edx = 0;
++    }
++
++#endif //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
++
++} // namespace
++
++CpuId::CpuId():
++    sse2(false),
++    sse3(false),
++    ssse3(false),
++    sse4_1(false),
++    sse4_2(false),
++    avx(false),
++    f16c(false)
++{
++    bool osxsave = false;
++    int  max     = 0;
++    int  eax, ebx, ecx, edx;
++
++    cpuid(0, max, ebx, ecx, edx);
++    if (max > 0)
++    {
++        cpuid(1, eax, ebx, ecx, edx);
++        sse2    = ( edx & (1<<26) );
++        sse3    = ( ecx & (1<< 0) );
++        ssse3   = ( ecx & (1<< 9) );
++        sse4_1  = ( ecx & (1<<19) );
++        sse4_2  = ( ecx & (1<<20) );
++        osxsave = ( ecx & (1<<27) );
++        avx     = ( ecx & (1<<28) );
++        f16c    = ( ecx & (1<<29) );
++
++        if (!osxsave)
++        {
++            avx = f16c = false;
++        }
++        else
++        {
++            xgetbv(0, eax, edx);
++            // eax bit 1 - SSE managed, bit 2 - AVX managed
++            if ((eax & 6) != 6)
++            {
++                avx = f16c = false;
++            }
++        }
++    }
++
++#if defined(IMF_HAVE_SSE2) && defined(__ANDROID__)
++    sse2 = true;
++    sse3 = true;
++#ifdef __x86_64__
++    ssse3 = true;
++    sse4_1 = true;
++#endif
++#endif
++}
++
++OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
diff --git a/setup.py b/setup.py
index 4589bde8..f6684f91 100644
--- a/setup.py
+++ b/setup.py
@@ -149,6 +149,8 @@ def main():
                                               # see https://github.com/skvark/opencv-python/issues/138
     if sys.platform.startswith('linux') and not x64:
         cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
+        # patch openEXR when building on i386, see: https://github.com/openexr/openexr/issues/128
+        subprocess.check_call(["patch", "-p0", "<", "patches/patchOpenEXR"])
 
 
     if 'CMAKE_ARGS' in os.environ:

From c36d98e09e3c89d44ab30543fba7d3ad0744f465 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 23 Aug 2019 08:20:11 -0400
Subject: [PATCH 230/566] fix patch file

---
 patches/patchOpenEXR | 304 ++++---------------------------------------
 1 file changed, 22 insertions(+), 282 deletions(-)

diff --git a/patches/patchOpenEXR b/patches/patchOpenEXR
index 52dba087..6633e844 100644
--- a/patches/patchOpenEXR
+++ b/patches/patchOpenEXR
@@ -1,288 +1,28 @@
 diff -ruN opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp
---- opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-22 20:02:54.769176800 +0300
-+++ opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-23 14:31:17.103949100 +0300
-@@ -1,138 +1,146 @@
--///////////////////////////////////////////////////////////////////////////
--//
--// Copyright (c) 2009-2014 DreamWorks Animation LLC. 
--//
--// All rights reserved.
--//
--// Redistribution and use in source and binary forms, with or without
--// modification, are permitted provided that the following conditions are
--// met:
--// *       Redistributions of source code must retain the above copyright
--// notice, this list of conditions and the following disclaimer.
--// *       Redistributions in binary form must reproduce the above
--// copyright notice, this list of conditions and the following disclaimer
--// in the documentation and/or other materials provided with the
--// distribution.
--// *       Neither the name of DreamWorks Animation nor the names of
--// its contributors may be used to endorse or promote products derived
--// from this software without specific prior written permission.
--//
--// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
--// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
--// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
--// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
--// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
--// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
--// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
--// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
--// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
--// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
--// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--//
--///////////////////////////////////////////////////////////////////////////
--
--#include "ImfSimd.h"
--#include "ImfSystemSpecific.h"
--#include "ImfNamespace.h"
--#include "OpenEXRConfig.h"
--
--OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
--
--namespace {
--#if defined(IMF_HAVE_SSE2) && defined(__GNUC__) && !defined(__ANDROID__)
--
--    // Helper functions for gcc + SSE enabled
--    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
--    {
+--- opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-23 08:11:43.536117200 -0400
++++ opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-23 08:16:58.337879800 -0400
+@@ -44,11 +44,19 @@
+     // Helper functions for gcc + SSE enabled
+     void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
+     {
 -        __asm__ __volatile__ (
 -            "cpuid"
 -            : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) 
 -            : /* Input   */ "a"(n)
 -            : /* Clobber */);
--    }
--
--#else // IMF_HAVE_SSE2 && __GNUC__
--
--    // Helper functions for generic compiler - all disabled
--    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
--    {
--        eax = ebx = ecx = edx = 0;
--    }
--
--#endif // IMF_HAVE_SSE2 && __GNUC__
--
--
--#ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
--
--    void xgetbv(int n, int &eax, int &edx)
--    {
--        __asm__ __volatile__ (
--            "xgetbv"
--            : /* Output  */ "=a"(eax), "=d"(edx) 
--            : /* Input   */ "c"(n)
--            : /* Clobber */);
--    }
--
--#else //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
--
--    void xgetbv(int n, int &eax, int &edx)
--    {
--        eax = edx = 0;
--    }
--
--#endif //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
--
--} // namespace 
--
--CpuId::CpuId():
--    sse2(false), 
--    sse3(false), 
--    ssse3(false),
--    sse4_1(false), 
--    sse4_2(false), 
--    avx(false), 
--    f16c(false)
--{
--    bool osxsave = false;
--    int  max     = 0;
--    int  eax, ebx, ecx, edx;
--
--    cpuid(0, max, ebx, ecx, edx);
--    if (max > 0)
--    {
--        cpuid(1, eax, ebx, ecx, edx);
--        sse2    = ( edx & (1<<26) );
--        sse3    = ( ecx & (1<< 0) );
--        ssse3   = ( ecx & (1<< 9) );
--        sse4_1  = ( ecx & (1<<19) );
--        sse4_2  = ( ecx & (1<<20) );
--        osxsave = ( ecx & (1<<27) );
--        avx     = ( ecx & (1<<28) );
--        f16c    = ( ecx & (1<<29) );
--
--        if (!osxsave)
--        {
--            avx = f16c = false;
--        }
--        else
--        {
--            xgetbv(0, eax, edx);
--            // eax bit 1 - SSE managed, bit 2 - AVX managed
--            if ((eax & 6) != 6)
--            {
--                avx = f16c = false;
--            }
--        }
--    }
--
--#if defined(IMF_HAVE_SSE2) && defined(__ANDROID__)
--    sse2 = true;
--    sse3 = true;
--#ifdef __x86_64__
--    ssse3 = true;
--    sse4_1 = true;
--#endif
--#endif
--}
--
--OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
-+///////////////////////////////////////////////////////////////////////////
-+//
-+// Copyright (c) 2009-2014 DreamWorks Animation LLC.
-+//
-+// All rights reserved.
-+//
-+// Redistribution and use in source and binary forms, with or without
-+// modification, are permitted provided that the following conditions are
-+// met:
-+// *       Redistributions of source code must retain the above copyright
-+// notice, this list of conditions and the following disclaimer.
-+// *       Redistributions in binary form must reproduce the above
-+// copyright notice, this list of conditions and the following disclaimer
-+// in the documentation and/or other materials provided with the
-+// distribution.
-+// *       Neither the name of DreamWorks Animation nor the names of
-+// its contributors may be used to endorse or promote products derived
-+// from this software without specific prior written permission.
-+//
-+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-+//
-+///////////////////////////////////////////////////////////////////////////
-+
-+#include "ImfSimd.h"
-+#include "ImfSystemSpecific.h"
-+#include "ImfNamespace.h"
-+#include "OpenEXRConfig.h"
-+
-+OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
-+
-+namespace {
-+#if defined(IMF_HAVE_SSE2) && defined(__GNUC__) && !defined(__ANDROID__)
-+
-+    // Helper functions for gcc + SSE enabled
-+    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
-+    {
-+		#ifdef __i386__
-+	        __asm__ __volatile__ (
-+	            "pushl %%ebx; cpuid; movl %%ebx, %0; popl %%ebx"
-+	            : /* Output  */ "=m"(ebx), "=a"(eax), "=c"(ecx), "=d"(edx)
-+	            : /* Input   */ "a"(n)
-+	            : /* Clobber */);
-+		#else
-+	         __asm__ __volatile__ (
-+	             "cpuid"
-+	             : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
-+	             : /* Input   */ "a"(n)
-+	             : /* Clobber */);
-+		#endif
-+    }
-+
-+#else // IMF_HAVE_SSE2 && __GNUC__
-+
-+    // Helper functions for generic compiler - all disabled
-+    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
-+    {
-+        eax = ebx = ecx = edx = 0;
-+    }
-+
-+#endif // IMF_HAVE_SSE2 && __GNUC__
-+
-+
-+#ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
-+
-+    void xgetbv(int n, int &eax, int &edx)
-+    {
-+        __asm__ __volatile__ (
-+            "xgetbv"
-+            : /* Output  */ "=a"(eax), "=d"(edx)
-+            : /* Input   */ "c"(n)
-+            : /* Clobber */);
-+    }
-+
-+#else //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
-+
-+    void xgetbv(int n, int &eax, int &edx)
-+    {
-+        eax = edx = 0;
-+    }
-+
-+#endif //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
-+
-+} // namespace
-+
-+CpuId::CpuId():
-+    sse2(false),
-+    sse3(false),
-+    ssse3(false),
-+    sse4_1(false),
-+    sse4_2(false),
-+    avx(false),
-+    f16c(false)
-+{
-+    bool osxsave = false;
-+    int  max     = 0;
-+    int  eax, ebx, ecx, edx;
-+
-+    cpuid(0, max, ebx, ecx, edx);
-+    if (max > 0)
-+    {
-+        cpuid(1, eax, ebx, ecx, edx);
-+        sse2    = ( edx & (1<<26) );
-+        sse3    = ( ecx & (1<< 0) );
-+        ssse3   = ( ecx & (1<< 9) );
-+        sse4_1  = ( ecx & (1<<19) );
-+        sse4_2  = ( ecx & (1<<20) );
-+        osxsave = ( ecx & (1<<27) );
-+        avx     = ( ecx & (1<<28) );
-+        f16c    = ( ecx & (1<<29) );
-+
-+        if (!osxsave)
-+        {
-+            avx = f16c = false;
-+        }
-+        else
-+        {
-+            xgetbv(0, eax, edx);
-+            // eax bit 1 - SSE managed, bit 2 - AVX managed
-+            if ((eax & 6) != 6)
-+            {
-+                avx = f16c = false;
-+            }
-+        }
-+    }
-+
-+#if defined(IMF_HAVE_SSE2) && defined(__ANDROID__)
-+    sse2 = true;
-+    sse3 = true;
-+#ifdef __x86_64__
-+    ssse3 = true;
-+    sse4_1 = true;
-+#endif
-+#endif
-+}
-+
-+OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
++        #ifdef __i386__
++            __asm__ __volatile__ (
++                "pushl %%ebx; cpuid; movl %%ebx, %0; popl %%ebx"
++                : /* Output  */ "=m"(ebx), "=a"(eax), "=c"(ecx), "=d"(edx) 
++                : /* Input   */ "a"(n)
++                : /* Clobber */);
++        #else
++            __asm__ __volatile__ (
++                "cpuid"
++                : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) 
++                : /* Input   */ "a"(n)
++                : /* Clobber */);
++        #endif
+     }
+ 
+ #else // IMF_HAVE_SSE2 && __GNUC__

From 45a77d6c6e24519de68e08f71742f078526623c4 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 25 Aug 2019 15:57:26 +0300
Subject: [PATCH 231/566] fix subprocess call

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index f6684f91..5f67e56b 100644
--- a/setup.py
+++ b/setup.py
@@ -150,7 +150,7 @@ def main():
     if sys.platform.startswith('linux') and not x64:
         cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
         # patch openEXR when building on i386, see: https://github.com/openexr/openexr/issues/128
-        subprocess.check_call(["patch", "-p0", "<", "patches/patchOpenEXR"])
+        subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
 
 
     if 'CMAKE_ARGS' in os.environ:

From 22e5ae842115a00a2f8a4d34b82c6f8eb767433f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 25 Aug 2019 10:55:31 -0400
Subject: [PATCH 232/566] fix patch

---
 patches/patchOpenEXR | 66 ++++++++++++++++++++++++++++++++------------
 1 file changed, 49 insertions(+), 17 deletions(-)

diff --git a/patches/patchOpenEXR b/patches/patchOpenEXR
index 6633e844..e2a1ffc7 100644
--- a/patches/patchOpenEXR
+++ b/patches/patchOpenEXR
@@ -1,28 +1,60 @@
 diff -ruN opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp
---- opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-23 08:11:43.536117200 -0400
-+++ opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-23 08:16:58.337879800 -0400
-@@ -44,11 +44,19 @@
+--- opencv/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-25 10:40:57.596395000 -0400
++++ opencv_patched/3rdparty/openexr/IlmImf/ImfSystemSpecific.cpp	2019-08-25 10:53:15.331689900 -0400
+@@ -40,21 +40,19 @@
+ 
+ namespace {
+ #if defined(IMF_HAVE_SSE2) && defined(__GNUC__) && !defined(__ANDROID__)
+-
++#include <cpuid.h>
      // Helper functions for gcc + SSE enabled
-     void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
+-    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
++    void cpuid(unsigned int n, unsigned int &eax, unsigned int &ebx,
++					unsigned int &ecx, unsigned int &edx)
      {
 -        __asm__ __volatile__ (
 -            "cpuid"
 -            : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) 
 -            : /* Input   */ "a"(n)
 -            : /* Clobber */);
-+        #ifdef __i386__
-+            __asm__ __volatile__ (
-+                "pushl %%ebx; cpuid; movl %%ebx, %0; popl %%ebx"
-+                : /* Output  */ "=m"(ebx), "=a"(eax), "=c"(ecx), "=d"(edx) 
-+                : /* Input   */ "a"(n)
-+                : /* Clobber */);
-+        #else
-+            __asm__ __volatile__ (
-+                "cpuid"
-+                : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) 
-+                : /* Input   */ "a"(n)
-+                : /* Clobber */);
-+        #endif
++        __get_cpuid(n, &eax, &ebx, &ecx, &edx);
      }
  
  #else // IMF_HAVE_SSE2 && __GNUC__
+ 
+     // Helper functions for generic compiler - all disabled
+-    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
++    void cpuid(unsigned int n, unsigned int &eax, unsigned int &ebx,
++					unsigned int &ecx, unsigned int &edx)
+     {
+         eax = ebx = ecx = edx = 0;
+     }
+@@ -64,7 +62,7 @@
+ 
+ #ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
+ 
+-    void xgetbv(int n, int &eax, int &edx)
++    void xgetbv(unsigned int n, unsigned int &eax, unsigned int &edx)
+     {
+         __asm__ __volatile__ (
+             "xgetbv"
+@@ -75,7 +73,7 @@
+ 
+ #else //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
+ 
+-    void xgetbv(int n, int &eax, int &edx)
++    void xgetbv(unsigned int n, unsigned int &eax, unsigned int &edx)
+     {
+         eax = edx = 0;
+     }
+@@ -94,8 +92,8 @@
+     f16c(false)
+ {
+     bool osxsave = false;
+-    int  max     = 0;
+-    int  eax, ebx, ecx, edx;
++    unsigned int  max     = 0;
++    unsigned int  eax, ebx, ecx, edx;
+ 
+     cpuid(0, max, ebx, ecx, edx);
+     if (max > 0)

From 299b0ded0c7ca2085e26454814c951f18cd8cc94 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 26 Oct 2019 15:47:07 +0300
Subject: [PATCH 233/566] update multibuild

---
 multibuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multibuild b/multibuild
index 951b6c64..160edd79 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit 951b6c64f01853cf2569000bb30ecd01a16bba0b
+Subproject commit 160edd796c25c0aa400b73ce79cecfa1758c181e

From 95ebeea602b39e84fb618cb7af0cdd9ec513ab0d Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 26 Oct 2019 15:49:28 +0300
Subject: [PATCH 234/566] add Python 3.8 to the matrix and use custom script to
 install it

---
 appveyor.yml | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/appveyor.yml b/appveyor.yml
index 3e755db9..8225a473 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -46,6 +46,14 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
+    - PYTHON: "C:/Python38"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python38-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
     - PYTHON: "C:/Python27"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
@@ -86,6 +94,14 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
+    - PYTHON: "C:/Python38"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python38-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
     - PYTHON: "C:/Python27"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
@@ -126,6 +142,14 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
+    - PYTHON: "C:/Python38"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python38-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
     - PYTHON: "C:/Python27"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
@@ -166,9 +190,24 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
+    - PYTHON: "C:/Python38"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python38-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
 matrix:
     fast_finish: true
 
+install:
+  - ps: |
+      if (-not (Test-Path $env:PYTHON)) {
+        curl -o install_python.ps1 https://raw.githubusercontent.com/matthew-brett/multibuild/11a389d78892cf90addac8f69433d5e22bfa422a/install_python.ps1
+        .\install_python.ps1
+      }
+
 build_script:
 - cmd: |
     "%PYTHON%/python.exe" -m pip install --upgrade pip

From b6b19b3182e4932f46a4b7f5bb3b8df1404c3654 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 27 Oct 2019 13:06:38 +0200
Subject: [PATCH 235/566] add Python to path

---
 appveyor.yml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/appveyor.yml b/appveyor.yml
index 8225a473..f6e447be 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -207,6 +207,9 @@ install:
         curl -o install_python.ps1 https://raw.githubusercontent.com/matthew-brett/multibuild/11a389d78892cf90addac8f69433d5e22bfa422a/install_python.ps1
         .\install_python.ps1
       }
+  - ps: if (-not (Test-Path $env:PYTHON)) { throw "No $env:PYTHON" }
+  - "set PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
+  - python --version
 
 build_script:
 - cmd: |

From bbd9f5f409451e92cb53f31905a4aa712d310aab Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 27 Oct 2019 13:57:41 +0200
Subject: [PATCH 236/566] echos for debug purposes

---
 .travis.yml | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index e6213b1c..b8e6510c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -635,16 +635,20 @@ before_install: |
     # Multibuild doesn't have releases, so --depth would break eventually (see
     # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
     git submodule update --init multibuild
+    echo "Source multibuild/common_utils.sh"
     source multibuild/common_utils.sh
     # https://github.com/matthew-brett/multibuild/issues/116
     if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+    echo "Source multibuild/travis_steps.sh"
     source multibuild/travis_steps.sh
     # This sets -x
+    echo "Source travis_multibuild_customize.sh"
     source travis_multibuild_customize.sh
     echo $ENABLE_CONTRIB > contrib.enabled
     echo $ENABLE_HEADLESS > headless.enabled
 
     if [ -n "$IS_OSX" ]; then
+        echo "homebrew"
         TAPS="$(brew --repository)/Library/Taps"
         if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
             rm -rf "$TAPS/caskroom/homebrew-cask"
@@ -658,7 +662,7 @@ before_install: |
 
         brew_cache_cleanup
     fi
-
+    echo "end"
     # Not interested in travis internal scripts' output
     set +x
 

From d85f52543be61effdaec4e9eb13f09d31f2ecf20 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 27 Oct 2019 14:23:12 +0200
Subject: [PATCH 237/566] downgrade multibuild

---
 multibuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multibuild b/multibuild
index 160edd79..951b6c64 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit 160edd796c25c0aa400b73ce79cecfa1758c181e
+Subproject commit 951b6c64f01853cf2569000bb30ecd01a16bba0b

From dd9dc06439dab33c2d9bc0a8b455432d106def3a Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 27 Oct 2019 19:27:30 +0200
Subject: [PATCH 238/566] try changing slash type

---
 appveyor.yml | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index f6e447be..021487d9 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -46,11 +46,11 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python38"
+    - PYTHON: "C:\\Python38"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python38-x64"
+    - PYTHON: "C:\\Python38-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
@@ -94,11 +94,11 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python38"
+    - PYTHON: "C:\\Python38"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python38-x64"
+    - PYTHON: "C:\\Python38-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
@@ -142,11 +142,11 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python38"
+    - PYTHON: "C:\\Python38"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python38-x64"
+    - PYTHON: "C:\\Python38-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
@@ -190,11 +190,11 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python38"
+    - PYTHON: "C:\\Python38"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python38-x64"
+    - PYTHON: "C:\\Python38-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 

From 46db5a5b459c600bc4ca8062d344a1e5c5cf4a08 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 27 Oct 2019 20:17:01 +0200
Subject: [PATCH 239/566] disable libvidstab

---
 travis_config.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index af888179..3dc56c9c 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -64,8 +64,8 @@ if [ -n "$IS_OSX" ]; then
                 if (!$found_blank && /^$/) {$_.="conflicts_with \"ffmpeg\"\n\n"; $found_blank=1; next;}
                 if (!$bottle_block && /^\s*bottle do$/) { $bottle_block=1; next; }
                 if ($bottle_block) { if (/^\s*end\s*$/) { $bottle_block=0} elsif (/^\s*sha256\s/) {$_=""} next; }
-if (/^\s*depends_on "(x264|x265|xvid|frei0r|rubberband)"$/) {$_=""; next;}
-                if (/^\s*--enable-(gpl|libx264|libx265|libxvid|frei0r|librubberband)$/) {$_=""; next;}
+if (/^\s*depends_on "(x264|x265|xvid|frei0r|rubberband|vidstab)"$/) {$_=""; next;}
+                if (/^\s*--enable-(gpl|libx264|libx265|libxvid|frei0r|librubberband|libvidstab)$/) {$_=""; next;}
                 ' <"$FF_FORMULA" >"$LFF_FORMULA"
             diff -u "$FF_FORMULA" "$LFF_FORMULA" || test $? -le 1
 
@@ -86,7 +86,7 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
-    
+
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
 
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
@@ -117,10 +117,10 @@ function pre_build {
         brew_go_bootstrap_mode 0
         return 0
     fi
-    
+
     # Have to install macpython late to avoid conflict with Homebrew Python update
     before_install
-    
+
   else
     echo "Running for linux"
   fi

From 6ef3cef7e5fcb483eeec24c9eaf7632c484686bf Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 27 Oct 2019 21:51:46 +0200
Subject: [PATCH 240/566] fix name

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index 3dc56c9c..13dc22f7 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -64,7 +64,7 @@ if [ -n "$IS_OSX" ]; then
                 if (!$found_blank && /^$/) {$_.="conflicts_with \"ffmpeg\"\n\n"; $found_blank=1; next;}
                 if (!$bottle_block && /^\s*bottle do$/) { $bottle_block=1; next; }
                 if ($bottle_block) { if (/^\s*end\s*$/) { $bottle_block=0} elsif (/^\s*sha256\s/) {$_=""} next; }
-if (/^\s*depends_on "(x264|x265|xvid|frei0r|rubberband|vidstab)"$/) {$_=""; next;}
+if (/^\s*depends_on "(x264|x265|xvid|frei0r|rubberband|libvidstab)"$/) {$_=""; next;}
                 if (/^\s*--enable-(gpl|libx264|libx265|libxvid|frei0r|librubberband|libvidstab)$/) {$_=""; next;}
                 ' <"$FF_FORMULA" >"$LFF_FORMULA"
             diff -u "$FF_FORMULA" "$LFF_FORMULA" || test $? -le 1

From c1210dbb03f444465b8487d2f0ae1e2b102001d1 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 28 Oct 2019 17:02:52 +0200
Subject: [PATCH 241/566] add Python 3.8 to setup.py

---
 setup.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index 6c75a9d4..9f4545ad 100644
--- a/setup.py
+++ b/setup.py
@@ -202,6 +202,7 @@ def main():
           'Programming Language :: Python :: 3.5',
           'Programming Language :: Python :: 3.6',
           'Programming Language :: Python :: 3.7',
+          'Programming Language :: Python :: 3.8',
           'Programming Language :: C++',
           'Programming Language :: Python :: Implementation :: CPython',
           'Topic :: Scientific/Engineering',

From 5cd0ffb76cea477e6c2572fb032fbde939fb9459 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 18 Nov 2019 19:26:56 +0200
Subject: [PATCH 242/566] remove global PLAT, possible fix for multibuild
 failure

---
 .travis.yml | 25 ++++++++++++++++++++++++-
 multibuild  |  2 +-
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index b8e6510c..7c5a223b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,7 +7,6 @@ env:
         - BDIST_PARAMS=""
         - CONFIG_PATH="travis_config.sh"
         - USE_CCACHE=1
-        - PLAT=x86_64
         - UNICODE_WIDTH=32
 
 
@@ -241,6 +240,7 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -249,6 +249,7 @@ matrix:
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -273,6 +274,7 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -288,6 +290,7 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -304,6 +307,7 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.11.3
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -321,6 +325,7 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -339,6 +344,7 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -347,6 +353,7 @@ matrix:
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -371,6 +378,7 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -386,6 +394,7 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -402,6 +411,7 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.11.3
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -419,6 +429,7 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -437,6 +448,7 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -445,6 +457,7 @@ matrix:
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -469,6 +482,7 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -484,6 +498,7 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -500,6 +515,7 @@ matrix:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -517,6 +533,7 @@ matrix:
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -536,6 +553,7 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -544,6 +562,7 @@ matrix:
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -568,6 +587,7 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -583,6 +603,7 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -599,6 +620,7 @@ matrix:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -616,6 +638,7 @@ matrix:
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
diff --git a/multibuild b/multibuild
index 951b6c64..68a4af04 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit 951b6c64f01853cf2569000bb30ecd01a16bba0b
+Subproject commit 68a4af043e2adb0d9353d4a0e1f3d871203237aa

From 6cc1821597ade6226463c4944a7a72e2336acfc4 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 18 Nov 2019 19:34:03 +0200
Subject: [PATCH 243/566] try another change

---
 .travis.yml | 1 +
 setup.py    | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 7c5a223b..117cc05f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,6 +8,7 @@ env:
         - CONFIG_PATH="travis_config.sh"
         - USE_CCACHE=1
         - UNICODE_WIDTH=32
+        - MB_PYTHON_OSX_VER=10.9
 
 
 # Host Python is never used
diff --git a/setup.py b/setup.py
index 9f4545ad..e461affb 100644
--- a/setup.py
+++ b/setup.py
@@ -138,7 +138,7 @@ def main():
         cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
                                                 # https://github.com/skvark/opencv-python/issues/21
         cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
-        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.8")
+        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9")
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with

From 458525fdef74a6a2f8d47662ea1a323b71905884 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 18 Nov 2019 20:24:57 +0200
Subject: [PATCH 244/566] maybe the issue is the missing MB_PYTHON_VERSION

---
 .travis.yml | 25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 117cc05f..8c059f5c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,6 +8,7 @@ env:
         - CONFIG_PATH="travis_config.sh"
         - USE_CCACHE=1
         - UNICODE_WIDTH=32
+        - MB_PYTHON_VERSION=3.7
         - MB_PYTHON_OSX_VER=10.9
 
 
@@ -241,7 +242,6 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -250,7 +250,6 @@ matrix:
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -275,7 +274,6 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -291,7 +289,6 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -308,7 +305,6 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.11.3
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -326,7 +322,6 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -345,7 +340,6 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -354,7 +348,6 @@ matrix:
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -379,7 +372,6 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -395,7 +387,6 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -412,7 +403,6 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.11.3
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -430,7 +420,6 @@ matrix:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -449,7 +438,6 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -458,7 +446,6 @@ matrix:
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -483,7 +470,6 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -499,7 +485,6 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -516,7 +501,6 @@ matrix:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -534,7 +518,6 @@ matrix:
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -554,7 +537,6 @@ matrix:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -563,7 +545,6 @@ matrix:
         - UNICODE_WIDTH=16
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -588,7 +569,6 @@ matrix:
         - MB_PYTHON_VERSION=3.4
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -604,7 +584,6 @@ matrix:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -621,7 +600,6 @@ matrix:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -639,7 +617,6 @@ matrix:
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - PLAT=x86_64
       cache:
         directories: $HOME/.ccache
     - os: linux

From ac7076921f689957b8fac199581ca0efbd83ff5a Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 18 Nov 2019 20:43:10 +0200
Subject: [PATCH 245/566] drop Python 3.4

---
 .travis.yml | 92 -----------------------------------------------------
 README.md   |  4 +--
 setup.py    |  1 -
 3 files changed, 2 insertions(+), 95 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 8c059f5c..10390843 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -73,14 +73,6 @@ matrix:
         - ENABLE_HEADLESS=0
       workspaces:
         use: brew_cache
-    - os: osx
-      osx_image: xcode8.3
-      env:
-        - MB_PYTHON_VERSION=3.4
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      workspaces:
-        use: brew_cache
     - os: osx
       osx_image: xcode8.3
       env:
@@ -116,14 +108,6 @@ matrix:
         - ENABLE_HEADLESS=1
       workspaces:
         use: brew_cache
-    - os: osx
-      osx_image: xcode8.3
-      env:
-        - MB_PYTHON_VERSION=3.4
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      workspaces:
-        use: brew_cache
     - os: osx
       osx_image: xcode8.3
       env:
@@ -159,14 +143,6 @@ matrix:
         - ENABLE_HEADLESS=0
       workspaces:
         use: brew_cache
-    - os: osx
-      osx_image: xcode8.3
-      env:
-        - MB_PYTHON_VERSION=3.4
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      workspaces:
-        use: brew_cache
     - os: osx
       osx_image: xcode8.3
       env:
@@ -202,14 +178,6 @@ matrix:
         - ENABLE_HEADLESS=1
       workspaces:
         use: brew_cache
-    - os: osx
-      osx_image: xcode8.3
-      env:
-        - MB_PYTHON_VERSION=3.4
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      workspaces:
-        use: brew_cache
     - os: osx
       osx_image: xcode8.3
       env:
@@ -269,21 +237,6 @@ matrix:
         - ENABLE_HEADLESS=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=3.4
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=3.4
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
@@ -367,21 +320,6 @@ matrix:
         - ENABLE_HEADLESS=1
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=3.4
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=3.4
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
@@ -465,21 +403,6 @@ matrix:
         - ENABLE_HEADLESS=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=3.4
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=3.4
-        - PLAT=i686
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
@@ -564,21 +487,6 @@ matrix:
         - ENABLE_HEADLESS=1
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=3.4
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=3.4
-        - PLAT=i686
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
diff --git a/README.md b/README.md
index 0db6eb08..68e5d78b 100644
--- a/README.md
+++ b/README.md
@@ -156,12 +156,12 @@ The default ``manylinux`` images have been extended with some OpenCV dependencie
 
 Python 2.7 is the only supported version in 2.x series. Python 2.7 support will be dropped in the end of 2019.
 
-Python 3.x releases follow Numpy releases. For example Python 3.3 is no longer supported by Numpy so support for it has been dropped in ``opencv-python``, too.
+Python 3.x releases are provided for officially supported versions (not in EOL).
 
 Currently, builds for following Python versions are provided:
 
 - 2.7
-- 3.4
 - 3.5
 - 3.6
 - 3.7
+- 3.8
diff --git a/setup.py b/setup.py
index e461affb..441c1582 100644
--- a/setup.py
+++ b/setup.py
@@ -198,7 +198,6 @@ def main():
           'Programming Language :: Python :: 2',
           'Programming Language :: Python :: 2.7',
           'Programming Language :: Python :: 3',
-          'Programming Language :: Python :: 3.4',
           'Programming Language :: Python :: 3.5',
           'Programming Language :: Python :: 3.6',
           'Programming Language :: Python :: 3.7',

From bc086c8884a431a3456e85fccffbc79915ea4943 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 18 Nov 2019 20:49:54 +0200
Subject: [PATCH 246/566] add Python 3.8 to Travis build matrix

---
 .travis.yml | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 setup.py    |  2 ++
 2 files changed, 70 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index 10390843..7ef5dd3d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -286,6 +286,23 @@ matrix:
         - TEST_DEPENDS=numpy==1.14.5
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.17.3
+      cache:
+        directories: $HOME/.ccache
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - PLAT=i686
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.17.3
+      cache:
+        directories: $HOME/.ccache
 
     # headless builds for Linux
     - os: linux
@@ -369,6 +386,23 @@ matrix:
         - TEST_DEPENDS=numpy==1.14.5
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.17.3
+      cache:
+        directories: $HOME/.ccache
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - PLAT=i686
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.17.3
+      cache:
+        directories: $HOME/.ccache
 
     # contrib builds for Linux
     - os: linux
@@ -452,6 +486,23 @@ matrix:
         - ENABLE_HEADLESS=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - TEST_DEPENDS=numpy==1.17.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - PLAT=i686
+        - TEST_DEPENDS=numpy==1.17.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
 
 
     # headless contrib builds for Linux
@@ -536,6 +587,23 @@ matrix:
         - ENABLE_HEADLESS=1
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - TEST_DEPENDS=numpy==1.17.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
+    - os: linux
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - PLAT=i686
+        - TEST_DEPENDS=numpy==1.17.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
 
 # The first line is printed in the folding header in Travis output
 before_install: |
diff --git a/setup.py b/setup.py
index 441c1582..5d9981ff 100644
--- a/setup.py
+++ b/setup.py
@@ -28,6 +28,8 @@ def main():
         minimum_supported_numpy = "1.11.3"
     if sys.version_info[:2] >= (3, 7):
         minimum_supported_numpy = "1.14.5"
+    if sys.version_info[:2] >= (3, 8):
+        minimum_supported_numpy = "1.17.3"
 
     numpy_version = get_or_install("numpy", minimum_supported_numpy)
     get_or_install("scikit-build")

From 9297e4ef49169228935c45f4e61183632091dc44 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 18 Nov 2019 21:06:45 +0200
Subject: [PATCH 247/566] migrate to Appveyor Python 3.8 version and drop
 Python 3.4

---
 appveyor.yml | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index 021487d9..899fa335 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -46,11 +46,11 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\\Python38"
+    - PYTHON: "C:/Python38"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\\Python38-x64"
+    - PYTHON: "C:/Python38-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
@@ -94,11 +94,11 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\\Python38"
+    - PYTHON: "C:/Python38"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\\Python38-x64"
+    - PYTHON: "C:/Python38-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
@@ -142,11 +142,11 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\\Python38"
+    - PYTHON: "C:/Python38"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\\Python38-x64"
+    - PYTHON: "C:/Python38-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
@@ -190,27 +190,17 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\\Python38"
+    - PYTHON: "C:/Python38"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\\Python38-x64"
+    - PYTHON: "C:/Python38-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
 matrix:
     fast_finish: true
 
-install:
-  - ps: |
-      if (-not (Test-Path $env:PYTHON)) {
-        curl -o install_python.ps1 https://raw.githubusercontent.com/matthew-brett/multibuild/11a389d78892cf90addac8f69433d5e22bfa422a/install_python.ps1
-        .\install_python.ps1
-      }
-  - ps: if (-not (Test-Path $env:PYTHON)) { throw "No $env:PYTHON" }
-  - "set PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
-  - python --version
-
 build_script:
 - cmd: |
     "%PYTHON%/python.exe" -m pip install --upgrade pip

From 3c518c5c5150fd21684f6c6d9fa84d8df24e8574 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 18 Nov 2019 22:27:53 +0200
Subject: [PATCH 248/566] build matrix fixes

---
 .travis.yml  | 36 ++++++++++++++++++++++++++++++++++++
 appveyor.yml | 32 --------------------------------
 2 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 7ef5dd3d..92b43fa6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -98,6 +98,15 @@ matrix:
         - TEST_DEPENDS=numpy==1.14.5
       workspaces:
         use: brew_cache
+    - os: osx
+      osx_image: xcode8.3
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.17.3
+      workspaces:
+        use: brew_cache
 
     # headless builds for MacOS
     - os: osx
@@ -133,6 +142,15 @@ matrix:
         - TEST_DEPENDS=numpy==1.14.5
       workspaces:
         use: brew_cache
+    - os: osx
+      osx_image: xcode8.3
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.17.3
+      workspaces:
+        use: brew_cache
 
     # Contrib builds for MacOS
     - os: osx
@@ -168,6 +186,15 @@ matrix:
         - TEST_DEPENDS=numpy==1.14.5
       workspaces:
         use: brew_cache
+    - os: osx
+      osx_image: xcode8.3
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.17.3
+      workspaces:
+        use: brew_cache
 
     # headless contrib builds for MacOS
     - os: osx
@@ -203,6 +230,15 @@ matrix:
         - TEST_DEPENDS=numpy==1.14.5
       workspaces:
         use: brew_cache
+    - os: osx
+      osx_image: xcode8.3
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.17.3
+      workspaces:
+        use: brew_cache
 
     # default builds for Linux
     - os: linux
diff --git a/appveyor.yml b/appveyor.yml
index 899fa335..bebe6e16 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -14,14 +14,6 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python34"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python34-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
@@ -62,14 +54,6 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python34"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python34-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
@@ -110,14 +94,6 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python34"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python34-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
@@ -158,14 +134,6 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python34"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python34-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1

From dfc59fe3a38be8926e5b0b63528dbd05b1fc17eb Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Tue, 19 Nov 2019 08:40:56 +0200
Subject: [PATCH 249/566] Update .travis.yml

---
 .travis.yml | 2 --
 1 file changed, 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 92b43fa6..d5f56edd 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,8 +9,6 @@ env:
         - USE_CCACHE=1
         - UNICODE_WIDTH=32
         - MB_PYTHON_VERSION=3.7
-        - MB_PYTHON_OSX_VER=10.9
-
 
 # Host Python is never used
 language: generic

From 59243695afc3ad161cd5ce9bc1d753f88cb4d19d Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 19 Nov 2019 17:56:38 +0200
Subject: [PATCH 250/566] OpenCV 3.4.8

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index ddbd10c0..6bdb9ca7 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit ddbd10c0019f3ee5f43b7902d47e7fc4303a6574
+Subproject commit 6bdb9ca725de52ada2b452699fbbd39d8ef41188
diff --git a/opencv_contrib b/opencv_contrib
index 0915b7ea..9d3efbd8 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 0915b7eaddba3c06d83e201c9a7595e73801f417
+Subproject commit 9d3efbd8f159f04fdb4e1d05693c922b5f06b1d7

From 9fc0c169344018e99f4b3e044c1461aaf079d09e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 19 Nov 2019 18:24:44 +0200
Subject: [PATCH 251/566] revert ffmpeg binary search path

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index e45eee5a..cac1456b 100644
--- a/setup.py
+++ b/setup.py
@@ -78,7 +78,7 @@ def main():
     # Path regexes with forward slashes relative to CMake install dir.
     rearrange_cmake_output_data = {
 
-        'cv2': ([r'bin/opencv_videoio_ffmpeg\d{3}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else []) +
+        'cv2': ([r'bin/opencv_ffmpeg\d{3}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else []) +
         # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
         # Naming conventions vary so widely between versions and OSes
         # had to give up on checking them.

From 32ce23ec0f971db4b88cbeff837e2e57000817b2 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 19 Nov 2019 19:28:28 +0200
Subject: [PATCH 252/566] fix data search path

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index cac1456b..24666ab0 100644
--- a/setup.py
+++ b/setup.py
@@ -85,7 +85,7 @@ def main():
         ['python/cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
 
         'cv2.data': [  # OPENCV_OTHER_INSTALL_PATH
-            ('etc' if os.name == 'nt' else 'share/opencv4') +
+            ('etc' if os.name == 'nt' else 'share/OpenCV') +
             r'/haarcascades/.*\.xml'
         ]
     }

From 61a7ec4441816d7ff8e951ba3f8ac1f10f6bd252 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 20 Nov 2019 18:40:15 +0200
Subject: [PATCH 253/566] OpenCV 4.1.2

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index ddbd10c0..4c71dbf0 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit ddbd10c0019f3ee5f43b7902d47e7fc4303a6574
+Subproject commit 4c71dbf0af70e8728b8a791695b083540af72887
diff --git a/opencv_contrib b/opencv_contrib
index 0915b7ea..83e98d24 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 0915b7eaddba3c06d83e201c9a7595e73801f417
+Subproject commit 83e98d2424bbe3854d4686dc6c9cf9a15812e8d7

From 68bb866cf8abdad5ffe4ec867d3668c106f2997f Mon Sep 17 00:00:00 2001
From: Pascal Chambon <pythoniks@gmail.com>
Date: Fri, 22 Nov 2019 17:07:12 +0100
Subject: [PATCH 254/566] add workaround for DLL errors in Windows Server.

---
 README.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/README.md b/README.md
index 68e5d78b..a8798ac6 100644
--- a/README.md
+++ b/README.md
@@ -52,6 +52,8 @@ A: If the import fails on Windows, make sure you have [Visual C++ redistributabl
 
 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](https://support.microsoft.com/en-us/help/3145500/media-feature-pack-list-for-windows-n-editions).
 
+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](https://github.com/skvark/opencv-python/issues/36) for a manual fix.
 
 If you still encounter the error after you have checked all the previous solutions, download [Dependencies](https://github.com/lucasg/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.

From 852f34dc71d12ed7cc9ede68d906234dccd0ca62 Mon Sep 17 00:00:00 2001
From: Mateusz Bysiek <mateusz.bysiek@gmail.com>
Date: Sat, 7 Dec 2019 14:31:05 +0900
Subject: [PATCH 255/566] don't use deprecated brew tap-pin

instead refer to the full package name when installing

fixes https://github.com/skvark/opencv-python/issues/266

context:
https://brew.sh/2019/04/04/homebrew-2.1.0/
https://github.com/Homebrew/brew/pull/5925
---
 travis_config.sh | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index 13dc22f7..36ca29aa 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -98,11 +98,10 @@ function pre_build {
 
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
-    brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
     if [ -n "$CACHE_STAGE" ]; then
-        brew_install_and_cache_within_time_limit qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
+        brew_install_and_cache_within_time_limit cartr/qt4/qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
-        brew install qt@4
+        brew install cartr/qt4/qt@4
     fi
 
     echo 'Installing FFmpeg'

From 22c900da5462e5e0d4c4b0d7f2e02287fd1e520e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E5=BB=BA=E5=86=9B?= <wjjn3033@corp.netease.com>
Date: Fri, 27 Dec 2019 16:29:51 +0800
Subject: [PATCH 256/566] fix: give up get_config_var() and use
 get_config_vars() instead.

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 5d9981ff..56f8fa72 100644
--- a/setup.py
+++ b/setup.py
@@ -67,7 +67,7 @@ def main():
 
     package_data = {
         'cv2':
-            ['*%s' % sysconfig.get_config_var('SO')] +
+            ['*%s' % sysconfig.get_config_vars().get('SO')] +
             (['*.dll'] if os.name == 'nt' else []) +
             ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
         'cv2.data':

From e3f80d932394050ff8b8a5233d57cf85a3955309 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 9 Jan 2020 19:45:41 +0200
Subject: [PATCH 257/566] update dockerfiles

---
 docker/Dockerfile_i686   | 4 ++--
 docker/Dockerfile_x86_64 | 4 ++--
 docker/README.md         | 6 ++----
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
index d5b315a2..cffc998c 100644
--- a/docker/Dockerfile_i686
+++ b/docker/Dockerfile_i686
@@ -61,8 +61,8 @@ RUN cd ~/ffmpeg_sources && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
-    tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.14.01/nasm-2.14.01.tar.bz2 && \
+    tar -xf nasm-2.14.01.tar.bz2 && cd nasm-2.14.01 && ./autogen.sh && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
diff --git a/docker/Dockerfile_x86_64 b/docker/Dockerfile_x86_64
index f7b0b081..c4d47bc7 100644
--- a/docker/Dockerfile_x86_64
+++ b/docker/Dockerfile_x86_64
@@ -61,8 +61,8 @@ RUN cd ~/ffmpeg_sources && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
-    tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.14.01/nasm-2.14.01.tar.bz2 && \
+    tar -xf nasm-2.14.01.tar.bz2 && cd nasm-2.14.01 && ./autogen.sh && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
diff --git a/docker/README.md b/docker/README.md
index e31d7a07..4ac6033c 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -2,13 +2,11 @@
 
 This folder includes Dockerfiles for extending both ``i686`` and ``x86_64`` manylinux images.
 
-The extended images were created to be able to build OpenCV in reasonable time with Travis.
-
-These images have been built locally because the process takes over 1,5 hours with modern i7 processor. The images are hosted at https://quay.io/user/skvark.
+The extended images were created to be able to build OpenCV in reasonable time with Travis. The images are hosted at https://quay.io/user/skvark.
 
 The images have following extra software installed:
 
 - Qt 4.8.7
 - Cmake 3.9.0
-- FFmpeg with libvpx (latest snapshots at the build time) and recent openssl
+- FFmpeg with libvpx (latest snapshots at the build time) and recent openssl + other FFmpeg dependencies built from sources
 - Some missing headers included from more recent Linux to be able to enable V4L / V4L2 support in OpenCV
\ No newline at end of file

From aec30500ac592fdfb24ac1547731f0fa91d1e04f Mon Sep 17 00:00:00 2001
From: Mateusz Bysiek <mateusz.bysiek@gmail.com>
Date: Sat, 7 Dec 2019 14:31:05 +0900
Subject: [PATCH 258/566] don't use deprecated brew tap-pin

instead refer to the full package name when installing

fixes https://github.com/skvark/opencv-python/issues/266

context:
https://brew.sh/2019/04/04/homebrew-2.1.0/
https://github.com/Homebrew/brew/pull/5925
---
 travis_config.sh | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index f79883f1..526d7180 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -98,11 +98,10 @@ function pre_build {
 
     echo 'Installing QT4'
     brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
-    brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
     if [ -n "$CACHE_STAGE" ]; then
-        brew_install_and_cache_within_time_limit qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
+        brew_install_and_cache_within_time_limit cartr/qt4/qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
-        brew install qt@4
+        brew install cartr/qt4/qt@4
     fi
 
     echo 'Installing FFmpeg'

From 89d683499f4822a71acc47e6d89c77c1ff09fae4 Mon Sep 17 00:00:00 2001
From: Pascal Chambon <pythoniks@gmail.com>
Date: Fri, 22 Nov 2019 17:07:12 +0100
Subject: [PATCH 259/566] add workaround for DLL errors in Windows Server.

---
 README.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/README.md b/README.md
index 12222ab5..40326573 100644
--- a/README.md
+++ b/README.md
@@ -52,6 +52,8 @@ A: If the import fails on Windows, make sure you have [Visual C++ redistributabl
 
 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](https://support.microsoft.com/en-us/help/3145500/media-feature-pack-list-for-windows-n-editions).
 
+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](https://github.com/skvark/opencv-python/issues/36) for a manual fix.
 
 If you still encounter the error after you have checked all the previous solutions, download [Dependencies](https://github.com/lucasg/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.

From 3848ecfb208ae7d19675fdcd9f0d16efec0cf49b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E5=BB=BA=E5=86=9B?= <wjjn3033@corp.netease.com>
Date: Fri, 27 Dec 2019 16:29:51 +0800
Subject: [PATCH 260/566] fix: give up get_config_var() and use
 get_config_vars() instead.

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 24666ab0..2cce857e 100644
--- a/setup.py
+++ b/setup.py
@@ -67,7 +67,7 @@ def main():
 
     package_data = {
         'cv2':
-            ['*%s' % sysconfig.get_config_var('SO')] +
+            ['*%s' % sysconfig.get_config_vars().get('SO')] +
             (['*.dll'] if os.name == 'nt' else []) +
             ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
         'cv2.data':

From cde3c56bb0ce65a2c73ea833ba5b3b88f2e3188f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 9 Jan 2020 19:45:41 +0200
Subject: [PATCH 261/566] update dockerfiles

---
 docker/Dockerfile_i686   | 4 ++--
 docker/Dockerfile_x86_64 | 4 ++--
 docker/README.md         | 6 ++----
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/docker/Dockerfile_i686 b/docker/Dockerfile_i686
index d5b315a2..cffc998c 100644
--- a/docker/Dockerfile_i686
+++ b/docker/Dockerfile_i686
@@ -61,8 +61,8 @@ RUN cd ~/ffmpeg_sources && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
-    tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.14.01/nasm-2.14.01.tar.bz2 && \
+    tar -xf nasm-2.14.01.tar.bz2 && cd nasm-2.14.01 && ./autogen.sh && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
diff --git a/docker/Dockerfile_x86_64 b/docker/Dockerfile_x86_64
index f7b0b081..c4d47bc7 100644
--- a/docker/Dockerfile_x86_64
+++ b/docker/Dockerfile_x86_64
@@ -61,8 +61,8 @@ RUN cd ~/ffmpeg_sources && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2 && \
-    tar -xf nasm-2.13.02.tar.bz2 && cd nasm-2.13.02 && ./autogen.sh && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.14.01/nasm-2.14.01.tar.bz2 && \
+    tar -xf nasm-2.14.01.tar.bz2 && cd nasm-2.14.01 && ./autogen.sh && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
diff --git a/docker/README.md b/docker/README.md
index e31d7a07..4ac6033c 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -2,13 +2,11 @@
 
 This folder includes Dockerfiles for extending both ``i686`` and ``x86_64`` manylinux images.
 
-The extended images were created to be able to build OpenCV in reasonable time with Travis.
-
-These images have been built locally because the process takes over 1,5 hours with modern i7 processor. The images are hosted at https://quay.io/user/skvark.
+The extended images were created to be able to build OpenCV in reasonable time with Travis. The images are hosted at https://quay.io/user/skvark.
 
 The images have following extra software installed:
 
 - Qt 4.8.7
 - Cmake 3.9.0
-- FFmpeg with libvpx (latest snapshots at the build time) and recent openssl
+- FFmpeg with libvpx (latest snapshots at the build time) and recent openssl + other FFmpeg dependencies built from sources
 - Some missing headers included from more recent Linux to be able to enable V4L / V4L2 support in OpenCV
\ No newline at end of file

From cd5aa672c399081ba0880ffe7d30fb73ebf65bf9 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 9 Jan 2020 21:35:13 +0200
Subject: [PATCH 262/566] OpenCV 3.4.9

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 6bdb9ca7..64e6cf9f 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 6bdb9ca725de52ada2b452699fbbd39d8ef41188
+Subproject commit 64e6cf9fe50ef25d317d3529a42d4862b93f002a
diff --git a/opencv_contrib b/opencv_contrib
index 9d3efbd8..91b39aa0 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 9d3efbd8f159f04fdb4e1d05693c922b5f06b1d7
+Subproject commit 91b39aa038600425038df6722a5b4d1b5d7b5ca6

From 6b55cee8fec8e661f33ecaf90556ece17d0fd3a6 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 9 Jan 2020 21:40:02 +0200
Subject: [PATCH 263/566] OpenCV 4.2.0

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 4c71dbf0..bda89a64 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 4c71dbf0af70e8728b8a791695b083540af72887
+Subproject commit bda89a6469aa79ecd8713967916bd754bff1d931
diff --git a/opencv_contrib b/opencv_contrib
index 83e98d24..65abc709 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 83e98d2424bbe3854d4686dc6c9cf9a15812e8d7
+Subproject commit 65abc7090dedc84bbedec4dfd143f0340e52114f

From 5d4357b6719c5a370c3444b216fbbf980d661686 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 11 Jan 2020 14:41:54 +0200
Subject: [PATCH 264/566] try to fix macos builds

---
 travis_config.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index 526d7180..a2bd4d44 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -101,6 +101,8 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         brew_install_and_cache_within_time_limit cartr/qt4/qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
+        # Added due to: Error: openssl@1.0 is already installed from homebrew/core! Please `brew uninstall openssl@1.0` first."
+        brew uninstall openssl@1.0
         brew install cartr/qt4/qt@4
     fi
 
@@ -119,7 +121,7 @@ function pre_build {
 
     # Have to install macpython late to avoid conflict with Homebrew Python update
     before_install
-    
+
   else
     echo "Running for linux"
   fi

From 7abef67bbc857f8ec84ccecf3d721cc58f1d2d9f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 11 Jan 2020 15:49:16 +0200
Subject: [PATCH 265/566] Revert "try to fix macos builds"

This reverts commit 5d4357b6719c5a370c3444b216fbbf980d661686.
---
 travis_config.sh | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index a2bd4d44..526d7180 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -101,8 +101,6 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         brew_install_and_cache_within_time_limit cartr/qt4/qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
-        # Added due to: Error: openssl@1.0 is already installed from homebrew/core! Please `brew uninstall openssl@1.0` first."
-        brew uninstall openssl@1.0
         brew install cartr/qt4/qt@4
     fi
 
@@ -121,7 +119,7 @@ function pre_build {
 
     # Have to install macpython late to avoid conflict with Homebrew Python update
     before_install
-
+    
   else
     echo "Running for linux"
   fi

From cc739293cc43f857cd3938a54b8ff5c4360d89f3 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 11 Jan 2020 16:40:16 +0200
Subject: [PATCH 266/566] try to repair

---
 travis_config.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index 526d7180..f2d885b1 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -101,6 +101,8 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         brew_install_and_cache_within_time_limit cartr/qt4/qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
+        brew tap --repair
+        brew audit cartr/qt4/qt@4
         brew install cartr/qt4/qt@4
     fi
 
@@ -119,7 +121,7 @@ function pre_build {
 
     # Have to install macpython late to avoid conflict with Homebrew Python update
     before_install
-    
+
   else
     echo "Running for linux"
   fi

From 37ef0d5a4ddae8aa4c6ad8fdbc7ea457294f3271 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 11 Jan 2020 17:06:42 +0200
Subject: [PATCH 267/566] remove audit

---
 travis_config.sh | 1 -
 1 file changed, 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index f2d885b1..f7c773b9 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -102,7 +102,6 @@ function pre_build {
         brew_install_and_cache_within_time_limit cartr/qt4/qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew tap --repair
-        brew audit cartr/qt4/qt@4
         brew install cartr/qt4/qt@4
     fi
 

From fbcfa54625998b8d7418e68e4fdde305a946245d Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 13 Jan 2020 17:51:17 +0200
Subject: [PATCH 268/566] switch to Qt5

---
 setup.py         | 5 ++++-
 travis_config.sh | 8 +++-----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/setup.py b/setup.py
index 2cce857e..779ea233 100644
--- a/setup.py
+++ b/setup.py
@@ -123,9 +123,12 @@ def main():
     ] + (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
 
     # OS-specific components
-    if (sys.platform == 'darwin' or sys.platform.startswith('linux')) and not build_headless:
+    if sys.platform.startswith('linux') and not build_headless:
         cmake_args.append("-DWITH_QT=4")
 
+    if sys.platform == 'darwin' and not build_headless:
+        cmake_args.append("-DWITH_QT=5")
+
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
         cmake_args.append("-DWITH_WIN32UI=OFF")
diff --git a/travis_config.sh b/travis_config.sh
index f7c773b9..3db6e4e5 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -96,13 +96,11 @@ function pre_build {
         brew_add_local_bottles
     fi
 
-    echo 'Installing QT4'
-    brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
+    echo 'Installing qt5'
     if [ -n "$CACHE_STAGE" ]; then
-        brew_install_and_cache_within_time_limit cartr/qt4/qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
+        brew_install_and_cache_within_time_limit qt5 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
-        brew tap --repair
-        brew install cartr/qt4/qt@4
+        brew install qt5
     fi
 
     echo 'Installing FFmpeg'

From 8a6e17eac33130a0f2c8e41abbc53dfe1c827b0b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jan 2020 19:14:31 +0200
Subject: [PATCH 269/566] Revert "switch to Qt5"

This reverts commit fbcfa54625998b8d7418e68e4fdde305a946245d.
---
 setup.py         | 5 +----
 travis_config.sh | 8 +++++---
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/setup.py b/setup.py
index 779ea233..2cce857e 100644
--- a/setup.py
+++ b/setup.py
@@ -123,12 +123,9 @@ def main():
     ] + (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
 
     # OS-specific components
-    if sys.platform.startswith('linux') and not build_headless:
+    if (sys.platform == 'darwin' or sys.platform.startswith('linux')) and not build_headless:
         cmake_args.append("-DWITH_QT=4")
 
-    if sys.platform == 'darwin' and not build_headless:
-        cmake_args.append("-DWITH_QT=5")
-
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
         cmake_args.append("-DWITH_WIN32UI=OFF")
diff --git a/travis_config.sh b/travis_config.sh
index 3db6e4e5..f7c773b9 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -96,11 +96,13 @@ function pre_build {
         brew_add_local_bottles
     fi
 
-    echo 'Installing qt5'
+    echo 'Installing QT4'
+    brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
     if [ -n "$CACHE_STAGE" ]; then
-        brew_install_and_cache_within_time_limit qt5 || { [ $? -gt 1 ] && return 2 || return 0; }
+        brew_install_and_cache_within_time_limit cartr/qt4/qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
-        brew install qt5
+        brew tap --repair
+        brew install cartr/qt4/qt@4
     fi
 
     echo 'Installing FFmpeg'

From 6d91fc217fa44ba57b76cb92025ddb120d74c1d2 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jan 2020 19:15:56 +0200
Subject: [PATCH 270/566] try again with qt4

---
 travis_config.sh | 1 -
 1 file changed, 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index f7c773b9..36ca29aa 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -101,7 +101,6 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         brew_install_and_cache_within_time_limit cartr/qt4/qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
-        brew tap --repair
         brew install cartr/qt4/qt@4
     fi
 

From a7991d7dd5a9be8e3e2a493fd0c461d7b6731f62 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 16 Jan 2020 17:16:34 +0200
Subject: [PATCH 271/566] upgrade macOS env to xcode9.4 and use Qt5

---
 .travis.yml      | 42 +++++++++++++++++++++---------------------
 setup.py         |  5 ++++-
 travis_config.sh |  7 +++----
 3 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index d5f56edd..92165672 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -38,7 +38,7 @@ matrix:
   include:
 
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       stage: s1
       workspaces:
         create:
@@ -64,7 +64,7 @@ matrix:
       #further jobs in the list will use the same stage until the next assignment
     - stage: final
       os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
@@ -72,7 +72,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -80,7 +80,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -88,7 +88,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -97,7 +97,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
         - ENABLE_CONTRIB=0
@@ -108,7 +108,7 @@ matrix:
 
     # headless builds for MacOS
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
@@ -116,7 +116,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -124,7 +124,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -132,7 +132,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -141,7 +141,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
         - ENABLE_CONTRIB=0
@@ -152,7 +152,7 @@ matrix:
 
     # Contrib builds for MacOS
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
@@ -160,7 +160,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -168,7 +168,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
@@ -176,7 +176,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -185,7 +185,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
         - ENABLE_CONTRIB=1
@@ -196,7 +196,7 @@ matrix:
 
     # headless contrib builds for MacOS
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
@@ -204,7 +204,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -212,7 +212,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
@@ -220,7 +220,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -229,7 +229,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
         - ENABLE_CONTRIB=1
diff --git a/setup.py b/setup.py
index 2cce857e..779ea233 100644
--- a/setup.py
+++ b/setup.py
@@ -123,9 +123,12 @@ def main():
     ] + (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
 
     # OS-specific components
-    if (sys.platform == 'darwin' or sys.platform.startswith('linux')) and not build_headless:
+    if sys.platform.startswith('linux') and not build_headless:
         cmake_args.append("-DWITH_QT=4")
 
+    if sys.platform == 'darwin' and not build_headless:
+        cmake_args.append("-DWITH_QT=5")
+
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
         cmake_args.append("-DWITH_WIN32UI=OFF")
diff --git a/travis_config.sh b/travis_config.sh
index 36ca29aa..3db6e4e5 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -96,12 +96,11 @@ function pre_build {
         brew_add_local_bottles
     fi
 
-    echo 'Installing QT4'
-    brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
+    echo 'Installing qt5'
     if [ -n "$CACHE_STAGE" ]; then
-        brew_install_and_cache_within_time_limit cartr/qt4/qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
+        brew_install_and_cache_within_time_limit qt5 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
-        brew install cartr/qt4/qt@4
+        brew install qt5
     fi
 
     echo 'Installing FFmpeg'

From f92b787105f5b9c7787d3562484ba061e8fda18a Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 16 Jan 2020 18:19:56 +0200
Subject: [PATCH 272/566] update multibuild

---
 multibuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multibuild b/multibuild
index 68a4af04..24d35a4a 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit 68a4af043e2adb0d9353d4a0e1f3d871203237aa
+Subproject commit 24d35a4af2583473a0ec224dbe1990dd1e0ace5d

From 932c024377bef7957e5e3ff0937fad27cfb7dc5f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 21 Jan 2020 16:19:04 +0200
Subject: [PATCH 273/566] unlink python2

---
 travis_config.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/travis_config.sh b/travis_config.sh
index 3db6e4e5..a3fa30d6 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -108,6 +108,7 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
+        brew unlink python@2
         brew install ffmpeg_opencv
     fi
 

From 64a747aeee7cecff16b90d4850b5b46f6486290d Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 21 Jan 2020 17:23:49 +0200
Subject: [PATCH 274/566] link qt5

---
 travis_config.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/travis_config.sh b/travis_config.sh
index a3fa30d6..eeb58f10 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -101,6 +101,7 @@ function pre_build {
         brew_install_and_cache_within_time_limit qt5 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew install qt5
+        brew link qt5 --force
     fi
 
     echo 'Installing FFmpeg'

From f62aef6028cec7bd03ae6eaa880881e5d7d46578 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 1 Feb 2020 13:54:06 +0200
Subject: [PATCH 275/566] try just exporting to the path

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index eeb58f10..27875867 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -101,7 +101,7 @@ function pre_build {
         brew_install_and_cache_within_time_limit qt5 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew install qt5
-        brew link qt5 --force
+        export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 
     echo 'Installing FFmpeg'

From a7e34e9cff72bb9b4ccb2dae604e62e3a6261863 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 1 Feb 2020 14:25:11 +0200
Subject: [PATCH 276/566] update multibuild

---
 multibuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multibuild b/multibuild
index 24d35a4a..6b0ddb52 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit 24d35a4af2583473a0ec224dbe1990dd1e0ace5d
+Subproject commit 6b0ddb5281f59d976c8026c082c9d73faf274790

From 625ee6301a0c747bfa2d4f38aede5091fab5c140 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 1 Feb 2020 22:14:31 +0200
Subject: [PATCH 277/566] update macOS targets

---
 .travis.yml | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index d5f56edd..92165672 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -38,7 +38,7 @@ matrix:
   include:
 
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       stage: s1
       workspaces:
         create:
@@ -64,7 +64,7 @@ matrix:
       #further jobs in the list will use the same stage until the next assignment
     - stage: final
       os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
@@ -72,7 +72,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -80,7 +80,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -88,7 +88,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -97,7 +97,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
         - ENABLE_CONTRIB=0
@@ -108,7 +108,7 @@ matrix:
 
     # headless builds for MacOS
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=0
@@ -116,7 +116,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -124,7 +124,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -132,7 +132,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -141,7 +141,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
         - ENABLE_CONTRIB=0
@@ -152,7 +152,7 @@ matrix:
 
     # Contrib builds for MacOS
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
@@ -160,7 +160,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -168,7 +168,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
@@ -176,7 +176,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -185,7 +185,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
         - ENABLE_CONTRIB=1
@@ -196,7 +196,7 @@ matrix:
 
     # headless contrib builds for MacOS
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=2.7
         - ENABLE_CONTRIB=1
@@ -204,7 +204,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -212,7 +212,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
@@ -220,7 +220,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=1
@@ -229,7 +229,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
-      osx_image: xcode8.3
+      osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
         - ENABLE_CONTRIB=1

From 2e02b3bd046521a304857547d883e5b957c0a501 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 1 Feb 2020 22:15:44 +0200
Subject: [PATCH 278/566] change to qt5 on macOS

---
 travis_config.sh | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index 36ca29aa..27875867 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -96,12 +96,12 @@ function pre_build {
         brew_add_local_bottles
     fi
 
-    echo 'Installing QT4'
-    brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
+    echo 'Installing qt5'
     if [ -n "$CACHE_STAGE" ]; then
-        brew_install_and_cache_within_time_limit cartr/qt4/qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
+        brew_install_and_cache_within_time_limit qt5 || { [ $? -gt 1 ] && return 2 || return 0; }
     else
-        brew install cartr/qt4/qt@4
+        brew install qt5
+        export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 
     echo 'Installing FFmpeg'
@@ -109,6 +109,7 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
+        brew unlink python@2
         brew install ffmpeg_opencv
     fi
 

From d7f2269bbc90eb3a8a07f9fa34d93961df08f28d Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 1 Feb 2020 22:16:53 +0200
Subject: [PATCH 279/566] update README

---
 README.md | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index a8798ac6..84b7bae3 100644
--- a/README.md
+++ b/README.md
@@ -140,6 +140,8 @@ A release is made and uploaded to PyPI when a new tag is pushed to master branch
 
 ``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:
@@ -166,4 +168,4 @@ Currently, builds for following Python versions are provided:
 - 3.5
 - 3.6
 - 3.7
-- 3.8
+- 3.8
\ No newline at end of file

From 7604aa0973bcd603350acdf5395fd9a979d5aef7 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 1 Feb 2020 22:17:31 +0200
Subject: [PATCH 280/566] add newline

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 84b7bae3..40326573 100644
--- a/README.md
+++ b/README.md
@@ -168,4 +168,4 @@ Currently, builds for following Python versions are provided:
 - 3.5
 - 3.6
 - 3.7
-- 3.8
\ No newline at end of file
+- 3.8

From e3e8ce62bd55d62e0b6f410f0a9a7da50419638e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 2 Feb 2020 15:32:33 +0200
Subject: [PATCH 281/566] fix qt version for macOS

---
 setup.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 56f8fa72..b355fab1 100644
--- a/setup.py
+++ b/setup.py
@@ -123,9 +123,12 @@ def main():
     ] + (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
 
     # OS-specific components
-    if (sys.platform == 'darwin' or sys.platform.startswith('linux')) and not build_headless:
+    if sys.platform.startswith('linux') and not build_headless:
         cmake_args.append("-DWITH_QT=4")
 
+    if sys.platform == 'darwin' and not build_headless:
+        cmake_args.append("-DWITH_QT=5")
+
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
         cmake_args.append("-DWITH_WIN32UI=OFF")

From 1ca69aaa7dbacfc72dbb7a03a0cb5556a693420b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 2 Feb 2020 15:33:33 +0200
Subject: [PATCH 282/566] update multibuild

---
 multibuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multibuild b/multibuild
index 68a4af04..6b0ddb52 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit 68a4af043e2adb0d9353d4a0e1f3d871203237aa
+Subproject commit 6b0ddb5281f59d976c8026c082c9d73faf274790

From 6c98a57fd5ce1d2e4dbfbc5b900fd1191ff3649e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 21 Mar 2020 16:26:24 +0200
Subject: [PATCH 283/566] drop Python 2.7, experimental Azure Storage artifact
 upload support

---
 .travis.yml | 175 ++++------------------------------------------------
 1 file changed, 13 insertions(+), 162 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 92165672..89cd98c0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -63,14 +63,6 @@ matrix:
     # default builds for MacOS
       #further jobs in the list will use the same stage until the next assignment
     - stage: final
-      os: osx
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      workspaces:
-        use: brew_cache
     - os: osx
       osx_image: xcode9.4
       env:
@@ -107,14 +99,6 @@ matrix:
         use: brew_cache
 
     # headless builds for MacOS
-    - os: osx
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      workspaces:
-        use: brew_cache
     - os: osx
       osx_image: xcode9.4
       env:
@@ -151,14 +135,6 @@ matrix:
         use: brew_cache
 
     # Contrib builds for MacOS
-    - os: osx
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      workspaces:
-        use: brew_cache
     - os: osx
       osx_image: xcode9.4
       env:
@@ -195,14 +171,6 @@ matrix:
         use: brew_cache
 
     # headless contrib builds for MacOS
-    - os: osx
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      workspaces:
-        use: brew_cache
     - os: osx
       osx_image: xcode9.4
       env:
@@ -239,38 +207,6 @@ matrix:
         use: brew_cache
 
     # default builds for Linux
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
@@ -339,38 +275,6 @@ matrix:
         directories: $HOME/.ccache
 
     # headless builds for Linux
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
@@ -439,38 +343,6 @@ matrix:
         directories: $HOME/.ccache
 
     # contrib builds for Linux
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
@@ -540,38 +412,6 @@ matrix:
 
 
     # headless contrib builds for Linux
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       env:
         - MB_PYTHON_VERSION=3.5
@@ -711,7 +551,7 @@ before_cache: |
     set +x; set +e
 
 after_success: |
-    # Upload wheels to pypi if requested
+    # Upload wheels to pypi if tag is set, otherwise save to Azure Storage
     if [ -n "$TRAVIS_TAG" ]; then
         set -x
 
@@ -742,5 +582,16 @@ after_success: |
         twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         set +x
     else
-        echo "Tag not set, deployment skipped."
+        set -x
+
+        if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
+          curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
+        else
+          brew install azure-cli
+        fi
+
+        az storage container create -n ${$TRAVIS_COMMIT} --public-access blob
+        az storage blob upload-batch -d ${$TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern *.whl
+
+        set -x
     fi

From 2fd09dc0c3872f496d4c294b20de7c35ef75c39b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 21 Mar 2020 16:59:27 +0200
Subject: [PATCH 284/566] fix variable name typo

---
 .travis.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 89cd98c0..01437347 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -590,8 +590,8 @@ after_success: |
           brew install azure-cli
         fi
 
-        az storage container create -n ${$TRAVIS_COMMIT} --public-access blob
-        az storage blob upload-batch -d ${$TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern *.whl
+        az storage container create -n ${TRAVIS_COMMIT} --public-access blob
+        az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern *.whl
 
         set -x
     fi

From 582621015b677d0a5135434c30e88976a4f69c9b Mon Sep 17 00:00:00 2001
From: David Lechner <david@lechnology.com>
Date: Thu, 13 Feb 2020 20:17:00 -0600
Subject: [PATCH 285/566] gitignore _skbuild/

---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 87caa5f8..0367e1b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -67,3 +67,4 @@ target/
 # Build temporary files
 /contrib.enabled
 /cv_version.py
+_skbuild/

From d1a71597a42a635a218292b94c0e826a2224c4ae Mon Sep 17 00:00:00 2001
From: David Lechner <david@lechnology.com>
Date: Fri, 14 Feb 2020 14:40:22 -0600
Subject: [PATCH 286/566] fix missing Qt plugin on macOS

---
 cv2/__init__.py        |  7 +++++++
 patches/patchQtPlugins | 12 ++++++++++++
 setup.py               |  2 ++
 3 files changed, 21 insertions(+)
 create mode 100644 patches/patchQtPlugins

diff --git a/cv2/__init__.py b/cv2/__init__.py
index 7612351b..ee8cd254 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -1,4 +1,6 @@
 import importlib
+import os
+import sys
 
 from .cv2 import *
 from .data import *
@@ -6,3 +8,8 @@
 # wildcard import above does not import "private" variables like __version__
 # this makes them available
 globals().update(importlib.import_module('cv2.cv2').__dict__)
+
+if sys.platform == 'darwin':
+    os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.join(
+        os.path.dirname(os.path.abspath(__file__)), 'qt', 'plugins'
+    )
diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
new file mode 100644
index 00000000..00b84582
--- /dev/null
+++ b/patches/patchQtPlugins
@@ -0,0 +1,12 @@
+diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt
+index 8ccad4d03a..0d5e2a79e9 100644
+--- a/opencv/CMakeLists.txt
++++ b/opencv/CMakeLists.txt
+@@ -1164,6 +1164,7 @@ if(WITH_QT OR HAVE_QT)
+   if(HAVE_QT5)
+     status("    QT:" "YES (ver ${Qt5Core_VERSION_STRING})")
+     status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt5OpenGL_LIBRARIES} ${Qt5OpenGL_VERSION_STRING})" ELSE NO)
++    install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
+   elseif(HAVE_QT)
+     status("    QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
+     status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)
diff --git a/setup.py b/setup.py
index b355fab1..302adc52 100644
--- a/setup.py
+++ b/setup.py
@@ -128,6 +128,7 @@ def main():
 
     if sys.platform == 'darwin' and not build_headless:
         cmake_args.append("-DWITH_QT=5")
+        rearrange_cmake_output_data['cv2.qt.plugins.platforms'] = [(r'lib/qt/plugins/platforms/libqcocoa\.dylib')]
 
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
@@ -144,6 +145,7 @@ def main():
                                                 # https://github.com/skvark/opencv-python/issues/21
         cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
         cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9")
+        subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with

From 280b0053987940d9d733d54daf559a16a08f74e4 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 22 Mar 2020 13:13:41 +0200
Subject: [PATCH 287/566] remove Python 2.7 from appveyor.yml

---
 appveyor.yml | 32 --------------------------------
 1 file changed, 32 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index bebe6e16..dab586c7 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -6,14 +6,6 @@ environment:
     secure: 0bXSOVjf9x8L7nErTivu92TF1FwNosTjFJQPmxp8Dys=
 
   matrix:
-    - PYTHON: "C:/Python27"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python27-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
@@ -46,14 +38,6 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python27"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python27-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
@@ -86,14 +70,6 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python27"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python27-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
@@ -126,14 +102,6 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python27"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python27-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1

From e0e4c577b1f0e6f450c8fc0d7e6d1e281f3c7f41 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 22 Mar 2020 14:15:41 +0200
Subject: [PATCH 288/566] matrix -> jobs, disable global default build by
 moving params to the matrix

---
 .travis.yml | 122 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 115 insertions(+), 7 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 01437347..a1816035 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,12 +10,6 @@ env:
         - UNICODE_WIDTH=32
         - MB_PYTHON_VERSION=3.7
 
-# Host Python is never used
-language: generic
-services: docker
-# https://docs.travis-ci.com/user/reference/xenial
-dist: xenial
-
 # Save some time, we and setup check them out on demand instead
 # https://docs.travis-ci.com/user/customizing-the-build/#Git-Clone-Depth
 git:
@@ -33,8 +27,10 @@ stages:
   - s1
   - final
 
-matrix:
+jobs:
   fast_finish: true
+  exclude:
+    - language: ruby
   include:
 
     - os: osx
@@ -64,6 +60,7 @@ matrix:
       #further jobs in the list will use the same stage until the next assignment
     - stage: final
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
@@ -72,6 +69,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
@@ -80,6 +78,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
@@ -89,6 +88,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
@@ -100,6 +100,7 @@ matrix:
 
     # headless builds for MacOS
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
@@ -108,6 +109,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
@@ -116,6 +118,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
@@ -125,6 +128,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
@@ -136,6 +140,7 @@ matrix:
 
     # Contrib builds for MacOS
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
@@ -144,6 +149,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
@@ -152,6 +158,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
@@ -161,6 +168,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
@@ -172,6 +180,7 @@ matrix:
 
     # headless contrib builds for MacOS
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
@@ -180,6 +189,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
@@ -188,6 +198,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
@@ -197,6 +208,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
@@ -208,6 +220,9 @@ matrix:
 
     # default builds for Linux
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -215,6 +230,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
@@ -223,6 +241,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -231,6 +252,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
@@ -240,6 +264,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -248,6 +275,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - PLAT=i686
@@ -257,6 +287,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - ENABLE_CONTRIB=0
@@ -265,6 +298,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - PLAT=i686
@@ -276,6 +312,9 @@ matrix:
 
     # headless builds for Linux
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -283,6 +322,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
@@ -291,6 +333,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -299,6 +344,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
@@ -308,6 +356,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -316,6 +367,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - PLAT=i686
@@ -325,6 +379,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - ENABLE_CONTRIB=0
@@ -333,6 +390,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - PLAT=i686
@@ -344,6 +404,9 @@ matrix:
 
     # contrib builds for Linux
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -351,6 +414,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
@@ -359,6 +425,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - TEST_DEPENDS=numpy==1.11.3
@@ -367,6 +436,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
@@ -376,6 +448,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - TEST_DEPENDS=numpy==1.14.5
@@ -384,6 +459,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - PLAT=i686
@@ -393,6 +471,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - TEST_DEPENDS=numpy==1.17.3
@@ -401,6 +482,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - PLAT=i686
@@ -413,6 +497,9 @@ matrix:
 
     # headless contrib builds for Linux
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -420,6 +507,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
@@ -428,6 +518,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - TEST_DEPENDS=numpy==1.11.3
@@ -436,6 +529,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
@@ -445,6 +541,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - TEST_DEPENDS=numpy==1.14.5
@@ -453,6 +552,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - PLAT=i686
@@ -462,6 +564,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - TEST_DEPENDS=numpy==1.17.3
@@ -470,6 +575,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - PLAT=i686

From 2947930b8117410171970fa4244a7c766e23284d Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 22 Mar 2020 14:18:20 +0200
Subject: [PATCH 289/566] add missing language

---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index a1816035..2def6217 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -32,8 +32,8 @@ jobs:
   exclude:
     - language: ruby
   include:
-
     - os: osx
+      language: generic
       osx_image: xcode9.4
       stage: s1
       workspaces:

From 54c6e4091b0d233b676adb0540a83dacd05bc3a0 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 22 Mar 2020 18:13:12 +0200
Subject: [PATCH 290/566] update multibuild and remove global MB_PYTHON_VERSION

---
 .travis.yml | 1 -
 multibuild  | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 2def6217..4ac4a233 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,7 +8,6 @@ env:
         - CONFIG_PATH="travis_config.sh"
         - USE_CCACHE=1
         - UNICODE_WIDTH=32
-        - MB_PYTHON_VERSION=3.7
 
 # Save some time, we and setup check them out on demand instead
 # https://docs.travis-ci.com/user/customizing-the-build/#Git-Clone-Depth
diff --git a/multibuild b/multibuild
index 6b0ddb52..1a9ddbee 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit 6b0ddb5281f59d976c8026c082c9d73faf274790
+Subproject commit 1a9ddbee89c90f38e86928e0a897af2245a8f30a

From cc33ed4146c227550af627f147addd3af3fe153b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 22 Mar 2020 18:24:36 +0200
Subject: [PATCH 291/566] workaround for multibuild error in cache step

---
 .travis.yml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index 4ac4a233..75801595 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -32,6 +32,8 @@ jobs:
     - language: ruby
   include:
     - os: osx
+      env:
+        - MB_PYTHON_VERSION=3.8
       language: generic
       osx_image: xcode9.4
       stage: s1

From 17d330fd9b4d2d2fe7f8ed6b03f60fa04d2e0491 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 22 Mar 2020 20:37:43 +0200
Subject: [PATCH 292/566] try to fix cmake python 3.7 errors

---
 setup.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/setup.py b/setup.py
index 302adc52..d9bae544 100644
--- a/setup.py
+++ b/setup.py
@@ -102,14 +102,16 @@ def main():
         "-G", "Unix Makefiles"  # don't make CMake try (and fail) Ninja first
     ]) + [
         # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
-        "-DPYTHON%d_EXECUTABLE=%s" % (sys.version_info[0], sys.executable),
-        "-DBUILD_opencv_python%d=ON" % sys.version_info[0],
+        "-DPYTHON_DEFAULT_EXECUTABLE=%s" % sys.executable,
+        "-DPYTHON3_EXECUTABLE=%s" % sys.executable,
+        "-DBUILD_opencv_python3=ON",
+        "-DBUILD_opencv_python2=OFF",
 
         # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
         "-DOPENCV_SKIP_PYTHON_LOADER=ON",
         # Relative dir to install the built module to in the build tree.
         # The default is generated from sysconfig, we'd rather have a constant for simplicity
-        "-DOPENCV_PYTHON%d_INSTALL_PATH=python" % sys.version_info[0],
+        "-DOPENCV_PYTHON3_INSTALL_PATH=python",
         # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
         # and skbuild bails out on seeing that
         "-DINSTALL_CREATE_DISTRIB=ON",
@@ -202,8 +204,6 @@ def main():
           'Operating System :: POSIX',
           'Operating System :: Unix',
           'Programming Language :: Python',
-          'Programming Language :: Python :: 2',
-          'Programming Language :: Python :: 2.7',
           'Programming Language :: Python :: 3',
           'Programming Language :: Python :: 3.5',
           'Programming Language :: Python :: 3.6',

From 40a20f9013bb7549392f3a75b16ad126f3b14724 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 24 Mar 2020 16:46:28 +0200
Subject: [PATCH 293/566] update multibuild

---
 multibuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multibuild b/multibuild
index 1a9ddbee..da36cd54 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit 1a9ddbee89c90f38e86928e0a897af2245a8f30a
+Subproject commit da36cd5408e03cad504217de4a21bb8f19f2fb2f

From 2801a962a667e049f62d6f46d70bbf4bd9de42ab Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 28 Mar 2020 13:55:24 +0200
Subject: [PATCH 294/566] merge changes from master, update licenses

---
 .gitignore             |   1 +
 .travis.yml            | 302 ++++++++++++++++++-----------------------
 LICENSE-3RD-PARTY.txt  | 174 +++++++++++++++++++++++-
 LICENSE.txt            |   2 +-
 README.md              |   7 +-
 cv2/__init__.py        |   7 +
 patches/patchQtPlugins |  12 ++
 setup.py               |   4 +-
 8 files changed, 329 insertions(+), 180 deletions(-)
 create mode 100644 patches/patchQtPlugins

diff --git a/.gitignore b/.gitignore
index 87caa5f8..0367e1b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -67,3 +67,4 @@ target/
 # Build temporary files
 /contrib.enabled
 /cv_version.py
+_skbuild/
diff --git a/.travis.yml b/.travis.yml
index 92165672..75801595 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,13 +8,6 @@ env:
         - CONFIG_PATH="travis_config.sh"
         - USE_CCACHE=1
         - UNICODE_WIDTH=32
-        - MB_PYTHON_VERSION=3.7
-
-# Host Python is never used
-language: generic
-services: docker
-# https://docs.travis-ci.com/user/reference/xenial
-dist: xenial
 
 # Save some time, we and setup check them out on demand instead
 # https://docs.travis-ci.com/user/customizing-the-build/#Git-Clone-Depth
@@ -33,11 +26,15 @@ stages:
   - s1
   - final
 
-matrix:
+jobs:
   fast_finish: true
+  exclude:
+    - language: ruby
   include:
-
     - os: osx
+      env:
+        - MB_PYTHON_VERSION=3.8
+      language: generic
       osx_image: xcode9.4
       stage: s1
       workspaces:
@@ -63,15 +60,8 @@ matrix:
     # default builds for MacOS
       #further jobs in the list will use the same stage until the next assignment
     - stage: final
-      os: osx
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      workspaces:
-        use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
@@ -80,6 +70,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
@@ -88,6 +79,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
@@ -97,6 +89,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
@@ -108,14 +101,7 @@ matrix:
 
     # headless builds for MacOS
     - os: osx
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      workspaces:
-        use: brew_cache
-    - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
@@ -124,6 +110,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
@@ -132,6 +119,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
@@ -141,6 +129,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
@@ -152,14 +141,7 @@ matrix:
 
     # Contrib builds for MacOS
     - os: osx
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      workspaces:
-        use: brew_cache
-    - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
@@ -168,6 +150,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
@@ -176,6 +159,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
@@ -185,6 +169,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
@@ -196,14 +181,7 @@ matrix:
 
     # headless contrib builds for MacOS
     - os: osx
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      workspaces:
-        use: brew_cache
-    - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.5
@@ -212,6 +190,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.6
@@ -220,6 +199,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.7
@@ -229,6 +209,7 @@ matrix:
       workspaces:
         use: brew_cache
     - os: osx
+      language: generic
       osx_image: xcode9.4
       env:
         - MB_PYTHON_VERSION=3.8
@@ -240,38 +221,9 @@ matrix:
 
     # default builds for Linux
     - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -279,6 +231,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
@@ -287,6 +242,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -295,6 +253,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
@@ -304,6 +265,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -312,6 +276,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - PLAT=i686
@@ -321,6 +288,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - ENABLE_CONTRIB=0
@@ -329,6 +299,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - PLAT=i686
@@ -340,38 +313,9 @@ matrix:
 
     # headless builds for Linux
     - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=0
@@ -379,6 +323,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
@@ -387,6 +334,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
@@ -395,6 +345,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
@@ -404,6 +357,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - ENABLE_CONTRIB=0
@@ -412,6 +368,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - PLAT=i686
@@ -421,6 +380,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - ENABLE_CONTRIB=0
@@ -429,6 +391,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - PLAT=i686
@@ -440,38 +405,9 @@ matrix:
 
     # contrib builds for Linux
     - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -479,6 +415,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
@@ -487,6 +426,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - TEST_DEPENDS=numpy==1.11.3
@@ -495,6 +437,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
@@ -504,6 +449,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - TEST_DEPENDS=numpy==1.14.5
@@ -512,6 +460,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - PLAT=i686
@@ -521,6 +472,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - TEST_DEPENDS=numpy==1.17.3
@@ -529,6 +483,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - PLAT=i686
@@ -541,38 +498,9 @@ matrix:
 
     # headless contrib builds for Linux
     - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      env:
-        - MB_PYTHON_VERSION=2.7
-        - PLAT=i686
-        - UNICODE_WIDTH=16
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - ENABLE_CONTRIB=1
@@ -580,6 +508,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.5
         - PLAT=i686
@@ -588,6 +519,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - TEST_DEPENDS=numpy==1.11.3
@@ -596,6 +530,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
@@ -605,6 +542,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - TEST_DEPENDS=numpy==1.14.5
@@ -613,6 +553,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.7
         - PLAT=i686
@@ -622,6 +565,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - TEST_DEPENDS=numpy==1.17.3
@@ -630,6 +576,9 @@ matrix:
       cache:
         directories: $HOME/.ccache
     - os: linux
+      language: generic
+      dist: xenial
+      services: docker
       env:
         - MB_PYTHON_VERSION=3.8
         - PLAT=i686
@@ -711,7 +660,7 @@ before_cache: |
     set +x; set +e
 
 after_success: |
-    # Upload wheels to pypi if requested
+    # Upload wheels to pypi if tag is set, otherwise save to Azure Storage
     if [ -n "$TRAVIS_TAG" ]; then
         set -x
 
@@ -742,5 +691,16 @@ after_success: |
         twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         set +x
     else
-        echo "Tag not set, deployment skipped."
+        set -x
+
+        if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
+          curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
+        else
+          brew install azure-cli
+        fi
+
+        az storage container create -n ${TRAVIS_COMMIT} --public-access blob
+        az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern *.whl
+
+        set -x
     fi
diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index 9daba95c..83551feb 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -10,12 +10,13 @@ copy or use the software.
                For Open Source Computer Vision Library
                        (3-clause BSD License)
 
-Copyright (C) 2000-2018, Intel Corporation, all rights reserved.
+Copyright (C) 2000-2020, Intel Corporation, all rights reserved.
 Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
 Copyright (C) 2009-2016, NVIDIA Corporation, all rights reserved.
 Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
 Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
 Copyright (C) 2015-2016, Itseez Inc., all rights reserved.
+Copyright (C) 2019-2020, Xperience AI, all rights reserved.
 Third party copyrights are property of their respective owners.
 
 Redistribution and use in source and binary forms, with or without modification,
@@ -80,7 +81,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 ------------------------------------------------------------------------------
 FFmpeg is redistributed within opencv-python Windows packages.
-Qt 4.8.7 is redistributed within opencv-python Linux and macOS packages.
+Qt 4.8.7 is redistributed within opencv-python Linux packages.
 This license applies to FFmpeg and Qt binaries in the directory cv2/.
 
                   GNU LESSER GENERAL PUBLIC LICENSE
@@ -585,3 +586,172 @@ necessary.  Here is a sample; alter the names:
   Ty Coon, President of Vice
 
 That's all there is to it!
+
+------------------------------------------------------------------------------
+Qt 5 is redistributed within opencv-pytho macOS packages.
+This license applies to Qt binaries in the directory cv2/.
+
+                   GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+  This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+  0. Additional Definitions.
+
+  As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+  "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+  An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+  A "Combined Work" is a work produced by combining or linking an
+Application with the Library.  The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+  The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+  The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+  1. Exception to Section 3 of the GNU GPL.
+
+  You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+  2. Conveying Modified Versions.
+
+  If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+   a) under this License, provided that you make a good faith effort to
+   ensure that, in the event an Application does not supply the
+   function or data, the facility still operates, and performs
+   whatever part of its purpose remains meaningful, or
+
+   b) under the GNU GPL, with none of the additional permissions of
+   this License applicable to that copy.
+
+  3. Object Code Incorporating Material from Library Header Files.
+
+  The object code form of an Application may incorporate material from
+a header file that is part of the Library.  You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+   a) Give prominent notice with each copy of the object code that the
+   Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the object code with a copy of the GNU GPL and this license
+   document.
+
+  4. Combined Works.
+
+  You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+   a) Give prominent notice with each copy of the Combined Work that
+   the Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the Combined Work with a copy of the GNU GPL and this license
+   document.
+
+   c) For a Combined Work that displays copyright notices during
+   execution, include the copyright notice for the Library among
+   these notices, as well as a reference directing the user to the
+   copies of the GNU GPL and this license document.
+
+   d) Do one of the following:
+
+       0) Convey the Minimal Corresponding Source under the terms of this
+       License, and the Corresponding Application Code in a form
+       suitable for, and under terms that permit, the user to
+       recombine or relink the Application with a modified version of
+       the Linked Version to produce a modified Combined Work, in the
+       manner specified by section 6 of the GNU GPL for conveying
+       Corresponding Source.
+
+       1) Use a suitable shared library mechanism for linking with the
+       Library.  A suitable mechanism is one that (a) uses at run time
+       a copy of the Library already present on the user's computer
+       system, and (b) will operate properly with a modified version
+       of the Library that is interface-compatible with the Linked
+       Version.
+
+   e) Provide Installation Information, but only if you would otherwise
+   be required to provide such information under section 6 of the
+   GNU GPL, and only to the extent that such information is
+   necessary to install and execute a modified version of the
+   Combined Work produced by recombining or relinking the
+   Application with a modified version of the Linked Version. (If
+   you use option 4d0, the Installation Information must accompany
+   the Minimal Corresponding Source and Corresponding Application
+   Code. If you use option 4d1, you must provide the Installation
+   Information in the manner specified by section 6 of the GNU GPL
+   for conveying Corresponding Source.)
+
+  5. Combined Libraries.
+
+  You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+   a) Accompany the combined library with a copy of the same work based
+   on the Library, uncombined with any other library facilities,
+   conveyed under the terms of this License.
+
+   b) Give prominent notice with the combined library that part of it
+   is a work based on the Library, and explaining where to find the
+   accompanying uncombined form of the same work.
+
+  6. Revised Versions of the GNU Lesser General Public License.
+
+  The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+  Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+  If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
\ No newline at end of file
diff --git a/LICENSE.txt b/LICENSE.txt
index e8005c63..328bf506 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,6 +1,6 @@
 MIT License
 
-Copyright (c) 2016-2018 Olli-Pekka Heinisuo and contributors
+Copyright (c) Olli-Pekka Heinisuo
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 40326573..46806e1a 100644
--- a/README.md
+++ b/README.md
@@ -128,7 +128,9 @@ Third party package licenses are at [LICENSE-3RD-PARTY.txt](https://github.com/s
 
 All wheels ship with [FFmpeg](http://ffmpeg.org) licensed under the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
 
-Linux and MacOS 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).
+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).
+
+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).
 
 ### Versioning
 
@@ -158,13 +160,10 @@ The default ``manylinux`` images have been extended with some OpenCV dependencie
 
 ### Supported Python versions
 
-Python 2.7 is the only supported version in 2.x series. Python 2.7 support will be dropped in the end of 2019.
-
 Python 3.x releases are provided for officially supported versions (not in EOL).
 
 Currently, builds for following Python versions are provided:
 
-- 2.7
 - 3.5
 - 3.6
 - 3.7
diff --git a/cv2/__init__.py b/cv2/__init__.py
index 7612351b..ee8cd254 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -1,4 +1,6 @@
 import importlib
+import os
+import sys
 
 from .cv2 import *
 from .data import *
@@ -6,3 +8,8 @@
 # wildcard import above does not import "private" variables like __version__
 # this makes them available
 globals().update(importlib.import_module('cv2.cv2').__dict__)
+
+if sys.platform == 'darwin':
+    os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.join(
+        os.path.dirname(os.path.abspath(__file__)), 'qt', 'plugins'
+    )
diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
new file mode 100644
index 00000000..00b84582
--- /dev/null
+++ b/patches/patchQtPlugins
@@ -0,0 +1,12 @@
+diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt
+index 8ccad4d03a..0d5e2a79e9 100644
+--- a/opencv/CMakeLists.txt
++++ b/opencv/CMakeLists.txt
+@@ -1164,6 +1164,7 @@ if(WITH_QT OR HAVE_QT)
+   if(HAVE_QT5)
+     status("    QT:" "YES (ver ${Qt5Core_VERSION_STRING})")
+     status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt5OpenGL_LIBRARIES} ${Qt5OpenGL_VERSION_STRING})" ELSE NO)
++    install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
+   elseif(HAVE_QT)
+     status("    QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
+     status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)
diff --git a/setup.py b/setup.py
index 779ea233..3f9ca68d 100644
--- a/setup.py
+++ b/setup.py
@@ -128,6 +128,7 @@ def main():
 
     if sys.platform == 'darwin' and not build_headless:
         cmake_args.append("-DWITH_QT=5")
+        rearrange_cmake_output_data['cv2.qt.plugins.platforms'] = [(r'lib/qt/plugins/platforms/libqcocoa\.dylib')]
 
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
@@ -144,6 +145,7 @@ def main():
                                                 # https://github.com/skvark/opencv-python/issues/21
         cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
         cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9")
+        subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
     if sys.platform == 'darwin' and build_contrib:
         cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -std=c++11 -Wno-c++11-narrowing")
@@ -203,8 +205,6 @@ def main():
           'Operating System :: POSIX',
           'Operating System :: Unix',
           'Programming Language :: Python',
-          'Programming Language :: Python :: 2',
-          'Programming Language :: Python :: 2.7',
           'Programming Language :: Python :: 3',
           'Programming Language :: Python :: 3.5',
           'Programming Language :: Python :: 3.6',

From b043422b263cd87c8767dd8134716f8ec847f5a5 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 28 Mar 2020 13:56:02 +0200
Subject: [PATCH 295/566] update multibuild

---
 multibuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multibuild b/multibuild
index 6b0ddb52..da36cd54 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit 6b0ddb5281f59d976c8026c082c9d73faf274790
+Subproject commit da36cd5408e03cad504217de4a21bb8f19f2fb2f

From e67bb4408050cc0322a4f18691d1f1de782922d1 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 28 Mar 2020 13:58:59 +0200
Subject: [PATCH 296/566] update README and licenses

---
 LICENSE-3RD-PARTY.txt | 174 +++++++++++++++++++++++++++++++++++++++++-
 LICENSE.txt           |   2 +-
 README.md             |   7 +-
 3 files changed, 176 insertions(+), 7 deletions(-)

diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index 9daba95c..83551feb 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -10,12 +10,13 @@ copy or use the software.
                For Open Source Computer Vision Library
                        (3-clause BSD License)
 
-Copyright (C) 2000-2018, Intel Corporation, all rights reserved.
+Copyright (C) 2000-2020, Intel Corporation, all rights reserved.
 Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
 Copyright (C) 2009-2016, NVIDIA Corporation, all rights reserved.
 Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
 Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
 Copyright (C) 2015-2016, Itseez Inc., all rights reserved.
+Copyright (C) 2019-2020, Xperience AI, all rights reserved.
 Third party copyrights are property of their respective owners.
 
 Redistribution and use in source and binary forms, with or without modification,
@@ -80,7 +81,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 ------------------------------------------------------------------------------
 FFmpeg is redistributed within opencv-python Windows packages.
-Qt 4.8.7 is redistributed within opencv-python Linux and macOS packages.
+Qt 4.8.7 is redistributed within opencv-python Linux packages.
 This license applies to FFmpeg and Qt binaries in the directory cv2/.
 
                   GNU LESSER GENERAL PUBLIC LICENSE
@@ -585,3 +586,172 @@ necessary.  Here is a sample; alter the names:
   Ty Coon, President of Vice
 
 That's all there is to it!
+
+------------------------------------------------------------------------------
+Qt 5 is redistributed within opencv-pytho macOS packages.
+This license applies to Qt binaries in the directory cv2/.
+
+                   GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+  This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+  0. Additional Definitions.
+
+  As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+  "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+  An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+  A "Combined Work" is a work produced by combining or linking an
+Application with the Library.  The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+  The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+  The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+  1. Exception to Section 3 of the GNU GPL.
+
+  You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+  2. Conveying Modified Versions.
+
+  If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+   a) under this License, provided that you make a good faith effort to
+   ensure that, in the event an Application does not supply the
+   function or data, the facility still operates, and performs
+   whatever part of its purpose remains meaningful, or
+
+   b) under the GNU GPL, with none of the additional permissions of
+   this License applicable to that copy.
+
+  3. Object Code Incorporating Material from Library Header Files.
+
+  The object code form of an Application may incorporate material from
+a header file that is part of the Library.  You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+   a) Give prominent notice with each copy of the object code that the
+   Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the object code with a copy of the GNU GPL and this license
+   document.
+
+  4. Combined Works.
+
+  You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+   a) Give prominent notice with each copy of the Combined Work that
+   the Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the Combined Work with a copy of the GNU GPL and this license
+   document.
+
+   c) For a Combined Work that displays copyright notices during
+   execution, include the copyright notice for the Library among
+   these notices, as well as a reference directing the user to the
+   copies of the GNU GPL and this license document.
+
+   d) Do one of the following:
+
+       0) Convey the Minimal Corresponding Source under the terms of this
+       License, and the Corresponding Application Code in a form
+       suitable for, and under terms that permit, the user to
+       recombine or relink the Application with a modified version of
+       the Linked Version to produce a modified Combined Work, in the
+       manner specified by section 6 of the GNU GPL for conveying
+       Corresponding Source.
+
+       1) Use a suitable shared library mechanism for linking with the
+       Library.  A suitable mechanism is one that (a) uses at run time
+       a copy of the Library already present on the user's computer
+       system, and (b) will operate properly with a modified version
+       of the Library that is interface-compatible with the Linked
+       Version.
+
+   e) Provide Installation Information, but only if you would otherwise
+   be required to provide such information under section 6 of the
+   GNU GPL, and only to the extent that such information is
+   necessary to install and execute a modified version of the
+   Combined Work produced by recombining or relinking the
+   Application with a modified version of the Linked Version. (If
+   you use option 4d0, the Installation Information must accompany
+   the Minimal Corresponding Source and Corresponding Application
+   Code. If you use option 4d1, you must provide the Installation
+   Information in the manner specified by section 6 of the GNU GPL
+   for conveying Corresponding Source.)
+
+  5. Combined Libraries.
+
+  You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+   a) Accompany the combined library with a copy of the same work based
+   on the Library, uncombined with any other library facilities,
+   conveyed under the terms of this License.
+
+   b) Give prominent notice with the combined library that part of it
+   is a work based on the Library, and explaining where to find the
+   accompanying uncombined form of the same work.
+
+  6. Revised Versions of the GNU Lesser General Public License.
+
+  The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+  Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+  If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
\ No newline at end of file
diff --git a/LICENSE.txt b/LICENSE.txt
index e8005c63..328bf506 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,6 +1,6 @@
 MIT License
 
-Copyright (c) 2016-2018 Olli-Pekka Heinisuo and contributors
+Copyright (c) Olli-Pekka Heinisuo
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 40326573..4c082db6 100644
--- a/README.md
+++ b/README.md
@@ -128,7 +128,9 @@ Third party package licenses are at [LICENSE-3RD-PARTY.txt](https://github.com/s
 
 All wheels ship with [FFmpeg](http://ffmpeg.org) licensed under the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
 
-Linux and MacOS 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).
+Linux 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).
+
+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).
 
 ### Versioning
 
@@ -158,13 +160,10 @@ The default ``manylinux`` images have been extended with some OpenCV dependencie
 
 ### Supported Python versions
 
-Python 2.7 is the only supported version in 2.x series. Python 2.7 support will be dropped in the end of 2019.
-
 Python 3.x releases are provided for officially supported versions (not in EOL).
 
 Currently, builds for following Python versions are provided:
 
-- 2.7
 - 3.5
 - 3.6
 - 3.7

From 64f8d2e7dab397a2424f17260765364c678ba2ae Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 28 Mar 2020 13:59:35 +0200
Subject: [PATCH 297/566] fix typo

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 4c082db6..46806e1a 100644
--- a/README.md
+++ b/README.md
@@ -128,7 +128,7 @@ Third party package licenses are at [LICENSE-3RD-PARTY.txt](https://github.com/s
 
 All wheels ship with [FFmpeg](http://ffmpeg.org) licensed under the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
 
-Linux 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).
+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).
 
 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).
 

From d608d694dd9564adfed51b26738dbeffde26a01c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 28 Mar 2020 14:09:16 +0200
Subject: [PATCH 298/566] disable MSMF in headless builds #263

---
 setup.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index d9bae544..758082ca 100644
--- a/setup.py
+++ b/setup.py
@@ -136,6 +136,7 @@ def main():
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
         cmake_args.append("-DWITH_WIN32UI=OFF")
         cmake_args.append("-DWITH_QT=OFF")
+        cmake_args.append("-DWITH_MSMF=OFF") # see: https://github.com/skvark/opencv-python/issues/263
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_V4L=ON")

From 07c4d737e2dad55c5f9238257b5104e9949b36fd Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 28 Mar 2020 14:09:55 +0200
Subject: [PATCH 299/566] disable MSMF in headless builds #263

---
 setup.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index 3f9ca68d..4ebb8811 100644
--- a/setup.py
+++ b/setup.py
@@ -134,6 +134,7 @@ def main():
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
         cmake_args.append("-DWITH_WIN32UI=OFF")
         cmake_args.append("-DWITH_QT=OFF")
+        cmake_args.append("-DWITH_MSMF=OFF") # see: https://github.com/skvark/opencv-python/issues/263
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_V4L=ON")

From fcb818b12885bbc780db116c39a9c4207d626898 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 28 Mar 2020 21:05:50 +0200
Subject: [PATCH 300/566] remove python 2.7

---
 appveyor.yml | 32 --------------------------------
 1 file changed, 32 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index bebe6e16..dab586c7 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -6,14 +6,6 @@ environment:
     secure: 0bXSOVjf9x8L7nErTivu92TF1FwNosTjFJQPmxp8Dys=
 
   matrix:
-    - PYTHON: "C:/Python27"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python27-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
@@ -46,14 +38,6 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python27"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python27-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
@@ -86,14 +70,6 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python27"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python27-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
@@ -126,14 +102,6 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python27"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python27-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
     - PYTHON: "C:/Python35"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1

From 184ab925f06b3b5a71eba4fcb847c9ad80106678 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 4 Apr 2020 20:16:51 +0300
Subject: [PATCH 301/566] update README

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 46806e1a..6a710cd2 100644
--- a/README.md
+++ b/README.md
@@ -64,7 +64,7 @@ A: Make sure you have removed old manual installations of OpenCV Python bindings
 
 **Q: Why the packages do not include non-free algorithms?**
 
-A: Non-free algorithms such as SIFT and SURF are not included in these packages because they are patented and therefore cannot be distributed as built binaries. See this issue for more info: https://github.com/skvark/opencv-python/issues/126
+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)?**
 

From fb48abe6af6239d4166328ce9062a5d529b194a9 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 4 Apr 2020 20:17:11 +0300
Subject: [PATCH 302/566] update README

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 46806e1a..6a710cd2 100644
--- a/README.md
+++ b/README.md
@@ -64,7 +64,7 @@ A: Make sure you have removed old manual installations of OpenCV Python bindings
 
 **Q: Why the packages do not include non-free algorithms?**
 
-A: Non-free algorithms such as SIFT and SURF are not included in these packages because they are patented and therefore cannot be distributed as built binaries. See this issue for more info: https://github.com/skvark/opencv-python/issues/126
+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)?**
 

From c08b0d771b8722ffeb859474b1b4a67e0f11a370 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 4 Apr 2020 20:18:18 +0300
Subject: [PATCH 303/566] OpenCV 3.4.10

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 64e6cf9f..1cc1e6fa 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 64e6cf9fe50ef25d317d3529a42d4862b93f002a
+Subproject commit 1cc1e6fa563f160b54f9c62da965002cab55ca96
diff --git a/opencv_contrib b/opencv_contrib
index 91b39aa0..5d2cf95a 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 91b39aa038600425038df6722a5b4d1b5d7b5ca6
+Subproject commit 5d2cf95afce53d1f742117ae39c9189a0ae4b4dd

From 35755449c6f233d877fac7594e5af82f8642fcac Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 4 Apr 2020 20:19:26 +0300
Subject: [PATCH 304/566] OpenCV 4.3.0

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index bda89a64..01b2c5a7 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit bda89a6469aa79ecd8713967916bd754bff1d931
+Subproject commit 01b2c5a77ca6dbef3baef24ebc0a5984579231d9
diff --git a/opencv_contrib b/opencv_contrib
index 65abc709..e6f32c6a 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 65abc7090dedc84bbedec4dfd143f0340e52114f
+Subproject commit e6f32c6a69043456a806a4e802ee3ce7b7059c93

From d958923cdd6fd7e23cb62722f645c64fbc6796fd Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 5 Apr 2020 12:54:45 +0300
Subject: [PATCH 305/566] fix FFmpeg binary regex pattern

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 4ebb8811..962775ee 100644
--- a/setup.py
+++ b/setup.py
@@ -78,7 +78,7 @@ def main():
     # Path regexes with forward slashes relative to CMake install dir.
     rearrange_cmake_output_data = {
 
-        'cv2': ([r'bin/opencv_ffmpeg\d{3}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else []) +
+        'cv2': ([r'bin/opencv_ffmpeg\d{3,4}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else []) +
         # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
         # Naming conventions vary so widely between versions and OSes
         # had to give up on checking them.

From 3d074bebe9c5519127075005c3bdae94079ab038 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 5 Apr 2020 15:52:13 +0300
Subject: [PATCH 306/566] initial manylinux2014 changes

---
 docker/{ => manylinux1}/Dockerfile_i686   |  0
 docker/{ => manylinux1}/Dockerfile_x86_64 |  0
 docker/manylinux2014/Dockerfile_i686      | 54 +++++++++++++++++++++++
 docker/manylinux2014/Dockerfile_x86_64    | 52 ++++++++++++++++++++++
 setup.py                                  | 19 ++------
 travis_multibuild_customize.sh            |  2 +-
 6 files changed, 110 insertions(+), 17 deletions(-)
 rename docker/{ => manylinux1}/Dockerfile_i686 (100%)
 rename docker/{ => manylinux1}/Dockerfile_x86_64 (100%)
 create mode 100644 docker/manylinux2014/Dockerfile_i686
 create mode 100644 docker/manylinux2014/Dockerfile_x86_64

diff --git a/docker/Dockerfile_i686 b/docker/manylinux1/Dockerfile_i686
similarity index 100%
rename from docker/Dockerfile_i686
rename to docker/manylinux1/Dockerfile_i686
diff --git a/docker/Dockerfile_x86_64 b/docker/manylinux1/Dockerfile_x86_64
similarity index 100%
rename from docker/Dockerfile_x86_64
rename to docker/manylinux1/Dockerfile_x86_64
diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
new file mode 100644
index 00000000..1c6568fe
--- /dev/null
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -0,0 +1,54 @@
+FROM quay.io/pypa/manylinux2014_i686:latest
+
+RUN yum install freetype-devel bzip2-devel curl-devel qt5-qtbase-devel -y
+
+RUN mkdir ~/ffmpeg_sources && \
+    cd ~/ffmpeg_sources && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
+    tar -xf OpenSSL_1_1_1c.tar.gz && \
+    cd openssl-OpenSSL_1_1_1c && \
+    # in i686, ./config detects x64 in i686 container without linux32
+    # when run from "docker build"
+    linux32 ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    #skip installing documentation
+    make install_sw && \
+    rm -rf ~/openssl_build
+
+RUN cd ~/ffmpeg_sources && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.14.01/nasm-2.14.01.tar.bz2 && \
+    tar -xf nasm-2.14.01.tar.bz2 && cd nasm-2.14.01 && ./autogen.sh && \
+    linux32 ./configure && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN cd ~/ffmpeg_sources && \
+    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
+    tar -xf yasm-1.3.0.tar.gz && \
+    cd yasm-1.3.0 && \
+    linux32 ./configure && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN cd ~/ffmpeg_sources && \
+    git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
+    cd libvpx && \
+    linux32 ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN cd ~/ffmpeg_sources && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
+    tar -xf ffmpeg-snapshot.tar.bz2 && \
+    cd ffmpeg && \
+    PATH=~/bin:$PATH && \
+    PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" linux32 ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install && \
+    echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
+    ldconfig && \
+    rm -rf ~/ffmpeg_sources
+
+ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
+ENV LDFLAGS -L/root/ffmpeg_build/lib
+ENV PATH "$HOME/bin:$PATH"
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
new file mode 100644
index 00000000..ff613b51
--- /dev/null
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -0,0 +1,52 @@
+FROM quay.io/pypa/manylinux2014_x86_64:latest
+
+RUN yum install freetype-devel bzip2-devel curl-devel qt5-qtbase-devel -y
+
+RUN mkdir ~/ffmpeg_sources && \
+    cd ~/ffmpeg_sources && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
+    tar -xf OpenSSL_1_1_1c.tar.gz && \
+    cd openssl-OpenSSL_1_1_1c && \
+    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    # skip installing documentation
+    make install_sw && \
+    rm -rf ~/openssl_build
+
+RUN cd ~/ffmpeg_sources && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.14.01/nasm-2.14.01.tar.bz2 && \
+    tar -xf nasm-2.14.01.tar.bz2 && cd nasm-2.14.01 && ./autogen.sh && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN cd ~/ffmpeg_sources && \
+    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
+    tar -xf yasm-1.3.0.tar.gz && \
+    cd yasm-1.3.0 && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN cd ~/ffmpeg_sources && \
+    git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
+    cd libvpx && \
+    ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN cd ~/ffmpeg_sources && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
+    tar -xf ffmpeg-snapshot.tar.bz2 && \
+    cd ffmpeg && \
+    PATH=~/bin:$PATH && \
+    PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install && \
+    echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
+    ldconfig && \
+    rm -rf ~/ffmpeg_sources
+
+ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
+ENV LDFLAGS -L/root/ffmpeg_build/lib
+ENV PATH "$HOME/bin:$PATH"
diff --git a/setup.py b/setup.py
index 758082ca..a2b9e7a8 100644
--- a/setup.py
+++ b/setup.py
@@ -33,6 +33,7 @@ def main():
 
     numpy_version = get_or_install("numpy", minimum_supported_numpy)
     get_or_install("scikit-build")
+    get_or_install("cmake")
     import skbuild
 
     if os.path.exists('.git'):
@@ -125,11 +126,10 @@ def main():
     ] + (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
 
     # OS-specific components
-    if sys.platform.startswith('linux') and not build_headless:
-        cmake_args.append("-DWITH_QT=4")
+    if sys.platform.startswith('linux') or sys.platform == 'darwin' and not build_headless:
+        cmake_args.append("-DWITH_QT=5")
 
     if sys.platform == 'darwin' and not build_headless:
-        cmake_args.append("-DWITH_QT=5")
         rearrange_cmake_output_data['cv2.qt.plugins.platforms'] = [(r'lib/qt/plugins/platforms/libqcocoa\.dylib')]
 
     if build_headless:
@@ -144,22 +144,9 @@ def main():
 
     # Fixes for macOS builds
     if sys.platform == 'darwin':
-        cmake_args.append("-DWITH_LAPACK=OFF")  # Some OSX LAPACK fns are incompatible, see
-                                                # https://github.com/skvark/opencv-python/issues/21
-        cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
         cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9")
         subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
-    if sys.platform.startswith('linux'):
-        cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with
-                                              # devtoolset-2 GCC 4.8.2 or vanilla GCC 4.9.4
-                                              # see https://github.com/skvark/opencv-python/issues/138
-    if sys.platform.startswith('linux') and not x64:
-        cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
-        # patch openEXR when building on i386, see: https://github.com/openexr/openexr/issues/128
-        subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
-
-
     if 'CMAKE_ARGS' in os.environ:
         import shlex
         cmake_args.extend(shlex.split(os.environ['CMAKE_ARGS']))
diff --git a/travis_multibuild_customize.sh b/travis_multibuild_customize.sh
index e34f5b26..5a9451be 100644
--- a/travis_multibuild_customize.sh
+++ b/travis_multibuild_customize.sh
@@ -3,4 +3,4 @@
 export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
 set -x
 REPO_DIR=$(dirname "${BASH_SOURCE[0]}")
-DOCKER_IMAGE='quay.io/skvark/manylinux1_$plat'
+DOCKER_IMAGE='quay.io/skvark/manylinux2014_$plat'

From e165257d7b091466e8f4b4f77c7c9d89e37a7a83 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 5 Apr 2020 16:30:34 +0300
Subject: [PATCH 307/566] fix qmake command and add ccache to i686 image

---
 docker/manylinux2014/Dockerfile_i686 | 7 +++++++
 travis_config.sh                     | 4 +++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index 1c6568fe..83957c6e 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -49,6 +49,13 @@ RUN cd ~/ffmpeg_sources && \
     ldconfig && \
     rm -rf ~/ffmpeg_sources
 
+RUN curl -O -L https://github.com/ccache/ccache/releases/download/v3.7.9/ccache-3.7.9.tar.gz && \
+    tar -xf ccache-3.7.9.tar.gz && \
+    cd ccache-3.7.9 && \
+    linux32 ./configure && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 ENV PATH "$HOME/bin:$PATH"
diff --git a/travis_config.sh b/travis_config.sh
index 27875867..c750bef2 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -104,6 +104,8 @@ function pre_build {
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 
+    qmake -query
+
     echo 'Installing FFmpeg'
 
     if [ -n "$CACHE_STAGE" ]; then
@@ -123,8 +125,8 @@ function pre_build {
 
   else
     echo "Running for linux"
+      qmake-qt5 -query
   fi
-  qmake -query
 }
 
 function run_tests {

From 23cdaad09344fefb8d13edc039414fbcd9c13f67 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 5 Apr 2020 16:52:11 +0300
Subject: [PATCH 308/566] remove qmake query

---
 travis_config.sh | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index c750bef2..fbf565b5 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -104,8 +104,6 @@ function pre_build {
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 
-    qmake -query
-
     echo 'Installing FFmpeg'
 
     if [ -n "$CACHE_STAGE" ]; then
@@ -125,7 +123,6 @@ function pre_build {
 
   else
     echo "Running for linux"
-      qmake-qt5 -query
   fi
 }
 

From 1b9bf2bc7cf9d3bf898953659bc0aaf9277882e2 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 5 Apr 2020 18:23:01 +0300
Subject: [PATCH 309/566] override ccache multibuild function, format setup.py
 with black and add DPYTHON3_LIBRARY and DPYTHON3_INCLUDE_DIR

---
 setup.py         | 334 +++++++++++++++++++++++++++++------------------
 travis_config.sh |  26 ++++
 2 files changed, 231 insertions(+), 129 deletions(-)

diff --git a/setup.py b/setup.py
index a2b9e7a8..2ba9295a 100644
--- a/setup.py
+++ b/setup.py
@@ -36,19 +36,24 @@ def main():
     get_or_install("cmake")
     import skbuild
 
-    if os.path.exists('.git'):
+    if os.path.exists(".git"):
 
         import pip._internal.vcs.git as git
+
         g = git.Git()  # NOTE: pip API's are internal, this has to be refactored
 
         g.run_command(["submodule", "sync"])
-        g.run_command(["submodule", "update", "--init", "--recursive", cmake_source_dir])
+        g.run_command(
+            ["submodule", "update", "--init", "--recursive", cmake_source_dir]
+        )
 
         if build_contrib:
-            g.run_command(["submodule", "update", "--init", "--recursive", "opencv_contrib"])
+            g.run_command(
+                ["submodule", "update", "--init", "--recursive", "opencv_contrib"]
+            )
 
     # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
-    x64 = sys.maxsize > 2**32
+    x64 = sys.maxsize > 2 ** 32
 
     package_name = "opencv-python"
 
@@ -61,116 +66,153 @@ def main():
     if build_headless and not build_contrib:
         package_name = "opencv-python-headless"
 
-    long_description = io.open('README.md', encoding="utf-8").read()
+    long_description = io.open("README.md", encoding="utf-8").read()
     package_version = get_opencv_version()
 
-    packages = ['cv2', 'cv2.data']
+    packages = ["cv2", "cv2.data"]
 
     package_data = {
-        'cv2':
-            ['*%s' % sysconfig.get_config_vars().get('SO')] +
-            (['*.dll'] if os.name == 'nt' else []) +
-            ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
-        'cv2.data':
-            ["*.xml"]
+        "cv2": ["*%s" % sysconfig.get_config_vars().get("SO")]
+        + (["*.dll"] if os.name == "nt" else [])
+        + ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
+        "cv2.data": ["*.xml"],
     }
 
     # Files from CMake output to copy to package.
     # Path regexes with forward slashes relative to CMake install dir.
     rearrange_cmake_output_data = {
-
-        'cv2': ([r'bin/opencv_videoio_ffmpeg\d{3}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else []) +
+        "cv2": (
+            [r"bin/opencv_videoio_ffmpeg\d{3}%s\.dll" % ("_64" if x64 else "")]
+            if os.name == "nt"
+            else []
+        )
+        +
         # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
         # Naming conventions vary so widely between versions and OSes
         # had to give up on checking them.
-        ['python/cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
-
-        'cv2.data': [  # OPENCV_OTHER_INSTALL_PATH
-            ('etc' if os.name == 'nt' else 'share/opencv4') +
-            r'/haarcascades/.*\.xml'
-        ]
+        ["python/cv2[^/]*%(ext)s" % {"ext": re.escape(sysconfig.get_config_var("SO"))}],
+        "cv2.data": [  # OPENCV_OTHER_INSTALL_PATH
+            ("etc" if os.name == "nt" else "share/opencv4") + r"/haarcascades/.*\.xml"
+        ],
     }
 
     # Files in sourcetree outside package dir that should be copied to package.
     # Raw paths relative to sourcetree root.
-    files_outside_package_dir = {
-        'cv2': ['LICENSE.txt', 'LICENSE-3RD-PARTY.txt']
-    }
+    files_outside_package_dir = {"cv2": ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"]}
 
-    cmake_args = ([
-        "-G", "Visual Studio 14" + (" Win64" if x64 else '')
-    ] if os.name == 'nt' else [
-        "-G", "Unix Makefiles"  # don't make CMake try (and fail) Ninja first
-    ]) + [
-        # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
-        "-DPYTHON_DEFAULT_EXECUTABLE=%s" % sys.executable,
-        "-DPYTHON3_EXECUTABLE=%s" % sys.executable,
-        "-DBUILD_opencv_python3=ON",
-        "-DBUILD_opencv_python2=OFF",
-
-        # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
-        "-DOPENCV_SKIP_PYTHON_LOADER=ON",
-        # Relative dir to install the built module to in the build tree.
-        # The default is generated from sysconfig, we'd rather have a constant for simplicity
-        "-DOPENCV_PYTHON3_INSTALL_PATH=python",
-        # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
-        # and skbuild bails out on seeing that
-        "-DINSTALL_CREATE_DISTRIB=ON",
-
-        # See opencv/CMakeLists.txt for options and defaults
-        "-DBUILD_opencv_apps=OFF",
-        "-DBUILD_SHARED_LIBS=OFF",
-        "-DBUILD_TESTS=OFF",
-        "-DBUILD_PERF_TESTS=OFF",
-        "-DBUILD_DOCS=OFF"
-    ] + (["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
+    cmake_args = (
+        (
+            ["-G", "Visual Studio 14" + (" Win64" if x64 else "")]
+            if os.name == "nt"
+            else ["-G", "Unix Makefiles"]  # don't make CMake try (and fail) Ninja first
+        )
+        + [
+            # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
+            "-DPYTHON_DEFAULT_EXECUTABLE=%s" % sys.executable,
+            "-DPYTHON3_INCLUDE_DIR=%s" % sysconfig.get_paths()["include"],
+            "-DBUILD_opencv_python3=ON",
+            "-DBUILD_opencv_python2=OFF",
+            # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
+            "-DOPENCV_SKIP_PYTHON_LOADER=ON",
+            # Relative dir to install the built module to in the build tree.
+            # The default is generated from sysconfig, we'd rather have a constant for simplicity
+            "-DOPENCV_PYTHON3_INSTALL_PATH=python",
+            # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
+            # and skbuild bails out on seeing that
+            "-DINSTALL_CREATE_DISTRIB=ON",
+            # See opencv/CMakeLists.txt for options and defaults
+            "-DBUILD_opencv_apps=OFF",
+            "-DBUILD_SHARED_LIBS=OFF",
+            "-DBUILD_TESTS=OFF",
+            "-DBUILD_PERF_TESTS=OFF",
+            "-DBUILD_DOCS=OFF",
+        ]
+        + (
+            [
+                "-DPYTHON3_LIBRARY=%s"
+                % os.path.join(
+                    *[
+                        sysconfig.get_config_var("BINDIR"),
+                        "libs",
+                        "python{}.lib".format(
+                            "".join(str(v) for v in sys.version_info[:2])
+                        ),
+                    ]
+                )
+            ]
+            if sys.platform.startswith("win")
+            else [
+                "-DPYTHON3_LIBRARY=%s"
+                % os.path.join(
+                    "/usr/lib/x86_64-linux-gnu/", sysconfig.get_config_var("LDLIBRARY")
+                )
+            ]
+        )
+        + (
+            ["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")]
+            if build_contrib
+            else []
+        )
+    )
 
     # OS-specific components
-    if sys.platform.startswith('linux') or sys.platform == 'darwin' and not build_headless:
+    if (
+        sys.platform.startswith("linux")
+        or sys.platform == "darwin"
+        and not build_headless
+    ):
         cmake_args.append("-DWITH_QT=5")
 
-    if sys.platform == 'darwin' and not build_headless:
-        rearrange_cmake_output_data['cv2.qt.plugins.platforms'] = [(r'lib/qt/plugins/platforms/libqcocoa\.dylib')]
+    if sys.platform == "darwin" and not build_headless:
+        rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
+            (r"lib/qt/plugins/platforms/libqcocoa\.dylib")
+        ]
 
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
         cmake_args.append("-DWITH_WIN32UI=OFF")
         cmake_args.append("-DWITH_QT=OFF")
-        cmake_args.append("-DWITH_MSMF=OFF") # see: https://github.com/skvark/opencv-python/issues/263
+        cmake_args.append(
+            "-DWITH_MSMF=OFF"
+        )  # see: https://github.com/skvark/opencv-python/issues/263
 
-    if sys.platform.startswith('linux'):
+    if sys.platform.startswith("linux"):
         cmake_args.append("-DWITH_V4L=ON")
         cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 
     # Fixes for macOS builds
-    if sys.platform == 'darwin':
+    if sys.platform == "darwin":
         cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9")
         subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
-    if 'CMAKE_ARGS' in os.environ:
+    if "CMAKE_ARGS" in os.environ:
         import shlex
-        cmake_args.extend(shlex.split(os.environ['CMAKE_ARGS']))
+
+        cmake_args.extend(shlex.split(os.environ["CMAKE_ARGS"]))
         del shlex
 
     # ABI config variables are introduced in PEP 425
     if sys.version_info[:2] < (3, 2):
         import warnings
-        warnings.filterwarnings('ignore', r"Config variable '[^']+' is unset, "
-                                          r"Python ABI tag may be incorrect",
-                                category=RuntimeWarning)
+
+        warnings.filterwarnings(
+            "ignore",
+            r"Config variable '[^']+' is unset, " r"Python ABI tag may be incorrect",
+            category=RuntimeWarning,
+        )
         del warnings
 
     # works via side effect
-    RearrangeCMakeOutput(rearrange_cmake_output_data,
-                         files_outside_package_dir,
-                         package_data.keys())
+    RearrangeCMakeOutput(
+        rearrange_cmake_output_data, files_outside_package_dir, package_data.keys()
+    )
 
     skbuild.setup(
         name=package_name,
         version=package_version,
-        url='https://github.com/skvark/opencv-python',
-        license='MIT',
-        description='Wrapper package for OpenCV python bindings.',
+        url="https://github.com/skvark/opencv-python",
+        license="MIT",
+        description="Wrapper package for OpenCV python bindings.",
         long_description=long_description,
         long_description_content_type="text/markdown",
         packages=packages,
@@ -180,32 +222,32 @@ def main():
         ext_modules=EmptyListWithLength(),
         install_requires="numpy>=%s" % numpy_version,
         classifiers=[
-          'Development Status :: 5 - Production/Stable',
-          'Environment :: Console',
-          'Intended Audience :: Developers',
-          'Intended Audience :: Education',
-          'Intended Audience :: Information Technology',
-          'Intended Audience :: Science/Research',
-          'License :: OSI Approved :: MIT License',
-          'Operating System :: MacOS',
-          'Operating System :: Microsoft :: Windows',
-          'Operating System :: POSIX',
-          'Operating System :: Unix',
-          'Programming Language :: Python',
-          'Programming Language :: Python :: 3',
-          'Programming Language :: Python :: 3.5',
-          'Programming Language :: Python :: 3.6',
-          'Programming Language :: Python :: 3.7',
-          'Programming Language :: Python :: 3.8',
-          'Programming Language :: C++',
-          'Programming Language :: Python :: Implementation :: CPython',
-          'Topic :: Scientific/Engineering',
-          'Topic :: Scientific/Engineering :: Image Recognition',
-          'Topic :: Software Development',
+            "Development Status :: 5 - Production/Stable",
+            "Environment :: Console",
+            "Intended Audience :: Developers",
+            "Intended Audience :: Education",
+            "Intended Audience :: Information Technology",
+            "Intended Audience :: Science/Research",
+            "License :: OSI Approved :: MIT License",
+            "Operating System :: MacOS",
+            "Operating System :: Microsoft :: Windows",
+            "Operating System :: POSIX",
+            "Operating System :: Unix",
+            "Programming Language :: Python",
+            "Programming Language :: Python :: 3",
+            "Programming Language :: Python :: 3.5",
+            "Programming Language :: Python :: 3.6",
+            "Programming Language :: Python :: 3.7",
+            "Programming Language :: Python :: 3.8",
+            "Programming Language :: C++",
+            "Programming Language :: Python :: Implementation :: CPython",
+            "Topic :: Scientific/Engineering",
+            "Topic :: Scientific/Engineering :: Image Recognition",
+            "Topic :: Software Development",
         ],
         cmake_args=cmake_args,
         cmake_source_dir=cmake_source_dir,
-          )
+    )
 
 
 class RearrangeCMakeOutput(object):
@@ -213,11 +255,13 @@ class RearrangeCMakeOutput(object):
         Patch SKBuild logic to only take files related to the Python package
         and construct a file hierarchy that SKBuild expects (see below)
     """
+
     _setuptools_wrap = None
 
     # Have to wrap a function reference, or it's converted
     # into an instance method on attr assignment
     import argparse
+
     wraps = argparse.Namespace(_classify_installed_files=None)
     del argparse
 
@@ -231,8 +275,12 @@ def __init__(self, package_paths_re, files_outside_package, packages):
         import skbuild.setuptools_wrap
 
         cls._setuptools_wrap = skbuild.setuptools_wrap
-        cls.wraps._classify_installed_files = cls._setuptools_wrap._classify_installed_files
-        cls._setuptools_wrap._classify_installed_files = self._classify_installed_files_override
+        cls.wraps._classify_installed_files = (
+            cls._setuptools_wrap._classify_installed_files
+        )
+        cls._setuptools_wrap._classify_installed_files = (
+            self._classify_installed_files_override
+        )
 
         cls.package_paths_re = package_paths_re
         cls.files_outside_package = files_outside_package
@@ -240,16 +288,25 @@ def __init__(self, package_paths_re, files_outside_package, packages):
 
     def __del__(self):
         cls = self.__class__
-        cls._setuptools_wrap._classify_installed_files = cls.wraps._classify_installed_files
+        cls._setuptools_wrap._classify_installed_files = (
+            cls.wraps._classify_installed_files
+        )
         cls.wraps._classify_installed_files = None
         cls._setuptools_wrap = None
 
-    def _classify_installed_files_override(self, install_paths,
-            package_data, package_prefixes,
-            py_modules, new_py_modules,
-            scripts, new_scripts,
-            data_files,
-            cmake_source_dir, cmake_install_reldir):
+    def _classify_installed_files_override(
+        self,
+        install_paths,
+        package_data,
+        package_prefixes,
+        py_modules,
+        new_py_modules,
+        scripts,
+        new_scripts,
+        data_files,
+        cmake_source_dir,
+        cmake_install_reldir,
+    ):
         """
             From all CMake output, we're only interested in a few files
             and must place them into CMake install dir according
@@ -264,10 +321,15 @@ def _classify_installed_files_override(self, install_paths,
 
         # 'relpath'/'reldir' = relative to CMAKE_INSTALL_DIR/cmake_install_dir
         # 'path'/'dir' = relative to sourcetree root
-        cmake_install_dir = os.path.join(cls._setuptools_wrap.CMAKE_INSTALL_DIR(),
-                                         cmake_install_reldir)
-        install_relpaths = [os.path.relpath(p, cmake_install_dir) for p in install_paths]
-        fslash_install_relpaths = [p.replace(os.path.sep, '/') for p in install_relpaths]
+        cmake_install_dir = os.path.join(
+            cls._setuptools_wrap.CMAKE_INSTALL_DIR(), cmake_install_reldir
+        )
+        install_relpaths = [
+            os.path.relpath(p, cmake_install_dir) for p in install_paths
+        ]
+        fslash_install_relpaths = [
+            p.replace(os.path.sep, "/") for p in install_relpaths
+        ]
         relpaths_zip = list(zip(fslash_install_relpaths, install_relpaths))
         del install_relpaths, fslash_install_relpaths
 
@@ -276,25 +338,28 @@ def _classify_installed_files_override(self, install_paths,
         print("Copying files from CMake output")
 
         for package_name, relpaths_re in cls.package_paths_re.items():
-            package_dest_reldir = package_name.replace('.', os.path.sep)
+            package_dest_reldir = package_name.replace(".", os.path.sep)
             for relpath_re in relpaths_re:
                 found = False
-                r = re.compile(relpath_re+'$')
+                r = re.compile(relpath_re + "$")
                 for fslash_relpath, relpath in relpaths_zip:
                     m = r.match(fslash_relpath)
-                    if not m: continue
+                    if not m:
+                        continue
                     found = True
                     new_install_relpath = os.path.join(
-                        package_dest_reldir,
-                        os.path.basename(relpath))
+                        package_dest_reldir, os.path.basename(relpath)
+                    )
                     cls._setuptools_wrap._copy_file(
                         os.path.join(cmake_install_dir, relpath),
                         os.path.join(cmake_install_dir, new_install_relpath),
-                        hide_listing=False)
+                        hide_listing=False,
+                    )
                     final_install_relpaths.append(new_install_relpath)
                     del m, fslash_relpath, new_install_relpath
                 else:
-                    if not found: raise Exception("Not found: '%s'" % relpath_re)
+                    if not found:
+                        raise Exception("Not found: '%s'" % relpath_re)
                 del r, found
 
         del relpaths_zip
@@ -302,30 +367,37 @@ def _classify_installed_files_override(self, install_paths,
         print("Copying files from non-default sourcetree locations")
 
         for package_name, paths in cls.files_outside_package.items():
-            package_dest_reldir = package_name.replace('.', os.path.sep)
+            package_dest_reldir = package_name.replace(".", os.path.sep)
             for path in paths:
                 new_install_relpath = os.path.join(
-                        package_dest_reldir,
-                        # Don't yet have a need to copy
-                        # to subdirectories of package dir
-                        os.path.basename(path))
+                    package_dest_reldir,
+                    # Don't yet have a need to copy
+                    # to subdirectories of package dir
+                    os.path.basename(path),
+                )
                 cls._setuptools_wrap._copy_file(
-                    path, os.path.join(cmake_install_dir, new_install_relpath),
-                    hide_listing=False
+                    path,
+                    os.path.join(cmake_install_dir, new_install_relpath),
+                    hide_listing=False,
                 )
                 final_install_relpaths.append(new_install_relpath)
 
-        final_install_paths = [os.path.join(cmake_install_dir, p) for p in final_install_relpaths]
+        final_install_paths = [
+            os.path.join(cmake_install_dir, p) for p in final_install_relpaths
+        ]
 
         return (cls.wraps._classify_installed_files)(
             final_install_paths,
-            package_data, package_prefixes,
-            py_modules, new_py_modules,
-            scripts, new_scripts,
+            package_data,
+            package_prefixes,
+            py_modules,
+            new_py_modules,
+            scripts,
+            new_scripts,
             data_files,
             # To get around a check that prepends source dir to paths and breaks package detection code.
-            cmake_source_dir='',
-            cmake_install_dir=cmake_install_reldir
+            cmake_source_dir="",
+            cmake_install_dir=cmake_install_reldir,
         )
 
 
@@ -338,15 +410,15 @@ def get_opencv_version():
     # cv_version.py should be generated by running find_version.py
     runpy.run_path("find_version.py")
     from cv_version import opencv_version
+
     return opencv_version
 
 
 def get_build_env_var_by_name(flag_name):
-
     flag_set = False
 
     try:
-        flag_set = bool(int(os.getenv('ENABLE_' + flag_name.upper() , None)))
+        flag_set = bool(int(os.getenv("ENABLE_" + flag_name.upper(), None)))
     except Exception:
         pass
 
@@ -363,15 +435,19 @@ def get_or_install(name, version=None):
     """ If a package is already installed, build against it. If not, install """
     # Do not import 3rd-party modules into the current process
     import json
+
     js_packages = json.loads(
-        subprocess.check_output([sys.executable, "-m", "pip", "list", "--format", "json"]).decode('ascii'))  # valid names & versions are ASCII as per PEP 440
+        subprocess.check_output(
+            [sys.executable, "-m", "pip", "list", "--format", "json"]
+        ).decode("ascii")
+    )  # valid names & versions are ASCII as per PEP 440
     try:
-        [package] = (package for package in js_packages if package['name'] == name)
+        [package] = (package for package in js_packages if package["name"] == name)
     except ValueError:
         install_packages("%s==%s" % (name, version) if version else name)
         return version
     else:
-        return package['version']
+        return package["version"]
 
 
 # This creates a list which is empty but returns a length of 1.
@@ -381,5 +457,5 @@ def __len__(self):
         return 1
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     main()
diff --git a/travis_config.sh b/travis_config.sh
index fbf565b5..cc5c0e24 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -5,6 +5,32 @@
 #See multibuild/README.rst
 echo "===  Loading config.sh  === "
 
+# custom ccache install because manylinux2014 i686 does not have ccache package
+function activate_ccache {
+    # Link up the correct location for ccache
+    mkdir -p /parent-home/.ccache
+    ln -s /parent-home/.ccache $HOME/.ccache
+
+    # Now install ccache
+    if [ "$(get_platform)" == x86_64 ]; then
+        suppress yum_install ccache
+    fi
+
+    # Create fake compilers and prepend them to the PATH
+    # Note that yum is supposed to create these for us,
+    # but I had trouble finding them
+    local ccache_dir=/usr/lib/ccache/compilers
+    mkdir -p $ccache_dir
+    ln -s /usr/bin/ccache $ccache_dir/gcc
+    ln -s /usr/bin/ccache $ccache_dir/g++
+    ln -s /usr/bin/ccache $ccache_dir/cc
+    ln -s /usr/bin/ccache $ccache_dir/c++
+    export PATH=$ccache_dir:$PATH
+
+    # Prove to the developer that ccache is activated
+    echo "Using C compiler: $(which gcc)"
+}
+
 # To see build progress
 function build_wheel {
     build_bdist_wheel $@

From c69e05d74a0820bce5b7faae854307eead9ac339 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 5 Apr 2020 20:40:50 +0300
Subject: [PATCH 310/566] just disable ccache for i686

---
 .travis.yml      | 16 ++++++++++++++++
 travis_config.sh | 26 --------------------------
 2 files changed, 16 insertions(+), 26 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 75801595..abdd069a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -239,6 +239,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -262,6 +263,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.11.3
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -285,6 +287,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -308,6 +311,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.17.3
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
 
@@ -331,6 +335,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -354,6 +359,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.11.3
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -377,6 +383,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -400,6 +407,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.17.3
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
 
@@ -423,6 +431,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -446,6 +455,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -469,6 +479,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -492,6 +503,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
 
@@ -516,6 +528,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -539,6 +552,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -562,6 +576,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -585,6 +600,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
 
diff --git a/travis_config.sh b/travis_config.sh
index cc5c0e24..fbf565b5 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -5,32 +5,6 @@
 #See multibuild/README.rst
 echo "===  Loading config.sh  === "
 
-# custom ccache install because manylinux2014 i686 does not have ccache package
-function activate_ccache {
-    # Link up the correct location for ccache
-    mkdir -p /parent-home/.ccache
-    ln -s /parent-home/.ccache $HOME/.ccache
-
-    # Now install ccache
-    if [ "$(get_platform)" == x86_64 ]; then
-        suppress yum_install ccache
-    fi
-
-    # Create fake compilers and prepend them to the PATH
-    # Note that yum is supposed to create these for us,
-    # but I had trouble finding them
-    local ccache_dir=/usr/lib/ccache/compilers
-    mkdir -p $ccache_dir
-    ln -s /usr/bin/ccache $ccache_dir/gcc
-    ln -s /usr/bin/ccache $ccache_dir/g++
-    ln -s /usr/bin/ccache $ccache_dir/cc
-    ln -s /usr/bin/ccache $ccache_dir/c++
-    export PATH=$ccache_dir:$PATH
-
-    # Prove to the developer that ccache is activated
-    echo "Using C compiler: $(which gcc)"
-}
-
 # To see build progress
 function build_wheel {
     build_bdist_wheel $@

From 8690b218ec6f7f7143a3f5e01b97a30e9b198a41 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 5 Apr 2020 22:03:26 +0300
Subject: [PATCH 311/566] add manually built cmake to i686, lapack

---
 docker/manylinux2014/Dockerfile_i686   | 12 +++++++++++-
 docker/manylinux2014/Dockerfile_x86_64 |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index 83957c6e..6133dc19 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -1,6 +1,6 @@
 FROM quay.io/pypa/manylinux2014_i686:latest
 
-RUN yum install freetype-devel bzip2-devel curl-devel qt5-qtbase-devel -y
+RUN yum install freetype-devel bzip2-devel curl-devel qt5-qtbase-devel lapack-devel -y
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
@@ -56,6 +56,16 @@ RUN curl -O -L https://github.com/ccache/ccache/releases/download/v3.7.9/ccache-
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
 
+RUN curl -O -L https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-3.17.0.tar.gz && \
+    tar -xf cmake-3.17.0.tar.gz && \
+    cd cmake-3.17.0 && \
+    export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
+    ./configure --system-curl && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf cmake-3.17.0*
+
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 ENV PATH "$HOME/bin:$PATH"
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index ff613b51..55d6b4c2 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -1,6 +1,6 @@
 FROM quay.io/pypa/manylinux2014_x86_64:latest
 
-RUN yum install freetype-devel bzip2-devel curl-devel qt5-qtbase-devel -y
+RUN yum install freetype-devel bzip2-devel curl-devel qt5-qtbase-devel lapack-devel -y
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \

From c5bb48b13c7254eb9760e4829e9b5bb612f0ae24 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 5 Apr 2020 23:00:36 +0300
Subject: [PATCH 312/566] openEXR patch is still needed

---
 setup.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/setup.py b/setup.py
index 2ba9295a..68c125b5 100644
--- a/setup.py
+++ b/setup.py
@@ -180,6 +180,9 @@ def main():
         cmake_args.append("-DWITH_V4L=ON")
         cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 
+    if sys.platform.startswith('linux') and not x64:
+        subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
+
     # Fixes for macOS builds
     if sys.platform == "darwin":
         cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9")

From 2945f7f9b517f7b76e6e68288b3213b21df30065 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 6 Apr 2020 18:11:00 +0300
Subject: [PATCH 313/566] update dockerfiles, fix setup.py

---
 docker/README.md                       | 11 +++----
 docker/manylinux2014/Dockerfile_i686   |  2 +-
 docker/manylinux2014/Dockerfile_x86_64 |  2 +-
 setup.py                               | 45 ++++++--------------------
 4 files changed, 16 insertions(+), 44 deletions(-)

diff --git a/docker/README.md b/docker/README.md
index 4ac6033c..7e09ee10 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -1,12 +1,9 @@
 ### Customized manylinux images for opencv-python
 
-This folder includes Dockerfiles for extending both ``i686`` and ``x86_64`` manylinux images.
+The subfolders include Dockerfiles for extending both ``i686`` and ``x86_64`` manylinux1 and manylinux2014 images.
 
-The extended images were created to be able to build OpenCV in reasonable time with Travis. The images are hosted at https://quay.io/user/skvark.
+Manylinux2014 is used in wheels with version 3.4.10.* / 4.3.0.* and above. 
 
-The images have following extra software installed:
+The extended images were created to be able to build OpenCV in reasonable time with Travis. The images are hosted at https://quay.io/user/skvark.
 
-- Qt 4.8.7
-- Cmake 3.9.0
-- FFmpeg with libvpx (latest snapshots at the build time) and recent openssl + other FFmpeg dependencies built from sources
-- Some missing headers included from more recent Linux to be able to enable V4L / V4L2 support in OpenCV
\ No newline at end of file
+See the dockerfiles for more info.
\ No newline at end of file
diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index 6133dc19..68678e8c 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -1,6 +1,6 @@
 FROM quay.io/pypa/manylinux2014_i686:latest
 
-RUN yum install freetype-devel bzip2-devel curl-devel qt5-qtbase-devel lapack-devel -y
+RUN yum install freetype-devel bzip2-devel curl-devel qt5-qtbase-devel blas-devel lapack-devel atlas-devel -y
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index 55d6b4c2..f6987f9d 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -1,6 +1,6 @@
 FROM quay.io/pypa/manylinux2014_x86_64:latest
 
-RUN yum install freetype-devel bzip2-devel curl-devel qt5-qtbase-devel lapack-devel -y
+RUN yum install freetype-devel bzip2-devel curl-devel qt5-qtbase-devel blas-devel lapack-devel atlas-devel -y
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
diff --git a/setup.py b/setup.py
index 68c125b5..3b82f34d 100644
--- a/setup.py
+++ b/setup.py
@@ -34,7 +34,13 @@ def main():
     numpy_version = get_or_install("numpy", minimum_supported_numpy)
     get_or_install("scikit-build")
     get_or_install("cmake")
+
     import skbuild
+    from skbuild import cmaker
+
+    python_version = cmaker.CMaker.get_python_version()
+    python_lib_path = cmaker.CMaker.get_python_library(python_version)
+    python_include_dir = cmaker.CMaker.get_python_include_dir(python_version)
 
     if os.path.exists(".git"):
 
@@ -109,7 +115,8 @@ def main():
         + [
             # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
             "-DPYTHON_DEFAULT_EXECUTABLE=%s" % sys.executable,
-            "-DPYTHON3_INCLUDE_DIR=%s" % sysconfig.get_paths()["include"],
+            "-DPYTHON3_INCLUDE_DIR=%s" % python_include_dir,
+            "-DPYTHON3_LIBRARY=%s" % python_lib_path,
             "-DBUILD_opencv_python3=ON",
             "-DBUILD_opencv_python2=OFF",
             # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
@@ -127,27 +134,6 @@ def main():
             "-DBUILD_PERF_TESTS=OFF",
             "-DBUILD_DOCS=OFF",
         ]
-        + (
-            [
-                "-DPYTHON3_LIBRARY=%s"
-                % os.path.join(
-                    *[
-                        sysconfig.get_config_var("BINDIR"),
-                        "libs",
-                        "python{}.lib".format(
-                            "".join(str(v) for v in sys.version_info[:2])
-                        ),
-                    ]
-                )
-            ]
-            if sys.platform.startswith("win")
-            else [
-                "-DPYTHON3_LIBRARY=%s"
-                % os.path.join(
-                    "/usr/lib/x86_64-linux-gnu/", sysconfig.get_config_var("LDLIBRARY")
-                )
-            ]
-        )
         + (
             ["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")]
             if build_contrib
@@ -178,9 +164,10 @@ def main():
 
     if sys.platform.startswith("linux"):
         cmake_args.append("-DWITH_V4L=ON")
+        cmake_args.append("-DWITH_LAPACK=ON")
         cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 
-    if sys.platform.startswith('linux') and not x64:
+    if sys.platform.startswith("linux") and not x64:
         subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
 
     # Fixes for macOS builds
@@ -190,21 +177,9 @@ def main():
 
     if "CMAKE_ARGS" in os.environ:
         import shlex
-
         cmake_args.extend(shlex.split(os.environ["CMAKE_ARGS"]))
         del shlex
 
-    # ABI config variables are introduced in PEP 425
-    if sys.version_info[:2] < (3, 2):
-        import warnings
-
-        warnings.filterwarnings(
-            "ignore",
-            r"Config variable '[^']+' is unset, " r"Python ABI tag may be incorrect",
-            category=RuntimeWarning,
-        )
-        del warnings
-
     # works via side effect
     RearrangeCMakeOutput(
         rearrange_cmake_output_data, files_outside_package_dir, package_data.keys()

From a3f18434d0f0081a5dbc67f2a5c9d2079718f63c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 6 Apr 2020 18:25:39 +0300
Subject: [PATCH 314/566] Python 3 executable

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 3b82f34d..1cc5d0e2 100644
--- a/setup.py
+++ b/setup.py
@@ -114,7 +114,7 @@ def main():
         )
         + [
             # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
-            "-DPYTHON_DEFAULT_EXECUTABLE=%s" % sys.executable,
+            "-DPYTHON3_EXECUTABLE=%s" % sys.executable,
             "-DPYTHON3_INCLUDE_DIR=%s" % python_include_dir,
             "-DPYTHON3_LIBRARY=%s" % python_lib_path,
             "-DBUILD_opencv_python3=ON",

From 49ed880fd366de21d094debfe17555ccdc9bd306 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 6 Apr 2020 18:45:35 +0300
Subject: [PATCH 315/566] cmake needs forward slashes

---
 setup.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index 1cc5d0e2..24aa0116 100644
--- a/setup.py
+++ b/setup.py
@@ -39,8 +39,8 @@ def main():
     from skbuild import cmaker
 
     python_version = cmaker.CMaker.get_python_version()
-    python_lib_path = cmaker.CMaker.get_python_library(python_version)
-    python_include_dir = cmaker.CMaker.get_python_include_dir(python_version)
+    python_lib_path = cmaker.CMaker.get_python_library(python_version).replace('\\', '/')
+    python_include_dir = cmaker.CMaker.get_python_include_dir(python_version).replace('\\', '/')
 
     if os.path.exists(".git"):
 

From cca2a16e34fe5f7e39ab3d3d0cbc2b3a25f926ce Mon Sep 17 00:00:00 2001
From: Jordan Speicher <uSpike@users.noreply.github.com>
Date: Wed, 8 Apr 2020 17:08:31 -0500
Subject: [PATCH 316/566] Only patch when called with "bdist_wheel"

"pip wheel" will call setup.py multiple times, so we should only run "patch" once when setup.py is called with "bdist_wheel".
---
 setup.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index 758082ca..41552579 100644
--- a/setup.py
+++ b/setup.py
@@ -148,7 +148,8 @@ def main():
                                                 # https://github.com/skvark/opencv-python/issues/21
         cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
         cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9")
-        subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
+        if "bdist_wheel" in sys.argv:
+            subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with
@@ -157,7 +158,8 @@ def main():
     if sys.platform.startswith('linux') and not x64:
         cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
         # patch openEXR when building on i386, see: https://github.com/openexr/openexr/issues/128
-        subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
+        if "bdist_wheel" in sys.argv:
+            subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
 
 
     if 'CMAKE_ARGS' in os.environ:

From a8dfcf21b1470921aec027a2532db37b7a1ba27e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 21 May 2020 13:34:06 +0300
Subject: [PATCH 317/566] Qt5 requires platform plugins also on Linux, update
 i686 Dockerfile

---
 cv2/__init__.py                      | 2 +-
 docker/manylinux2014/Dockerfile_i686 | 6 ++++++
 setup.py                             | 5 +++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/cv2/__init__.py b/cv2/__init__.py
index ee8cd254..1207db95 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -9,7 +9,7 @@
 # this makes them available
 globals().update(importlib.import_module('cv2.cv2').__dict__)
 
-if sys.platform == 'darwin':
+if sys.platform == 'darwin' or sys.platform.startswith("linux"):
     os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), 'qt', 'plugins'
     )
diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index 68678e8c..e9e49d61 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -68,4 +68,10 @@ RUN curl -O -L https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-
 
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
+
+# in i686, yum metadata ends up with slightly wrong timestamps
+# which inhibits its update
+# https://github.com/skvark/opencv-python/issues/148
+RUN yum clean all
+
 ENV PATH "$HOME/bin:$PATH"
diff --git a/setup.py b/setup.py
index 24aa0116..d5e524dd 100644
--- a/setup.py
+++ b/setup.py
@@ -154,6 +154,11 @@ def main():
             (r"lib/qt/plugins/platforms/libqcocoa\.dylib")
         ]
 
+    if sys.platform.startswith("linux") and not build_headless:
+        rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
+            (r"lib/qt/plugins/platforms/libqxcb\.so")
+        ]
+
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
         cmake_args.append("-DWITH_WIN32UI=OFF")

From c048e37be4dc7174308d409d1740cad4c40a9172 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 21 May 2020 19:02:30 +0300
Subject: [PATCH 318/566] fix plugin path

---
 setup.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/setup.py b/setup.py
index d5e524dd..b116f7bc 100644
--- a/setup.py
+++ b/setup.py
@@ -155,9 +155,14 @@ def main():
         ]
 
     if sys.platform.startswith("linux") and not build_headless:
-        rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
-            (r"lib/qt/plugins/platforms/libqxcb\.so")
-        ]
+        if x64:
+          rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
+              (r"/usr/lib64/qt5/plugins/platforms/libqxcb\.so")
+          ]
+        else:
+          rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
+              (r"/usr/lib/qt5/plugins/platforms/libqxcb\.so")
+          ]
 
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless

From 3c4db7e1d803d43fae8d07090e7dd2064c509f74 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 21 May 2020 20:41:04 +0300
Subject: [PATCH 319/566] forgot to enable the patch

---
 setup.py | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/setup.py b/setup.py
index b116f7bc..6eadf3aa 100644
--- a/setup.py
+++ b/setup.py
@@ -155,14 +155,9 @@ def main():
         ]
 
     if sys.platform.startswith("linux") and not build_headless:
-        if x64:
-          rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
-              (r"/usr/lib64/qt5/plugins/platforms/libqxcb\.so")
-          ]
-        else:
-          rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
-              (r"/usr/lib/qt5/plugins/platforms/libqxcb\.so")
-          ]
+        rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
+            (r"lib/qt/plugins/platforms/libqxcb\.so")
+        ]
 
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
@@ -180,10 +175,12 @@ def main():
     if sys.platform.startswith("linux") and not x64:
         subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
 
+    if sys.platform.startswith("linux") or sys.platform == "darwin":
+        subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
+
     # Fixes for macOS builds
     if sys.platform == "darwin":
         cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9")
-        subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
     if "CMAKE_ARGS" in os.environ:
         import shlex

From c7dcf432f47488a31426c11928fd912359050675 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 22 May 2020 17:54:01 +0300
Subject: [PATCH 320/566] update qt patch

---
 patches/patchQtPlugins | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index 00b84582..44d47010 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -1,12 +1,18 @@
+Submodule opencv contains modified content
 diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt
-index 8ccad4d03a..0d5e2a79e9 100644
+index 4c0b3880fc..dbe1a74622 100644
 --- a/opencv/CMakeLists.txt
 +++ b/opencv/CMakeLists.txt
-@@ -1164,6 +1164,7 @@ if(WITH_QT OR HAVE_QT)
+@@ -1187,6 +1187,12 @@ if(WITH_QT OR HAVE_QT)
    if(HAVE_QT5)
      status("    QT:" "YES (ver ${Qt5Core_VERSION_STRING})")
      status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt5OpenGL_LIBRARIES} ${Qt5OpenGL_VERSION_STRING})" ELSE NO)
-+    install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
++    if(APPLE)
++      install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
++    endif()
++    if(UNIX)
++      install(DIRECTORY ${Qt5_DIR}/../../qt5/plugins DESTINATION lib/qt)
++    endif()
    elseif(HAVE_QT)
      status("    QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
      status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)

From 8c7037b7fd11bdd6acf2eb4eba912c5f562b5891 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 22 May 2020 18:51:38 +0300
Subject: [PATCH 321/566] fix if

---
 patches/patchQtPlugins | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index 44d47010..01b640b3 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -1,6 +1,7 @@
+Submodule opencv contains untracked content
 Submodule opencv contains modified content
 diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt
-index 4c0b3880fc..dbe1a74622 100644
+index 4c0b3880fc..54da25f151 100644
 --- a/opencv/CMakeLists.txt
 +++ b/opencv/CMakeLists.txt
 @@ -1187,6 +1187,12 @@ if(WITH_QT OR HAVE_QT)
@@ -10,7 +11,7 @@ index 4c0b3880fc..dbe1a74622 100644
 +    if(APPLE)
 +      install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
 +    endif()
-+    if(UNIX)
++    if(UNIX AND NOT APPLE)
 +      install(DIRECTORY ${Qt5_DIR}/../../qt5/plugins DESTINATION lib/qt)
 +    endif()
    elseif(HAVE_QT)

From d2060ea2e9649a0e41b0ee8beb7810cdbd598281 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 23 Jun 2020 21:30:20 +0300
Subject: [PATCH 322/566] use custom Qt5 build

---
 docker/manylinux2014/Dockerfile_i686   | 17 ++++++++++++++++-
 docker/manylinux2014/Dockerfile_x86_64 | 17 ++++++++++++++++-
 patches/patchQtPlugins                 |  4 +---
 3 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index e9e49d61..cf0250bf 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -1,6 +1,21 @@
 FROM quay.io/pypa/manylinux2014_i686:latest
 
-RUN yum install freetype-devel bzip2-devel curl-devel qt5-qtbase-devel blas-devel lapack-devel atlas-devel -y
+RUN yum install freetype-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 bzip2-devel curl-devel blas-devel lapack-devel atlas-devel -y
+
+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 && \
+    tar -xf qt-everywhere-src-5.15.0.tar.xz && \
+    cd qt-everywhere* && \
+    export MAKEFLAGS=-j$(nproc) && \
+    # OpenCV only links against QtCore, QtGui, QtTest
+    ./configure -prefix /opt/Qt5.15.0 -release -opensource -confirm-license -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -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 && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf qt-everywhere-src-5.15.0 && \
+    rm qt-everywhere-src-5.15.0.tar.xz
+
+ENV QTDIR /opt/Qt5.15.0
+ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index f6987f9d..4f4c6239 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -1,6 +1,21 @@
 FROM quay.io/pypa/manylinux2014_x86_64:latest
 
-RUN yum install freetype-devel bzip2-devel curl-devel qt5-qtbase-devel blas-devel lapack-devel atlas-devel -y
+RUN yum install freetype-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 bzip2-devel curl-devel blas-devel lapack-devel atlas-devel -y
+
+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 && \
+    tar -xf qt-everywhere-src-5.15.0.tar.xz && \
+    cd qt-everywhere* && \
+    export MAKEFLAGS=-j$(nproc) && \
+    # OpenCV only links against QtCore, QtGui, QtTest
+    ./configure -prefix /opt/Qt5.15.0 -release -opensource -confirm-license -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -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 && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf qt-everywhere-src-5.15.0 && \
+    rm qt-everywhere-src-5.15.0.tar.xz
+
+ENV QTDIR /opt/Qt5.15.0
+ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index 01b640b3..e84aca44 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -1,5 +1,3 @@
-Submodule opencv contains untracked content
-Submodule opencv contains modified content
 diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt
 index 4c0b3880fc..54da25f151 100644
 --- a/opencv/CMakeLists.txt
@@ -12,7 +10,7 @@ index 4c0b3880fc..54da25f151 100644
 +      install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
 +    endif()
 +    if(UNIX AND NOT APPLE)
-+      install(DIRECTORY ${Qt5_DIR}/../../qt5/plugins DESTINATION lib/qt)
++      install(DIRECTORY /opt/Qt5.15.0/plugins DESTINATION lib/qt)
 +    endif()
    elseif(HAVE_QT)
      status("    QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")

From 3290234917b6aca6c490cccd10e971c8bf75e107 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 24 Jun 2020 17:20:40 +0300
Subject: [PATCH 323/566] disable dbus

---
 docker/manylinux2014/Dockerfile_i686   | 2 +-
 docker/manylinux2014/Dockerfile_x86_64 | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index cf0250bf..8631e76b 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -7,7 +7,7 @@ RUN curl -O -L https://download.qt.io/official_releases/qt/5.15/5.15.0/single/qt
     cd qt-everywhere* && \
     export MAKEFLAGS=-j$(nproc) && \
     # OpenCV only links against QtCore, QtGui, QtTest
-    ./configure -prefix /opt/Qt5.15.0 -release -opensource -confirm-license -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -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 && \
+    ./configure -prefix /opt/Qt5.15.0 -release -opensource -confirm-license -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 && \
     make && \
     make install && \
     cd .. && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index 4f4c6239..ac68a786 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -7,7 +7,7 @@ RUN curl -O -L https://download.qt.io/official_releases/qt/5.15/5.15.0/single/qt
     cd qt-everywhere* && \
     export MAKEFLAGS=-j$(nproc) && \
     # OpenCV only links against QtCore, QtGui, QtTest
-    ./configure -prefix /opt/Qt5.15.0 -release -opensource -confirm-license -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -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 && \
+    ./configure -prefix /opt/Qt5.15.0 -release -opensource -confirm-license -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 && \
     make && \
     make install && \
     cd .. && \

From d4401cfc81c8938611b10628a19426c199f0b12c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 24 Jun 2020 18:30:56 +0300
Subject: [PATCH 324/566] set LD_LIBRARY_PATH

---
 travis_config.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/travis_config.sh b/travis_config.sh
index fbf565b5..035791d2 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -24,6 +24,7 @@ if [ -n "$IS_OSX" ]; then
   export MAKEFLAGS="-j$(sysctl -n hw.ncpu)"
 else
   echo "    > Linux environment "
+  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt5.15.0/lib # Qt5 libs for auditwheel
   export MAKEFLAGS="-j$(grep -E '^processor[[:space:]]*:' /proc/cpuinfo | wc -l)"
 fi
 

From 3da5b1bba3c8f642133a8dd38424aa249c103598 Mon Sep 17 00:00:00 2001
From: johnthagen <johnthagen@users.noreply.github.com>
Date: Thu, 25 Jun 2020 19:15:05 -0400
Subject: [PATCH 325/566] Fix typo in license

---
 LICENSE-3RD-PARTY.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index 83551feb..5b45451b 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -588,7 +588,7 @@ necessary.  Here is a sample; alter the names:
 That's all there is to it!
 
 ------------------------------------------------------------------------------
-Qt 5 is redistributed within opencv-pytho macOS packages.
+Qt 5 is redistributed within opencv-python macOS packages.
 This license applies to Qt binaries in the directory cv2/.
 
                    GNU LESSER GENERAL PUBLIC LICENSE
@@ -754,4 +754,4 @@ General Public License ever published by the Free Software Foundation.
 whether future versions of the GNU Lesser General Public License shall
 apply, that proxy's public statement of acceptance of any version is
 permanent authorization for you to choose that version for the
-Library.
\ No newline at end of file
+Library.

From 61591fec97cc86f064b91fd002b556918c7bd8ba Mon Sep 17 00:00:00 2001
From: johnthagen <johnthagen@users.noreply.github.com>
Date: Fri, 26 Jun 2020 07:05:31 -0400
Subject: [PATCH 326/566] Fix FFmpeg packaging reference

---
 LICENSE-3RD-PARTY.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index 5b45451b..786dc063 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -80,7 +80,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 ------------------------------------------------------------------------------
-FFmpeg is redistributed within opencv-python Windows packages.
+FFmpeg is redistributed within all opencv-python packages.
 Qt 4.8.7 is redistributed within opencv-python Linux packages.
 This license applies to FFmpeg and Qt binaries in the directory cv2/.
 

From db574be4e2912384cd910dc3ed600704539e4c98 Mon Sep 17 00:00:00 2001
From: johnthagen <johnthagen@users.noreply.github.com>
Date: Fri, 26 Jun 2020 07:07:52 -0400
Subject: [PATCH 327/566] Correct headless license reference

---
 LICENSE-3RD-PARTY.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index 786dc063..43b0dec7 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -81,7 +81,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 ------------------------------------------------------------------------------
 FFmpeg is redistributed within all opencv-python packages.
-Qt 4.8.7 is redistributed within opencv-python Linux packages.
+Qt 4.8.7 is redistributed within non-headless opencv-python Linux packages.
 This license applies to FFmpeg and Qt binaries in the directory cv2/.
 
                   GNU LESSER GENERAL PUBLIC LICENSE
@@ -588,7 +588,7 @@ necessary.  Here is a sample; alter the names:
 That's all there is to it!
 
 ------------------------------------------------------------------------------
-Qt 5 is redistributed within opencv-python macOS packages.
+Qt 5 is redistributed within non-headless opencv-python macOS packages.
 This license applies to Qt binaries in the directory cv2/.
 
                    GNU LESSER GENERAL PUBLIC LICENSE

From 1bba3e6f4fe1653a72a7a43ada4e8ac36b6462f4 Mon Sep 17 00:00:00 2001
From: johnthagen <johnthagen@users.noreply.github.com>
Date: Fri, 26 Jun 2020 07:09:24 -0400
Subject: [PATCH 328/566] Fix headless Qt license reference in README

---
 README.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 6a710cd2..024abe3b 100644
--- a/README.md
+++ b/README.md
@@ -128,9 +128,9 @@ Third party package licenses are at [LICENSE-3RD-PARTY.txt](https://github.com/s
 
 All wheels ship with [FFmpeg](http://ffmpeg.org) licensed under the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
 
-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).
+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).
 
-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).
+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).
 
 ### Versioning
 

From 89e798669c92d945041049fda53641a37be64c9e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 26 Jun 2020 18:50:47 +0300
Subject: [PATCH 329/566] test namespaced Qt

---
 docker/manylinux2014/Dockerfile_i686   | 2 +-
 docker/manylinux2014/Dockerfile_x86_64 | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index 8631e76b..d5e071dd 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -7,7 +7,7 @@ RUN curl -O -L https://download.qt.io/official_releases/qt/5.15/5.15.0/single/qt
     cd qt-everywhere* && \
     export MAKEFLAGS=-j$(nproc) && \
     # OpenCV only links against QtCore, QtGui, QtTest
-    ./configure -prefix /opt/Qt5.15.0 -release -opensource -confirm-license -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 && \
+    ./configure -prefix /opt/Qt5.15.0 -platform linux-g++-32 -qtnamespace QtOpenCVPython -release -opensource -confirm-license -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 && \
     make && \
     make install && \
     cd .. && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index ac68a786..2d6faa29 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -7,7 +7,7 @@ RUN curl -O -L https://download.qt.io/official_releases/qt/5.15/5.15.0/single/qt
     cd qt-everywhere* && \
     export MAKEFLAGS=-j$(nproc) && \
     # OpenCV only links against QtCore, QtGui, QtTest
-    ./configure -prefix /opt/Qt5.15.0 -release -opensource -confirm-license -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 && \
+    ./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 && \
     make && \
     make install && \
     cd .. && \

From 61f843f0291360f1d870b82913d3dec012ff40b7 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 30 Jun 2020 21:42:41 +0300
Subject: [PATCH 330/566] back to Qt4

---
 .travis.yml                            | 32 +++++++++++++-------------
 cv2/__init__.py                        |  2 +-
 docker/manylinux2014/Dockerfile_i686   | 17 +-------------
 docker/manylinux2014/Dockerfile_x86_64 | 17 +-------------
 patches/patchQtPlugins                 | 13 ++++-------
 setup.py                               | 18 ++++-----------
 travis_config.sh                       |  3 ++-
 7 files changed, 30 insertions(+), 72 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index abdd069a..a0e3e53d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -239,7 +239,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -263,7 +263,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.11.3
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -287,7 +287,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -311,7 +311,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.17.3
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
 
@@ -335,7 +335,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -359,7 +359,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.11.3
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -383,7 +383,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -407,7 +407,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.17.3
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
 
@@ -431,7 +431,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -455,7 +455,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -479,7 +479,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -503,7 +503,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
 
@@ -528,7 +528,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -552,7 +552,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -576,7 +576,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -600,7 +600,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-        - USE_CCACHE=0
+
       cache:
         directories: $HOME/.ccache
 
diff --git a/cv2/__init__.py b/cv2/__init__.py
index 1207db95..ee8cd254 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -9,7 +9,7 @@
 # this makes them available
 globals().update(importlib.import_module('cv2.cv2').__dict__)
 
-if sys.platform == 'darwin' or sys.platform.startswith("linux"):
+if sys.platform == 'darwin':
     os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), 'qt', 'plugins'
     )
diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index d5e071dd..c0586ee5 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -1,21 +1,6 @@
 FROM quay.io/pypa/manylinux2014_i686:latest
 
-RUN yum install freetype-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 bzip2-devel curl-devel blas-devel lapack-devel atlas-devel -y
-
-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 && \
-    tar -xf qt-everywhere-src-5.15.0.tar.xz && \
-    cd qt-everywhere* && \
-    export MAKEFLAGS=-j$(nproc) && \
-    # OpenCV only links against QtCore, QtGui, QtTest
-    ./configure -prefix /opt/Qt5.15.0 -platform linux-g++-32 -qtnamespace QtOpenCVPython -release -opensource -confirm-license -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 && \
-    make && \
-    make install && \
-    cd .. && \
-    rm -rf qt-everywhere-src-5.15.0 && \
-    rm qt-everywhere-src-5.15.0.tar.xz
-
-ENV QTDIR /opt/Qt5.15.0
-ENV PATH "$QTDIR/bin:$PATH"
+RUN yum install bzip2-devel curl-devel zlib-devel qt-x11 -y
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index 2d6faa29..d84c6e8b 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -1,21 +1,6 @@
 FROM quay.io/pypa/manylinux2014_x86_64:latest
 
-RUN yum install freetype-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 bzip2-devel curl-devel blas-devel lapack-devel atlas-devel -y
-
-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 && \
-    tar -xf qt-everywhere-src-5.15.0.tar.xz && \
-    cd qt-everywhere* && \
-    export MAKEFLAGS=-j$(nproc) && \
-    # OpenCV only links against QtCore, QtGui, QtTest
-    ./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 && \
-    make && \
-    make install && \
-    cd .. && \
-    rm -rf qt-everywhere-src-5.15.0 && \
-    rm qt-everywhere-src-5.15.0.tar.xz
-
-ENV QTDIR /opt/Qt5.15.0
-ENV PATH "$QTDIR/bin:$PATH"
+RUN yum install bzip2-devel curl-devel zlib-devel qt-x11 -y
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index e84aca44..c69ef795 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -1,17 +1,12 @@
 diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt
-index 4c0b3880fc..54da25f151 100644
+index 8ccad4d03a..0d5e2a79e9 100644
 --- a/opencv/CMakeLists.txt
 +++ b/opencv/CMakeLists.txt
-@@ -1187,6 +1187,12 @@ if(WITH_QT OR HAVE_QT)
+@@ -1164,6 +1164,7 @@ if(WITH_QT OR HAVE_QT)
    if(HAVE_QT5)
      status("    QT:" "YES (ver ${Qt5Core_VERSION_STRING})")
      status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt5OpenGL_LIBRARIES} ${Qt5OpenGL_VERSION_STRING})" ELSE NO)
-+    if(APPLE)
-+      install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
-+    endif()
-+    if(UNIX AND NOT APPLE)
-+      install(DIRECTORY /opt/Qt5.15.0/plugins DESTINATION lib/qt)
-+    endif()
++    install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
    elseif(HAVE_QT)
      status("    QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
-     status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)
+     status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 6eadf3aa..843d5f03 100644
--- a/setup.py
+++ b/setup.py
@@ -142,23 +142,15 @@ def main():
     )
 
     # OS-specific components
-    if (
-        sys.platform.startswith("linux")
-        or sys.platform == "darwin"
-        and not build_headless
-    ):
-        cmake_args.append("-DWITH_QT=5")
+    if sys.platform.startswith('linux') and not build_headless:
+        cmake_args.append("-DWITH_QT=4")
 
-    if sys.platform == "darwin" and not build_headless:
+    if sys.platform == 'darwin' and not build_headless:
+        cmake_args.append("-DWITH_QT=5")
         rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
             (r"lib/qt/plugins/platforms/libqcocoa\.dylib")
         ]
 
-    if sys.platform.startswith("linux") and not build_headless:
-        rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
-            (r"lib/qt/plugins/platforms/libqxcb\.so")
-        ]
-
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
         cmake_args.append("-DWITH_WIN32UI=OFF")
@@ -175,7 +167,7 @@ def main():
     if sys.platform.startswith("linux") and not x64:
         subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
 
-    if sys.platform.startswith("linux") or sys.platform == "darwin":
+    if sys.platform == "darwin":
         subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
     # Fixes for macOS builds
diff --git a/travis_config.sh b/travis_config.sh
index 035791d2..b958fad7 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -24,7 +24,6 @@ if [ -n "$IS_OSX" ]; then
   export MAKEFLAGS="-j$(sysctl -n hw.ncpu)"
 else
   echo "    > Linux environment "
-  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt5.15.0/lib # Qt5 libs for auditwheel
   export MAKEFLAGS="-j$(grep -E '^processor[[:space:]]*:' /proc/cpuinfo | wc -l)"
 fi
 
@@ -97,6 +96,8 @@ function pre_build {
         brew_add_local_bottles
     fi
 
+    brew style
+
     echo 'Installing qt5'
     if [ -n "$CACHE_STAGE" ]; then
         brew_install_and_cache_within_time_limit qt5 || { [ $? -gt 1 ] && return 2 || return 0; }

From 51f52b2745c15f7ca1a16b00b40194d1858deab7 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 30 Jun 2020 23:17:20 +0300
Subject: [PATCH 331/566] use correct package

---
 docker/manylinux2014/Dockerfile_i686   | 2 +-
 docker/manylinux2014/Dockerfile_x86_64 | 2 +-
 travis_config.sh                       | 2 --
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index c0586ee5..c50a5018 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -1,6 +1,6 @@
 FROM quay.io/pypa/manylinux2014_i686:latest
 
-RUN yum install bzip2-devel curl-devel zlib-devel qt-x11 -y
+RUN yum install bzip2-devel curl-devel zlib-devel qt-devel -y
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index d84c6e8b..df7e106e 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -1,6 +1,6 @@
 FROM quay.io/pypa/manylinux2014_x86_64:latest
 
-RUN yum install bzip2-devel curl-devel zlib-devel qt-x11 -y
+RUN yum install bzip2-devel curl-devel zlib-devel qt-devel -y
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
diff --git a/travis_config.sh b/travis_config.sh
index b958fad7..fbf565b5 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -96,8 +96,6 @@ function pre_build {
         brew_add_local_bottles
     fi
 
-    brew style
-
     echo 'Installing qt5'
     if [ -n "$CACHE_STAGE" ]; then
         brew_install_and_cache_within_time_limit qt5 || { [ $? -gt 1 ] && return 2 || return 0; }

From 4e154a8d21e11f3781d0fbf5804027c19af5983e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 30 Jun 2020 23:48:21 +0300
Subject: [PATCH 332/566] disable ccache again

---
 .travis.yml | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index a0e3e53d..abdd069a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -239,7 +239,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -263,7 +263,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.11.3
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -287,7 +287,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -311,7 +311,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.17.3
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
 
@@ -335,7 +335,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -359,7 +359,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.11.3
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -383,7 +383,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -407,7 +407,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.17.3
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
 
@@ -431,7 +431,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -455,7 +455,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -479,7 +479,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -503,7 +503,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
 
@@ -528,7 +528,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -552,7 +552,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.11.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -576,7 +576,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.14.5
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -600,7 +600,7 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
-
+        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
 

From 58be0655ec4de3dfda6d514d92931478e8d05fee Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 2 Jul 2020 21:08:51 +0300
Subject: [PATCH 333/566] update licenses

---
 LICENSE-3RD-PARTY.txt | 877 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 872 insertions(+), 5 deletions(-)

diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index 83551feb..5c6c7632 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -45,7 +45,7 @@ or tort (including negligence or otherwise) arising in any way out of
 the use of this software, even if advised of the possibility of such damage.
 
 ------------------------------------------------------------------------------
-libvpx is redistributed within opencv-python Linux packages.
+libvpx is redistributed within all opencv-python Linux packages.
 This license applies to libvpx binary in the directory cv2/.
 
 Copyright (c) 2010, The WebM Project authors. All rights reserved.
@@ -80,9 +80,10 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 ------------------------------------------------------------------------------
-FFmpeg is redistributed within opencv-python Windows packages.
+FFmpeg is redistributed within all opencv-python packages.
 Qt 4.8.7 is redistributed within opencv-python Linux packages.
-This license applies to FFmpeg and Qt binaries in the directory cv2/.
+Libuuid is redistributed within all opencv-python Linux packages.
+This license applies to FFmpeg, Qt and libuuid binaries in the directory cv2/.
 
                   GNU LESSER GENERAL PUBLIC LICENSE
                        Version 2.1, February 1999
@@ -588,7 +589,7 @@ necessary.  Here is a sample; alter the names:
 That's all there is to it!
 
 ------------------------------------------------------------------------------
-Qt 5 is redistributed within opencv-pytho macOS packages.
+Qt 5 is redistributed within opencv-python macOS packages.
 This license applies to Qt binaries in the directory cv2/.
 
                    GNU LESSER GENERAL PUBLIC LICENSE
@@ -754,4 +755,870 @@ General Public License ever published by the Free Software Foundation.
 whether future versions of the GNU Lesser General Public License shall
 apply, that proxy's public statement of acceptance of any version is
 permanent authorization for you to choose that version for the
-Library.
\ No newline at end of file
+Library.
+
+------------------------------------------------------------------------------
+bzip2 is redistributed within all opencv-python Linux packages.
+This license applies to libbz2 binary in the directory cv2/.
+
+This program, "bzip2", the associated library "libbzip2", and all
+documentation, are copyright (C) 1996-2010 Julian R Seward.  All
+rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+
+2. The origin of this software must not be misrepresented; you must 
+   not claim that you wrote the original software.  If you use this 
+   software in a product, an acknowledgment in the product 
+   documentation would be appreciated but is not required.
+
+3. Altered source versions must be plainly marked as such, and must
+   not be misrepresented as being the original software.
+
+4. The name of the author may not be used to endorse or promote 
+   products derived from this software without specific prior written 
+   permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Julian Seward, jseward@bzip.org
+bzip2/libbzip2 version 1.0.6 of 6 September 2010
+
+------------------------------------------------------------------------------
+libcrypto and libssl are redistributed within all opencv-python Linux packages.
+This license applies to libcrypto and libssl binaries in the directory cv2/.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        https://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+------------------------------------------------------------------------------
+libexpat is redistributed within all opencv-python Linux packages.
+This license applies to libexpat binary in the directory cv2/.
+
+Copyright (c) 1998-2000 Thai Open Source Software Center Ltd and Clark Cooper
+Copyright (c) 2001-2019 Expat maintainers
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+------------------------------------------------------------------------------
+libfontconfig is redistributed within all opencv-python Linux packages.
+This license applies to libfontconfig binary in the directory cv2/.
+
+Copyright © 2000,2001,2002,2003,2004,2006,2007 Keith Packard
+Copyright © 2005 Patrick Lam
+Copyright © 2009 Roozbeh Pournader
+Copyright © 2008,2009 Red Hat, Inc.
+Copyright © 2008 Danilo Šegan
+Copyright © 2012 Google, Inc.
+
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation, and that the name of the author(s) not be used in
+advertising or publicity pertaining to distribution of the software without
+specific, written prior permission.  The authors make no
+representations about the suitability of this software for any purpose.  It
+is provided "as is" without express or implied warranty.
+
+THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+------------------------------------------------------------------------------
+libfreetype is redistributed within opencv-python Linux packages.
+This license applies to libfreetype binary in the directory cv2/.
+
+                    The FreeType Project LICENSE
+                    ----------------------------
+
+                            2006-Jan-27
+
+                    Copyright 1996-2002, 2006 by
+          David Turner, Robert Wilhelm, and Werner Lemberg
+
+
+
+Introduction
+============
+
+  The FreeType  Project is distributed in  several archive packages;
+  some of them may contain, in addition to the FreeType font engine,
+  various tools and  contributions which rely on, or  relate to, the
+  FreeType Project.
+
+  This  license applies  to all  files found  in such  packages, and
+  which do not  fall under their own explicit  license.  The license
+  affects  thus  the  FreeType   font  engine,  the  test  programs,
+  documentation and makefiles, at the very least.
+
+  This  license   was  inspired  by  the  BSD,   Artistic,  and  IJG
+  (Independent JPEG  Group) licenses, which  all encourage inclusion
+  and  use of  free  software in  commercial  and freeware  products
+  alike.  As a consequence, its main points are that:
+
+    o We don't promise that this software works. However, we will be
+      interested in any kind of bug reports. (`as is' distribution)
+
+    o You can  use this software for whatever you  want, in parts or
+      full form, without having to pay us. (`royalty-free' usage)
+
+    o You may not pretend that  you wrote this software.  If you use
+      it, or  only parts of it,  in a program,  you must acknowledge
+      somewhere  in  your  documentation  that  you  have  used  the
+      FreeType code. (`credits')
+
+  We  specifically  permit  and  encourage  the  inclusion  of  this
+  software, with  or without modifications,  in commercial products.
+  We  disclaim  all warranties  covering  The  FreeType Project  and
+  assume no liability related to The FreeType Project.
+
+
+  Finally,  many  people  asked  us  for  a  preferred  form  for  a
+  credit/disclaimer to use in compliance with this license.  We thus
+  encourage you to use the following text:
+
+   """
+    Portions of this software are copyright © <year> The FreeType
+    Project (www.freetype.org).  All rights reserved.
+   """
+
+  Please replace <year> with the value from the FreeType version you
+  actually use.
+
+
+Legal Terms
+===========
+
+0. Definitions
+--------------
+
+  Throughout this license,  the terms `package', `FreeType Project',
+  and  `FreeType  archive' refer  to  the  set  of files  originally
+  distributed  by the  authors  (David Turner,  Robert Wilhelm,  and
+  Werner Lemberg) as the `FreeType Project', be they named as alpha,
+  beta or final release.
+
+  `You' refers to  the licensee, or person using  the project, where
+  `using' is a generic term including compiling the project's source
+  code as  well as linking it  to form a  `program' or `executable'.
+  This  program is  referred to  as  `a program  using the  FreeType
+  engine'.
+
+  This  license applies  to all  files distributed  in  the original
+  FreeType  Project,   including  all  source   code,  binaries  and
+  documentation,  unless  otherwise  stated   in  the  file  in  its
+  original, unmodified form as  distributed in the original archive.
+  If you are  unsure whether or not a particular  file is covered by
+  this license, you must contact us to verify this.
+
+  The FreeType  Project is copyright (C) 1996-2000  by David Turner,
+  Robert Wilhelm, and Werner Lemberg.  All rights reserved except as
+  specified below.
+
+1. No Warranty
+--------------
+
+  THE FREETYPE PROJECT  IS PROVIDED `AS IS' WITHOUT  WARRANTY OF ANY
+  KIND, EITHER  EXPRESS OR IMPLIED,  INCLUDING, BUT NOT  LIMITED TO,
+  WARRANTIES  OF  MERCHANTABILITY   AND  FITNESS  FOR  A  PARTICULAR
+  PURPOSE.  IN NO EVENT WILL ANY OF THE AUTHORS OR COPYRIGHT HOLDERS
+  BE LIABLE  FOR ANY DAMAGES CAUSED  BY THE USE OR  THE INABILITY TO
+  USE, OF THE FREETYPE PROJECT.
+
+2. Redistribution
+-----------------
+
+  This  license  grants  a  worldwide, royalty-free,  perpetual  and
+  irrevocable right  and license to use,  execute, perform, compile,
+  display,  copy,   create  derivative  works   of,  distribute  and
+  sublicense the  FreeType Project (in  both source and  object code
+  forms)  and  derivative works  thereof  for  any  purpose; and  to
+  authorize others  to exercise  some or all  of the  rights granted
+  herein, subject to the following conditions:
+
+    o Redistribution of  source code  must retain this  license file
+      (`FTL.TXT') unaltered; any  additions, deletions or changes to
+      the original  files must be clearly  indicated in accompanying
+      documentation.   The  copyright   notices  of  the  unaltered,
+      original  files must  be  preserved in  all  copies of  source
+      files.
+
+    o Redistribution in binary form must provide a  disclaimer  that
+      states  that  the software is based in part of the work of the
+      FreeType Team,  in  the  distribution  documentation.  We also
+      encourage you to put an URL to the FreeType web page  in  your
+      documentation, though this isn't mandatory.
+
+  These conditions  apply to any  software derived from or  based on
+  the FreeType Project,  not just the unmodified files.   If you use
+  our work, you  must acknowledge us.  However, no  fee need be paid
+  to us.
+
+3. Advertising
+--------------
+
+  Neither the  FreeType authors and  contributors nor you  shall use
+  the name of the  other for commercial, advertising, or promotional
+  purposes without specific prior written permission.
+
+  We suggest,  but do not require, that  you use one or  more of the
+  following phrases to refer  to this software in your documentation
+  or advertising  materials: `FreeType Project',  `FreeType Engine',
+  `FreeType library', or `FreeType Distribution'.
+
+  As  you have  not signed  this license,  you are  not  required to
+  accept  it.   However,  as  the FreeType  Project  is  copyrighted
+  material, only  this license, or  another one contracted  with the
+  authors, grants you  the right to use, distribute,  and modify it.
+  Therefore,  by  using,  distributing,  or modifying  the  FreeType
+  Project, you indicate that you understand and accept all the terms
+  of this license.
+
+4. Contacts
+-----------
+
+  There are two mailing lists related to FreeType:
+
+    o freetype@nongnu.org
+
+      Discusses general use and applications of FreeType, as well as
+      future and  wanted additions to the  library and distribution.
+      If  you are looking  for support,  start in  this list  if you
+      haven't found anything to help you in the documentation.
+
+    o freetype-devel@nongnu.org
+
+      Discusses bugs,  as well  as engine internals,  design issues,
+      specific licenses, porting, etc.
+
+  Our home page can be found at
+
+    https://www.freetype.org
+
+------------------------------------------------------------------------------
+libpng is redistributed within all opencv-python Linux packages.
+This license applies to libpng binary in the directory cv2/.
+
+PNG Reference Library License version 2
+---------------------------------------
+
+ * Copyright (c) 1995-2019 The PNG Reference Library Authors.
+ * Copyright (c) 2018-2019 Cosmin Truta.
+ * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson.
+ * Copyright (c) 1996-1997 Andreas Dilger.
+ * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
+
+The software is supplied "as is", without warranty of any kind,
+express or implied, including, without limitation, the warranties
+of merchantability, fitness for a particular purpose, title, and
+non-infringement.  In no event shall the Copyright owners, or
+anyone distributing the software, be liable for any damages or
+other liability, whether in contract, tort or otherwise, arising
+from, out of, or in connection with the software, or the use or
+other dealings in the software, even if advised of the possibility
+of such damage.
+
+Permission is hereby granted to use, copy, modify, and distribute
+this software, or portions hereof, for any purpose, without fee,
+subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+    must not claim that you wrote the original software.  If you
+    use this software in a product, an acknowledgment in the product
+    documentation would be appreciated, but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and must
+    not be misrepresented as being the original software.
+
+ 3. This Copyright notice may not be removed or altered from any
+    source or altered source distribution.
+
+
+PNG Reference Library License version 1 (for libpng 0.5 through 1.6.35)
+-----------------------------------------------------------------------
+
+libpng versions 1.0.7, July 1, 2000, through 1.6.35, July 15, 2018 are
+Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson, are
+derived from libpng-1.0.6, and are distributed according to the same
+disclaimer and license as libpng-1.0.6 with the following individuals
+added to the list of Contributing Authors:
+
+    Simon-Pierre Cadieux
+    Eric S. Raymond
+    Mans Rullgard
+    Cosmin Truta
+    Gilles Vollant
+    James Yu
+    Mandar Sahastrabuddhe
+    Google Inc.
+    Vadim Barkov
+
+and with the following additions to the disclaimer:
+
+    There is no warranty against interference with your enjoyment of
+    the library or against infringement.  There is no warranty that our
+    efforts or the library will fulfill any of your particular purposes
+    or needs.  This library is provided with all faults, and the entire
+    risk of satisfactory quality, performance, accuracy, and effort is
+    with the user.
+
+Some files in the "contrib" directory and some configure-generated
+files that are distributed with libpng have other copyright owners, and
+are released under other open source licenses.
+
+libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
+Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
+libpng-0.96, and are distributed according to the same disclaimer and
+license as libpng-0.96, with the following individuals added to the
+list of Contributing Authors:
+
+    Tom Lane
+    Glenn Randers-Pehrson
+    Willem van Schaik
+
+libpng versions 0.89, June 1996, through 0.96, May 1997, are
+Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
+and are distributed according to the same disclaimer and license as
+libpng-0.88, with the following individuals added to the list of
+Contributing Authors:
+
+    John Bowler
+    Kevin Bracey
+    Sam Bushell
+    Magnus Holmgren
+    Greg Roelofs
+    Tom Tanner
+
+Some files in the "scripts" directory have other copyright owners,
+but are released under this license.
+
+libpng versions 0.5, May 1995, through 0.88, January 1996, are
+Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
+
+For the purposes of this copyright and license, "Contributing Authors"
+is defined as the following set of individuals:
+
+    Andreas Dilger
+    Dave Martindale
+    Guy Eric Schalnat
+    Paul Schmidt
+    Tim Wegner
+
+The PNG Reference Library is supplied "AS IS".  The Contributing
+Authors and Group 42, Inc. disclaim all warranties, expressed or
+implied, including, without limitation, the warranties of
+merchantability and of fitness for any purpose.  The Contributing
+Authors and Group 42, Inc. assume no liability for direct, indirect,
+incidental, special, exemplary, or consequential damages, which may
+result from the use of the PNG Reference Library, even if advised of
+the possibility of such damage.
+
+Permission is hereby granted to use, copy, modify, and distribute this
+source code, or portions hereof, for any purpose, without fee, subject
+to the following restrictions:
+
+ 1. The origin of this source code must not be misrepresented.
+
+ 2. Altered versions must be plainly marked as such and must not
+    be misrepresented as being the original source.
+
+ 3. This Copyright notice may not be removed or altered from any
+    source or altered source distribution.
+
+The Contributing Authors and Group 42, Inc. specifically permit,
+without fee, and encourage the use of this source code as a component
+to supporting the PNG file format in commercial products.  If you use
+this source code in a product, acknowledgment is not required but would
+be appreciated.
+
+------------------------------------------------------------------------------
+libz is redistributed within all opencv-python Linux packages.
+This license applies to libz binary in the directory cv2/.
+
+  Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+
+  Jean-loup Gailly        Mark Adler
+  jloup@gzip.org          madler@alumni.caltech.edu
+
+------------------------------------------------------------------------------
+libXcursor is redistributed within opencv-python Linux packages.
+This license applies to libXcursor binary in the directory cv2/.
+
+Copyright © 2002 Keith Packard
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation, and that the name of Keith Packard not be used in
+advertising or publicity pertaining to distribution of the software without
+specific, written prior permission.  Keith Packard makes no
+representations about the suitability of this software for any purpose.  It
+is provided "as is" without express or implied warranty.
+
+KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+------------------------------------------------------------------------------
+libXfixes is redistributed within opencv-python Linux packages.
+This license applies to libXfixes binary in the directory cv2/.
+
+Copyright © 2001,2003 Keith Packard
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation, and that the name of Keith Packard not be used in
+advertising or publicity pertaining to distribution of the software without
+specific, written prior permission.  Keith Packard makes no
+representations about the suitability of this software for any purpose.  It
+is provided "as is" without express or implied warranty.
+
+KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+------------------------------------------------------------------------------
+libXi is redistributed within opencv-python Linux packages.
+This license applies to libXi binary in the directory cv2/.
+
+Copyright 1989, 1998  The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
+
+      All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Hewlett-Packard not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+Copyright 2008 Peter Hutterer
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the author shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the author.
+
+Copyright © 2009 Red Hat, Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+------------------------------------------------------------------------------
+libXinerama is redistributed within opencv-python Linux packages.
+This license applies to libXinerama binary in the directory cv2/.
+
+Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
+BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Digital Equipment Corporation
+shall not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from Digital
+Equipment Corporation.
+
+------------------------------------------------------------------------------
+libXrandr is redistributed within opencv-python Linux packages.
+This license applies to libXrandr binary in the directory cv2/.
+
+Copyright © 2000, Compaq Computer Corporation,
+Copyright © 2002, Hewlett Packard, Inc.
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation, and that the name of Compaq or HP not be used in advertising
+or publicity pertaining to distribution of the software without specific,
+written prior permission.  HP makes no representations about the
+suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+
+HP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL HP
+BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+Copyright © 2000 Compaq Computer Corporation, Inc.
+Copyright © 2002 Hewlett-Packard Company, Inc.
+Copyright © 2006 Intel Corporation
+Copyright © 2008 Red Hat, Inc.
+Copyright © 2011 Dave Airlie
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting documentation, and
+that the name of the copyright holders not be used in advertising or
+publicity pertaining to distribution of the software without specific,
+written prior permission.  The copyright holders make no representations
+about the suitability of this software for any purpose.  It is provided "as
+is" without express or implied warranty.
+
+THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+OF THIS SOFTWARE.
+
+Copyright © 2000 Compaq Computer Corporation, Inc.
+Copyright © 2002 Hewlett Packard Company, Inc.
+Copyright © 2006 Keith Packard
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting documentation, and
+that the name of the copyright holders not be used in advertising or
+publicity pertaining to distribution of the software without specific,
+written prior permission.  The copyright holders make no representations
+about the suitability of this software for any purpose.  It is provided "as
+is" without express or implied warranty.
+
+THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+OF THIS SOFTWARE.

From bad9466ea11157db91113a9af47428cf00cd2d31 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 2 Jul 2020 21:24:49 +0300
Subject: [PATCH 334/566] update README

---
 README.md | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/README.md b/README.md
index 6a710cd2..28f76c08 100644
--- a/README.md
+++ b/README.md
@@ -118,6 +118,17 @@ In addition to any variables that OpenCV's build accepts, we recognize:
 - ``ENABLE_CONTRIB`` and ``ENABLE_HEADLESS``. Set to ``1`` to build the contrib and/or headless version
 - ``CMAKE_ARGS``. Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build.
 
+### Manual builds
+
+If some dependency is not enabled in the pre-built wheels, you can also run the `setup.py` locally to create a custom wheel.
+
+1. Clone this repository: `git clone --recursive https://github.com/skvark/opencv-python.git`
+2. Go to the root of the repository 
+3. Add custom Cmake flags if needed, for example: `export CMAKE_FLAGS="-DSOME_FLAG=ON -DSOME_OTHER_FLAG=OFF"`
+4. Run ``python setup.py bdist_wheel``
+     - Optionally use the `manylinux` images as a build hosts if maximum portability is needed (and run `auditwheel` for the wheel after build)
+5. You'll have the wheel file in the `dist` folder and you can do with that whatever you wish (upload to local PyPI index, use as dependency in a CI job which runs the PyInstaller / PyOxidizer bundler for your app etc.)
+
 ### Licensing
 
 Opencv-python package (scripts in this repository) is available under MIT license.
@@ -132,6 +143,8 @@ Linux wheels ship with [Qt 4.8.7](http://doc.qt.io/qt-4.8/lgpl.html) licensed un
 
 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).
 
+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).
+
 ### 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.
@@ -168,3 +181,10 @@ Currently, builds for following Python versions are provided:
 - 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.
+

From 1d880124ee0ae4b8edb4d1042706fc5a7ec1064f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 2 Jul 2020 22:12:46 +0300
Subject: [PATCH 335/566] try to fix the brew issue

---
 travis_config.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/travis_config.sh b/travis_config.sh
index fbf565b5..9da98202 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -94,6 +94,8 @@ function pre_build {
         brew update
         generate_ffmpeg_formula
         brew_add_local_bottles
+    else
+        brew style
     fi
 
     echo 'Installing qt5'

From 7fdd4fc46a73bfeb661606b5c40bcaee790d57fc Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 2 Jul 2020 22:19:58 +0300
Subject: [PATCH 336/566] change the command location and fix README

---
 README.md        | 2 +-
 travis_config.sh | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 28f76c08..9daa1a4f 100644
--- a/README.md
+++ b/README.md
@@ -127,7 +127,7 @@ If some dependency is not enabled in the pre-built wheels, you can also run the
 3. Add custom Cmake flags if needed, for example: `export CMAKE_FLAGS="-DSOME_FLAG=ON -DSOME_OTHER_FLAG=OFF"`
 4. Run ``python setup.py bdist_wheel``
      - Optionally use the `manylinux` images as a build hosts if maximum portability is needed (and run `auditwheel` for the wheel after build)
-5. You'll have the wheel file in the `dist` folder and you can do with that whatever you wish (upload to local PyPI index, use as dependency in a CI job which runs the PyInstaller / PyOxidizer bundler for your app etc.)
+5. You'll have the wheel file in the `dist` folder and you can do with that whatever you wish
 
 ### Licensing
 
diff --git a/travis_config.sh b/travis_config.sh
index 9da98202..b8defe87 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -89,13 +89,13 @@ function pre_build {
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
 
+    brew style
+
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then
         brew update
         generate_ffmpeg_formula
         brew_add_local_bottles
-    else
-        brew style
     fi
 
     echo 'Installing qt5'

From 048b9c1ea986a0bddf57ad07732be0d84ddb9cf9 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 2 Jul 2020 22:31:11 +0300
Subject: [PATCH 337/566] try update-reset

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index b8defe87..aaa276b2 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -89,7 +89,7 @@ function pre_build {
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
 
-    brew style
+    brew update-reset
 
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then

From 05413b407f5e7a5626c624dcf6bad4764531d464 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 3 Jul 2020 21:37:48 +0300
Subject: [PATCH 338/566] try to install homebrew

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index aaa276b2..9df4c072 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -89,7 +89,7 @@ function pre_build {
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
 
-    brew update-reset
+    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
 
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then

From b2b07000196a2230ab1f6ee5cc4071b8ad87f484 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 3 Jul 2020 22:27:47 +0300
Subject: [PATCH 339/566] revert back to original...

---
 travis_config.sh | 2 --
 1 file changed, 2 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index 9df4c072..fbf565b5 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -89,8 +89,6 @@ function pre_build {
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
 
-    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
-
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then
         brew update

From f2b30d60fde1d2b6a17dd3978914e0c0239661f3 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 4 Jul 2020 23:09:51 +0300
Subject: [PATCH 340/566] add macOS licenses

---
 LICENSE-3RD-PARTY.txt | 1163 +++++++++++++++++++++++++++++++++--------
 1 file changed, 935 insertions(+), 228 deletions(-)

diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index 5c6c7632..3148b06c 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -83,7 +83,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 FFmpeg is redistributed within all opencv-python packages.
 Qt 4.8.7 is redistributed within opencv-python Linux packages.
 Libuuid is redistributed within all opencv-python Linux packages.
-This license applies to FFmpeg, Qt and libuuid binaries in the directory cv2/.
+
+Libbluray, libgnutls, libnettle, libhogweed, libintl, libmp3lame, libp11,
+librtmp, libsoxr, libtasn1,  are redistributed within all opencv-python macOS packages.
+
+This license applies to the above library binaries in the directory cv2/.
 
                   GNU LESSER GENERAL PUBLIC LICENSE
                        Version 2.1, February 1999
@@ -543,54 +547,13 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 DAMAGES.
 
                      END OF TERMS AND CONDITIONS
-
-           How to Apply These Terms to Your New Libraries
-
-  If you develop a new library, and you want it to be of the greatest
-possible use to the public, we recommend making it free software that
-everyone can redistribute and change.  You can do so by permitting
-redistribution under these terms (or, alternatively, under the terms of the
-ordinary General Public License).
-
-  To apply these terms, attach the following notices to the library.  It is
-safest to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least the
-"copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the library's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-Also add information on how to contact you by electronic and paper mail.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the library, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the
-  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
-
-  <signature of Ty Coon>, 1 April 1990
-  Ty Coon, President of Vice
-
-That's all there is to it!
 
 ------------------------------------------------------------------------------
 Qt 5 is redistributed within opencv-python macOS packages.
-This license applies to Qt binaries in the directory cv2/.
+libgmp is redistributed within opencv-python macOS packages.
+libidn2 is redistributed within opencv-python macOS packages.
+libunistring is redistributed within opencv-python macOS packages.
+This license applies to the above binaries in the directory cv2/.
 
                    GNU LESSER GENERAL PUBLIC LICENSE
                        Version 3, 29 June 2007
@@ -800,185 +763,133 @@ Julian Seward, jseward@bzip.org
 bzip2/libbzip2 version 1.0.6 of 6 September 2010
 
 ------------------------------------------------------------------------------
-libcrypto and libssl are redistributed within all opencv-python Linux packages.
-This license applies to libcrypto and libssl binaries in the directory cv2/.
-
-                                 Apache License
-                           Version 2.0, January 2004
-                        https://www.apache.org/licenses/
-
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-   1. Definitions.
-
-      "License" shall mean the terms and conditions for use, reproduction,
-      and distribution as defined by Sections 1 through 9 of this document.
-
-      "Licensor" shall mean the copyright owner or entity authorized by
-      the copyright owner that is granting the License.
-
-      "Legal Entity" shall mean the union of the acting entity and all
-      other entities that control, are controlled by, or are under common
-      control with that entity. For the purposes of this definition,
-      "control" means (i) the power, direct or indirect, to cause the
-      direction or management of such entity, whether by contract or
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
-      outstanding shares, or (iii) beneficial ownership of such entity.
-
-      "You" (or "Your") shall mean an individual or Legal Entity
-      exercising permissions granted by this License.
-
-      "Source" form shall mean the preferred form for making modifications,
-      including but not limited to software source code, documentation
-      source, and configuration files.
-
-      "Object" form shall mean any form resulting from mechanical
-      transformation or translation of a Source form, including but
-      not limited to compiled object code, generated documentation,
-      and conversions to other media types.
-
-      "Work" shall mean the work of authorship, whether in Source or
-      Object form, made available under the License, as indicated by a
-      copyright notice that is included in or attached to the work
-      (an example is provided in the Appendix below).
-
-      "Derivative Works" shall mean any work, whether in Source or Object
-      form, that is based on (or derived from) the Work and for which the
-      editorial revisions, annotations, elaborations, or other modifications
-      represent, as a whole, an original work of authorship. For the purposes
-      of this License, Derivative Works shall not include works that remain
-      separable from, or merely link (or bind by name) to the interfaces of,
-      the Work and Derivative Works thereof.
-
-      "Contribution" shall mean any work of authorship, including
-      the original version of the Work and any modifications or additions
-      to that Work or Derivative Works thereof, that is intentionally
-      submitted to Licensor for inclusion in the Work by the copyright owner
-      or by an individual or Legal Entity authorized to submit on behalf of
-      the copyright owner. For the purposes of this definition, "submitted"
-      means any form of electronic, verbal, or written communication sent
-      to the Licensor or its representatives, including but not limited to
-      communication on electronic mailing lists, source code control systems,
-      and issue tracking systems that are managed by, or on behalf of, the
-      Licensor for the purpose of discussing and improving the Work, but
-      excluding communication that is conspicuously marked or otherwise
-      designated in writing by the copyright owner as "Not a Contribution."
-
-      "Contributor" shall mean Licensor and any individual or Legal Entity
-      on behalf of whom a Contribution has been received by Licensor and
-      subsequently incorporated within the Work.
-
-   2. Grant of Copyright License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      copyright license to reproduce, prepare Derivative Works of,
-      publicly display, publicly perform, sublicense, and distribute the
-      Work and such Derivative Works in Source or Object form.
-
-   3. Grant of Patent License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      (except as stated in this section) patent license to make, have made,
-      use, offer to sell, sell, import, and otherwise transfer the Work,
-      where such license applies only to those patent claims licensable
-      by such Contributor that are necessarily infringed by their
-      Contribution(s) alone or by combination of their Contribution(s)
-      with the Work to which such Contribution(s) was submitted. If You
-      institute patent litigation against any entity (including a
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
-      or a Contribution incorporated within the Work constitutes direct
-      or contributory patent infringement, then any patent licenses
-      granted to You under this License for that Work shall terminate
-      as of the date such litigation is filed.
-
-   4. Redistribution. You may reproduce and distribute copies of the
-      Work or Derivative Works thereof in any medium, with or without
-      modifications, and in Source or Object form, provided that You
-      meet the following conditions:
-
-      (a) You must give any other recipients of the Work or
-          Derivative Works a copy of this License; and
-
-      (b) You must cause any modified files to carry prominent notices
-          stating that You changed the files; and
-
-      (c) You must retain, in the Source form of any Derivative Works
-          that You distribute, all copyright, patent, trademark, and
-          attribution notices from the Source form of the Work,
-          excluding those notices that do not pertain to any part of
-          the Derivative Works; and
-
-      (d) If the Work includes a "NOTICE" text file as part of its
-          distribution, then any Derivative Works that You distribute must
-          include a readable copy of the attribution notices contained
-          within such NOTICE file, excluding those notices that do not
-          pertain to any part of the Derivative Works, in at least one
-          of the following places: within a NOTICE text file distributed
-          as part of the Derivative Works; within the Source form or
-          documentation, if provided along with the Derivative Works; or,
-          within a display generated by the Derivative Works, if and
-          wherever such third-party notices normally appear. The contents
-          of the NOTICE file are for informational purposes only and
-          do not modify the License. You may add Your own attribution
-          notices within Derivative Works that You distribute, alongside
-          or as an addendum to the NOTICE text from the Work, provided
-          that such additional attribution notices cannot be construed
-          as modifying the License.
-
-      You may add Your own copyright statement to Your modifications and
-      may provide additional or different license terms and conditions
-      for use, reproduction, or distribution of Your modifications, or
-      for any such Derivative Works as a whole, provided Your use,
-      reproduction, and distribution of the Work otherwise complies with
-      the conditions stated in this License.
-
-   5. Submission of Contributions. Unless You explicitly state otherwise,
-      any Contribution intentionally submitted for inclusion in the Work
-      by You to the Licensor shall be under the terms and conditions of
-      this License, without any additional terms or conditions.
-      Notwithstanding the above, nothing herein shall supersede or modify
-      the terms of any separate license agreement you may have executed
-      with Licensor regarding such Contributions.
-
-   6. Trademarks. This License does not grant permission to use the trade
-      names, trademarks, service marks, or product names of the Licensor,
-      except as required for reasonable and customary use in describing the
-      origin of the Work and reproducing the content of the NOTICE file.
-
-   7. Disclaimer of Warranty. Unless required by applicable law or
-      agreed to in writing, Licensor provides the Work (and each
-      Contributor provides its Contributions) on an "AS IS" BASIS,
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-      implied, including, without limitation, any warranties or conditions
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-      PARTICULAR PURPOSE. You are solely responsible for determining the
-      appropriateness of using or redistributing the Work and assume any
-      risks associated with Your exercise of permissions under this License.
-
-   8. Limitation of Liability. In no event and under no legal theory,
-      whether in tort (including negligence), contract, or otherwise,
-      unless required by applicable law (such as deliberate and grossly
-      negligent acts) or agreed to in writing, shall any Contributor be
-      liable to You for damages, including any direct, indirect, special,
-      incidental, or consequential damages of any character arising as a
-      result of this License or out of the use or inability to use the
-      Work (including but not limited to damages for loss of goodwill,
-      work stoppage, computer failure or malfunction, or any and all
-      other commercial damages or losses), even if such Contributor
-      has been advised of the possibility of such damages.
-
-   9. Accepting Warranty or Additional Liability. While redistributing
-      the Work or Derivative Works thereof, You may choose to offer,
-      and charge a fee for, acceptance of support, warranty, indemnity,
-      or other liability obligations and/or rights consistent with this
-      License. However, in accepting such obligations, You may act only
-      on Your own behalf and on Your sole responsibility, not on behalf
-      of any other Contributor, and only if You agree to indemnify,
-      defend, and hold each Contributor harmless for any liability
-      incurred by, or claims asserted against, such Contributor by reason
-      of your accepting any such warranty or additional liability.
-
-   END OF TERMS AND CONDITIONS
+libcrypto and libssl are redistributed within all opencv-python Linux and macOS packages.
+libopencore-amrnb and libopencore-amrwb are redistributed within all opencv-python Linux and macOS packages.
+This license applies to above binaries in the directory cv2/.
+
+  LICENSE ISSUES
+  ==============
+
+  The OpenSSL toolkit stays under a double license, i.e. both the conditions of
+  the OpenSSL License and the original SSLeay license apply to the toolkit.
+  See below for the actual license texts.
+
+  OpenSSL License
+  ---------------
+
+/* ====================================================================
+ * Copyright (c) 1998-2019 The OpenSSL Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ *    software must display the following acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+ Original SSLeay License
+ -----------------------
+
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ *
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to.  The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    "This product includes cryptographic software written by
+ *     Eric Young (eay@cryptsoft.com)"
+ *    The word 'cryptographic' can be left out if the rouines from the library
+ *    being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from
+ *    the apps directory (application code) you must include an acknowledgement:
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
 
 ------------------------------------------------------------------------------
 libexpat is redistributed within all opencv-python Linux packages.
@@ -1007,7 +918,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 ------------------------------------------------------------------------------
-libfontconfig is redistributed within all opencv-python Linux packages.
+libfontconfig is redistributed within all opencv-python Linux and macOS packages.
 This license applies to libfontconfig binary in the directory cv2/.
 
 Copyright © 2000,2001,2002,2003,2004,2006,2007 Keith Packard
@@ -1037,7 +948,7 @@ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 PERFORMANCE OF THIS SOFTWARE.
 
 ------------------------------------------------------------------------------
-libfreetype is redistributed within opencv-python Linux packages.
+libfreetype is redistributed within opencv-python Linux and macOS packages.
 This license applies to libfreetype binary in the directory cv2/.
 
                     The FreeType Project LICENSE
@@ -1208,7 +1119,7 @@ Legal Terms
     https://www.freetype.org
 
 ------------------------------------------------------------------------------
-libpng is redistributed within all opencv-python Linux packages.
+libpng is redistributed within all opencv-python Linux and macOS packages.
 This license applies to libpng binary in the directory cv2/.
 
 PNG Reference Library License version 2
@@ -1622,3 +1533,799 @@ CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 OF THIS SOFTWARE.
+
+------------------------------------------------------------------------------
+libdav1d is redistributed within opencv-python macOS packages.
+This license applies to libdav1d binary in the directory cv2/.
+
+Copyright © 2018-2019, VideoLAN and dav1d authors
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+   list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------------------------------------------------------------------
+libffi is redistributed within opencv-python macOS packages.
+This license applies to libffi binary in the directory cv2/.
+
+libffi - Copyright (c) 1996-2020  Anthony Green, Red Hat, Inc and others.
+See source files for details.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+``Software''), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+------------------------------------------------------------------------------
+libogg is redistributed within opencv-python macOS packages.
+This license applies to libogg binary in the directory cv2/.
+
+Copyright (c) 2002, Xiph.org Foundation
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+- Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+- Neither the name of the Xiph.org Foundation nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------------------------------------------------------------------
+libopenjp2 is redistributed within opencv-python macOS packages.
+This license applies to libopenjp2 binary in the directory cv2/.
+
+The copyright in this software is being made available under the 2-clauses 
+BSD License, included below. This software may be subject to other third 
+party and contributor rights, including patent rights, and no such rights
+are granted under this license.
+
+Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
+Copyright (c) 2002-2014, Professor Benoit Macq
+Copyright (c) 2003-2014, Antonin Descampe
+Copyright (c) 2003-2009, Francois-Olivier Devaux
+Copyright (c) 2005, Herve Drolon, FreeImage Team
+Copyright (c) 2002-2003, Yannick Verschueren
+Copyright (c) 2001-2003, David Janssens
+Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France 
+Copyright (c) 2012, CS Systemes d'Information, France
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+------------------------------------------------------------------------------
+libopus is redistributed within opencv-python macOS packages.
+This license applies to libopus binary in the directory cv2/.
+
+Copyright 2001-2011 Xiph.Org, Skype Limited, Octasic,
+                    Jean-Marc Valin, Timothy B. Terriberry,
+                    CSIRO, Gregory Maxwell, Mark Borgerding,
+                    Erik de Castro Lopo
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+- Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+- Neither the name of Internet Society, IETF or IETF Trust, nor the
+names of specific contributors, may be used to endorse or promote
+products derived from this software without specific prior written
+permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Opus is subject to the royalty-free patent licenses which are
+specified at:
+
+Xiph.Org Foundation:
+https://datatracker.ietf.org/ipr/1524/
+
+Microsoft Corporation:
+https://datatracker.ietf.org/ipr/1914/
+
+Broadcom Corporation:
+https://datatracker.ietf.org/ipr/1526/
+
+------------------------------------------------------------------------------
+librav1e is redistributed within opencv-python macOS packages.
+This license applies to librav1e binary in the directory cv2/.
+
+BSD 2-Clause License
+
+Copyright (c) 2017-2020, the rav1e contributors
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+  this list of conditions and the following disclaimer in the documentation
+  and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------------------------------------------------------------------
+libsnappy is redistributed within opencv-python macOS packages.
+This license applies to libsnappy binary in the directory cv2/.
+
+Copyright 2011, Google Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+    * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------------------------------------------------------------------
+libspeex is redistributed within opencv-python macOS packages.
+This license applies to libspeex binary in the directory cv2/.
+
+Copyright 2002-2008   Xiph.org Foundation
+Copyright 2002-2008   Jean-Marc Valin
+Copyright 2005-2007 Analog Devices Inc.
+Copyright 2005-2008 Commonwealth Scientific and Industrial Research 
+                        Organisation (CSIRO)
+Copyright 1993, 2002, 2006 David Rowe
+Copyright 2003    EpicGames
+Copyright 1992-1994 Jutta Degener, Carsten Bormann
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+- Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+- Neither the name of the Xiph.org Foundation nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------------------------------------------------------------------
+libsrt is redistributed within opencv-python macOS packages.
+This license applies to libsrt binary in the directory cv2/.
+
+/*
+ *  
+ * Copyright (c) 2001-2017 Cisco Systems, Inc.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ *   Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * 
+ *   Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the following
+ *   disclaimer in the documentation and/or other materials provided
+ *   with the distribution.
+ * 
+ *   Neither the name of the Cisco Systems, Inc. nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+
+ Mozilla Public License Version 2.0
+==================================
+
+1. Definitions
+--------------
+
+1.1. "Contributor"
+    means each individual or legal entity that creates, contributes to
+    the creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+    means the combination of the Contributions of others (if any) used
+    by a Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+    means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+    means Source Code Form to which the initial Contributor has attached
+    the notice in Exhibit A, the Executable Form of such Source Code
+    Form, and Modifications of such Source Code Form, in each case
+    including portions thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+    means
+
+    (a) that the initial Contributor has attached the notice described
+        in Exhibit B to the Covered Software; or
+
+    (b) that the Covered Software was made available under the terms of
+        version 1.1 or earlier of the License, but not also under the
+        terms of a Secondary License.
+
+1.6. "Executable Form"
+    means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+    means a work that combines Covered Software with other material, in 
+    a separate file or files, that is not Covered Software.
+
+1.8. "License"
+    means this document.
+
+1.9. "Licensable"
+    means having the right to grant, to the maximum extent possible,
+    whether at the time of the initial grant or subsequently, any and
+    all of the rights conveyed by this License.
+
+1.10. "Modifications"
+    means any of the following:
+
+    (a) any file in Source Code Form that results from an addition to,
+        deletion from, or modification of the contents of Covered
+        Software; or
+
+    (b) any new file in Source Code Form that contains any Covered
+        Software.
+
+1.11. "Patent Claims" of a Contributor
+    means any patent claim(s), including without limitation, method,
+    process, and apparatus claims, in any patent Licensable by such
+    Contributor that would be infringed, but for the grant of the
+    License, by the making, using, selling, offering for sale, having
+    made, import, or transfer of either its Contributions or its
+    Contributor Version.
+
+1.12. "Secondary License"
+    means either the GNU General Public License, Version 2.0, the GNU
+    Lesser General Public License, Version 2.1, the GNU Affero General
+    Public License, Version 3.0, or any later versions of those
+    licenses.
+
+1.13. "Source Code Form"
+    means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+    means an individual or a legal entity exercising rights under this
+    License. For legal entities, "You" includes any entity that
+    controls, is controlled by, or is under common control with You. For
+    purposes of this definition, "control" means (a) the power, direct
+    or indirect, to cause the direction or management of such entity,
+    whether by contract or otherwise, or (b) ownership of more than
+    fifty percent (50%) of the outstanding shares or beneficial
+    ownership of such entity.
+
+2. License Grants and Conditions
+--------------------------------
+
+2.1. Grants
+
+Each Contributor hereby grants You a world-wide, royalty-free,
+non-exclusive license:
+
+(a) under intellectual property rights (other than patent or trademark)
+    Licensable by such Contributor to use, reproduce, make available,
+    modify, display, perform, distribute, and otherwise exploit its
+    Contributions, either on an unmodified basis, with Modifications, or
+    as part of a Larger Work; and
+
+(b) under Patent Claims of such Contributor to make, use, sell, offer
+    for sale, have made, import, and otherwise transfer either its
+    Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+The licenses granted in Section 2.1 with respect to any Contribution
+become effective for each Contribution on the date the Contributor first
+distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+The licenses granted in this Section 2 are the only rights granted under
+this License. No additional rights or licenses will be implied from the
+distribution or licensing of Covered Software under this License.
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
+Contributor:
+
+(a) for any code that a Contributor has removed from Covered Software;
+    or
+
+(b) for infringements caused by: (i) Your and any other third party's
+    modifications of Covered Software, or (ii) the combination of its
+    Contributions with other software (except as part of its Contributor
+    Version); or
+
+(c) under Patent Claims infringed by Covered Software in the absence of
+    its Contributions.
+
+This License does not grant any rights in the trademarks, service marks,
+or logos of any Contributor (except as may be necessary to comply with
+the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+No Contributor makes additional grants as a result of Your choice to
+distribute the Covered Software under a subsequent version of this
+License (see Section 10.2) or under the terms of a Secondary License (if
+permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+Each Contributor represents that the Contributor believes its
+Contributions are its original creation(s) or it has sufficient rights
+to grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+This License is not intended to limit any rights You have under
+applicable copyright doctrines of fair use, fair dealing, or other
+equivalents.
+
+2.7. Conditions
+
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
+in Section 2.1.
+
+3. Responsibilities
+-------------------
+
+3.1. Distribution of Source Form
+
+All distribution of Covered Software in Source Code Form, including any
+Modifications that You create or to which You contribute, must be under
+the terms of this License. You must inform recipients that the Source
+Code Form of the Covered Software is governed by the terms of this
+License, and how they can obtain a copy of this License. You may not
+attempt to alter or restrict the recipients' rights in the Source Code
+Form.
+
+3.2. Distribution of Executable Form
+
+If You distribute Covered Software in Executable Form then:
+
+(a) such Covered Software must also be made available in Source Code
+    Form, as described in Section 3.1, and You must inform recipients of
+    the Executable Form how they can obtain a copy of such Source Code
+    Form by reasonable means in a timely manner, at a charge no more
+    than the cost of distribution to the recipient; and
+
+(b) You may distribute such Executable Form under the terms of this
+    License, or sublicense it under different terms, provided that the
+    license for the Executable Form does not attempt to limit or alter
+    the recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+You may create and distribute a Larger Work under terms of Your choice,
+provided that You also comply with the requirements of this License for
+the Covered Software. If the Larger Work is a combination of Covered
+Software with a work governed by one or more Secondary Licenses, and the
+Covered Software is not Incompatible With Secondary Licenses, this
+License permits You to additionally distribute such Covered Software
+under the terms of such Secondary License(s), so that the recipient of
+the Larger Work may, at their option, further distribute the Covered
+Software under the terms of either this License or such Secondary
+License(s).
+
+3.4. Notices
+
+You may not remove or alter the substance of any license notices
+(including copyright notices, patent notices, disclaimers of warranty,
+or limitations of liability) contained within the Source Code Form of
+the Covered Software, except that You may alter any license notices to
+the extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+You may choose to offer, and to charge a fee for, warranty, support,
+indemnity or liability obligations to one or more recipients of Covered
+Software. However, You may do so only on Your own behalf, and not on
+behalf of any Contributor. You must make it absolutely clear that any
+such warranty, support, indemnity, or liability obligation is offered by
+You alone, and You hereby agree to indemnify every Contributor for any
+liability incurred by such Contributor as a result of warranty, support,
+indemnity or liability terms You offer. You may include additional
+disclaimers of warranty and limitations of liability specific to any
+jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+---------------------------------------------------
+
+If it is impossible for You to comply with any of the terms of this
+License with respect to some or all of the Covered Software due to
+statute, judicial order, or regulation then You must: (a) comply with
+the terms of this License to the maximum extent possible; and (b)
+describe the limitations and the code they affect. Such description must
+be placed in a text file included with all distributions of the Covered
+Software under this License. Except to the extent prohibited by statute
+or regulation, such description must be sufficiently detailed for a
+recipient of ordinary skill to be able to understand it.
+
+5. Termination
+--------------
+
+5.1. The rights granted under this License will terminate automatically
+if You fail to comply with any of its terms. However, if You become
+compliant, then the rights granted under this License from a particular
+Contributor are reinstated (a) provisionally, unless and until such
+Contributor explicitly and finally terminates Your grants, and (b) on an
+ongoing basis, if such Contributor fails to notify You of the
+non-compliance by some reasonable means prior to 60 days after You have
+come back into compliance. Moreover, Your grants from a particular
+Contributor are reinstated on an ongoing basis if such Contributor
+notifies You of the non-compliance by some reasonable means, this is the
+first time You have received notice of non-compliance with this License
+from such Contributor, and You become compliant prior to 30 days after
+Your receipt of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+infringement claim (excluding declaratory judgment actions,
+counter-claims, and cross-claims) alleging that a Contributor Version
+directly or indirectly infringes any patent, then the rights granted to
+You by any and all Contributors for the Covered Software under Section
+2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
+end user license agreements (excluding distributors and resellers) which
+have been validly granted by You or Your distributors under this License
+prior to termination shall survive termination.
+
+************************************************************************
+*                                                                      *
+*  6. Disclaimer of Warranty                                           *
+*  -------------------------                                           *
+*                                                                      *
+*  Covered Software is provided under this License on an "as is"       *
+*  basis, without warranty of any kind, either expressed, implied, or  *
+*  statutory, including, without limitation, warranties that the       *
+*  Covered Software is free of defects, merchantable, fit for a        *
+*  particular purpose or non-infringing. The entire risk as to the     *
+*  quality and performance of the Covered Software is with You.        *
+*  Should any Covered Software prove defective in any respect, You     *
+*  (not any Contributor) assume the cost of any necessary servicing,   *
+*  repair, or correction. This disclaimer of warranty constitutes an   *
+*  essential part of this License. No use of any Covered Software is   *
+*  authorized under this License except under this disclaimer.         *
+*                                                                      *
+************************************************************************
+
+************************************************************************
+*                                                                      *
+*  7. Limitation of Liability                                          *
+*  --------------------------                                          *
+*                                                                      *
+*  Under no circumstances and under no legal theory, whether tort      *
+*  (including negligence), contract, or otherwise, shall any           *
+*  Contributor, or anyone who distributes Covered Software as          *
+*  permitted above, be liable to You for any direct, indirect,         *
+*  special, incidental, or consequential damages of any character      *
+*  including, without limitation, damages for lost profits, loss of    *
+*  goodwill, work stoppage, computer failure or malfunction, or any    *
+*  and all other commercial damages or losses, even if such party      *
+*  shall have been informed of the possibility of such damages. This   *
+*  limitation of liability shall not apply to liability for death or   *
+*  personal injury resulting from such party's negligence to the       *
+*  extent applicable law prohibits such limitation. Some               *
+*  jurisdictions do not allow the exclusion or limitation of           *
+*  incidental or consequential damages, so this exclusion and          *
+*  limitation may not apply to You.                                    *
+*                                                                      *
+************************************************************************
+
+8. Litigation
+-------------
+
+Any litigation relating to this License may be brought only in the
+courts of a jurisdiction where the defendant maintains its principal
+place of business and such litigation shall be governed by laws of that
+jurisdiction, without reference to its conflict-of-law provisions.
+Nothing in this Section shall prevent a party's ability to bring
+cross-claims or counter-claims.
+
+9. Miscellaneous
+----------------
+
+This License represents the complete agreement concerning the subject
+matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent
+necessary to make it enforceable. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+shall not be used to construe this License against a Contributor.
+
+10. Versions of the License
+---------------------------
+
+10.1. New Versions
+
+Mozilla Foundation is the license steward. Except as provided in Section
+10.3, no one other than the license steward has the right to modify or
+publish new versions of this License. Each version will be given a
+distinguishing version number.
+
+10.2. Effect of New Versions
+
+You may distribute the Covered Software under the terms of the version
+of the License under which You originally received the Covered Software,
+or under the terms of any subsequent version published by the license
+steward.
+
+10.3. Modified Versions
+
+If you create software not governed by this License, and you want to
+create a new license for such software, you may create and use a
+modified version of this License if you rename the license and remove
+any references to the name of the license steward (except to note that
+such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+Licenses
+
+If You choose to distribute Source Code Form that is Incompatible With
+Secondary Licenses under the terms of this version of the License, the
+notice described in Exhibit B of this License must be attached.
+
+Exhibit A - Source Code Form License Notice
+-------------------------------------------
+
+  This Source Code Form is subject to the terms of the Mozilla Public
+  License, v. 2.0. If a copy of the MPL was not distributed with this
+  file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular
+file, then You may include the notice in a location (such as a LICENSE
+file in a relevant directory) where a recipient would be likely to look
+for such a notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+---------------------------------------------------------
+
+  This Source Code Form is "Incompatible With Secondary Licenses", as
+  defined by the Mozilla Public License, v. 2.0.
+
+------------------------------------------------------------------------------
+libtheoradec and libtheoraenc are redistributed within opencv-python macOS packages.
+This license applies to libtheoradec and libtheoraenc binaries in the directory cv2/.
+
+  Copyright (C) 2002-2009 Xiph.org Foundation
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+- Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+- Neither the name of the Xiph.org Foundation nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------------------------------------------------------------------
+libwebp and libwebpmux are redistributed within opencv-python macOS packages.
+This license applies to libwebp  and libwebpmux binaries in the directory cv2/.
+
+Copyright (c) 2010, Google Inc. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+  * Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+
+  * Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in
+    the documentation and/or other materials provided with the
+    distribution.
+
+  * Neither the name of Google nor the names of its contributors may
+    be used to endorse or promote products derived from this software
+    without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------------------------------------------------------------------
+libvorbis and libvorbisenc are redistributed within opencv-python macOS packages.
+This license applies to libvorbis and libvorbisenc binaries in the directory cv2/.
+
+Copyright (c) 2002-2020 Xiph.org Foundation
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+- Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+- Neither the name of the Xiph.org Foundation nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file

From 75bbcf68f18a64fbf43c0ee19ca439434e3c09c7 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 13 Jul 2020 19:23:21 +0300
Subject: [PATCH 341/566] initial sdist support

---
 .travis.yml     | 190 +++++++++++++++++++++++++++++++++---------------
 MANIFEST.in     |  10 +++
 find_version.py |  96 ++++++++++++------------
 pyproject.toml  |   2 +
 setup.py        |  84 ++++++---------------
 5 files changed, 219 insertions(+), 163 deletions(-)
 create mode 100644 MANIFEST.in
 create mode 100644 pyproject.toml

diff --git a/.travis.yml b/.travis.yml
index abdd069a..49d1ac4c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,10 +4,10 @@ env:
         # pip dependencies to _test_ your project
         - TEST_DEPENDS="numpy==1.11.1"
         # params to bdist_wheel. used to set osx build target.
-        - BDIST_PARAMS=""
         - CONFIG_PATH="travis_config.sh"
         - USE_CCACHE=1
         - UNICODE_WIDTH=32
+        - SDIST=0
 
 # Save some time, we and setup check them out on demand instead
 # https://docs.travis-ci.com/user/customizing-the-build/#Git-Clone-Depth
@@ -28,6 +28,7 @@ stages:
 
 jobs:
   fast_finish: true
+  # Travis exclude is buggy, this seems to be the only way to disable default build
   exclude:
     - language: ruby
   include:
@@ -57,6 +58,40 @@ jobs:
           # used in OSX custom build script dealing with local bottle caching
           - $HOME/local_bottle_metadata
 
+    # source distributions
+    - os: linux
+      env:
+        - SDIST=1
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+      python: "3.8"
+      language: python
+      dist: xenial
+    - os: linux
+      env:
+        - SDIST=1
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+      python: "3.8"
+      language: python
+      dist: xenial
+    - os: linux
+      env:
+        - SDIST=1
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+      python: "3.8"
+      language: python
+      dist: xenial
+    - os: linux
+      env:
+        - SDIST=1
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+      python: "3.8"
+      language: python
+      dist: xenial
+
     # default builds for MacOS
       #further jobs in the list will use the same stage until the next assignment
     - stage: final
@@ -606,56 +641,74 @@ jobs:
 
 # The first line is printed in the folding header in Travis output
 before_install: |
-    # Check out and prepare the source
     set -e
-    # Multibuild doesn't have releases, so --depth would break eventually (see
-    # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
-    git submodule update --init multibuild
-    echo "Source multibuild/common_utils.sh"
-    source multibuild/common_utils.sh
-    # https://github.com/matthew-brett/multibuild/issues/116
-    if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
-    echo "Source multibuild/travis_steps.sh"
-    source multibuild/travis_steps.sh
-    # This sets -x
-    echo "Source travis_multibuild_customize.sh"
-    source travis_multibuild_customize.sh
-    echo $ENABLE_CONTRIB > contrib.enabled
-    echo $ENABLE_HEADLESS > headless.enabled
 
-    if [ -n "$IS_OSX" ]; then
-        echo "homebrew"
-        TAPS="$(brew --repository)/Library/Taps"
-        if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
-            rm -rf "$TAPS/caskroom/homebrew-cask"
-        fi
-        find "$TAPS" -type d -name .git -exec \
-                bash -xec '
-                    cd $(dirname '\''{}'\'') || echo "status: $?"
-                    git clean -fxd || echo "status: $?"
-                    sleep 1 || echo "status: $?"
-                    git status || echo "status: $?"' \; || echo "status: $?"
+    if [ -z "$SDIST" ]; then
+        echo "sdist build"
+    else
+        # Check out and prepare the source
+        # Multibuild doesn't have releases, so --depth would break eventually (see
+        # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+        git submodule update --init multibuild
 
-        brew_cache_cleanup
+        source multibuild/common_utils.sh
+
+        # https://github.com/matthew-brett/multibuild/issues/116
+        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+
+        source multibuild/travis_steps.sh
+        # This sets -x
+
+        source travis_multibuild_customize.sh
+        echo $ENABLE_CONTRIB > contrib.enabled
+        echo $ENABLE_HEADLESS > headless.enabled
+
+        if [ -n "$IS_OSX" ]; then
+            echo "homebrew"
+            TAPS="$(brew --repository)/Library/Taps"
+            if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
+                rm -rf "$TAPS/caskroom/homebrew-cask"
+            fi
+            find "$TAPS" -type d -name .git -exec \
+                    bash -xec '
+                        cd $(dirname '\''{}'\'') || echo "status: $?"
+                        git clean -fxd || echo "status: $?"
+                        sleep 1 || echo "status: $?"
+                        git status || echo "status: $?"' \; || echo "status: $?"
+            brew_cache_cleanup
+        fi
+        echo "end"
+        # Not interested in travis internal scripts' output
     fi
-    echo "end"
-    # Not interested in travis internal scripts' output
+
     set +x
 
 install: |
     # Build and package
     set -x
-    build_wheel $REPO_DIR $PLAT
+
+    if [ -z "$SDIST" ]; then
+        python setup.py sdist
+    else
+        build_wheel $REPO_DIR $PLAT
+    fi
+
     set +x
 
 script: |
     # Install and run tests
     set -x
-    install_run $PLAT && rc=$? || rc=$?
+
+    if [ -z "$SDIST" ]; then
+      echo "sdist"
+    else
+        install_run $PLAT && rc=$? || rc=$?
+    fi
+
     set +x
 
-    #otherwise, Travis logic terminates prematurely
-    #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
+    # otherwise, Travis logic terminates prematurely
+    # https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
     trap ERR
 
     test "$rc" -eq 0
@@ -676,19 +729,11 @@ before_cache: |
     set +x; set +e
 
 after_success: |
-    # Upload wheels to pypi if tag is set, otherwise save to Azure Storage
-    if [ -n "$TRAVIS_TAG" ]; then
-        set -x
+    # Upload wheels to pypi if tag is set
 
-        if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-          pip install --user twine
-          pip install --user --upgrade six
-        fi
+    set -x
 
-        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
-          pip install twine
-          pip install --upgrade pyOpenSSL
-        fi
+    if [ -n "$TRAVIS_TAG" ]; then
 
         if [[ $ENABLE_CONTRIB == 0 ]]; then
             if [[ $ENABLE_HEADLESS == 0 ]]; then
@@ -704,19 +749,50 @@ after_success: |
             fi
         fi
 
-        twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
-        set +x
-    else
-        set -x
-
         if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-          curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
-        else
-          brew install azure-cli
+          pip install --user twine
+          pip install --user --upgrade six
+
+          if [ -z "$SDIST" ]; then
+            twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
+          else
+            twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
+          fi
+
         fi
 
-        az storage container create -n ${TRAVIS_COMMIT} --public-access blob
-        az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern *.whl
+        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
+          # macpython 3.5 doesn't support recent TLS protocols which causes twine
+          # upload to fail, so we use the system Python to run twine
+          /usr/bin/python -m ensurepip --user
+          /usr/bin/python -m pip install --user -U pip
+          /usr/bin/python -m pip install --user -U -I twine
+
+          if [ -z "$SDIST" ]; then
+            /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
+          else
+            /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
+          fi
+
+        fi
 
-        set -x
     fi
+
+    # Save to Azure storage always
+
+    if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
+      curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
+    else
+      brew install azure-cli
+    fi
+
+    az storage container create -n ${TRAVIS_COMMIT} --public-access blob
+
+    if [ -z "$SDIST" ]; then
+      az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/dist --pattern *.gz
+    else
+      az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern *.whl
+    fi
+
+    set +x
+
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 00000000..480bb3d4
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,10 @@
+include LICENSE-3RD-PARTY.txt
+include LICENSE.txt
+include README.md
+include find_version.py
+include setup.py
+recursive-include cv2 *
+recursive-include docker *
+recursive-include opencv *
+recursive-include opencv_contrib *
+recursive-include patches *
diff --git a/find_version.py b/find_version.py
index 519542e4..b7ad0613 100644
--- a/find_version.py
+++ b/find_version.py
@@ -2,49 +2,53 @@
 import os
 import subprocess
 
-opencv_version = ""
-# dig out the version from OpenCV sources
-version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp"
-
-with open(version_file_path, 'r') as f:
-    for line in f:
-        words = line.split()
-
-        if "CV_VERSION_MAJOR" in words:
-            opencv_version += words[2]
-            opencv_version += "."
-
-        if "CV_VERSION_MINOR" in words:
-            opencv_version += words[2]
-            opencv_version += "."
-
-        if "CV_VERSION_REVISION" in words:
-            opencv_version += words[2]
-            break
-
-# used in local dev releases
-git_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).splitlines()[0].decode()
-# this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
-try:
-    tag = subprocess.check_output(['git', 'describe', '--tags'], stderr = subprocess.STDOUT).splitlines()[0].decode().split('-')
-except subprocess.CalledProcessError as e:
-    # no tags reachable (e.g. on a topic branch in a fork), see
-    # https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
-    if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
-        tag=[]
-    else:
-        print(e.output); raise
-
-if len(tag) == 1:
-    # tag identifies the build and should be a sequential revision number
-    version = tag[0]
-    opencv_version += ".{}".format(version)
-else:
-    # local version identifier, not to be published on PyPI
-    version = git_hash
-    opencv_version += "+{}".format(version)
-
-print("Version: ", opencv_version)
-
-with open('cv_version.py', 'w') as f:
-    f.write('opencv_version = "{}"'.format(opencv_version))
+if __name__ == "__main__":
+  contrib = sys.argv[1]
+  headless = sys.argv[2]
+
+  opencv_version = ""
+  # dig out the version from OpenCV sources
+  version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp"
+
+  with open(version_file_path, 'r') as f:
+      for line in f:
+          words = line.split()
+
+          if "CV_VERSION_MAJOR" in words:
+              opencv_version += words[2]
+              opencv_version += "."
+
+          if "CV_VERSION_MINOR" in words:
+              opencv_version += words[2]
+              opencv_version += "."
+
+          if "CV_VERSION_REVISION" in words:
+              opencv_version += words[2]
+              break
+
+  # used in local dev releases
+  git_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).splitlines()[0].decode()
+  # this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
+  try:
+      tag = subprocess.check_output(['git', 'describe', '--tags'], stderr = subprocess.STDOUT).splitlines()[0].decode().split('-')
+  except subprocess.CalledProcessError as e:
+      # no tags reachable (e.g. on a topic branch in a fork), see
+      # https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
+      if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
+          tag=[]
+      else:
+          print(e.output); raise
+
+  if len(tag) == 1:
+      # tag identifies the build and should be a sequential revision number
+      version = tag[0]
+      opencv_version += ".{}".format(version)
+  else:
+      # local version identifier, not to be published on PyPI
+      version = git_hash
+      opencv_version += "+{}".format(version)
+
+  with open('cv2/version.py', 'w') as f:
+      f.write("opencv_version = \"{}\"\n".format(opencv_version))
+      f.write("contrib = {}\n".format(contrib))
+      f.write("headless = {}".format(headless))
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 00000000..ef8a4804
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,2 @@
+[build-system]
+requires = ["setuptools", "wheel", "scikit-build", "cmake"]
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 843d5f03..4bde2f7f 100644
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,3 @@
-# No 3rd-party modules here, see "3rd-party" note below
 import io
 import os
 import os.path
@@ -7,23 +6,20 @@
 import subprocess
 import re
 import sysconfig
+import skbuild
+from skbuild import cmaker
 
 
 def main():
-
     os.chdir(os.path.dirname(os.path.abspath(__file__)))
 
-    # These are neede for source fetching
+    # These are needed for source fetching
     cmake_source_dir = "opencv"
+    minimum_supported_numpy = "1.11.1"
     build_contrib = get_build_env_var_by_name("contrib")
     # headless flag to skip GUI deps if needed
     build_headless = get_build_env_var_by_name("headless")
 
-    # Only import 3rd-party modules after having installed all the build dependencies:
-    # any of them, or their dependencies, can be updated during that process,
-    # leading to version conflicts
-    minimum_supported_numpy = "1.11.1"
-
     if sys.version_info[:2] >= (3, 6):
         minimum_supported_numpy = "1.11.3"
     if sys.version_info[:2] >= (3, 7):
@@ -31,21 +27,14 @@ def main():
     if sys.version_info[:2] >= (3, 8):
         minimum_supported_numpy = "1.17.3"
 
-    numpy_version = get_or_install("numpy", minimum_supported_numpy)
-    get_or_install("scikit-build")
-    get_or_install("cmake")
-
-    import skbuild
-    from skbuild import cmaker
+    numpy_version = "numpy>=%s" % minimum_supported_numpy
 
     python_version = cmaker.CMaker.get_python_version()
     python_lib_path = cmaker.CMaker.get_python_library(python_version).replace('\\', '/')
     python_include_dir = cmaker.CMaker.get_python_include_dir(python_version).replace('\\', '/')
 
     if os.path.exists(".git"):
-
         import pip._internal.vcs.git as git
-
         g = git.Git()  # NOTE: pip API's are internal, this has to be refactored
 
         g.run_command(["submodule", "sync"])
@@ -58,6 +47,8 @@ def main():
                 ["submodule", "update", "--init", "--recursive", "opencv_contrib"]
             )
 
+    package_version, build_contrib, build_headless = get_opencv_version(build_contrib, build_headless)
+
     # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
     x64 = sys.maxsize > 2 ** 32
 
@@ -73,12 +64,11 @@ def main():
         package_name = "opencv-python-headless"
 
     long_description = io.open("README.md", encoding="utf-8").read()
-    package_version = get_opencv_version()
 
     packages = ["cv2", "cv2.data"]
 
     package_data = {
-        "cv2": ["*%s" % sysconfig.get_config_vars().get("SO")]
+        "cv2": ["*%s" % sysconfig.get_config_vars().get("SO"), "version.py"]
         + (["*.dll"] if os.name == "nt" else [])
         + ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
         "cv2.data": ["*.xml"],
@@ -96,7 +86,7 @@ def main():
         # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
         # Naming conventions vary so widely between versions and OSes
         # had to give up on checking them.
-        ["python/cv2[^/]*%(ext)s" % {"ext": re.escape(sysconfig.get_config_var("SO"))}],
+        ["python/cv2[^/]*%(ext)s" % {"ext": re.escape(sysconfig.get_config_var("EXT_SUFFIX"))}],
         "cv2.data": [  # OPENCV_OTHER_INSTALL_PATH
             ("etc" if os.name == "nt" else "share/opencv4") + r"/haarcascades/.*\.xml"
         ],
@@ -108,7 +98,7 @@ def main():
 
     cmake_args = (
         (
-            ["-G", "Visual Studio 14" + (" Win64" if x64 else "")]
+            ["-G", "Visual Studio 15" + (" Win64" if x64 else "")]
             if os.name == "nt"
             else ["-G", "Unix Makefiles"]  # don't make CMake try (and fail) Ninja first
         )
@@ -170,15 +160,6 @@ def main():
     if sys.platform == "darwin":
         subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
-    # Fixes for macOS builds
-    if sys.platform == "darwin":
-        cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9")
-
-    if "CMAKE_ARGS" in os.environ:
-        import shlex
-        cmake_args.extend(shlex.split(os.environ["CMAKE_ARGS"]))
-        del shlex
-
     # works via side effect
     RearrangeCMakeOutput(
         rearrange_cmake_output_data, files_outside_package_dir, package_data.keys()
@@ -197,7 +178,7 @@ def main():
         maintainer="Olli-Pekka Heinisuo",
         include_package_data=True,
         ext_modules=EmptyListWithLength(),
-        install_requires="numpy>=%s" % numpy_version,
+        install_requires=numpy_version,
         classifiers=[
             "Development Status :: 5 - Production/Stable",
             "Environment :: Console",
@@ -377,19 +358,22 @@ def _classify_installed_files_override(
             cmake_install_dir=cmake_install_reldir,
         )
 
+def get_opencv_version(contrib, headless):
+    # cv2/version.py should be generated by running find_version.py
+    version = {}
+    here = os.path.abspath(os.path.dirname(__file__))
+    version_file = os.path.join(here, "cv2", "version.py")
 
-def install_packages(*requirements):
-    # No more convenient way until PEP 518 is implemented; setuptools only handles eggs
-    subprocess.check_call([sys.executable, "-m", "pip", "install"] + list(requirements))
-
+    if not os.path.exists(version_file):
+      old_args = sys.argv.copy()
+      sys.argv = ['', str(contrib), str(headless)]
+      runpy.run_path("find_version.py ", run_name="__main__")
+      sys.argv = old_args
 
-def get_opencv_version():
-    # cv_version.py should be generated by running find_version.py
-    runpy.run_path("find_version.py")
-    from cv_version import opencv_version
-
-    return opencv_version
+    with open(version_file) as fp:
+        exec(fp.read(), version)
 
+    return version['opencv_version'], version['contrib'], version['headless']
 
 def get_build_env_var_by_name(flag_name):
     flag_set = False
@@ -407,26 +391,6 @@ def get_build_env_var_by_name(flag_name):
 
     return flag_set
 
-
-def get_or_install(name, version=None):
-    """ If a package is already installed, build against it. If not, install """
-    # Do not import 3rd-party modules into the current process
-    import json
-
-    js_packages = json.loads(
-        subprocess.check_output(
-            [sys.executable, "-m", "pip", "list", "--format", "json"]
-        ).decode("ascii")
-    )  # valid names & versions are ASCII as per PEP 440
-    try:
-        [package] = (package for package in js_packages if package["name"] == name)
-    except ValueError:
-        install_packages("%s==%s" % (name, version) if version else name)
-        return version
-    else:
-        return package["version"]
-
-
 # This creates a list which is empty but returns a length of 1.
 # Should make the wheel a binary distribution and platlib compliant.
 class EmptyListWithLength(list):

From 55fc534a6776bec8f2c61834c8d9e273ff042ad5 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 13 Jul 2020 23:17:34 +0300
Subject: [PATCH 342/566] multiple fixes

---
 .travis.yml      | 14 ++++++++------
 MANIFEST.in      |  1 +
 appveyor.yml     |  2 +-
 pyproject.toml   |  8 +++++++-
 setup.py         |  5 ++---
 travis_config.sh |  2 +-
 6 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 49d1ac4c..2f5a9874 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -643,7 +643,7 @@ jobs:
 before_install: |
     set -e
 
-    if [ -z "$SDIST" ]; then
+    if [ -n "$SDIST" ]; then
         echo "sdist build"
     else
         # Check out and prepare the source
@@ -687,7 +687,9 @@ install: |
     # Build and package
     set -x
 
-    if [ -z "$SDIST" ]; then
+    if [ -n "$SDIST" ]; then
+        python -m pip install --upgrade pip
+        python -m pip install scikit-build
         python setup.py sdist
     else
         build_wheel $REPO_DIR $PLAT
@@ -699,7 +701,7 @@ script: |
     # Install and run tests
     set -x
 
-    if [ -z "$SDIST" ]; then
+    if [ -n "$SDIST" ]; then
       echo "sdist"
     else
         install_run $PLAT && rc=$? || rc=$?
@@ -753,7 +755,7 @@ after_success: |
           pip install --user twine
           pip install --user --upgrade six
 
-          if [ -z "$SDIST" ]; then
+          if [ -n "$SDIST" ]; then
             twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
           else
             twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
@@ -768,7 +770,7 @@ after_success: |
           /usr/bin/python -m pip install --user -U pip
           /usr/bin/python -m pip install --user -U -I twine
 
-          if [ -z "$SDIST" ]; then
+          if [ -n "$SDIST" ]; then
             /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
           else
             /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
@@ -788,7 +790,7 @@ after_success: |
 
     az storage container create -n ${TRAVIS_COMMIT} --public-access blob
 
-    if [ -z "$SDIST" ]; then
+    if [ -n "$SDIST" ]; then
       az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/dist --pattern *.gz
     else
       az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern *.whl
diff --git a/MANIFEST.in b/MANIFEST.in
index 480bb3d4..45cb6c40 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -3,6 +3,7 @@ include LICENSE.txt
 include README.md
 include find_version.py
 include setup.py
+include pyproject.toml
 recursive-include cv2 *
 recursive-include docker *
 recursive-include opencv *
diff --git a/appveyor.yml b/appveyor.yml
index dab586c7..ada90638 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -141,7 +141,7 @@ build_script:
 - cmd: |
     "%PYTHON%/python.exe" -m pip install --upgrade pip
     "%PYTHON%/python.exe" -m pip install --upgrade setuptools
-    "%PYTHON%/python.exe" setup.py bdist_wheel
+    "%PYTHON%/python.exe" -m pip wheel . --no-build-isolation --verbose
 
 before_test:
 - ps: |
diff --git a/pyproject.toml b/pyproject.toml
index ef8a4804..7522b5ef 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,2 +1,8 @@
 [build-system]
-requires = ["setuptools", "wheel", "scikit-build", "cmake"]
\ No newline at end of file
+requires = [
+  "setuptools", "wheel", "scikit-build", "cmake", "pip",
+  "numpy==1.11.3; python_version=='3.5'",
+  "numpy==1.13.3; python_version=='3.6'",
+  "numpy==1.14.5; python_version=='3.7'",
+  "numpy==1.17.3; python_version>='3.8'"
+]
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 4bde2f7f..fe8cbd47 100644
--- a/setup.py
+++ b/setup.py
@@ -15,13 +15,13 @@ def main():
 
     # These are needed for source fetching
     cmake_source_dir = "opencv"
-    minimum_supported_numpy = "1.11.1"
+    minimum_supported_numpy = "1.13.1"
     build_contrib = get_build_env_var_by_name("contrib")
     # headless flag to skip GUI deps if needed
     build_headless = get_build_env_var_by_name("headless")
 
     if sys.version_info[:2] >= (3, 6):
-        minimum_supported_numpy = "1.11.3"
+        minimum_supported_numpy = "1.13.3"
     if sys.version_info[:2] >= (3, 7):
         minimum_supported_numpy = "1.14.5"
     if sys.version_info[:2] >= (3, 8):
@@ -176,7 +176,6 @@ def main():
         packages=packages,
         package_data=package_data,
         maintainer="Olli-Pekka Heinisuo",
-        include_package_data=True,
         ext_modules=EmptyListWithLength(),
         install_requires=numpy_version,
         classifiers=[
diff --git a/travis_config.sh b/travis_config.sh
index fbf565b5..480a547b 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -14,7 +14,7 @@ function bdist_wheel_cmd {
     # copied from multibuild's common_utils.sh
     # add osx deployment target so it doesnt default to 10.6
     local abs_wheelhouse=$1
-    python setup.py bdist_wheel $BDIST_PARAMS
+    pip wheel . --no-build-isolation --verbose $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }

From eb679346a89f54bd9d669a00ffb1304dd3ad1ca4 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 13 Jul 2020 23:20:30 +0300
Subject: [PATCH 343/566] fix typo

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index fe8cbd47..e9b8b93a 100644
--- a/setup.py
+++ b/setup.py
@@ -366,7 +366,7 @@ def get_opencv_version(contrib, headless):
     if not os.path.exists(version_file):
       old_args = sys.argv.copy()
       sys.argv = ['', str(contrib), str(headless)]
-      runpy.run_path("find_version.py ", run_name="__main__")
+      runpy.run_path("find_version.py", run_name="__main__")
       sys.argv = old_args
 
     with open(version_file) as fp:

From 9c911168a0cde6b1bb5e8eec2ca5fcf88cb2c841 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 13 Jul 2020 23:21:50 +0300
Subject: [PATCH 344/566] add stage

---
 .travis.yml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index 2f5a9874..d3cbd821 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -60,6 +60,7 @@ jobs:
 
     # source distributions
     - os: linux
+      stage: s1
       env:
         - SDIST=1
         - ENABLE_CONTRIB=0
@@ -68,6 +69,7 @@ jobs:
       language: python
       dist: xenial
     - os: linux
+      stage: s1
       env:
         - SDIST=1
         - ENABLE_CONTRIB=0
@@ -76,6 +78,7 @@ jobs:
       language: python
       dist: xenial
     - os: linux
+      stage: s1
       env:
         - SDIST=1
         - ENABLE_CONTRIB=1
@@ -84,6 +87,7 @@ jobs:
       language: python
       dist: xenial
     - os: linux
+      stage: s1
       env:
         - SDIST=1
         - ENABLE_CONTRIB=1

From b404b877c91849570eb368ff26290980c611b863 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 13 Jul 2020 23:34:12 +0300
Subject: [PATCH 345/566] more fixes

---
 .travis.yml  | 72 ++++++++++++++++++++++++++--------------------------
 appveyor.yml |  2 +-
 2 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index d3cbd821..4af08b7d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -647,7 +647,7 @@ jobs:
 before_install: |
     set -e
 
-    if [ -n "$SDIST" ]; then
+    if [[ $SDIST == 1 ]]; then
         echo "sdist build"
     else
         # Check out and prepare the source
@@ -691,7 +691,7 @@ install: |
     # Build and package
     set -x
 
-    if [ -n "$SDIST" ]; then
+    if [[ $SDIST == 1 ]]; then
         python -m pip install --upgrade pip
         python -m pip install scikit-build
         python setup.py sdist
@@ -705,7 +705,7 @@ script: |
     # Install and run tests
     set -x
 
-    if [ -n "$SDIST" ]; then
+    if [[ $SDIST == 1 ]]; then
       echo "sdist"
     else
         install_run $PLAT && rc=$? || rc=$?
@@ -741,47 +741,47 @@ after_success: |
 
     if [ -n "$TRAVIS_TAG" ]; then
 
-        if [[ $ENABLE_CONTRIB == 0 ]]; then
-            if [[ $ENABLE_HEADLESS == 0 ]]; then
-              echo "This is default build. Deployment will be done to to PyPI entry opencv-python."
-            else
-              echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-python-headless."
-            fi
-        else
-            if [[ $ENABLE_HEADLESS == 0 ]]; then
-              echo "This is contrib build. Deployment will be done to to PyPI entry opencv-contrib-python."
-            else
-              echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-contrib-python-headless."
-            fi
-        fi
-
-        if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-          pip install --user twine
-          pip install --user --upgrade six
-
-          if [ -n "$SDIST" ]; then
-            twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
+      if [[ $ENABLE_CONTRIB == 0 ]]; then
+          if [[ $ENABLE_HEADLESS == 0 ]]; then
+            echo "This is default build. Deployment will be done to to PyPI entry opencv-python."
+          else
+            echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-python-headless."
+          fi
+      else
+          if [[ $ENABLE_HEADLESS == 0 ]]; then
+            echo "This is contrib build. Deployment will be done to to PyPI entry opencv-contrib-python."
           else
-            twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
+            echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-contrib-python-headless."
           fi
+      fi
+
+      if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
+        pip install --user twine
+        pip install --user --upgrade six
 
+        if [[ $SDIST == 1 ]]; then
+          twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
+        else
+          twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi
 
-        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
-          # macpython 3.5 doesn't support recent TLS protocols which causes twine
-          # upload to fail, so we use the system Python to run twine
-          /usr/bin/python -m ensurepip --user
-          /usr/bin/python -m pip install --user -U pip
-          /usr/bin/python -m pip install --user -U -I twine
+      fi
 
-          if [ -n "$SDIST" ]; then
-            /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
-          else
-            /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
-          fi
+      if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
+        # macpython 3.5 doesn't support recent TLS protocols which causes twine
+        # upload to fail, so we use the system Python to run twine
+        /usr/bin/python -m ensurepip --user
+        /usr/bin/python -m pip install --user -U pip
+        /usr/bin/python -m pip install --user -U -I twine
 
+        if [[ $SDIST == 1 ]]; then
+          /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
+        else
+          /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi
 
+      fi
+
     fi
 
     # Save to Azure storage always
@@ -794,7 +794,7 @@ after_success: |
 
     az storage container create -n ${TRAVIS_COMMIT} --public-access blob
 
-    if [ -n "$SDIST" ]; then
+    if [[ $SDIST == 1 ]]; then
       az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/dist --pattern *.gz
     else
       az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern *.whl
diff --git a/appveyor.yml b/appveyor.yml
index ada90638..511140c5 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -141,7 +141,7 @@ build_script:
 - cmd: |
     "%PYTHON%/python.exe" -m pip install --upgrade pip
     "%PYTHON%/python.exe" -m pip install --upgrade setuptools
-    "%PYTHON%/python.exe" -m pip wheel . --no-build-isolation --verbose
+    "%PYTHON%/python.exe" -m pip wheel . --verbose
 
 before_test:
 - ps: |

From 6a9d2f1c64937c4883cfa077a82e2f2fa8e9efbe Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 13 Jul 2020 23:39:30 +0300
Subject: [PATCH 346/566] Visual Studio 14, travis fixes

---
 .travis.yml | 106 ++++++++++++++++++++++++++--------------------------
 setup.py    |   2 +-
 2 files changed, 54 insertions(+), 54 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 4af08b7d..0b49e310 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -648,41 +648,41 @@ before_install: |
     set -e
 
     if [[ $SDIST == 1 ]]; then
-        echo "sdist build"
+      echo "sdist build"
     else
-        # Check out and prepare the source
-        # Multibuild doesn't have releases, so --depth would break eventually (see
-        # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
-        git submodule update --init multibuild
-
-        source multibuild/common_utils.sh
-
-        # https://github.com/matthew-brett/multibuild/issues/116
-        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
-
-        source multibuild/travis_steps.sh
-        # This sets -x
-
-        source travis_multibuild_customize.sh
-        echo $ENABLE_CONTRIB > contrib.enabled
-        echo $ENABLE_HEADLESS > headless.enabled
-
-        if [ -n "$IS_OSX" ]; then
-            echo "homebrew"
-            TAPS="$(brew --repository)/Library/Taps"
-            if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
-                rm -rf "$TAPS/caskroom/homebrew-cask"
-            fi
-            find "$TAPS" -type d -name .git -exec \
-                    bash -xec '
-                        cd $(dirname '\''{}'\'') || echo "status: $?"
-                        git clean -fxd || echo "status: $?"
-                        sleep 1 || echo "status: $?"
-                        git status || echo "status: $?"' \; || echo "status: $?"
-            brew_cache_cleanup
+      # Check out and prepare the source
+      # Multibuild doesn't have releases, so --depth would break eventually (see
+      # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+      git submodule update --init multibuild
+
+      source multibuild/common_utils.sh
+
+      # https://github.com/matthew-brett/multibuild/issues/116
+      if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+
+      source multibuild/travis_steps.sh
+      # This sets -x
+
+      source travis_multibuild_customize.sh
+      echo $ENABLE_CONTRIB > contrib.enabled
+      echo $ENABLE_HEADLESS > headless.enabled
+
+      if [ -n "$IS_OSX" ]; then
+        echo "homebrew"
+        TAPS="$(brew --repository)/Library/Taps"
+        if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
+            rm -rf "$TAPS/caskroom/homebrew-cask"
         fi
-        echo "end"
-        # Not interested in travis internal scripts' output
+        find "$TAPS" -type d -name .git -exec \
+                bash -xec '
+                    cd $(dirname '\''{}'\'') || echo "status: $?"
+                    git clean -fxd || echo "status: $?"
+                    sleep 1 || echo "status: $?"
+                    git status || echo "status: $?"' \; || echo "status: $?"
+        brew_cache_cleanup
+      fi
+      echo "end"
+      # Not interested in travis internal scripts' output
     fi
 
     set +x
@@ -692,11 +692,11 @@ install: |
     set -x
 
     if [[ $SDIST == 1 ]]; then
-        python -m pip install --upgrade pip
-        python -m pip install scikit-build
-        python setup.py sdist
+      python -m pip install --upgrade pip
+      python -m pip install scikit-build
+      python setup.py sdist
     else
-        build_wheel $REPO_DIR $PLAT
+      build_wheel $REPO_DIR $PLAT
     fi
 
     set +x
@@ -708,7 +708,7 @@ script: |
     if [[ $SDIST == 1 ]]; then
       echo "sdist"
     else
-        install_run $PLAT && rc=$? || rc=$?
+      install_run $PLAT && rc=$? || rc=$?
     fi
 
     set +x
@@ -724,12 +724,12 @@ before_cache: |
     set -e; set -x
     if [ -n "$IS_OSX" ]; then
 
-        # When Taps is cached, this dir causes "Error: file exists" on `brew update`
-        if [ -e "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask" ]; then
-            rm -rf "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask"
-        fi
+      # When Taps is cached, this dir causes "Error: file exists" on `brew update`
+      if [ -e "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask" ]; then
+        rm -rf "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask"
+      fi
 
-        brew_cache_cleanup
+      brew_cache_cleanup
 
     fi
     set +x; set +e
@@ -742,17 +742,17 @@ after_success: |
     if [ -n "$TRAVIS_TAG" ]; then
 
       if [[ $ENABLE_CONTRIB == 0 ]]; then
-          if [[ $ENABLE_HEADLESS == 0 ]]; then
-            echo "This is default build. Deployment will be done to to PyPI entry opencv-python."
-          else
-            echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-python-headless."
-          fi
+        if [[ $ENABLE_HEADLESS == 0 ]]; then
+          echo "This is default build. Deployment will be done to to PyPI entry opencv-python."
+        else
+          echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-python-headless."
+        fi
       else
-          if [[ $ENABLE_HEADLESS == 0 ]]; then
-            echo "This is contrib build. Deployment will be done to to PyPI entry opencv-contrib-python."
-          else
-            echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-contrib-python-headless."
-          fi
+        if [[ $ENABLE_HEADLESS == 0 ]]; then
+          echo "This is contrib build. Deployment will be done to to PyPI entry opencv-contrib-python."
+        else
+          echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-contrib-python-headless."
+        fi
       fi
 
       if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
diff --git a/setup.py b/setup.py
index e9b8b93a..acd585f6 100644
--- a/setup.py
+++ b/setup.py
@@ -98,7 +98,7 @@ def main():
 
     cmake_args = (
         (
-            ["-G", "Visual Studio 15" + (" Win64" if x64 else "")]
+            ["-G", "Visual Studio 14" + (" Win64" if x64 else "")]
             if os.name == "nt"
             else ["-G", "Unix Makefiles"]  # don't make CMake try (and fail) Ninja first
         )

From 09f01ddbda6c6ffc121fb21dc86a4f0748d31f74 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 13 Jul 2020 23:46:20 +0300
Subject: [PATCH 347/566] clean up travis

---
 .travis.yml | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 0b49e310..120ed69b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -647,9 +647,7 @@ jobs:
 before_install: |
     set -e
 
-    if [[ $SDIST == 1 ]]; then
-      echo "sdist build"
-    else
+    if [[ $SDIST == 0 ]]; then
       # Check out and prepare the source
       # Multibuild doesn't have releases, so --depth would break eventually (see
       # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
@@ -703,16 +701,13 @@ install: |
 
 script: |
     # Install and run tests
-    set -x
 
-    if [[ $SDIST == 1 ]]; then
-      echo "sdist"
-    else
+    if [[ $SDIST == 0 ]]; then
+      set -x
       install_run $PLAT && rc=$? || rc=$?
+      set +x
     fi
 
-    set +x
-
     # otherwise, Travis logic terminates prematurely
     # https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
     trap ERR

From 9fe282b6c5accf635366e9a18e4ac2d1d99a8d92 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 13 Jul 2020 23:52:00 +0300
Subject: [PATCH 348/566] trying to fix travis...

---
 .travis.yml | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 120ed69b..c2462d8f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -701,17 +701,15 @@ install: |
 
 script: |
     # Install and run tests
-
     if [[ $SDIST == 0 ]]; then
       set -x
       install_run $PLAT && rc=$? || rc=$?
       set +x
     fi
 
-    # otherwise, Travis logic terminates prematurely
-    # https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
+    #otherwise, Travis logic terminates prematurely
+    #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
     trap ERR
-
     test "$rc" -eq 0
 
 before_cache: |

From 51dcf9c06bda466df6d284e2ab95f0e8fd061347 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 13 Jul 2020 23:58:02 +0300
Subject: [PATCH 349/566] need to source multibuild to get past tests

---
 .travis.yml | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index c2462d8f..f80a8de7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -647,21 +647,22 @@ jobs:
 before_install: |
     set -e
 
-    if [[ $SDIST == 0 ]]; then
-      # Check out and prepare the source
-      # Multibuild doesn't have releases, so --depth would break eventually (see
-      # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
-      git submodule update --init multibuild
+    # Check out and prepare the source
+    # Multibuild doesn't have releases, so --depth would break eventually (see
+    # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+    git submodule update --init multibuild
+
+    source multibuild/common_utils.sh
 
-      source multibuild/common_utils.sh
+    # https://github.com/matthew-brett/multibuild/issues/116
+    if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
 
-      # https://github.com/matthew-brett/multibuild/issues/116
-      if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+    source multibuild/travis_steps.sh
+    # This sets -x
+    source travis_multibuild_customize.sh
 
-      source multibuild/travis_steps.sh
-      # This sets -x
+    if [[ $SDIST == 0 ]]; then
 
-      source travis_multibuild_customize.sh
       echo $ENABLE_CONTRIB > contrib.enabled
       echo $ENABLE_HEADLESS > headless.enabled
 

From 615cca37946456c4a4b348c2131af8929672fa0d Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 14 Jul 2020 00:10:37 +0300
Subject: [PATCH 350/566] save wheels to dist

---
 .travis.yml      | 32 +++++++++++++++++---------------
 appveyor.yml     |  2 +-
 travis_config.sh |  2 +-
 3 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index f80a8de7..ba7c691d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -647,22 +647,21 @@ jobs:
 before_install: |
     set -e
 
-    # Check out and prepare the source
-    # Multibuild doesn't have releases, so --depth would break eventually (see
-    # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
-    git submodule update --init multibuild
-
-    source multibuild/common_utils.sh
+    if [[ $SDIST == 0 ]]; then
+      # Check out and prepare the source
+      # Multibuild doesn't have releases, so --depth would break eventually (see
+      # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+      git submodule update --init multibuild
 
-    # https://github.com/matthew-brett/multibuild/issues/116
-    if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+      source multibuild/common_utils.sh
 
-    source multibuild/travis_steps.sh
-    # This sets -x
-    source travis_multibuild_customize.sh
+      # https://github.com/matthew-brett/multibuild/issues/116
+      if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
 
-    if [[ $SDIST == 0 ]]; then
+      source multibuild/travis_steps.sh
+      # This sets -x
 
+      source travis_multibuild_customize.sh
       echo $ENABLE_CONTRIB > contrib.enabled
       echo $ENABLE_HEADLESS > headless.enabled
 
@@ -702,12 +701,15 @@ install: |
 
 script: |
     # Install and run tests
-    if [[ $SDIST == 0 ]]; then
-      set -x
+    set -x
+    if [[ $SDIST == 1 ]]; then
+      echo "skipping tests because of sdist"
+    else
       install_run $PLAT && rc=$? || rc=$?
-      set +x
     fi
 
+    set +x
+
     #otherwise, Travis logic terminates prematurely
     #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
     trap ERR
diff --git a/appveyor.yml b/appveyor.yml
index 511140c5..4dd3421d 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -141,7 +141,7 @@ build_script:
 - cmd: |
     "%PYTHON%/python.exe" -m pip install --upgrade pip
     "%PYTHON%/python.exe" -m pip install --upgrade setuptools
-    "%PYTHON%/python.exe" -m pip wheel . --verbose
+    "%PYTHON%/python.exe" -m pip wheel . --verbose --wheel-dir=dist
 
 before_test:
 - ps: |
diff --git a/travis_config.sh b/travis_config.sh
index 480a547b..a30a42db 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -14,7 +14,7 @@ function bdist_wheel_cmd {
     # copied from multibuild's common_utils.sh
     # add osx deployment target so it doesnt default to 10.6
     local abs_wheelhouse=$1
-    pip wheel . --no-build-isolation --verbose $BDIST_PARAMS
+    pip wheel . --no-build-isolation --verbose --wheel-dir=dist $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }

From 106a9d81afc0636638f29b366ed32a6569b00db8 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 14 Jul 2020 00:14:50 +0300
Subject: [PATCH 351/566] try to skip the script step

---
 .travis.yml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index ba7c691d..37e1b0fd 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -61,6 +61,7 @@ jobs:
     # source distributions
     - os: linux
       stage: s1
+      script: skip
       env:
         - SDIST=1
         - ENABLE_CONTRIB=0
@@ -70,6 +71,7 @@ jobs:
       dist: xenial
     - os: linux
       stage: s1
+      script: skip
       env:
         - SDIST=1
         - ENABLE_CONTRIB=0
@@ -79,6 +81,7 @@ jobs:
       dist: xenial
     - os: linux
       stage: s1
+      script: skip
       env:
         - SDIST=1
         - ENABLE_CONTRIB=1
@@ -88,6 +91,7 @@ jobs:
       dist: xenial
     - os: linux
       stage: s1
+      script: skip
       env:
         - SDIST=1
         - ENABLE_CONTRIB=1

From fead8dfd58d842cd40e6b394f1e7e3810cfe1e0c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 14 Jul 2020 00:59:58 +0300
Subject: [PATCH 352/566] try absolute path

---
 appveyor.yml     | 2 +-
 travis_config.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index 4dd3421d..0a6e47f0 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -141,7 +141,7 @@ build_script:
 - cmd: |
     "%PYTHON%/python.exe" -m pip install --upgrade pip
     "%PYTHON%/python.exe" -m pip install --upgrade setuptools
-    "%PYTHON%/python.exe" -m pip wheel . --verbose --wheel-dir=dist
+    "%PYTHON%/python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
 
 before_test:
 - ps: |
diff --git a/travis_config.sh b/travis_config.sh
index a30a42db..9a079e8c 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -14,7 +14,7 @@ function bdist_wheel_cmd {
     # copied from multibuild's common_utils.sh
     # add osx deployment target so it doesnt default to 10.6
     local abs_wheelhouse=$1
-    pip wheel . --no-build-isolation --verbose --wheel-dir=dist $BDIST_PARAMS
+    pip wheel . --wheel-dir="$PWD/dist" --verbose $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }

From 43adb25e89e407bb51a6dd05e43f8021c7163c33 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 14 Jul 2020 15:22:12 +0300
Subject: [PATCH 353/566] fix regression

---
 setup.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index acd585f6..640bf3ea 100644
--- a/setup.py
+++ b/setup.py
@@ -154,10 +154,10 @@ def main():
         cmake_args.append("-DWITH_LAPACK=ON")
         cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 
-    if sys.platform.startswith("linux") and not x64:
+    if sys.platform.startswith("linux") and not x64 and "bdist_wheel" in sys.argv:
         subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
 
-    if sys.platform == "darwin":
+    if sys.platform == "darwin" and "bdist_wheel" in sys.argv:
         subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
     # works via side effect

From 9e21313bd8990e918e0b58654672f342a391eb35 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 14 Jul 2020 15:25:01 +0300
Subject: [PATCH 354/566] ignore warning

---
 appveyor.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/appveyor.yml b/appveyor.yml
index 0a6e47f0..46ea0087 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -148,7 +148,7 @@ before_test:
 
     cd ${Env:APPVEYOR_BUILD_FOLDER}\tests
     $env:PYTHONWARNINGS = "ignore:::pip._internal.cli.base_command"
-    &"${Env:PYTHON}/python.exe" -m pip install --user (ls "../dist/opencv_*.whl")
+    &"${Env:PYTHON}/python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
     if ($LastExitCode -ne 0) {throw $LastExitCode}
 
 test_script:

From 243e27398e9e09620c6e77bddbc84f462a05470b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 14 Jul 2020 22:08:26 +0300
Subject: [PATCH 355/566] upload only opencv wheels

---
 .travis.yml  | 2 +-
 appveyor.yml | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 37e1b0fd..aa3093fc 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -797,7 +797,7 @@ after_success: |
     if [[ $SDIST == 1 ]]; then
       az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/dist --pattern *.gz
     else
-      az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern *.whl
+      az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern opencv*.whl
     fi
 
     set +x
diff --git a/appveyor.yml b/appveyor.yml
index 46ea0087..03980bbf 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -158,7 +158,7 @@ test_script:
     "%PYTHON%/python.exe" -m unittest test
 
 artifacts:
-- path: dist\*.whl
+- path: dist\opencv*.whl
   name: wheels
 
 deploy_script:

From 705d1f0602fa147ca7945150238717af71c231c2 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jul 2020 15:18:05 +0300
Subject: [PATCH 356/566] use python instead of ruby

---
 .travis.yml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index aa3093fc..e6880e71 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,6 +20,8 @@ cache:
     # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
     - $HOME/.ccache
 
+language: python
+
 # Add more cache stages (s2 etc) and corresponding OSX jobs like s1
 # if brew builds start to take longer than one Travis time limit
 stages:
@@ -30,7 +32,7 @@ jobs:
   fast_finish: true
   # Travis exclude is buggy, this seems to be the only way to disable default build
   exclude:
-    - language: ruby
+    - language: python
   include:
     - os: osx
       env:

From 9a33dcf847cc9bc0a08ce73a66fc6e89f1f6645a Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jul 2020 16:16:56 +0300
Subject: [PATCH 357/566] test

---
 .travis.yml      | 4 +---
 travis_config.sh | 3 ++-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index e6880e71..aa3093fc 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,8 +20,6 @@ cache:
     # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
     - $HOME/.ccache
 
-language: python
-
 # Add more cache stages (s2 etc) and corresponding OSX jobs like s1
 # if brew builds start to take longer than one Travis time limit
 stages:
@@ -32,7 +30,7 @@ jobs:
   fast_finish: true
   # Travis exclude is buggy, this seems to be the only way to disable default build
   exclude:
-    - language: python
+    - language: ruby
   include:
     - os: osx
       env:
diff --git a/travis_config.sh b/travis_config.sh
index 9a079e8c..d606c838 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -14,7 +14,7 @@ function bdist_wheel_cmd {
     # copied from multibuild's common_utils.sh
     # add osx deployment target so it doesnt default to 10.6
     local abs_wheelhouse=$1
-    pip wheel . --wheel-dir="$PWD/dist" --verbose $BDIST_PARAMS
+    pip wheel --wheel-dir="$PWD/dist" . --verbose $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }
@@ -110,6 +110,7 @@ function pre_build {
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew unlink python@2
+        brew update
         brew install ffmpeg_opencv
     fi
 

From 43a2cb8623e31f038e50bc65f48392041c6c171c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jul 2020 16:59:48 +0300
Subject: [PATCH 358/566] verbose

---
 travis_config.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index d606c838..2f97fe9d 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -110,8 +110,7 @@ function pre_build {
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew unlink python@2
-        brew update
-        brew install ffmpeg_opencv
+        brew install ffmpeg_opencv --vd
     fi
 
     if [ -n "$CACHE_STAGE" ]; then

From 3f8604adbf329027b7dbe00eb0c672fe51cb3102 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jul 2020 18:16:30 +0300
Subject: [PATCH 359/566] try to vendor ruby

---
 appveyor.yml     |  2 +-
 setup.py         | 93 ++++++++++++++++++++++++++++++------------------
 travis_config.sh |  6 ++--
 3 files changed, 63 insertions(+), 38 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index 03980bbf..3a4fcb75 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -141,7 +141,7 @@ build_script:
 - cmd: |
     "%PYTHON%/python.exe" -m pip install --upgrade pip
     "%PYTHON%/python.exe" -m pip install --upgrade setuptools
-    "%PYTHON%/python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
+    set "CI_BUILD=True" && "%PYTHON%/python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
 
 before_test:
 - ps: |
diff --git a/setup.py b/setup.py
index 640bf3ea..6d9be880 100644
--- a/setup.py
+++ b/setup.py
@@ -13,11 +13,11 @@
 def main():
     os.chdir(os.path.dirname(os.path.abspath(__file__)))
 
-    # These are needed for source fetching
+    CI_BUILD = os.environ.get("CI_BUILD", "False")
+    is_CI_build = True if CI_BUILD == "True" else False
     cmake_source_dir = "opencv"
     minimum_supported_numpy = "1.13.1"
     build_contrib = get_build_env_var_by_name("contrib")
-    # headless flag to skip GUI deps if needed
     build_headless = get_build_env_var_by_name("headless")
 
     if sys.version_info[:2] >= (3, 6):
@@ -30,11 +30,16 @@ def main():
     numpy_version = "numpy>=%s" % minimum_supported_numpy
 
     python_version = cmaker.CMaker.get_python_version()
-    python_lib_path = cmaker.CMaker.get_python_library(python_version).replace('\\', '/')
-    python_include_dir = cmaker.CMaker.get_python_include_dir(python_version).replace('\\', '/')
+    python_lib_path = cmaker.CMaker.get_python_library(python_version).replace(
+        "\\", "/"
+    )
+    python_include_dir = cmaker.CMaker.get_python_include_dir(python_version).replace(
+        "\\", "/"
+    )
 
     if os.path.exists(".git"):
         import pip._internal.vcs.git as git
+
         g = git.Git()  # NOTE: pip API's are internal, this has to be refactored
 
         g.run_command(["submodule", "sync"])
@@ -47,7 +52,9 @@ def main():
                 ["submodule", "update", "--init", "--recursive", "opencv_contrib"]
             )
 
-    package_version, build_contrib, build_headless = get_opencv_version(build_contrib, build_headless)
+    package_version, build_contrib, build_headless = get_opencv_version(
+        build_contrib, build_headless
+    )
 
     # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
     x64 = sys.maxsize > 2 ** 32
@@ -86,7 +93,10 @@ def main():
         # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
         # Naming conventions vary so widely between versions and OSes
         # had to give up on checking them.
-        ["python/cv2[^/]*%(ext)s" % {"ext": re.escape(sysconfig.get_config_var("EXT_SUFFIX"))}],
+        [
+            "python/cv2[^/]*%(ext)s"
+            % {"ext": re.escape(sysconfig.get_config_var("EXT_SUFFIX"))}
+        ],
         "cv2.data": [  # OPENCV_OTHER_INSTALL_PATH
             ("etc" if os.name == "nt" else "share/opencv4") + r"/haarcascades/.*\.xml"
         ],
@@ -96,12 +106,14 @@ def main():
     # Raw paths relative to sourcetree root.
     files_outside_package_dir = {"cv2": ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"]}
 
+    ci_cmake_generator = (
+        ["-G", "Visual Studio 14" + (" Win64" if x64 else "")]
+        if os.name == "nt"
+        else ["-G", "Unix Makefiles"]
+    )
+
     cmake_args = (
-        (
-            ["-G", "Visual Studio 14" + (" Win64" if x64 else "")]
-            if os.name == "nt"
-            else ["-G", "Unix Makefiles"]  # don't make CMake try (and fail) Ninja first
-        )
+        (ci_cmake_generator if is_CI_build else [])
         + [
             # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
             "-DPYTHON3_EXECUTABLE=%s" % sys.executable,
@@ -131,33 +143,40 @@ def main():
         )
     )
 
-    # OS-specific components
-    if sys.platform.startswith('linux') and not build_headless:
-        cmake_args.append("-DWITH_QT=4")
-
-    if sys.platform == 'darwin' and not build_headless:
-        cmake_args.append("-DWITH_QT=5")
-        rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
-            (r"lib/qt/plugins/platforms/libqcocoa\.dylib")
-        ]
-
     if build_headless:
         # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
         cmake_args.append("-DWITH_WIN32UI=OFF")
         cmake_args.append("-DWITH_QT=OFF")
-        cmake_args.append(
-            "-DWITH_MSMF=OFF"
-        )  # see: https://github.com/skvark/opencv-python/issues/263
+        cmake_args.append("-DWITH_GTK=OFF")
+        if is_CI_build:
+            cmake_args.append(
+                "-DWITH_MSMF=OFF"
+            )  # see: https://github.com/skvark/opencv-python/issues/263
+
+    # OS-specific components during CI builds
+    if is_CI_build:
+        if sys.platform.startswith("linux") and not build_headless:
+            cmake_args.append("-DWITH_QT=4")
 
-    if sys.platform.startswith("linux"):
-        cmake_args.append("-DWITH_V4L=ON")
-        cmake_args.append("-DWITH_LAPACK=ON")
-        cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
+        if sys.platform == "darwin" and not build_headless:
+            cmake_args.append("-DWITH_QT=5")
+
+        if sys.platform.startswith("linux"):
+            cmake_args.append("-DWITH_V4L=ON")
+            cmake_args.append("-DWITH_LAPACK=ON")
+            cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 
     if sys.platform.startswith("linux") and not x64 and "bdist_wheel" in sys.argv:
         subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
 
-    if sys.platform == "darwin" and "bdist_wheel" in sys.argv:
+    if (
+        sys.platform == "darwin"
+        and "bdist_wheel" in sys.argv
+        and ("WITH_QT=5" in sys.argv or "WITH_QT=5" in cmake_args)
+    ):
+        rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
+            (r"lib/qt/plugins/platforms/libqcocoa\.dylib")
+        ]
         subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
     # works via side effect
@@ -357,22 +376,25 @@ def _classify_installed_files_override(
             cmake_install_dir=cmake_install_reldir,
         )
 
+
 def get_opencv_version(contrib, headless):
     # cv2/version.py should be generated by running find_version.py
     version = {}
     here = os.path.abspath(os.path.dirname(__file__))
     version_file = os.path.join(here, "cv2", "version.py")
 
-    if not os.path.exists(version_file):
-      old_args = sys.argv.copy()
-      sys.argv = ['', str(contrib), str(headless)]
-      runpy.run_path("find_version.py", run_name="__main__")
-      sys.argv = old_args
+    # generate a fresh version.py always when Git repository exists
+    if os.path.exists(".git"):
+        old_args = sys.argv.copy()
+        sys.argv = ["", str(contrib), str(headless)]
+        runpy.run_path("find_version.py", run_name="__main__")
+        sys.argv = old_args
 
     with open(version_file) as fp:
         exec(fp.read(), version)
 
-    return version['opencv_version'], version['contrib'], version['headless']
+    return version["opencv_version"], version["contrib"], version["headless"]
+
 
 def get_build_env_var_by_name(flag_name):
     flag_set = False
@@ -390,6 +412,7 @@ def get_build_env_var_by_name(flag_name):
 
     return flag_set
 
+
 # This creates a list which is empty but returns a length of 1.
 # Should make the wheel a binary distribution and platlib compliant.
 class EmptyListWithLength(list):
diff --git a/travis_config.sh b/travis_config.sh
index 2f97fe9d..b371b355 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -14,7 +14,7 @@ function bdist_wheel_cmd {
     # copied from multibuild's common_utils.sh
     # add osx deployment target so it doesnt default to 10.6
     local abs_wheelhouse=$1
-    pip wheel --wheel-dir="$PWD/dist" . --verbose $BDIST_PARAMS
+    CI_BUILD=1 pip wheel --wheel-dir="$PWD/dist" . --verbose $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }
@@ -89,9 +89,11 @@ function pre_build {
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
 
+    export HOMEBREW_FORCE_VENDOR_RUBY=1
+    brew update
+
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then
-        brew update
         generate_ffmpeg_formula
         brew_add_local_bottles
     fi

From 8bbf351be3cd5f5edba09d1d7e06c1d1f654bbb3 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jul 2020 21:24:14 +0300
Subject: [PATCH 360/566] fix flags

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index b371b355..a37e8160 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -112,7 +112,7 @@ function pre_build {
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew unlink python@2
-        brew install ffmpeg_opencv --vd
+        brew install -vd ffmpeg_opencv
     fi
 
     if [ -n "$CACHE_STAGE" ]; then

From 8541d771737df245557753ce5198655fd18619c6 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jul 2020 22:04:01 +0300
Subject: [PATCH 361/566] add brew style

---
 travis_config.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/travis_config.sh b/travis_config.sh
index a37e8160..f72480eb 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -90,6 +90,7 @@ function pre_build {
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
 
     export HOMEBREW_FORCE_VENDOR_RUBY=1
+    brew style
     brew update
 
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally

From e1b13aae1656180b4092ee6eb080951a8ffd96f9 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jul 2020 22:25:53 +0300
Subject: [PATCH 362/566] try updating homebrew

---
 .travis.yml      | 3 ++-
 travis_config.sh | 5 +----
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index aa3093fc..b29da346 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -670,7 +670,8 @@ before_install: |
       echo $ENABLE_HEADLESS > headless.enabled
 
       if [ -n "$IS_OSX" ]; then
-        echo "homebrew"
+        export HOMEBREW_FORCE_VENDOR_RUBY=1
+        brew upgrade
         TAPS="$(brew --repository)/Library/Taps"
         if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
             rm -rf "$TAPS/caskroom/homebrew-cask"
diff --git a/travis_config.sh b/travis_config.sh
index f72480eb..c2d4c6fc 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -89,12 +89,9 @@ function pre_build {
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
 
-    export HOMEBREW_FORCE_VENDOR_RUBY=1
-    brew style
-    brew update
-
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then
+        brew update
         generate_ffmpeg_formula
         brew_add_local_bottles
     fi

From 34df00569a4c34f19e188bfd7dd4cb648902758a Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jul 2020 22:36:15 +0300
Subject: [PATCH 363/566] try brew doctor

---
 .travis.yml      | 2 --
 travis_config.sh | 1 +
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index b29da346..7d0509c1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -670,8 +670,6 @@ before_install: |
       echo $ENABLE_HEADLESS > headless.enabled
 
       if [ -n "$IS_OSX" ]; then
-        export HOMEBREW_FORCE_VENDOR_RUBY=1
-        brew upgrade
         TAPS="$(brew --repository)/Library/Taps"
         if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
             rm -rf "$TAPS/caskroom/homebrew-cask"
diff --git a/travis_config.sh b/travis_config.sh
index c2d4c6fc..bbf9816f 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -88,6 +88,7 @@ function pre_build {
     echo "Running for OSX"
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
+    brew doctor
 
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then

From bb9c8670600b006bbe22658945e491ed6f7a07e5 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jul 2020 22:48:39 +0300
Subject: [PATCH 364/566] add sbin to path

---
 .travis.yml      | 1 +
 travis_config.sh | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 7d0509c1..c15ea7fe 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -670,6 +670,7 @@ before_install: |
       echo $ENABLE_HEADLESS > headless.enabled
 
       if [ -n "$IS_OSX" ]; then
+        echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile
         TAPS="$(brew --repository)/Library/Taps"
         if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
             rm -rf "$TAPS/caskroom/homebrew-cask"
diff --git a/travis_config.sh b/travis_config.sh
index bbf9816f..c2d4c6fc 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -88,7 +88,6 @@ function pre_build {
     echo "Running for OSX"
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
-    brew doctor
 
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then

From 04254a626f684bf26b4eef2f637a66c70782b42c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jul 2020 22:50:19 +0300
Subject: [PATCH 365/566] do not use bash profile

---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index c15ea7fe..a95fea50 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -670,7 +670,7 @@ before_install: |
       echo $ENABLE_HEADLESS > headless.enabled
 
       if [ -n "$IS_OSX" ]; then
-        echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile
+        export PATH="/usr/local/sbin:$PATH"
         TAPS="$(brew --repository)/Library/Taps"
         if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
             rm -rf "$TAPS/caskroom/homebrew-cask"

From d434c0113e112f7cc0e1d1e4beb1637ffa29253f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 15 Jul 2020 23:48:44 +0300
Subject: [PATCH 366/566] set travis user manually

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index c2d4c6fc..9e114b46 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -88,7 +88,7 @@ function pre_build {
     echo "Running for OSX"
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
-
+    export USER=travis
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then
         brew update

From 85bb4a397249fef78b6043934f57bab9121ae424 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 17 Jul 2020 14:17:48 +0300
Subject: [PATCH 367/566] update README, minor fixes, update issue template

---
 .github/issue_template.md | 27 +++++++++++++++++
 README.md                 | 62 ++++++++++++++++++++++++---------------
 cv2/__init__.py           | 11 ++++++-
 find_version.py           |  4 ++-
 setup.py                  | 35 ++++++++++++----------
 5 files changed, 97 insertions(+), 42 deletions(-)

diff --git a/.github/issue_template.md b/.github/issue_template.md
index a9091557..79146689 100644
--- a/.github/issue_template.md
+++ b/.github/issue_template.md
@@ -13,3 +13,30 @@ Write here what went wrong.
 - architecture (e.g. x86)
 - opencv-python version
 
+##### Issue submission checklist
+
+ - [ ] This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
+   <!--
+
+   Use Q&A forums such as https://answers.opencv.org/questions/ and https://stackoverflow.com/ and other communities
+   to discuss problems. Tickets without real issue statements related to this build toolchain will be closed.
+
+   -->
+ - [ ] I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
+   <!--
+
+   If you have some OpenCV bug report which needs to fixed in the C++ code, 
+   please report issue to the OpenCV repository: 
+
+   https://github.com/opencv/opencv/issues
+
+   See also:
+
+   * OpenCV documentation: https://docs.opencv.org
+   * OpenCV FAQ page: https://github.com/opencv/opencv/wiki/FAQ
+   * OpenCV forum: https://answers.opencv.org
+   * Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
+
+   -->
+ - [ ] The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
+ - [ ] I'm using the latest version of ``opencv-python``
diff --git a/README.md b/README.md
index 6b6f10ba..cb79ea3e 100644
--- a/README.md
+++ b/README.md
@@ -73,11 +73,11 @@ A: It's easier for users to understand ``opencv-python`` than ``cv2`` and it mak
 ## Documentation for opencv-python
 
 [![AppVeyor CI test status (Windows)](https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows)](https://ci.appveyor.com/project/skvark/opencv-python)
-[![Travis CI test status (Linux and OS X)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label=Linux+macOS)](https://travis-ci.org/skvark/opencv-python)
+[![Travis CI test status (Linux and macOS)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label=Linux+macOS)](https://travis-ci.org/skvark/opencv-python)
 
 The aim of this repository is to provide means to package each new [OpenCV release](https://github.com/opencv/opencv/releases) for the most used Python versions and platforms.
 
-### Build process
+### 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):
@@ -91,43 +91,57 @@ The build process for a single entry in the build matrices is as follows (see fo
    -  Contrib modules are also included as a submodule
 
 2. Find OpenCV version from the sources
-3. Install Python dependencies
 
-   - ``setup.py`` installs the dependencies itself, so you need to run it in an environment
-     where you have the rights to install modules with Pip for the running Python
-
-4. Build OpenCV
+3. 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
+4. Rearrange OpenCV's build result, add our custom files and generate wheel
 
-6. Linux and macOS wheels are transformed with auditwheel and delocate, correspondingly
+5. 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)
+6. Install the generated wheel
+7. Test that Python can import the library and run some sanity checks
+8. Use twine to upload the generated wheel to PyPI (only in release builds)
 
-Steps 1--5 are handled by ``setup.py bdist_wheel``.
+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:
+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
-- ``CMAKE_ARGS``. Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build.
+- ``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 `setup.py` locally to create a custom wheel.
+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/skvark/opencv-python.git`
-2. Go to the root of the repository 
-3. Add custom Cmake flags if needed, for example: `export CMAKE_FLAGS="-DSOME_FLAG=ON -DSOME_OTHER_FLAG=OFF"`
-4. Run ``python setup.py bdist_wheel``
-     - Optionally use the `manylinux` images as a build hosts if maximum portability is needed (and run `auditwheel` for the wheel after build)
-5. You'll have the wheel file in the `dist` folder and you can do with that whatever you wish
+2. ``cd opencv-python``
+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)
+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`
+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``.
+     - Optional: on Linux use 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)
+6. 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 for example with: 
+
+``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 and enable them. 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
 
@@ -147,7 +161,7 @@ The packages include also other binaries. Full list of licenses can be found fro
 
 ### 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.
+``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
 
@@ -177,7 +191,7 @@ Python 3.x releases are provided for officially supported versions (not in EOL).
 
 Currently, builds for following Python versions are provided:
 
-- 3.5
+- 3.5 (EOL in 2020-09-13, builds for 3.5 will not be provided after this)
 - 3.6
 - 3.7
 - 3.8
diff --git a/cv2/__init__.py b/cv2/__init__.py
index ee8cd254..b901c204 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -9,7 +9,16 @@
 # this makes them available
 globals().update(importlib.import_module('cv2.cv2').__dict__)
 
-if sys.platform == 'darwin':
+is_ci_build = False
+
+try:
+    from .version import ci_build
+    is_ci_build = ci_build
+except:
+    pass
+
+# the Qt plugin is included currently only in the pre-built wheels
+if sys.platform == 'darwin' and is_ci_build:
     os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), 'qt', 'plugins'
     )
diff --git a/find_version.py b/find_version.py
index b7ad0613..5210c8b1 100644
--- a/find_version.py
+++ b/find_version.py
@@ -5,6 +5,7 @@
 if __name__ == "__main__":
   contrib = sys.argv[1]
   headless = sys.argv[2]
+  ci_build = sys.argv[2]
 
   opencv_version = ""
   # dig out the version from OpenCV sources
@@ -51,4 +52,5 @@
   with open('cv2/version.py', 'w') as f:
       f.write("opencv_version = \"{}\"\n".format(opencv_version))
       f.write("contrib = {}\n".format(contrib))
-      f.write("headless = {}".format(headless))
+      f.write("headless = {}\n".format(headless))
+      f.write("ci_build = {}".format(ci_build))
diff --git a/setup.py b/setup.py
index 6d9be880..4be1ebd8 100644
--- a/setup.py
+++ b/setup.py
@@ -52,8 +52,8 @@ def main():
                 ["submodule", "update", "--init", "--recursive", "opencv_contrib"]
             )
 
-    package_version, build_contrib, build_headless = get_opencv_version(
-        build_contrib, build_headless
+    package_version, build_contrib, build_headless = get_and_set_info(
+        build_contrib, build_headless, is_CI_build
     )
 
     # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
@@ -153,31 +153,33 @@ def main():
                 "-DWITH_MSMF=OFF"
             )  # see: https://github.com/skvark/opencv-python/issues/263
 
+    if sys.platform.startswith("linux") and not x64 and "bdist_wheel" in sys.argv:
+        subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
+
     # OS-specific components during CI builds
     if is_CI_build:
         if sys.platform.startswith("linux") and not build_headless:
             cmake_args.append("-DWITH_QT=4")
 
         if sys.platform == "darwin" and not build_headless:
-            cmake_args.append("-DWITH_QT=5")
+            if "bdist_wheel" in sys.argv:
+                cmake_args.append("-DWITH_QT=5")
+                rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
+                    (r"lib/qt/plugins/platforms/libqcocoa\.dylib")
+                ]
+                subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
         if sys.platform.startswith("linux"):
             cmake_args.append("-DWITH_V4L=ON")
             cmake_args.append("-DWITH_LAPACK=ON")
             cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
 
-    if sys.platform.startswith("linux") and not x64 and "bdist_wheel" in sys.argv:
-        subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
+    # https://github.com/scikit-build/scikit-build/issues/479
+    if "CMAKE_ARGS" in os.environ:
+        import shlex
 
-    if (
-        sys.platform == "darwin"
-        and "bdist_wheel" in sys.argv
-        and ("WITH_QT=5" in sys.argv or "WITH_QT=5" in cmake_args)
-    ):
-        rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
-            (r"lib/qt/plugins/platforms/libqcocoa\.dylib")
-        ]
-        subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
+        cmake_args.extend(shlex.split(os.environ["CMAKE_ARGS"]))
+        del shlex
 
     # works via side effect
     RearrangeCMakeOutput(
@@ -377,16 +379,17 @@ def _classify_installed_files_override(
         )
 
 
-def get_opencv_version(contrib, headless):
+def get_and_set_info(contrib, headless, ci_build):
     # cv2/version.py should be generated by running find_version.py
     version = {}
     here = os.path.abspath(os.path.dirname(__file__))
     version_file = os.path.join(here, "cv2", "version.py")
 
     # generate a fresh version.py always when Git repository exists
+    # (in sdists the version.py file already exists)
     if os.path.exists(".git"):
         old_args = sys.argv.copy()
-        sys.argv = ["", str(contrib), str(headless)]
+        sys.argv = ["", str(contrib), str(headless), str(ci_build)]
         runpy.run_path("find_version.py", run_name="__main__")
         sys.argv = old_args
 

From c2d177ea560e87dbf374bb2169580ec1bc0b41d1 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 17 Jul 2020 15:31:29 +0300
Subject: [PATCH 368/566] fix sdist upload

---
 .travis.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index a95fea50..26b345b4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -760,7 +760,7 @@ after_success: |
         pip install --user --upgrade six
 
         if [[ $SDIST == 1 ]]; then
-          twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
+          twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
         else
           twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi
@@ -775,7 +775,7 @@ after_success: |
         /usr/bin/python -m pip install --user -U -I twine
 
         if [[ $SDIST == 1 ]]; then
-          /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
+          /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
         else
           /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi

From bf4e05620cf70123b4108f2069899c3347126c13 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 17 Jul 2020 15:33:05 +0300
Subject: [PATCH 369/566] fix sdist upload

---
 .travis.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index a95fea50..26b345b4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -760,7 +760,7 @@ after_success: |
         pip install --user --upgrade six
 
         if [[ $SDIST == 1 ]]; then
-          twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
+          twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
         else
           twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi
@@ -775,7 +775,7 @@ after_success: |
         /usr/bin/python -m pip install --user -U -I twine
 
         if [[ $SDIST == 1 ]]; then
-          /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
+          /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
         else
           /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi

From a464c98493e15da7aa84ff21ef72e4450a522bee Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 17 Jul 2020 23:18:32 +0300
Subject: [PATCH 370/566] fix find_version bug and clean up README

---
 README.md       | 8 ++++----
 find_version.py | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index cb79ea3e..c13b1b48 100644
--- a/README.md
+++ b/README.md
@@ -134,12 +134,12 @@ If some dependency is not enabled in the pre-built wheels, you can also run the
 
 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 for example with: 
+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``
+- ``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 and enable them. Headless distributions have hard coded CMake flags which disable all possible GUI dependencies. 
+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. 
 
diff --git a/find_version.py b/find_version.py
index 5210c8b1..76d9f86d 100644
--- a/find_version.py
+++ b/find_version.py
@@ -5,7 +5,7 @@
 if __name__ == "__main__":
   contrib = sys.argv[1]
   headless = sys.argv[2]
-  ci_build = sys.argv[2]
+  ci_build = sys.argv[3]
 
   opencv_version = ""
   # dig out the version from OpenCV sources

From f411d56c174c441164bacd2f47d814495929acbb Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 17 Jul 2020 23:18:32 +0300
Subject: [PATCH 371/566] fix find_version bug and clean up README

---
 README.md       | 8 ++++----
 find_version.py | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index cb79ea3e..c13b1b48 100644
--- a/README.md
+++ b/README.md
@@ -134,12 +134,12 @@ If some dependency is not enabled in the pre-built wheels, you can also run the
 
 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 for example with: 
+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``
+- ``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 and enable them. Headless distributions have hard coded CMake flags which disable all possible GUI dependencies. 
+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. 
 
diff --git a/find_version.py b/find_version.py
index 5210c8b1..76d9f86d 100644
--- a/find_version.py
+++ b/find_version.py
@@ -5,7 +5,7 @@
 if __name__ == "__main__":
   contrib = sys.argv[1]
   headless = sys.argv[2]
-  ci_build = sys.argv[2]
+  ci_build = sys.argv[3]
 
   opencv_version = ""
   # dig out the version from OpenCV sources

From 40042cd102c6874ffa0953c00a2d4419dd325d22 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 20 Jul 2020 15:39:53 +0300
Subject: [PATCH 372/566] update multibuild

---
 multibuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multibuild b/multibuild
index da36cd54..c2890dc8 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit da36cd5408e03cad504217de4a21bb8f19f2fb2f
+Subproject commit c2890dc8dc93f99b0eadd76f87aa181f6aea42da

From 0727f01375693a17b3c9c0f40d9a5fa22efbc79e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 20 Jul 2020 21:20:43 +0300
Subject: [PATCH 373/566] fix the CI build flag

---
 appveyor.yml | 2 +-
 setup.py     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index 3a4fcb75..8b058c68 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -141,7 +141,7 @@ build_script:
 - cmd: |
     "%PYTHON%/python.exe" -m pip install --upgrade pip
     "%PYTHON%/python.exe" -m pip install --upgrade setuptools
-    set "CI_BUILD=True" && "%PYTHON%/python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
+    set "CI_BUILD=1" && "%PYTHON%/python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
 
 before_test:
 - ps: |
diff --git a/setup.py b/setup.py
index 4be1ebd8..64162d68 100644
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@ def main():
     os.chdir(os.path.dirname(os.path.abspath(__file__)))
 
     CI_BUILD = os.environ.get("CI_BUILD", "False")
-    is_CI_build = True if CI_BUILD == "True" else False
+    is_CI_build = True if CI_BUILD == "1" else False
     cmake_source_dir = "opencv"
     minimum_supported_numpy = "1.13.1"
     build_contrib = get_build_env_var_by_name("contrib")

From 914404d62efacd8f3f84444c063555339ee7ef4d Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 21 Jul 2020 18:47:46 +0300
Subject: [PATCH 374/566] fix typo

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index c13b1b48..ddb0104c 100644
--- a/README.md
+++ b/README.md
@@ -123,7 +123,7 @@ If some dependency is not enabled in the pre-built wheels, you can also run the
 
 1. Clone this repository: `git clone --recursive https://github.com/skvark/opencv-python.git`
 2. ``cd opencv-python``
-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)
+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 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`
 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``.
      - Optional: on Linux use the `manylinux` images as a build hosts if maximum portability is needed and run `auditwheel` for the wheel after build

From 61a4bf292aa10d947d417a2878bc33a79b952e3e Mon Sep 17 00:00:00 2001
From: Ted Strzalkowski <tstrzalkowski@linkedin.com>
Date: Sun, 2 Aug 2020 11:22:06 -0700
Subject: [PATCH 375/566] Disable Java wrapper build by default.

- Java wrapper build isn't necessary for all Python builds.
- Java wrapper build can now be enabled with ``ENABLE_JAVA`` environment
  variable.
---
 README.md | 1 +
 setup.py  | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/README.md b/README.md
index ddb0104c..13462507 100644
--- a/README.md
+++ b/README.md
@@ -113,6 +113,7 @@ The build can be customized with environment variables. In addition to any varia
 
 - ``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.
diff --git a/setup.py b/setup.py
index 64162d68..323efaab 100644
--- a/setup.py
+++ b/setup.py
@@ -19,6 +19,7 @@ def main():
     minimum_supported_numpy = "1.13.1"
     build_contrib = get_build_env_var_by_name("contrib")
     build_headless = get_build_env_var_by_name("headless")
+    build_java = 'ON' if get_build_env_var_by_name("java") else 'OFF'
 
     if sys.version_info[:2] >= (3, 6):
         minimum_supported_numpy = "1.13.3"
@@ -121,6 +122,8 @@ def main():
             "-DPYTHON3_LIBRARY=%s" % python_lib_path,
             "-DBUILD_opencv_python3=ON",
             "-DBUILD_opencv_python2=OFF",
+            # Disable the Java build by default as it is not needed
+            "-DBUILD_opencv_java=%s" % build_java,
             # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
             "-DOPENCV_SKIP_PYTHON_LOADER=ON",
             # Relative dir to install the built module to in the build tree.

From f2f717bc610b7f1ee5338a0c40c785aa1f0449e8 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 29 Jul 2020 20:54:21 +0300
Subject: [PATCH 376/566] qt 5.13 test

---
 cv2/__init__.py                        |   8 +-
 cv2/data/__init__.py                   |   2 +-
 docker/manylinux2014/Dockerfile_i686   |  16 +++-
 docker/manylinux2014/Dockerfile_x86_64 |  16 +++-
 find_version.py                        | 114 ++++++++++++++-----------
 patches/patchQtPlugins                 |  13 ++-
 setup.py                               |  17 ++--
 tests/test.py                          |   1 +
 8 files changed, 118 insertions(+), 69 deletions(-)

diff --git a/cv2/__init__.py b/cv2/__init__.py
index b901c204..c7474d18 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -7,7 +7,7 @@
 
 # wildcard import above does not import "private" variables like __version__
 # this makes them available
-globals().update(importlib.import_module('cv2.cv2').__dict__)
+globals().update(importlib.import_module("cv2.cv2").__dict__)
 
 is_ci_build = False
 
@@ -18,7 +18,7 @@
     pass
 
 # the Qt plugin is included currently only in the pre-built wheels
-if sys.platform == 'darwin' and is_ci_build:
-    os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.join(
-        os.path.dirname(os.path.abspath(__file__)), 'qt', 'plugins'
+if (sys.platform == "darwin" or sys.platform.startswith("linux")) and is_ci_build:
+    os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.path.join(
+        os.path.dirname(os.path.abspath(__file__)), "qt", "plugins"
     )
diff --git a/cv2/data/__init__.py b/cv2/data/__init__.py
index 12c818d9..1cad2750 100644
--- a/cv2/data/__init__.py
+++ b/cv2/data/__init__.py
@@ -1,3 +1,3 @@
 import os
 
-haarcascades = os.path.join(os.path.dirname(__file__), '')
+haarcascades = os.path.join(os.path.dirname(__file__), "")
diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index c50a5018..4418bdac 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -1,6 +1,20 @@
 FROM quay.io/pypa/manylinux2014_i686:latest
 
-RUN yum install bzip2-devel curl-devel zlib-devel qt-devel -y
+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 freetype-devel -y
+
+RUN curl -O -L https://download.qt.io/official_releases/qt/5.13/5.13.2/single/qt-everywhere-src-5.13.2.tar.xz && \
+    tar -xf qt-everywhere-src-5.13.2.tar.xz && \
+    cd qt-everywhere* && \
+    export MAKEFLAGS=-j$(nproc) && \
+    ./configure -prefix /opt/Qt5.13.2 -release -opensource -confirm-license -qtnamespace QtOpenCVPython -qt-xcb -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 && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf qt-everywhere-src-5.13.2 && \
+    rm qt-everywhere-src-5.13.2.tar.xz
+
+ENV QTDIR /opt/Qt5.13.2
+ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index df7e106e..40bb529f 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -1,6 +1,20 @@
 FROM quay.io/pypa/manylinux2014_x86_64:latest
 
-RUN yum install bzip2-devel curl-devel zlib-devel qt-devel -y
+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 freetype-devel -y
+
+RUN curl -O -L https://download.qt.io/official_releases/qt/5.13/5.13.2/single/qt-everywhere-src-5.13.2.tar.xz && \
+    tar -xf qt-everywhere-src-5.13.2.tar.xz && \
+    cd qt-everywhere* && \
+    export MAKEFLAGS=-j$(nproc) && \
+    ./configure -prefix /opt/Qt5.13.2 -release -opensource -confirm-license -qtnamespace QtOpenCVPython -qt-xcb -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 && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf qt-everywhere-src-5.13.2 && \
+    rm qt-everywhere-src-5.13.2.tar.xz
+
+ENV QTDIR /opt/Qt5.13.2
+ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
diff --git a/find_version.py b/find_version.py
index 76d9f86d..80ae522b 100644
--- a/find_version.py
+++ b/find_version.py
@@ -3,54 +3,66 @@
 import subprocess
 
 if __name__ == "__main__":
-  contrib = sys.argv[1]
-  headless = sys.argv[2]
-  ci_build = sys.argv[3]
-
-  opencv_version = ""
-  # dig out the version from OpenCV sources
-  version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp"
-
-  with open(version_file_path, 'r') as f:
-      for line in f:
-          words = line.split()
-
-          if "CV_VERSION_MAJOR" in words:
-              opencv_version += words[2]
-              opencv_version += "."
-
-          if "CV_VERSION_MINOR" in words:
-              opencv_version += words[2]
-              opencv_version += "."
-
-          if "CV_VERSION_REVISION" in words:
-              opencv_version += words[2]
-              break
-
-  # used in local dev releases
-  git_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).splitlines()[0].decode()
-  # this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
-  try:
-      tag = subprocess.check_output(['git', 'describe', '--tags'], stderr = subprocess.STDOUT).splitlines()[0].decode().split('-')
-  except subprocess.CalledProcessError as e:
-      # no tags reachable (e.g. on a topic branch in a fork), see
-      # https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
-      if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
-          tag=[]
-      else:
-          print(e.output); raise
-
-  if len(tag) == 1:
-      # tag identifies the build and should be a sequential revision number
-      version = tag[0]
-      opencv_version += ".{}".format(version)
-  else:
-      # local version identifier, not to be published on PyPI
-      version = git_hash
-      opencv_version += "+{}".format(version)
-
-  with open('cv2/version.py', 'w') as f:
-      f.write("opencv_version = \"{}\"\n".format(opencv_version))
-      f.write("contrib = {}\n".format(contrib))
-      f.write("headless = {}\n".format(headless))
-      f.write("ci_build = {}".format(ci_build))
+    contrib = sys.argv[1]
+    headless = sys.argv[2]
+    ci_build = sys.argv[3]
+
+    opencv_version = ""
+    # dig out the version from OpenCV sources
+    version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp"
+
+    with open(version_file_path, "r") as f:
+        for line in f:
+            words = line.split()
+
+            if "CV_VERSION_MAJOR" in words:
+                opencv_version += words[2]
+                opencv_version += "."
+
+            if "CV_VERSION_MINOR" in words:
+                opencv_version += words[2]
+                opencv_version += "."
+
+            if "CV_VERSION_REVISION" in words:
+                opencv_version += words[2]
+                break
+
+    # used in local dev releases
+    git_hash = (
+        subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
+        .splitlines()[0]
+        .decode()
+    )
+    # this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
+    try:
+        tag = (
+            subprocess.check_output(
+                ["git", "describe", "--tags"], stderr=subprocess.STDOUT
+            )
+            .splitlines()[0]
+            .decode()
+            .split("-")
+        )
+    except subprocess.CalledProcessError as e:
+        # no tags reachable (e.g. on a topic branch in a fork), see
+        # https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
+        if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
+            tag = []
+        else:
+            print(e.output)
+            raise
+
+    if len(tag) == 1:
+        # tag identifies the build and should be a sequential revision number
+        version = tag[0]
+        opencv_version += ".{}".format(version)
+    else:
+        # local version identifier, not to be published on PyPI
+        version = git_hash
+        opencv_version += "+{}".format(version)
+
+    with open("cv2/version.py", "w") as f:
+        f.write('opencv_version = "{}"\n'.format(opencv_version))
+        f.write("contrib = {}\n".format(contrib))
+        f.write("headless = {}\n".format(headless))
+        f.write("ci_build = {}".format(ci_build))
diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index c69ef795..4e272c31 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -1,12 +1,17 @@
 diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt
-index 8ccad4d03a..0d5e2a79e9 100644
+index 4c0b3880fc..54da25f151 100644
 --- a/opencv/CMakeLists.txt
 +++ b/opencv/CMakeLists.txt
-@@ -1164,6 +1164,7 @@ if(WITH_QT OR HAVE_QT)
+@@ -1187,6 +1187,12 @@ if(WITH_QT OR HAVE_QT)
    if(HAVE_QT5)
      status("    QT:" "YES (ver ${Qt5Core_VERSION_STRING})")
      status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt5OpenGL_LIBRARIES} ${Qt5OpenGL_VERSION_STRING})" ELSE NO)
-+    install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
++    if(APPLE)
++      install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
++    endif()
++    if(UNIX AND NOT APPLE)
++      install(DIRECTORY /opt/Qt5.13.2/plugins DESTINATION lib/qt)
++    endif()
    elseif(HAVE_QT)
      status("    QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
-     status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)
\ No newline at end of file
+     status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)
diff --git a/setup.py b/setup.py
index 323efaab..79246636 100644
--- a/setup.py
+++ b/setup.py
@@ -159,18 +159,21 @@ def main():
     if sys.platform.startswith("linux") and not x64 and "bdist_wheel" in sys.argv:
         subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
 
-    # OS-specific components during CI builds
+    # OS-specific components during CI build_headless
     if is_CI_build:
-        if sys.platform.startswith("linux") and not build_headless:
-            cmake_args.append("-DWITH_QT=4")
 
-        if sys.platform == "darwin" and not build_headless:
-            if "bdist_wheel" in sys.argv:
-                cmake_args.append("-DWITH_QT=5")
+        if not build_headless and "bdist_wheel" in sys.argv:
+            cmake_args.append("-DWITH_QT=5")
+            subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
+
+            if sys.platform.startswith("linux"):
+                rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
+                    (r"lib/qt/plugins/platforms/libqxcb\.so")
+                ]
+            if sys.platform == "darwin":
                 rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
                     (r"lib/qt/plugins/platforms/libqcocoa\.dylib")
                 ]
-                subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
         if sys.platform.startswith("linux"):
             cmake_args.append("-DWITH_V4L=ON")
diff --git a/tests/test.py b/tests/test.py
index e520814f..54ee19dc 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -12,5 +12,6 @@ def test_import(self):
     def test_video_capture(self):
 
         import cv2
+
         cap = cv2.VideoCapture("SampleVideo_1280x720_1mb.mp4")
         self.assertTrue(cap.isOpened())

From 39198ec83399d7f403a3e6a11a6268e78c38ebca Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 29 Jul 2020 22:31:27 +0300
Subject: [PATCH 377/566] add ld lib path

---
 travis_config.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/travis_config.sh b/travis_config.sh
index 9e114b46..b6043d3a 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -24,6 +24,7 @@ if [ -n "$IS_OSX" ]; then
   export MAKEFLAGS="-j$(sysctl -n hw.ncpu)"
 else
   echo "    > Linux environment "
+  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt5.13.2/lib
   export MAKEFLAGS="-j$(grep -E '^processor[[:space:]]*:' /proc/cpuinfo | wc -l)"
 fi
 

From 5a8776ad18011a7be9cd5145c810e1ef7b45ade0 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 3 Aug 2020 12:54:44 +0300
Subject: [PATCH 378/566] fix typo, try without xcb helpers

---
 docker/manylinux2014/Dockerfile_i686   | 2 +-
 docker/manylinux2014/Dockerfile_x86_64 | 2 +-
 setup.py                               | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index 4418bdac..d8286b9a 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -6,7 +6,7 @@ RUN curl -O -L https://download.qt.io/official_releases/qt/5.13/5.13.2/single/qt
     tar -xf qt-everywhere-src-5.13.2.tar.xz && \
     cd qt-everywhere* && \
     export MAKEFLAGS=-j$(nproc) && \
-    ./configure -prefix /opt/Qt5.13.2 -release -opensource -confirm-license -qtnamespace QtOpenCVPython -qt-xcb -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 && \
+    ./configure -prefix /opt/Qt5.13.2 -release -opensource -confirm-license -qtnamespace QtOpenCVPython -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 && \
     make && \
     make install && \
     cd .. && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index 40bb529f..7e25d671 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -6,7 +6,7 @@ RUN curl -O -L https://download.qt.io/official_releases/qt/5.13/5.13.2/single/qt
     tar -xf qt-everywhere-src-5.13.2.tar.xz && \
     cd qt-everywhere* && \
     export MAKEFLAGS=-j$(nproc) && \
-    ./configure -prefix /opt/Qt5.13.2 -release -opensource -confirm-license -qtnamespace QtOpenCVPython -qt-xcb -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 && \
+    ./configure -prefix /opt/Qt5.13.2 -release -opensource -confirm-license -qtnamespace QtOpenCVPython -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 && \
     make && \
     make install && \
     cd .. && \
diff --git a/setup.py b/setup.py
index 79246636..764c2617 100644
--- a/setup.py
+++ b/setup.py
@@ -159,7 +159,7 @@ def main():
     if sys.platform.startswith("linux") and not x64 and "bdist_wheel" in sys.argv:
         subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
 
-    # OS-specific components during CI build_headless
+    # OS-specific components during CI builds
     if is_CI_build:
 
         if not build_headless and "bdist_wheel" in sys.argv:

From 19ecd1602719a09667628eef3b4b55c0d21c299e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 3 Aug 2020 22:54:43 +0300
Subject: [PATCH 379/566] qt5.15 again

---
 docker/manylinux2014/Dockerfile_i686   | 14 +++++++-------
 docker/manylinux2014/Dockerfile_x86_64 | 14 +++++++-------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index d8286b9a..8b217829 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -1,19 +1,19 @@
 FROM quay.io/pypa/manylinux2014_i686:latest
 
-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 freetype-devel -y
+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
 
-RUN curl -O -L https://download.qt.io/official_releases/qt/5.13/5.13.2/single/qt-everywhere-src-5.13.2.tar.xz && \
-    tar -xf qt-everywhere-src-5.13.2.tar.xz && \
+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 && \
+    tar -xf qt-everywhere-src-5.15.0.tar.xz && \
     cd qt-everywhere* && \
     export MAKEFLAGS=-j$(nproc) && \
-    ./configure -prefix /opt/Qt5.13.2 -release -opensource -confirm-license -qtnamespace QtOpenCVPython -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 && \
+    ./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 && \
     make && \
     make install && \
     cd .. && \
-    rm -rf qt-everywhere-src-5.13.2 && \
-    rm qt-everywhere-src-5.13.2.tar.xz
+    rm -rf qt-everywhere-src-5.15.0 && \
+    rm qt-everywhere-src-5.15.0.tar.xz
 
-ENV QTDIR /opt/Qt5.13.2
+ENV QTDIR /opt/Qt5.15.0
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index 7e25d671..cb14871c 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -1,19 +1,19 @@
 FROM quay.io/pypa/manylinux2014_x86_64:latest
 
-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 freetype-devel -y
+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
 
-RUN curl -O -L https://download.qt.io/official_releases/qt/5.13/5.13.2/single/qt-everywhere-src-5.13.2.tar.xz && \
-    tar -xf qt-everywhere-src-5.13.2.tar.xz && \
+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 && \
+    tar -xf qt-everywhere-src-5.15.0.tar.xz && \
     cd qt-everywhere* && \
     export MAKEFLAGS=-j$(nproc) && \
-    ./configure -prefix /opt/Qt5.13.2 -release -opensource -confirm-license -qtnamespace QtOpenCVPython -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 && \
+    ./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 && \
     make && \
     make install && \
     cd .. && \
-    rm -rf qt-everywhere-src-5.13.2 && \
-    rm qt-everywhere-src-5.13.2.tar.xz
+    rm -rf qt-everywhere-src-5.15.0 && \
+    rm qt-everywhere-src-5.15.0.tar.xz
 
-ENV QTDIR /opt/Qt5.13.2
+ENV QTDIR /opt/Qt5.15.0
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \

From 96be62b70347397c018716af62855e5a86e5f9db Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 3 Aug 2020 22:55:30 +0300
Subject: [PATCH 380/566] change path

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index b6043d3a..13299a4b 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -24,7 +24,7 @@ if [ -n "$IS_OSX" ]; then
   export MAKEFLAGS="-j$(sysctl -n hw.ncpu)"
 else
   echo "    > Linux environment "
-  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt5.13.2/lib
+  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt5.15.0/lib
   export MAKEFLAGS="-j$(grep -E '^processor[[:space:]]*:' /proc/cpuinfo | wc -l)"
 fi
 

From 3a85591397da732f69124e7eead7cc93f4698acf Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 3 Aug 2020 23:46:30 +0300
Subject: [PATCH 381/566] fix patch

---
 patches/patchQtPlugins | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index 4e272c31..e84aca44 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -10,7 +10,7 @@ index 4c0b3880fc..54da25f151 100644
 +      install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
 +    endif()
 +    if(UNIX AND NOT APPLE)
-+      install(DIRECTORY /opt/Qt5.13.2/plugins DESTINATION lib/qt)
++      install(DIRECTORY /opt/Qt5.15.0/plugins DESTINATION lib/qt)
 +    endif()
    elseif(HAVE_QT)
      status("    QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")

From 51520692f0daae66a9f94c637bf36b6b686fce8e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 5 Aug 2020 14:35:20 +0300
Subject: [PATCH 382/566] try to whitelist libxcb.so.1

---
 patch_auditwheel_whitelist.py | 16 ++++++++++++++++
 travis_config.sh              |  1 +
 2 files changed, 17 insertions(+)
 create mode 100644 patch_auditwheel_whitelist.py

diff --git a/patch_auditwheel_whitelist.py b/patch_auditwheel_whitelist.py
new file mode 100644
index 00000000..d0cbf5b2
--- /dev/null
+++ b/patch_auditwheel_whitelist.py
@@ -0,0 +1,16 @@
+from os.path import join, dirname, abspath
+import json
+
+from auditwheel import policy
+
+policies = None
+
+with open(join(dirname(abspath(policy.__file__)), "policy.json")) as f:
+    policies = json.load(f)
+
+for p in policies:
+    if p["name"] == "manylinux2014":
+        p["lib_whitelist"].append("libxcb.so.1")
+
+with open(join(dirname(abspath(policy.__file__)), "policy.json"), "w") as f:
+    f.write(json.dumps(policies))
diff --git a/travis_config.sh b/travis_config.sh
index 13299a4b..d1a80041 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -26,6 +26,7 @@ else
   echo "    > Linux environment "
   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt5.15.0/lib
   export MAKEFLAGS="-j$(grep -E '^processor[[:space:]]*:' /proc/cpuinfo | wc -l)"
+  python patch_auditwheel_whitelist.py
 fi
 
 if [ -n "$IS_OSX" ]; then

From aa791f185760607bc29790bea6789376c9eb8c2c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 5 Aug 2020 14:52:46 +0300
Subject: [PATCH 383/566] auditwheel is installed under py37

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index d1a80041..863423b3 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -26,7 +26,7 @@ else
   echo "    > Linux environment "
   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt5.15.0/lib
   export MAKEFLAGS="-j$(grep -E '^processor[[:space:]]*:' /proc/cpuinfo | wc -l)"
-  python patch_auditwheel_whitelist.py
+  /opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py
 fi
 
 if [ -n "$IS_OSX" ]; then

From b9b07a532d49fc93ff191569d2424a49ccaebda4 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 5 Aug 2020 15:23:06 +0300
Subject: [PATCH 384/566] fix patch location

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index 863423b3..d80d7147 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -16,6 +16,7 @@ function bdist_wheel_cmd {
     local abs_wheelhouse=$1
     CI_BUILD=1 pip wheel --wheel-dir="$PWD/dist" . --verbose $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
+    /opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }
 
@@ -26,7 +27,6 @@ else
   echo "    > Linux environment "
   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt5.15.0/lib
   export MAKEFLAGS="-j$(grep -E '^processor[[:space:]]*:' /proc/cpuinfo | wc -l)"
-  /opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py
 fi
 
 if [ -n "$IS_OSX" ]; then

From 9271f1a4f54761a897ae34f2bd0205472f5dc9ad Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Wed, 5 Aug 2020 16:13:17 +0300
Subject: [PATCH 385/566] Install azure-cli from Ubuntu repo because latest
 update broke batch upload

---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 26b345b4..edbbbd72 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -787,7 +787,7 @@ after_success: |
     # Save to Azure storage always
 
     if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-      curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
+      sudo apt-get install -y azure-cli=2.0.81+ds-4
     else
       brew install azure-cli
     fi

From 2bcf6a4e191b03f77bad8e44d96f50e1a206fd61 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Wed, 5 Aug 2020 16:55:11 +0300
Subject: [PATCH 386/566] use pip

---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index edbbbd72..07951314 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -787,7 +787,7 @@ after_success: |
     # Save to Azure storage always
 
     if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-      sudo apt-get install -y azure-cli=2.0.81+ds-4
+      pip install --user azure-cli==2.9.1
     else
       brew install azure-cli
     fi

From 3ec8958f321bc5e1c9c0e873413cfbba349d722a Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Wed, 5 Aug 2020 17:39:19 +0300
Subject: [PATCH 387/566] use py27 compatible version

---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 07951314..069e18a8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -787,7 +787,7 @@ after_success: |
     # Save to Azure storage always
 
     if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-      pip install --user azure-cli==2.9.1
+      pip install --user azure-cli==2.0.81
     else
       brew install azure-cli
     fi

From eaa3ca764aee622e63fdd678043f8ac6efbafca8 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 6 Aug 2020 20:19:15 +0300
Subject: [PATCH 388/566] azure-cli should work now

---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 069e18a8..26b345b4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -787,7 +787,7 @@ after_success: |
     # Save to Azure storage always
 
     if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-      pip install --user azure-cli==2.0.81
+      curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
     else
       brew install azure-cli
     fi

From 902a94edfd9533c892cd76cc785cf068787c143f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 7 Aug 2020 00:38:54 +0300
Subject: [PATCH 389/566] add fonts to the package

---
 setup.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/setup.py b/setup.py
index 764c2617..cad0f141 100644
--- a/setup.py
+++ b/setup.py
@@ -170,6 +170,17 @@ def main():
                 rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
                     (r"lib/qt/plugins/platforms/libqxcb\.so")
                 ]
+
+                # add fonts for Qt5
+                fonts = []
+                for file in os.listdir("/usr/share/fonts/dejavu"):
+                    if file.endswith(".ttf"):
+                        fonts.append(
+                            (r"/usr/share/fonts/dejavu/%s\.ttf" % file.split(".")[0])
+                        )
+
+                rearrange_cmake_output_data["cv2.qt.fonts"] = fonts
+
             if sys.platform == "darwin":
                 rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
                     (r"lib/qt/plugins/platforms/libqcocoa\.dylib")

From fa463c13c2a17bfd07e053f40da29f9107ad2a5e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 7 Aug 2020 00:47:35 +0300
Subject: [PATCH 390/566] set QT_QPA_FONTDIR

---
 cv2/__init__.py | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/cv2/__init__.py b/cv2/__init__.py
index c7474d18..7f7c1261 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -9,16 +9,25 @@
 # this makes them available
 globals().update(importlib.import_module("cv2.cv2").__dict__)
 
-is_ci_build = False
+ci_and_not_headless = False
 
 try:
-    from .version import ci_build
-    is_ci_build = ci_build
+    from .version import ci_build, headless
+
+    ci_and_not_headless = ci_build and not headless
 except:
     pass
 
 # the Qt plugin is included currently only in the pre-built wheels
-if (sys.platform == "darwin" or sys.platform.startswith("linux")) and is_ci_build:
+if (
+    sys.platform == "darwin" or sys.platform.startswith("linux")
+) and ci_and_not_headless:
     os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), "qt", "plugins"
     )
+
+# Qt will throw warning on Linux if fonts are not found
+if sys.platform.startswith("linux") and ci_and_not_headless:
+    os.environ["QT_QPA_FONTDIR"] = os.path.join(
+        os.path.dirname(os.path.abspath(__file__)), "qt", "fonts"
+    )

From 8ca25e7a0937707d56b8471fb0da33542545e94c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 7 Aug 2020 01:22:13 +0300
Subject: [PATCH 391/566] copy fonts

---
 patches/patchQtPlugins | 1 +
 setup.py               | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index e84aca44..d8571414 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -11,6 +11,7 @@ index 4c0b3880fc..54da25f151 100644
 +    endif()
 +    if(UNIX AND NOT APPLE)
 +      install(DIRECTORY /opt/Qt5.15.0/plugins DESTINATION lib/qt)
++      install(DIRECTORY /usr/share/fonts DESTINATION lib/qt)
 +    endif()
    elseif(HAVE_QT)
      status("    QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
diff --git a/setup.py b/setup.py
index cad0f141..daa4387f 100644
--- a/setup.py
+++ b/setup.py
@@ -176,7 +176,7 @@ def main():
                 for file in os.listdir("/usr/share/fonts/dejavu"):
                     if file.endswith(".ttf"):
                         fonts.append(
-                            (r"/usr/share/fonts/dejavu/%s\.ttf" % file.split(".")[0])
+                            (r"lib/qt/fonts/dejavu/%s\.ttf" % file.split(".")[0])
                         )
 
                 rearrange_cmake_output_data["cv2.qt.fonts"] = fonts

From 98d210d4244e5de84388a124ccbafee76cfb3b32 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 7 Aug 2020 14:10:36 +0300
Subject: [PATCH 392/566] update patch

---
 patches/patchQtPlugins | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index d8571414..221ab561 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -1,8 +1,7 @@
-diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt
-index 4c0b3880fc..54da25f151 100644
---- a/opencv/CMakeLists.txt
-+++ b/opencv/CMakeLists.txt
-@@ -1187,6 +1187,12 @@ if(WITH_QT OR HAVE_QT)
+diff -ruN opencv/CMakeLists.txt opencv_patched/CMakeLists.txt
+--- opencv/CMakeLists.txt       2020-08-07 14:09:05.665876400 +0300
++++ opencv_patched/CMakeLists.txt       2020-08-07 14:05:31.738510600 +0300
+@@ -1187,6 +1187,13 @@
    if(HAVE_QT5)
      status("    QT:" "YES (ver ${Qt5Core_VERSION_STRING})")
      status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt5OpenGL_LIBRARIES} ${Qt5OpenGL_VERSION_STRING})" ELSE NO)

From e2f2a872e4a5e9a680b0ab6d2a405288c4640baf Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 7 Aug 2020 11:44:10 +0000
Subject: [PATCH 393/566] update patch

---
 patches/patchQtPlugins | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index 221ab561..6919520e 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -1,6 +1,5 @@
-diff -ruN opencv/CMakeLists.txt opencv_patched/CMakeLists.txt
---- opencv/CMakeLists.txt       2020-08-07 14:09:05.665876400 +0300
-+++ opencv_patched/CMakeLists.txt       2020-08-07 14:05:31.738510600 +0300
+--- opencv/CMakeLists.txt	2020-08-07 11:24:37.662215917 +0000
++++ opencv_patched/CMakeLists.txt	2020-08-07 11:24:25.684215910 +0000
 @@ -1187,6 +1187,13 @@
    if(HAVE_QT5)
      status("    QT:" "YES (ver ${Qt5Core_VERSION_STRING})")

From c7f3271fb503a1afea26a85d24f798dbbc677b8d Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 7 Aug 2020 11:51:13 +0000
Subject: [PATCH 394/566] update patch

---
 patches/patchQtPlugins | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index 6919520e..246432d1 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -1,6 +1,8 @@
---- opencv/CMakeLists.txt	2020-08-07 11:24:37.662215917 +0000
-+++ opencv_patched/CMakeLists.txt	2020-08-07 11:24:25.684215910 +0000
-@@ -1187,6 +1187,13 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 4c0b3880fc..dffa0a4caa 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -1187,6 +1187,13 @@ if(WITH_QT OR HAVE_QT)
    if(HAVE_QT5)
      status("    QT:" "YES (ver ${Qt5Core_VERSION_STRING})")
      status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt5OpenGL_LIBRARIES} ${Qt5OpenGL_VERSION_STRING})" ELSE NO)

From 6ef230bacaf16d443041a9af9d38aebe076ec5c7 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 7 Aug 2020 11:57:39 +0000
Subject: [PATCH 395/566] wrong dir

---
 patches/patchQtPlugins | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index 246432d1..03560f17 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -1,7 +1,7 @@
-diff --git a/CMakeLists.txt b/CMakeLists.txt
+diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt
 index 4c0b3880fc..dffa0a4caa 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
+--- a/opencv/CMakeLists.txt
++++ b/opencv/CMakeLists.txt
 @@ -1187,6 +1187,13 @@ if(WITH_QT OR HAVE_QT)
    if(HAVE_QT5)
      status("    QT:" "YES (ver ${Qt5Core_VERSION_STRING})")

From a3f63146813b84c4cf1abbd44e339b81e656b2ac Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 7 Aug 2020 15:41:31 +0300
Subject: [PATCH 396/566] update license info

---
 LICENSE-3RD-PARTY.txt | 3 +--
 README.md             | 4 +---
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index e5aaa258..1cbfd56f 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -81,7 +81,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 ------------------------------------------------------------------------------
 FFmpeg is redistributed within all opencv-python packages.
-Qt 4.8.7 is redistributed within non-headless opencv-python Linux packages.
 Libuuid is redistributed within all opencv-python Linux packages.
 
 Libbluray, libgnutls, libnettle, libhogweed, libintl, libmp3lame, libp11,
@@ -549,7 +548,7 @@ DAMAGES.
                      END OF TERMS AND CONDITIONS
 
 ------------------------------------------------------------------------------
-Qt 5 is redistributed within non-headless opencv-python macOS packages.
+Qt 5 is redistributed within non-headless opencv-python Linux and macOS packages.
 libgmp is redistributed within opencv-python macOS packages.
 libidn2 is redistributed within opencv-python macOS packages.
 libunistring is redistributed within opencv-python macOS packages.
diff --git a/README.md b/README.md
index 13462507..513520e4 100644
--- a/README.md
+++ b/README.md
@@ -154,9 +154,7 @@ Third party package licenses are at [LICENSE-3RD-PARTY.txt](https://github.com/s
 
 All wheels ship with [FFmpeg](http://ffmpeg.org) licensed under the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
 
-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).
-
-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).
+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).
 
 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).
 

From a115f4bd2ae79107dd4735b1ac99f6c60fd84ed7 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 7 Aug 2020 16:19:23 +0300
Subject: [PATCH 397/566] update licenses

---
 LICENSE-3RD-PARTY.txt | 514 +++++++++++++++++++-----------------------
 1 file changed, 231 insertions(+), 283 deletions(-)

diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index 1cbfd56f..60c34bc0 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -81,7 +81,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 ------------------------------------------------------------------------------
 FFmpeg is redistributed within all opencv-python packages.
-Libuuid is redistributed within all opencv-python Linux packages.
 
 Libbluray, libgnutls, libnettle, libhogweed, libintl, libmp3lame, libp11,
 librtmp, libsoxr and libtasn1 are redistributed within all opencv-python macOS packages.
@@ -891,33 +890,7 @@ This license applies to above binaries in the directory cv2/.
  */
 
 ------------------------------------------------------------------------------
-libexpat is redistributed within all opencv-python Linux packages.
-This license applies to libexpat binary in the directory cv2/.
-
-Copyright (c) 1998-2000 Thai Open Source Software Center Ltd and Clark Cooper
-Copyright (c) 2001-2019 Expat maintainers
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-------------------------------------------------------------------------------
-libfontconfig is redistributed within all opencv-python Linux and macOS packages.
+libfontconfig is redistributed within all opencv-python macOS packages.
 This license applies to libfontconfig binary in the directory cv2/.
 
 Copyright © 2000,2001,2002,2003,2004,2006,2007 Keith Packard
@@ -1278,261 +1251,6 @@ This license applies to libz binary in the directory cv2/.
   Jean-loup Gailly        Mark Adler
   jloup@gzip.org          madler@alumni.caltech.edu
 
-------------------------------------------------------------------------------
-libXcursor is redistributed within opencv-python Linux packages.
-This license applies to libXcursor binary in the directory cv2/.
-
-Copyright © 2002 Keith Packard
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation, and that the name of Keith Packard not be used in
-advertising or publicity pertaining to distribution of the software without
-specific, written prior permission.  Keith Packard makes no
-representations about the suitability of this software for any purpose.  It
-is provided "as is" without express or implied warranty.
-
-KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
-DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
-------------------------------------------------------------------------------
-libXfixes is redistributed within opencv-python Linux packages.
-This license applies to libXfixes binary in the directory cv2/.
-
-Copyright © 2001,2003 Keith Packard
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation, and that the name of Keith Packard not be used in
-advertising or publicity pertaining to distribution of the software without
-specific, written prior permission.  Keith Packard makes no
-representations about the suitability of this software for any purpose.  It
-is provided "as is" without express or implied warranty.
-
-KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
-DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
-Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice (including the next
-paragraph) shall be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-
-------------------------------------------------------------------------------
-libXi is redistributed within opencv-python Linux packages.
-This license applies to libXi binary in the directory cv2/.
-
-Copyright 1989, 1998  The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
-
-      All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the name of Hewlett-Packard not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
-
-HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
-Copyright 2008 Peter Hutterer
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of the author shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from the author.
-
-Copyright © 2009 Red Hat, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice (including the next
-paragraph) shall be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-
-------------------------------------------------------------------------------
-libXinerama is redistributed within opencv-python Linux packages.
-This license applies to libXinerama binary in the directory cv2/.
-
-Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
-BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
-IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of Digital Equipment Corporation
-shall not be used in advertising or otherwise to promote the sale, use or other
-dealings in this Software without prior written authorization from Digital
-Equipment Corporation.
-
-------------------------------------------------------------------------------
-libXrandr is redistributed within opencv-python Linux packages.
-This license applies to libXrandr binary in the directory cv2/.
-
-Copyright © 2000, Compaq Computer Corporation,
-Copyright © 2002, Hewlett Packard, Inc.
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation, and that the name of Compaq or HP not be used in advertising
-or publicity pertaining to distribution of the software without specific,
-written prior permission.  HP makes no representations about the
-suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-
-HP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL HP
-BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
-OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
-CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-Copyright © 2000 Compaq Computer Corporation, Inc.
-Copyright © 2002 Hewlett-Packard Company, Inc.
-Copyright © 2006 Intel Corporation
-Copyright © 2008 Red Hat, Inc.
-Copyright © 2011 Dave Airlie
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that copyright
-notice and this permission notice appear in supporting documentation, and
-that the name of the copyright holders not be used in advertising or
-publicity pertaining to distribution of the software without specific,
-written prior permission.  The copyright holders make no representations
-about the suitability of this software for any purpose.  It is provided "as
-is" without express or implied warranty.
-
-THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
-DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
-OF THIS SOFTWARE.
-
-Copyright © 2000 Compaq Computer Corporation, Inc.
-Copyright © 2002 Hewlett Packard Company, Inc.
-Copyright © 2006 Keith Packard
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that copyright
-notice and this permission notice appear in supporting documentation, and
-that the name of the copyright holders not be used in advertising or
-publicity pertaining to distribution of the software without specific,
-written prior permission.  The copyright holders make no representations
-about the suitability of this software for any purpose.  It is provided "as
-is" without express or implied warranty.
-
-THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
-DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
-OF THIS SOFTWARE.
-
 ------------------------------------------------------------------------------
 libdav1d is redistributed within opencv-python macOS packages.
 This license applies to libdav1d binary in the directory cv2/.
@@ -2328,3 +2046,233 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+------------------------------------------------------------------------------
+Libxcb utility libraries are redistributed within opencv-python non-headless Linux packages.
+This license applies to libxcb related binaries in the directory cv2/.
+
+Copyright (C) 2001-2006 Bart Massey, Jamey Sharp, and Josh Triplett.
+All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall
+be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the names of the authors
+or their institutions shall not be used in advertising or
+otherwise to promote the sale, use or other dealings in this
+Software without prior written authorization from the
+authors.
+
+------------------------------------------------------------------------------
+Libxcb-image is redistributed within opencv-python non-headless Linux packages.
+This license applies to libxcb-image binary in the directory cv2/.
+
+Copyright © 2007-2008 Bart Massey <bart@cs.pdx.edu>
+Copyright © 2008 Julien Danjou <julien@danjou.info>
+Copyright © 2008 Keith Packard <keithp@keithp.com>
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use, copy,
+modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the names of the authors or
+their institutions shall not be used in advertising or otherwise to
+promote the sale, use or other dealings in this Software without
+prior written authorization from the authors.
+
+------------------------------------------------------------------------------
+Libxcb-util is redistributed within opencv-python non-headless Linux packages.
+This license applies to libxcb-util binary in the directory cv2/.
+
+Copyright © 2008 Bart Massey <bart@cs.pdx.edu>
+Copyright © 2008 Ian Osgood <iano@quirkster.com>
+Copyright © 2008 Jamey Sharp <jamey@minilop.net>
+Copyright © 2008 Josh Triplett <josh@freedesktop.org>
+Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use, copy,
+modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the names of the authors or
+their institutions shall not be used in advertising or otherwise to
+promote the sale, use or other dealings in this Software without
+prior written authorization from the authors.
+
+------------------------------------------------------------------------------
+Libxcb-render-util is redistributed within opencv-python non-headless Linux packages.
+This license applies to libxcb-render-util binary in the directory cv2/.
+
+Copyright © 2000 Keith Packard
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation, and that the name of Keith Packard not be used in
+advertising or publicity pertaining to distribution of the software without
+specific, written prior permission.  Keith Packard makes no
+representations about the suitability of this software for any purpose.  It
+is provided "as is" without express or implied warranty.
+
+KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+Copyright © 2006 Jamey Sharp.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the names of the authors or their
+institutions shall not be used in advertising or otherwise to promote the
+sale, use or other dealings in this Software without prior written
+authorization from the authors.
+
+Copyright © 2006 Ian Osgood
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the names of the authors or their
+institutions shall not be used in advertising or otherwise to promote the
+sale, use or other dealings in this Software without prior written
+authorization from the authors.
+
+------------------------------------------------------------------------------
+Libxcb-icccm is redistributed within opencv-python non-headless Linux packages.
+This license applies to Libxcb-icccm binary in the directory cv2/.
+
+Copyright © 2008-2011 Arnaud Fontaine <arnau@debian.org>
+Copyright © 2007-2008 Vincent Torri <vtorri@univ-evry.fr>
+
+Permission  is  hereby  granted,  free  of charge,  to  any  person
+obtaining  a copy  of  this software  and associated  documentation
+files   (the  "Software"),   to  deal   in  the   Software  without
+restriction, including without limitation  the rights to use, copy,
+modify, merge, publish,  distribute, sublicense, and/or sell copies
+of  the Software, and  to permit  persons to  whom the  Software is
+furnished to do so, subject to the following conditions:
+
+The  above copyright  notice and  this permission  notice  shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE  IS PROVIDED  "AS IS", WITHOUT  WARRANTY OF  ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT  NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY,   FITNESS    FOR   A   PARTICULAR    PURPOSE   AND
+NONINFRINGEMENT. IN  NO EVENT SHALL  THE AUTHORS BE LIABLE  FOR ANY
+CLAIM,  DAMAGES  OR  OTHER  LIABILITY,  WHETHER  IN  AN  ACTION  OF
+CONTRACT, TORT OR OTHERWISE, ARISING  FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as  contained in  this notice, the  names of the  authors or
+their institutions shall not be used in advertising or otherwise to
+promote the  sale, use or  other dealings in this  Software without
+prior written authorization from the authors.
+
+------------------------------------------------------------------------------
+libXau is redistributed within opencv-python non-headless Linux packages.
+This license applies to libXau binary in the directory cv2/.
+
+Copyright 1988, 1993, 1994, 1998  The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
\ No newline at end of file

From a49fdc600fe076d7729e15e97d3805e636eb1b73 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 8 Aug 2020 21:05:50 +0300
Subject: [PATCH 398/566] fix windows builds

---
 setup.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index fab105ef..f3b209b3 100644
--- a/setup.py
+++ b/setup.py
@@ -19,7 +19,7 @@ def main():
     minimum_supported_numpy = "1.13.1"
     build_contrib = get_build_env_var_by_name("contrib")
     build_headless = get_build_env_var_by_name("headless")
-    build_java = 'ON' if get_build_env_var_by_name("java") else 'OFF'
+    build_java = "ON" if get_build_env_var_by_name("java") else "OFF"
 
     if sys.version_info[:2] >= (3, 6):
         minimum_supported_numpy = "1.13.3"
@@ -162,7 +162,11 @@ def main():
     # OS-specific components during CI builds
     if is_CI_build:
 
-        if not build_headless and "bdist_wheel" in sys.argv:
+        if (
+            not build_headless
+            and "bdist_wheel" in sys.argv
+            and (sys.platform == "darwin" or sys.platform.startswith("linux"))
+        ):
             cmake_args.append("-DWITH_QT=5")
             subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 

From 2ff5f257aa6128016ea8419d37e54c57b2efe230 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 8 Aug 2020 21:05:50 +0300
Subject: [PATCH 399/566] fix windows builds

---
 setup.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index daa4387f..432f01cc 100644
--- a/setup.py
+++ b/setup.py
@@ -19,7 +19,7 @@ def main():
     minimum_supported_numpy = "1.13.1"
     build_contrib = get_build_env_var_by_name("contrib")
     build_headless = get_build_env_var_by_name("headless")
-    build_java = 'ON' if get_build_env_var_by_name("java") else 'OFF'
+    build_java = "ON" if get_build_env_var_by_name("java") else "OFF"
 
     if sys.version_info[:2] >= (3, 6):
         minimum_supported_numpy = "1.13.3"
@@ -162,7 +162,11 @@ def main():
     # OS-specific components during CI builds
     if is_CI_build:
 
-        if not build_headless and "bdist_wheel" in sys.argv:
+        if (
+            not build_headless
+            and "bdist_wheel" in sys.argv
+            and (sys.platform == "darwin" or sys.platform.startswith("linux"))
+        ):
             cmake_args.append("-DWITH_QT=5")
             subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 

From 2bc75407aab5e9ab4d6d1bc6f5f05d6c2545050b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 8 Aug 2020 23:49:13 +0300
Subject: [PATCH 400/566] patch only on linux

---
 travis_config.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index d80d7147..fe1b7865 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -16,7 +16,9 @@ function bdist_wheel_cmd {
     local abs_wheelhouse=$1
     CI_BUILD=1 pip wheel --wheel-dir="$PWD/dist" . --verbose $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
-    /opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py
+    if [ -z "$IS_OSX" ]; then
+      /opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py
+    fi
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }
 

From 70988b9e41a6e3a1833befb98775d09d3c85dd34 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 8 Aug 2020 23:49:13 +0300
Subject: [PATCH 401/566] patch only on linux

---
 travis_config.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index d80d7147..fe1b7865 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -16,7 +16,9 @@ function bdist_wheel_cmd {
     local abs_wheelhouse=$1
     CI_BUILD=1 pip wheel --wheel-dir="$PWD/dist" . --verbose $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
-    /opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py
+    if [ -z "$IS_OSX" ]; then
+      /opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py
+    fi
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }
 

From 689a9e10b734ea9891f9797ff3965bdd107a0aa1 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 9 Aug 2020 14:35:05 +0300
Subject: [PATCH 402/566] reduce verbosity

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index fe1b7865..3cf99356 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -14,7 +14,7 @@ function bdist_wheel_cmd {
     # copied from multibuild's common_utils.sh
     # add osx deployment target so it doesnt default to 10.6
     local abs_wheelhouse=$1
-    CI_BUILD=1 pip wheel --wheel-dir="$PWD/dist" . --verbose $BDIST_PARAMS
+    CI_BUILD=1 pip wheel --wheel-dir="$PWD/dist" . $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
     if [ -z "$IS_OSX" ]; then
       /opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py

From 8660b61dbc982049866b9fc08e8b35deba7e22b6 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 9 Aug 2020 14:35:05 +0300
Subject: [PATCH 403/566] reduce verbosity

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index fe1b7865..3cf99356 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -14,7 +14,7 @@ function bdist_wheel_cmd {
     # copied from multibuild's common_utils.sh
     # add osx deployment target so it doesnt default to 10.6
     local abs_wheelhouse=$1
-    CI_BUILD=1 pip wheel --wheel-dir="$PWD/dist" . --verbose $BDIST_PARAMS
+    CI_BUILD=1 pip wheel --wheel-dir="$PWD/dist" . $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
     if [ -z "$IS_OSX" ]; then
       /opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py

From e0ff6f905e418eea1c3055a18aa1931806bc44af Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 9 Aug 2020 16:08:04 +0300
Subject: [PATCH 404/566] fix min numpy version for 3.6

---
 .travis.yml | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 26b345b4..19072fca 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -119,6 +119,7 @@ jobs:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.13.3
       workspaces:
         use: brew_cache
     - os: osx
@@ -159,6 +160,7 @@ jobs:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.13.3
       workspaces:
         use: brew_cache
     - os: osx
@@ -199,6 +201,7 @@ jobs:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.13.3
       workspaces:
         use: brew_cache
     - os: osx
@@ -239,6 +242,7 @@ jobs:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.13.3
       workspaces:
         use: brew_cache
     - os: osx
@@ -293,7 +297,7 @@ jobs:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -305,7 +309,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
@@ -389,7 +393,7 @@ jobs:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -401,7 +405,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
@@ -483,7 +487,7 @@ jobs:
       services: docker
       env:
         - MB_PYTHON_VERSION=3.6
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
       cache:
@@ -495,7 +499,7 @@ jobs:
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
         - USE_CCACHE=0
@@ -580,7 +584,7 @@ jobs:
       services: docker
       env:
         - MB_PYTHON_VERSION=3.6
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
       cache:
@@ -592,7 +596,7 @@ jobs:
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
         - USE_CCACHE=0

From 52bc6985f9fcfccacd75fc6ae86c12dbba425150 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 9 Aug 2020 16:08:04 +0300
Subject: [PATCH 405/566] fix min numpy version for 3.6

---
 .travis.yml | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 26b345b4..19072fca 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -119,6 +119,7 @@ jobs:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.13.3
       workspaces:
         use: brew_cache
     - os: osx
@@ -159,6 +160,7 @@ jobs:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.13.3
       workspaces:
         use: brew_cache
     - os: osx
@@ -199,6 +201,7 @@ jobs:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.13.3
       workspaces:
         use: brew_cache
     - os: osx
@@ -239,6 +242,7 @@ jobs:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.13.3
       workspaces:
         use: brew_cache
     - os: osx
@@ -293,7 +297,7 @@ jobs:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -305,7 +309,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
@@ -389,7 +393,7 @@ jobs:
         - MB_PYTHON_VERSION=3.6
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
       cache:
         directories: $HOME/.ccache
     - os: linux
@@ -401,7 +405,7 @@ jobs:
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
@@ -483,7 +487,7 @@ jobs:
       services: docker
       env:
         - MB_PYTHON_VERSION=3.6
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
       cache:
@@ -495,7 +499,7 @@ jobs:
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
         - USE_CCACHE=0
@@ -580,7 +584,7 @@ jobs:
       services: docker
       env:
         - MB_PYTHON_VERSION=3.6
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
       cache:
@@ -592,7 +596,7 @@ jobs:
       env:
         - MB_PYTHON_VERSION=3.6
         - PLAT=i686
-        - TEST_DEPENDS=numpy==1.11.3
+        - TEST_DEPENDS=numpy==1.13.3
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
         - USE_CCACHE=0

From 4049947cdac87c7c75126b0c0c5f93c44bbc9754 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 9 Aug 2020 16:28:22 +0300
Subject: [PATCH 406/566] fix sdist upload

---
 .travis.yml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 19072fca..6355aaa0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -760,12 +760,12 @@ after_success: |
       fi
 
       if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-        pip install --user twine
-        pip install --user --upgrade six
-
         if [[ $SDIST == 1 ]]; then
+          pip install twine
           twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
         else
+          pip install --user twine
+          pip install --user --upgrade six
           twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi
 

From bad5cb13d9f992bbce540b3bef9b33c512201be7 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 9 Aug 2020 16:28:22 +0300
Subject: [PATCH 407/566] fix sdist upload

---
 .travis.yml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 19072fca..6355aaa0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -760,12 +760,12 @@ after_success: |
       fi
 
       if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-        pip install --user twine
-        pip install --user --upgrade six
-
         if [[ $SDIST == 1 ]]; then
+          pip install twine
           twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
         else
+          pip install --user twine
+          pip install --user --upgrade six
           twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi
 

From 469036736e22d2f1e6e08e5de096b74c64f4f794 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 9 Aug 2020 19:21:00 +0300
Subject: [PATCH 408/566] fix twine upload command

---
 .travis.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 6355aaa0..4f77cd77 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -779,9 +779,9 @@ after_success: |
         /usr/bin/python -m pip install --user -U -I twine
 
         if [[ $SDIST == 1 ]]; then
-          /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
+          /usr/bin/python -m twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
         else
-          /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
+          /usr/bin/python -m twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi
 
       fi

From 8d5aa2b7e3243121acf1657491594b9a295ed963 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 9 Aug 2020 19:21:00 +0300
Subject: [PATCH 409/566] fix twine upload command

---
 .travis.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 6355aaa0..4f77cd77 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -779,9 +779,9 @@ after_success: |
         /usr/bin/python -m pip install --user -U -I twine
 
         if [[ $SDIST == 1 ]]; then
-          /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
+          /usr/bin/python -m twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
         else
-          /usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
+          /usr/bin/python -m twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi
 
       fi

From 80e63d48392bb86b2fe35fc8593a314fc239e34a Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 10 Aug 2020 16:50:22 +0300
Subject: [PATCH 410/566] fix the travis USER issue

---
 .travis.yml      | 8 ++++----
 travis_config.sh | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 4f77cd77..81cc9d87 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -762,11 +762,11 @@ after_success: |
       if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
         if [[ $SDIST == 1 ]]; then
           pip install twine
-          twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
+          twine upload -u ${PYPI_USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
         else
           pip install --user twine
           pip install --user --upgrade six
-          twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
+          twine upload -u ${PYPI_USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi
 
       fi
@@ -779,9 +779,9 @@ after_success: |
         /usr/bin/python -m pip install --user -U -I twine
 
         if [[ $SDIST == 1 ]]; then
-          /usr/bin/python -m twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
+          /usr/bin/python -m twine upload -u ${PYPI_USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
         else
-          /usr/bin/python -m twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
+          /usr/bin/python -m twine upload -u ${PYPI_USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi
 
       fi
diff --git a/travis_config.sh b/travis_config.sh
index 3cf99356..59f82bbb 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -92,7 +92,7 @@ function pre_build {
     echo "Running for OSX"
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
-    export USER=travis
+
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then
         brew update

From 54b7720b45cfc564201a73dc428efba6ffe3129f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 10 Aug 2020 16:55:46 +0300
Subject: [PATCH 411/566] OpenCV 3.4.11

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 1cc1e6fa..e8d4259f 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 1cc1e6fa563f160b54f9c62da965002cab55ca96
+Subproject commit e8d4259f9ab787b512b9aa1203fc816fb9f19231
diff --git a/opencv_contrib b/opencv_contrib
index 5d2cf95a..3ce9ec6c 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 5d2cf95afce53d1f742117ae39c9189a0ae4b4dd
+Subproject commit 3ce9ec6c827b7b715ba9f7282f5670925c903b56

From a70c89ab9d746bca6b14b3cfe53f59cc4a02054b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 10 Aug 2020 16:57:02 +0300
Subject: [PATCH 412/566] add minimum supported Python version

---
 setup.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index f3b209b3..54aa5988 100644
--- a/setup.py
+++ b/setup.py
@@ -220,6 +220,7 @@ def main():
         maintainer="Olli-Pekka Heinisuo",
         ext_modules=EmptyListWithLength(),
         install_requires=numpy_version,
+        python_requires=">=3.5",
         classifiers=[
             "Development Status :: 5 - Production/Stable",
             "Environment :: Console",

From 8dc7a8db242cc98c0bfd7331cb03da467b995dbc Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 10 Aug 2020 16:50:22 +0300
Subject: [PATCH 413/566] fix the travis USER issue

---
 .travis.yml      | 8 ++++----
 travis_config.sh | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 4f77cd77..81cc9d87 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -762,11 +762,11 @@ after_success: |
       if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
         if [[ $SDIST == 1 ]]; then
           pip install twine
-          twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
+          twine upload -u ${PYPI_USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
         else
           pip install --user twine
           pip install --user --upgrade six
-          twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
+          twine upload -u ${PYPI_USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi
 
       fi
@@ -779,9 +779,9 @@ after_success: |
         /usr/bin/python -m pip install --user -U -I twine
 
         if [[ $SDIST == 1 ]]; then
-          /usr/bin/python -m twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
+          /usr/bin/python -m twine upload -u ${PYPI_USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
         else
-          /usr/bin/python -m twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
+          /usr/bin/python -m twine upload -u ${PYPI_USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
         fi
 
       fi
diff --git a/travis_config.sh b/travis_config.sh
index 3cf99356..59f82bbb 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -92,7 +92,7 @@ function pre_build {
     echo "Running for OSX"
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
-    export USER=travis
+
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then
         brew update

From 633e1cf3851b96a7fecc9703d0fda66f001f908c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 10 Aug 2020 16:57:02 +0300
Subject: [PATCH 414/566] add minimum supported Python version

---
 setup.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index 432f01cc..23584249 100644
--- a/setup.py
+++ b/setup.py
@@ -220,6 +220,7 @@ def main():
         maintainer="Olli-Pekka Heinisuo",
         ext_modules=EmptyListWithLength(),
         install_requires=numpy_version,
+        python_requires=">=3.5",
         classifiers=[
             "Development Status :: 5 - Production/Stable",
             "Environment :: Console",

From f073b0083541a90d53098c855bed9d6f3a879d65 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 10 Aug 2020 17:01:39 +0300
Subject: [PATCH 415/566] OpenCV 4.4.0

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index 01b2c5a7..c3bb57af 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 01b2c5a77ca6dbef3baef24ebc0a5984579231d9
+Subproject commit c3bb57afeaf030f10939204d48d7c2a3842f4293
diff --git a/opencv_contrib b/opencv_contrib
index e6f32c6a..5fae4082 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit e6f32c6a69043456a806a4e802ee3ce7b7059c93
+Subproject commit 5fae4082cc493efa5cb7a7486f9e009618a5198b

From f78c6a5160e00c085524f1bb3a98dc2b47f58767 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Tue, 11 Aug 2020 13:57:43 +0300
Subject: [PATCH 416/566] Add note about manylinux2014

---
 README.md | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 513520e4..e0caf36f 100644
--- a/README.md
+++ b/README.md
@@ -42,7 +42,11 @@ Frequently Asked Questions
 
 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 ...``?**
+**Q: Pip install fails with ``ModuleNotFoundError: No module named 'skbuild'``?**
+
+Since ``opencv-python`` version 3.4.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 3.4.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: Pip install 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/.
 

From 8a23c55330bf45ba03c821c527f2b5a96b14fc87 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Tue, 11 Aug 2020 13:57:43 +0300
Subject: [PATCH 417/566] Add note about manylinux2014

---
 README.md | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 513520e4..e0caf36f 100644
--- a/README.md
+++ b/README.md
@@ -42,7 +42,11 @@ Frequently Asked Questions
 
 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 ...``?**
+**Q: Pip install fails with ``ModuleNotFoundError: No module named 'skbuild'``?**
+
+Since ``opencv-python`` version 3.4.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 3.4.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: Pip install 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/.
 

From b68716e5b4276e2d057cee034c8716f1605d72df Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 11 Aug 2020 17:33:52 +0300
Subject: [PATCH 418/566] fix typo in version

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index e0caf36f..5ba434bf 100644
--- a/README.md
+++ b/README.md
@@ -44,7 +44,7 @@ A: No, the packages are special wheel binary packages and they already contain s
 
 **Q: Pip install fails with ``ModuleNotFoundError: No module named 'skbuild'``?**
 
-Since ``opencv-python`` version 3.4.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 3.4.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``.
+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 3.4.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: Pip install fails with ``Could not find a version that satisfies the requirement ...``?**
 

From e29f6f4c8c9ec356aea5be9a620c8c3e2884ab24 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 11 Aug 2020 17:33:52 +0300
Subject: [PATCH 419/566] fix typo in version

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index e0caf36f..5ba434bf 100644
--- a/README.md
+++ b/README.md
@@ -44,7 +44,7 @@ A: No, the packages are special wheel binary packages and they already contain s
 
 **Q: Pip install fails with ``ModuleNotFoundError: No module named 'skbuild'``?**
 
-Since ``opencv-python`` version 3.4.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 3.4.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``.
+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 3.4.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: Pip install fails with ``Could not find a version that satisfies the requirement ...``?**
 

From 3c332dfa4f613e3dc8cabd013b68c40243489198 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 11 Aug 2020 17:36:32 +0300
Subject: [PATCH 420/566] another typo

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 5ba434bf..946880d6 100644
--- a/README.md
+++ b/README.md
@@ -44,7 +44,7 @@ A: No, the packages are special wheel binary packages and they already contain s
 
 **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 3.4.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``.
+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: Pip install fails with ``Could not find a version that satisfies the requirement ...``?**
 

From d356af12a31fbcb6b7a82372555a7569639bb483 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 11 Aug 2020 17:36:32 +0300
Subject: [PATCH 421/566] another typo

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 5ba434bf..946880d6 100644
--- a/README.md
+++ b/README.md
@@ -44,7 +44,7 @@ A: No, the packages are special wheel binary packages and they already contain s
 
 **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 3.4.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``.
+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: Pip install fails with ``Could not find a version that satisfies the requirement ...``?**
 

From 0c349095f8f5263b277af407bae30ea0c864eb03 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 14 Aug 2020 18:26:23 +0300
Subject: [PATCH 422/566] add aarch64 Dockerfile

---
 docker/manylinux2014/Dockerfile_aarch64 | 66 +++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 docker/manylinux2014/Dockerfile_aarch64

diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
new file mode 100644
index 00000000..77af8a8a
--- /dev/null
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -0,0 +1,66 @@
+FROM quay.io/pypa/manylinux2014_aarch64:latest
+
+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
+
+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 && \
+    tar -xf qt-everywhere-src-5.15.0.tar.xz && \
+    cd qt-everywhere* && \
+    export MAKEFLAGS=-j$(nproc) && \
+    ./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 && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf qt-everywhere-src-5.15.0 && \
+    rm qt-everywhere-src-5.15.0.tar.xz
+
+ENV QTDIR /opt/Qt5.15.0
+ENV PATH "$QTDIR/bin:$PATH"
+
+RUN mkdir ~/ffmpeg_sources && \
+    cd ~/ffmpeg_sources && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
+    tar -xf OpenSSL_1_1_1c.tar.gz && \
+    cd openssl-OpenSSL_1_1_1c && \
+    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    # skip installing documentation
+    make install_sw && \
+    rm -rf ~/openssl_build
+
+RUN cd ~/ffmpeg_sources && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.14.01/nasm-2.14.01.tar.bz2 && \
+    tar -xf nasm-2.14.01.tar.bz2 && cd nasm-2.14.01 && ./autogen.sh && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN cd ~/ffmpeg_sources && \
+    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
+    tar -xf yasm-1.3.0.tar.gz && \
+    cd yasm-1.3.0 && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN cd ~/ffmpeg_sources && \
+    git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
+    cd libvpx && \
+    ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN cd ~/ffmpeg_sources && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
+    tar -xf ffmpeg-snapshot.tar.bz2 && \
+    cd ffmpeg && \
+    PATH=~/bin:$PATH && \
+    PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install && \
+    echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
+    ldconfig && \
+    rm -rf ~/ffmpeg_sources
+
+ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
+ENV LDFLAGS -L/root/ffmpeg_build/lib
+ENV PATH "$HOME/bin:$PATH"

From 24d580492217ed83d9f364892cc5bd9ee4b6b38e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 14 Aug 2020 18:34:28 +0300
Subject: [PATCH 423/566] force Qt 5.13

---
 travis_config.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index 59f82bbb..ba183b3b 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -14,7 +14,7 @@ function bdist_wheel_cmd {
     # copied from multibuild's common_utils.sh
     # add osx deployment target so it doesnt default to 10.6
     local abs_wheelhouse=$1
-    CI_BUILD=1 pip wheel --wheel-dir="$PWD/dist" . $BDIST_PARAMS
+    CI_BUILD=1 pip wheel --verbose --wheel-dir="$PWD/dist" . $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
     if [ -z "$IS_OSX" ]; then
       /opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py
@@ -102,9 +102,9 @@ function pre_build {
 
     echo 'Installing qt5'
     if [ -n "$CACHE_STAGE" ]; then
-        brew_install_and_cache_within_time_limit qt5 || { [ $? -gt 1 ] && return 2 || return 0; }
+        echo "Qt5 has bottle, no caching needed"
     else
-        brew install qt5
+        brew install qt@5.13
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 
@@ -114,7 +114,7 @@ function pre_build {
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew unlink python@2
-        brew install -vd ffmpeg_opencv
+        brew install ffmpeg_opencv
     fi
 
     if [ -n "$CACHE_STAGE" ]; then

From a055e92a53b3d89c07050013c5563606e5d8b3d7 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 14 Aug 2020 18:26:23 +0300
Subject: [PATCH 424/566] add aarch64 Dockerfile

---
 docker/manylinux2014/Dockerfile_aarch64 | 66 +++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 docker/manylinux2014/Dockerfile_aarch64

diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
new file mode 100644
index 00000000..77af8a8a
--- /dev/null
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -0,0 +1,66 @@
+FROM quay.io/pypa/manylinux2014_aarch64:latest
+
+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
+
+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 && \
+    tar -xf qt-everywhere-src-5.15.0.tar.xz && \
+    cd qt-everywhere* && \
+    export MAKEFLAGS=-j$(nproc) && \
+    ./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 && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf qt-everywhere-src-5.15.0 && \
+    rm qt-everywhere-src-5.15.0.tar.xz
+
+ENV QTDIR /opt/Qt5.15.0
+ENV PATH "$QTDIR/bin:$PATH"
+
+RUN mkdir ~/ffmpeg_sources && \
+    cd ~/ffmpeg_sources && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
+    tar -xf OpenSSL_1_1_1c.tar.gz && \
+    cd openssl-OpenSSL_1_1_1c && \
+    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    # skip installing documentation
+    make install_sw && \
+    rm -rf ~/openssl_build
+
+RUN cd ~/ffmpeg_sources && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.14.01/nasm-2.14.01.tar.bz2 && \
+    tar -xf nasm-2.14.01.tar.bz2 && cd nasm-2.14.01 && ./autogen.sh && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN cd ~/ffmpeg_sources && \
+    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
+    tar -xf yasm-1.3.0.tar.gz && \
+    cd yasm-1.3.0 && \
+    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN cd ~/ffmpeg_sources && \
+    git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
+    cd libvpx && \
+    ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN cd ~/ffmpeg_sources && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
+    tar -xf ffmpeg-snapshot.tar.bz2 && \
+    cd ffmpeg && \
+    PATH=~/bin:$PATH && \
+    PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install && \
+    echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
+    ldconfig && \
+    rm -rf ~/ffmpeg_sources
+
+ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
+ENV LDFLAGS -L/root/ffmpeg_build/lib
+ENV PATH "$HOME/bin:$PATH"

From 207e183ceb0055e1437bfa79ad3823357373afb8 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 14 Aug 2020 18:34:28 +0300
Subject: [PATCH 425/566] force Qt 5.13

---
 travis_config.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index 59f82bbb..ba183b3b 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -14,7 +14,7 @@ function bdist_wheel_cmd {
     # copied from multibuild's common_utils.sh
     # add osx deployment target so it doesnt default to 10.6
     local abs_wheelhouse=$1
-    CI_BUILD=1 pip wheel --wheel-dir="$PWD/dist" . $BDIST_PARAMS
+    CI_BUILD=1 pip wheel --verbose --wheel-dir="$PWD/dist" . $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
     if [ -z "$IS_OSX" ]; then
       /opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py
@@ -102,9 +102,9 @@ function pre_build {
 
     echo 'Installing qt5'
     if [ -n "$CACHE_STAGE" ]; then
-        brew_install_and_cache_within_time_limit qt5 || { [ $? -gt 1 ] && return 2 || return 0; }
+        echo "Qt5 has bottle, no caching needed"
     else
-        brew install qt5
+        brew install qt@5.13
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 
@@ -114,7 +114,7 @@ function pre_build {
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew unlink python@2
-        brew install -vd ffmpeg_opencv
+        brew install ffmpeg_opencv
     fi
 
     if [ -n "$CACHE_STAGE" ]; then

From 436e8f2b6f8438f50a793fdc0be3f7d08bf1af31 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 14 Aug 2020 21:11:45 +0300
Subject: [PATCH 426/566] 5.13.2

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index ba183b3b..e4f2c187 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -104,7 +104,7 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         echo "Qt5 has bottle, no caching needed"
     else
-        brew install qt@5.13
+        brew install qt@5.13.2
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 

From 4e5ea42d32c77a8e58c0ca63c825a73be6c9c2a7 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 14 Aug 2020 21:11:45 +0300
Subject: [PATCH 427/566] 5.13.2

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index ba183b3b..e4f2c187 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -104,7 +104,7 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         echo "Qt5 has bottle, no caching needed"
     else
-        brew install qt@5.13
+        brew install qt@5.13.2
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 

From f9b4c3ba9d5c7de596fa3625a2c14f423714f25c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 14 Aug 2020 23:18:31 +0300
Subject: [PATCH 428/566] direct link

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index e4f2c187..10bea551 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -104,7 +104,7 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         echo "Qt5 has bottle, no caching needed"
     else
-        brew install qt@5.13.2
+        brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 

From 67699a29b960bbde451ad14e43b8cb20e414a71d Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 14 Aug 2020 23:18:31 +0300
Subject: [PATCH 429/566] direct link

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index e4f2c187..10bea551 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -104,7 +104,7 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         echo "Qt5 has bottle, no caching needed"
     else
-        brew install qt@5.13.2
+        brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 

From 72f10b4c4a85bca743ca5844d38ef6307ace7964 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 15 Aug 2020 00:23:33 +0300
Subject: [PATCH 430/566] no auto update, use extract

---
 travis_config.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index 10bea551..8f13ca2b 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -92,6 +92,7 @@ function pre_build {
     echo "Running for OSX"
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
+    export HOMEBREW_NO_AUTO_UPDATE=1
 
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then
@@ -104,7 +105,8 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         echo "Qt5 has bottle, no caching needed"
     else
-        brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
+        brew extract qt --version=5.13.2
+        brew install qt@5.13.2
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 

From 0fca5426aa7dd52d9d5b0ba6b00aa61c649299cb Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 15 Aug 2020 00:23:33 +0300
Subject: [PATCH 431/566] no auto update, use extract

---
 travis_config.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index 10bea551..8f13ca2b 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -92,6 +92,7 @@ function pre_build {
     echo "Running for OSX"
 
     local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
+    export HOMEBREW_NO_AUTO_UPDATE=1
 
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
     if [ -n "$CACHE_STAGE" ]; then
@@ -104,7 +105,8 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         echo "Qt5 has bottle, no caching needed"
     else
-        brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
+        brew extract qt --version=5.13.2
+        brew install qt@5.13.2
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 

From 21be118bee9c3519cbb64aa5ef80dce7f3737f0b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 15 Aug 2020 01:13:26 +0300
Subject: [PATCH 432/566] just use the raw url directly

---
 travis_config.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index 8f13ca2b..9913c87e 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -105,8 +105,7 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         echo "Qt5 has bottle, no caching needed"
     else
-        brew extract qt --version=5.13.2
-        brew install qt@5.13.2
+        brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 

From e3cc9a8f14473b7cdeac373429e15a8bc66d73ce Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 15 Aug 2020 01:13:26 +0300
Subject: [PATCH 433/566] just use the raw url directly

---
 travis_config.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index 8f13ca2b..9913c87e 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -105,8 +105,7 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         echo "Qt5 has bottle, no caching needed"
     else
-        brew extract qt --version=5.13.2
-        brew install qt@5.13.2
+        brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 

From ebfac6b2034edc2b0e4de1746ddc0570a0d17ba2 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 16 Aug 2020 13:02:06 +0300
Subject: [PATCH 434/566] unlink and reinstall

---
 travis_config.sh | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index 9913c87e..ff07ae7d 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -101,14 +101,6 @@ function pre_build {
         brew_add_local_bottles
     fi
 
-    echo 'Installing qt5'
-    if [ -n "$CACHE_STAGE" ]; then
-        echo "Qt5 has bottle, no caching needed"
-    else
-        brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
-        export PATH="/usr/local/opt/qt/bin:$PATH"
-    fi
-
     echo 'Installing FFmpeg'
 
     if [ -n "$CACHE_STAGE" ]; then
@@ -118,6 +110,16 @@ function pre_build {
         brew install ffmpeg_opencv
     fi
 
+    echo 'Installing qt5'
+    
+    if [ -n "$CACHE_STAGE" ]; then
+        echo "Qt5 has bottle, no caching needed"
+    else
+        brew unlink qt
+        brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
+        export PATH="/usr/local/opt/qt/bin:$PATH"
+    fi
+
     if [ -n "$CACHE_STAGE" ]; then
         brew_go_bootstrap_mode 0
         return 0

From d53115c6848859005a7b3532b31473a95dd28b9f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 16 Aug 2020 13:02:06 +0300
Subject: [PATCH 435/566] unlink and reinstall

---
 travis_config.sh | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index 9913c87e..ff07ae7d 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -101,14 +101,6 @@ function pre_build {
         brew_add_local_bottles
     fi
 
-    echo 'Installing qt5'
-    if [ -n "$CACHE_STAGE" ]; then
-        echo "Qt5 has bottle, no caching needed"
-    else
-        brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
-        export PATH="/usr/local/opt/qt/bin:$PATH"
-    fi
-
     echo 'Installing FFmpeg'
 
     if [ -n "$CACHE_STAGE" ]; then
@@ -118,6 +110,16 @@ function pre_build {
         brew install ffmpeg_opencv
     fi
 
+    echo 'Installing qt5'
+    
+    if [ -n "$CACHE_STAGE" ]; then
+        echo "Qt5 has bottle, no caching needed"
+    else
+        brew unlink qt
+        brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
+        export PATH="/usr/local/opt/qt/bin:$PATH"
+    fi
+
     if [ -n "$CACHE_STAGE" ]; then
         brew_go_bootstrap_mode 0
         return 0

From 798a68964bc1953da8b6776b0c17ba3497c75666 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 16 Aug 2020 14:17:18 +0300
Subject: [PATCH 436/566] force qt uninstall

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index ff07ae7d..d5a1989b 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -115,7 +115,7 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         echo "Qt5 has bottle, no caching needed"
     else
-        brew unlink qt
+        brew uninstall --force qt@5.15.0
         brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi

From b0225dd657ac94dfb9e549ca3d6dc574837a23a6 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 16 Aug 2020 14:17:18 +0300
Subject: [PATCH 437/566] force qt uninstall

---
 travis_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index ff07ae7d..d5a1989b 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -115,7 +115,7 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         echo "Qt5 has bottle, no caching needed"
     else
-        brew unlink qt
+        brew uninstall --force qt@5.15.0
         brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi

From 8dc0f4d8b3f49f4bf5ada0fdeb048406fd0cc7f8 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 16 Aug 2020 16:17:17 +0300
Subject: [PATCH 438/566] use switch instead

---
 travis_config.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index d5a1989b..6f9f6511 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -115,8 +115,8 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         echo "Qt5 has bottle, no caching needed"
     else
-        brew uninstall --force qt@5.15.0
-        brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
+        brew switch qt 5.13.2
+        brew pin qt
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 

From 97642d5a01c25aad40db0badfbe2c941ad931b38 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 16 Aug 2020 16:17:17 +0300
Subject: [PATCH 439/566] use switch instead

---
 travis_config.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/travis_config.sh b/travis_config.sh
index d5a1989b..6f9f6511 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -115,8 +115,8 @@ function pre_build {
     if [ -n "$CACHE_STAGE" ]; then
         echo "Qt5 has bottle, no caching needed"
     else
-        brew uninstall --force qt@5.15.0
-        brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/079ce55db79acc87b91bec950249595b1584e119/Formula/qt.rb
+        brew switch qt 5.13.2
+        brew pin qt
         export PATH="/usr/local/opt/qt/bin:$PATH"
     fi
 

From 6454d369fcc90b848d3b71d08cc7f4335c92c9ad Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 17 Aug 2020 19:24:42 +0300
Subject: [PATCH 440/566] drop Python 3.5 support

---
 .travis.yml  | 121 +++------------------------------------------------
 appveyor.yml |  32 --------------
 setup.py     |   3 +-
 3 files changed, 6 insertions(+), 150 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 81cc9d87..f79e1907 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -103,15 +103,6 @@ jobs:
     # default builds for MacOS
       #further jobs in the list will use the same stage until the next assignment
     - stage: final
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      workspaces:
-        use: brew_cache
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -144,15 +135,6 @@ jobs:
         use: brew_cache
 
     # headless builds for MacOS
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      workspaces:
-        use: brew_cache
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -185,15 +167,6 @@ jobs:
         use: brew_cache
 
     # Contrib builds for MacOS
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      workspaces:
-        use: brew_cache
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -226,15 +199,6 @@ jobs:
         use: brew_cache
 
     # headless contrib builds for MacOS
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      workspaces:
-        use: brew_cache
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -267,28 +231,6 @@ jobs:
         use: brew_cache
 
     # default builds for Linux
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -361,30 +303,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-
-    # headless builds for Linux
     - os: linux
       language: generic
       dist: xenial
       services: docker
       env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
+        - MB_PYTHON_VERSION=3.8
         - PLAT=i686
         - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.17.3
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+
+    # headless builds for Linux
     - os: linux
       language: generic
       dist: xenial
@@ -459,28 +392,6 @@ jobs:
         directories: $HOME/.ccache
 
     # contrib builds for Linux
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - PLAT=i686
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -556,28 +467,6 @@ jobs:
 
 
     # headless contrib builds for Linux
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - PLAT=i686
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
diff --git a/appveyor.yml b/appveyor.yml
index 8b058c68..3dde3d23 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -6,14 +6,6 @@ environment:
     secure: 0bXSOVjf9x8L7nErTivu92TF1FwNosTjFJQPmxp8Dys=
 
   matrix:
-    - PYTHON: "C:/Python35"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python35-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
@@ -38,14 +30,6 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python35"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python35-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
@@ -70,14 +54,6 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python35"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python35-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
@@ -102,14 +78,6 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python35"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python35-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
diff --git a/setup.py b/setup.py
index 23584249..86a7667a 100644
--- a/setup.py
+++ b/setup.py
@@ -220,7 +220,7 @@ def main():
         maintainer="Olli-Pekka Heinisuo",
         ext_modules=EmptyListWithLength(),
         install_requires=numpy_version,
-        python_requires=">=3.5",
+        python_requires=">=3.6",
         classifiers=[
             "Development Status :: 5 - Production/Stable",
             "Environment :: Console",
@@ -235,7 +235,6 @@ def main():
             "Operating System :: Unix",
             "Programming Language :: Python",
             "Programming Language :: Python :: 3",
-            "Programming Language :: Python :: 3.5",
             "Programming Language :: Python :: 3.6",
             "Programming Language :: Python :: 3.7",
             "Programming Language :: Python :: 3.8",

From 928952d99a2be5c0c20e5a0de1df9b4ea3891ce2 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 17 Aug 2020 19:24:42 +0300
Subject: [PATCH 441/566] drop Python 3.5 support

---
 .travis.yml  | 121 +++------------------------------------------------
 appveyor.yml |  32 --------------
 setup.py     |   3 +-
 3 files changed, 6 insertions(+), 150 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 81cc9d87..f79e1907 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -103,15 +103,6 @@ jobs:
     # default builds for MacOS
       #further jobs in the list will use the same stage until the next assignment
     - stage: final
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      workspaces:
-        use: brew_cache
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -144,15 +135,6 @@ jobs:
         use: brew_cache
 
     # headless builds for MacOS
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      workspaces:
-        use: brew_cache
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -185,15 +167,6 @@ jobs:
         use: brew_cache
 
     # Contrib builds for MacOS
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      workspaces:
-        use: brew_cache
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -226,15 +199,6 @@ jobs:
         use: brew_cache
 
     # headless contrib builds for MacOS
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      workspaces:
-        use: brew_cache
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -267,28 +231,6 @@ jobs:
         use: brew_cache
 
     # default builds for Linux
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -361,30 +303,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-
-    # headless builds for Linux
     - os: linux
       language: generic
       dist: xenial
       services: docker
       env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
+        - MB_PYTHON_VERSION=3.8
         - PLAT=i686
         - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.17.3
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+
+    # headless builds for Linux
     - os: linux
       language: generic
       dist: xenial
@@ -459,28 +392,6 @@ jobs:
         directories: $HOME/.ccache
 
     # contrib builds for Linux
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - PLAT=i686
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -556,28 +467,6 @@ jobs:
 
 
     # headless contrib builds for Linux
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.5
-        - PLAT=i686
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
diff --git a/appveyor.yml b/appveyor.yml
index 8b058c68..3dde3d23 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -6,14 +6,6 @@ environment:
     secure: 0bXSOVjf9x8L7nErTivu92TF1FwNosTjFJQPmxp8Dys=
 
   matrix:
-    - PYTHON: "C:/Python35"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python35-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
@@ -38,14 +30,6 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python35"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python35-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
@@ -70,14 +54,6 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python35"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python35-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
@@ -102,14 +78,6 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python35"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python35-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
diff --git a/setup.py b/setup.py
index 54aa5988..212dbfcb 100644
--- a/setup.py
+++ b/setup.py
@@ -220,7 +220,7 @@ def main():
         maintainer="Olli-Pekka Heinisuo",
         ext_modules=EmptyListWithLength(),
         install_requires=numpy_version,
-        python_requires=">=3.5",
+        python_requires=">=3.6",
         classifiers=[
             "Development Status :: 5 - Production/Stable",
             "Environment :: Console",
@@ -235,7 +235,6 @@ def main():
             "Operating System :: Unix",
             "Programming Language :: Python",
             "Programming Language :: Python :: 3",
-            "Programming Language :: Python :: 3.5",
             "Programming Language :: Python :: 3.6",
             "Programming Language :: Python :: 3.7",
             "Programming Language :: Python :: 3.8",

From a82d7dd005d316e9e56ff8778dff01aec9f2ecb6 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 17 Aug 2020 19:40:24 +0300
Subject: [PATCH 442/566] test aarch64 build

---
 .travis.yml | 14 ++++++++++++++
 README.md   |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index f79e1907..acddcd8c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -316,6 +316,20 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - PLAT=aarch64
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.17.3
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
 
     # headless builds for Linux
     - os: linux
diff --git a/README.md b/README.md
index 946880d6..9061185c 100644
--- a/README.md
+++ b/README.md
@@ -77,7 +77,7 @@ A: It's easier for users to understand ``opencv-python`` than ``cv2`` and it mak
 ## Documentation for opencv-python
 
 [![AppVeyor CI test status (Windows)](https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows)](https://ci.appveyor.com/project/skvark/opencv-python)
-[![Travis CI test status (Linux and macOS)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label=Linux+macOS)](https://travis-ci.org/skvark/opencv-python)
+[![Travis CI test status (Linux and macOS)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label=Linux+macOS)](https://travis-ci.com/skvark/opencv-python.svg?branch=master)
 
 The aim of this repository is to provide means to package each new [OpenCV release](https://github.com/opencv/opencv/releases) for the most used Python versions and platforms.
 

From 5373fcc74fbad2ecde983a1ec568387ba9091896 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 17 Aug 2020 19:49:27 +0300
Subject: [PATCH 443/566] aarch64 needs to be rebuilt with cmake

---
 .travis.yml | 14 --------------
 README.md   |  2 +-
 2 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index acddcd8c..f79e1907 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -316,20 +316,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - PLAT=aarch64
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.17.3
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
 
     # headless builds for Linux
     - os: linux
diff --git a/README.md b/README.md
index 9061185c..b4ae108b 100644
--- a/README.md
+++ b/README.md
@@ -77,7 +77,7 @@ A: It's easier for users to understand ``opencv-python`` than ``cv2`` and it mak
 ## Documentation for opencv-python
 
 [![AppVeyor CI test status (Windows)](https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows)](https://ci.appveyor.com/project/skvark/opencv-python)
-[![Travis CI test status (Linux and macOS)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label=Linux+macOS)](https://travis-ci.com/skvark/opencv-python.svg?branch=master)
+[![Travis CI test status (Linux and macOS)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label=Linux+macOS)](https://travis-ci.com/github/skvark/opencv-python/)
 
 The aim of this repository is to provide means to package each new [OpenCV release](https://github.com/opencv/opencv/releases) for the most used Python versions and platforms.
 

From ab3674510b99ea1508e532078de6b6a990e0ccf6 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 17 Aug 2020 19:51:45 +0300
Subject: [PATCH 444/566] add ccache and cmake to aarch64 Dockerfile (requires
 rebuild)

---
 docker/manylinux2014/Dockerfile_aarch64 | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
index 77af8a8a..6d63116b 100644
--- a/docker/manylinux2014/Dockerfile_aarch64
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -61,6 +61,23 @@ RUN cd ~/ffmpeg_sources && \
     ldconfig && \
     rm -rf ~/ffmpeg_sources
 
+RUN curl -O -L https://github.com/ccache/ccache/releases/download/v3.7.9/ccache-3.7.9.tar.gz && \
+    tar -xf ccache-3.7.9.tar.gz && \
+    cd ccache-3.7.9 && \
+    linux32 ./configure && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install
+
+RUN curl -O -L https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-3.17.0.tar.gz && \
+    tar -xf cmake-3.17.0.tar.gz && \
+    cd cmake-3.17.0 && \
+    export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
+    ./configure --system-curl && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf cmake-3.17.0*
+
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 ENV PATH "$HOME/bin:$PATH"

From e4893f2c66f9087921ca4f1ca17d15acd1cadb4e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 17 Aug 2020 19:54:47 +0300
Subject: [PATCH 445/566] update README [skip ci]

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index b4ae108b..787aea38 100644
--- a/README.md
+++ b/README.md
@@ -77,7 +77,7 @@ A: It's easier for users to understand ``opencv-python`` than ``cv2`` and it mak
 ## Documentation for opencv-python
 
 [![AppVeyor CI test status (Windows)](https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows)](https://ci.appveyor.com/project/skvark/opencv-python)
-[![Travis CI test status (Linux and macOS)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label=Linux+macOS)](https://travis-ci.com/github/skvark/opencv-python/)
+[![Travis CI test status (Linux and macOS)](https://img.shields.io/travis/com/skvark/opencv-python/master?label=Linux%20%26%20macOS)](https://travis-ci.com/github/skvark/opencv-python/)
 
 The aim of this repository is to provide means to package each new [OpenCV release](https://github.com/opencv/opencv/releases) for the most used Python versions and platforms.
 

From 099ed15c17810affaa42fcd8eb151222a141a31d Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Wed, 26 Aug 2020 22:24:41 +0300
Subject: [PATCH 446/566] Make the README more clear

---
 README.md | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md
index 787aea38..6a32427b 100644
--- a/README.md
+++ b/README.md
@@ -2,28 +2,31 @@
 
 ## OpenCV on Wheels
 
-**Unofficial** pre-built OpenCV packages for Python.
+**Unofficial** 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. Select the correct package for your environment:
+2. Make sure that your `pip` version is at minimum 19.3: `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 expecially with the `manylinux` format.
+3. 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 with ``pip uninstall`` and reinstall only one package.
+    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)
 
-    - 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](https://docs.opencv.org/master/))
+    - 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](https://docs.opencv.org/master/))
 
-    **b.** Packages for server (headless) environments
+    **b.** Packages for server (headless) environments (such as Docker, cloud environments etc.)
 
-    These packages do not contain any GUI functionality. They are smaller and suitable for more restricted environments.
+    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 than OpenCV to create your GUI.
 
-    - 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](https://docs.opencv.org/master/))
+    - 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](https://docs.opencv.org/master/))
 
-3. Import the package:
+4. Import the package:
 
     ``import cv2``
 

From 893430f3f88d9aaff6ab58e298ef66177708dde2 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Sun, 6 Sep 2020 02:03:55 +0300
Subject: [PATCH 447/566] add more guidance, fix typos, drop Python 3.5

---
 README.md | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/README.md b/README.md
index 6a32427b..94a30d4b 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ Check the manual build section if you wish to compile the bindings from source t
 ### 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 at minimum 19.3: `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 expecially with the `manylinux` format.
+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.
@@ -19,9 +19,9 @@ Check the manual build section if you wish to compile the bindings from source t
     - 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](https://docs.opencv.org/master/))
 
-    **b.** Packages for server (headless) environments (such as Docker, cloud environments etc.)
+    **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 than OpenCV to create your GUI.
+    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](https://docs.opencv.org/master/))
@@ -131,16 +131,18 @@ If some dependency is not enabled in the pre-built wheels, you can also run the
 
 1. Clone this repository: `git clone --recursive https://github.com/skvark/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 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`
-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``.
-     - Optional: on Linux use 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)
+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. You'll have the wheel file in the `dist` folder 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
 
 #### 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.
+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: 
 
@@ -149,7 +151,7 @@ You can also force ``pip`` to build the wheels from the source distribution. Som
 
 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. 
+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
 
@@ -187,17 +189,14 @@ These artifacts can't be and will not be uploaded to PyPI.
 
 ### Manylinux wheels
 
-Linux wheels are built using [manylinux](https://github.com/pypa/python-manylinux-demo). 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.
+Linux wheels are built using [manylinux2014](https://github.com/pypa/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](https://github.com/skvark/opencv-python/tree/master/docker) for more info.
+The default ``manylinux2014`` images have been extended with some OpenCV dependencies. See [Docker folder](https://github.com/skvark/opencv-python/tree/master/docker) for more info.
 
 ### Supported Python versions
 
-Python 3.x releases are provided for officially supported versions (not in EOL).
+Python 3.x compatible pre-built wheels are provided for the officially supported Python 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

From 4ee3929119e51245bf2a4f704c98716d4a2a6e02 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 20 Sep 2020 14:08:08 +0300
Subject: [PATCH 448/566] disable nodelete, see #381

---
 docker/manylinux2014/Dockerfile_aarch64 | 2 +-
 docker/manylinux2014/Dockerfile_i686    | 2 +-
 docker/manylinux2014/Dockerfile_x86_64  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
index 6d63116b..81823a1e 100644
--- a/docker/manylinux2014/Dockerfile_aarch64
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -21,7 +21,7 @@ RUN mkdir ~/ffmpeg_sources && \
     curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
     tar -xf OpenSSL_1_1_1c.tar.gz && \
     cd openssl-OpenSSL_1_1_1c && \
-    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib -DOPENSSL_USE_NODELETE=0 && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     # skip installing documentation
     make install_sw && \
diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index 8b217829..b1ad7739 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -23,7 +23,7 @@ RUN mkdir ~/ffmpeg_sources && \
     cd openssl-OpenSSL_1_1_1c && \
     # in i686, ./config detects x64 in i686 container without linux32
     # when run from "docker build"
-    linux32 ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+    linux32 ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib -DOPENSSL_USE_NODELETE=0 && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     #skip installing documentation
     make install_sw && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index cb14871c..94583bc3 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -21,7 +21,7 @@ RUN mkdir ~/ffmpeg_sources && \
     curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
     tar -xf OpenSSL_1_1_1c.tar.gz && \
     cd openssl-OpenSSL_1_1_1c && \
-    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
+    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib -DOPENSSL_USE_NODELETE=0 && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     # skip installing documentation
     make install_sw && \

From c001042fefc533f7a68c24c249972dcb2596305b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 20 Sep 2020 17:00:13 +0300
Subject: [PATCH 449/566] update openssl, no-pinshared, see #381

---
 docker/manylinux2014/Dockerfile_aarch64 | 8 ++++----
 docker/manylinux2014/Dockerfile_i686    | 8 ++++----
 docker/manylinux2014/Dockerfile_x86_64  | 8 ++++----
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
index 81823a1e..5fb47264 100644
--- a/docker/manylinux2014/Dockerfile_aarch64
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -18,10 +18,10 @@ ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
-    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
-    tar -xf OpenSSL_1_1_1c.tar.gz && \
-    cd openssl-OpenSSL_1_1_1c && \
-    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib -DOPENSSL_USE_NODELETE=0 && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1g.tar.gz && \
+    tar -xf OpenSSL_1_1_1g.tar.gz && \
+    cd openssl-OpenSSL_1_1_1g && \
+    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" no-pinshared shared zlib && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     # skip installing documentation
     make install_sw && \
diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index b1ad7739..39fc1560 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -18,12 +18,12 @@ ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
-    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
-    tar -xf OpenSSL_1_1_1c.tar.gz && \
-    cd openssl-OpenSSL_1_1_1c && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1g.tar.gz && \
+    tar -xf OpenSSL_1_1_1g.tar.gz && \
+    cd openssl-OpenSSL_1_1_1g && \
     # in i686, ./config detects x64 in i686 container without linux32
     # when run from "docker build"
-    linux32 ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib -DOPENSSL_USE_NODELETE=0 && \
+    linux32 ./config --prefix="$HOME/ffmpeg_build" no-pinshared shared zlib && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     #skip installing documentation
     make install_sw && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index 94583bc3..010120ca 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -18,10 +18,10 @@ ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
-    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
-    tar -xf OpenSSL_1_1_1c.tar.gz && \
-    cd openssl-OpenSSL_1_1_1c && \
-    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib -DOPENSSL_USE_NODELETE=0 && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1g.tar.gz && \
+    tar -xf OpenSSL_1_1_1g.tar.gz && \
+    cd openssl-OpenSSL_1_1_1g && \
+    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" no-pinshared shared zlib && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     # skip installing documentation
     make install_sw && \

From 22086f8713c2114fc50c085e3fb7c60523868b27 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 22 Sep 2020 16:31:45 +0300
Subject: [PATCH 450/566] remove file

---
 docker/manylinux2014/Dockerfile_aarch64.orig | 93 --------------------
 1 file changed, 93 deletions(-)
 delete mode 100644 docker/manylinux2014/Dockerfile_aarch64.orig

diff --git a/docker/manylinux2014/Dockerfile_aarch64.orig b/docker/manylinux2014/Dockerfile_aarch64.orig
deleted file mode 100644
index 6edc4cef..00000000
--- a/docker/manylinux2014/Dockerfile_aarch64.orig
+++ /dev/null
@@ -1,93 +0,0 @@
-FROM quay.io/pypa/manylinux2014_aarch64:latest
-
-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
-
-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 && \
-    tar -xf qt-everywhere-src-5.15.0.tar.xz && \
-    cd qt-everywhere* && \
-    export MAKEFLAGS=-j$(nproc) && \
-    ./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 && \
-    make && \
-    make install && \
-    cd .. && \
-    rm -rf qt-everywhere-src-5.15.0 && \
-    rm qt-everywhere-src-5.15.0.tar.xz
-
-ENV QTDIR /opt/Qt5.15.0
-ENV PATH "$QTDIR/bin:$PATH"
-
-RUN mkdir ~/ffmpeg_sources && \
-    cd ~/ffmpeg_sources && \
-<<<<<<< HEAD
-    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz && \
-    tar -xf OpenSSL_1_1_1c.tar.gz && \
-    cd openssl-OpenSSL_1_1_1c && \
-    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" shared zlib && \
-=======
-    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1g.tar.gz && \
-    tar -xf OpenSSL_1_1_1g.tar.gz && \
-    cd openssl-OpenSSL_1_1_1g && \
-    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" no-pinshared shared zlib && \
->>>>>>> master
-    make -j$(getconf _NPROCESSORS_ONLN) && \
-    # skip installing documentation
-    make install_sw && \
-    rm -rf ~/openssl_build
-
-RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.14.01/nasm-2.14.01.tar.bz2 && \
-    tar -xf nasm-2.14.01.tar.bz2 && cd nasm-2.14.01 && ./autogen.sh && \
-    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
-    make -j$(getconf _NPROCESSORS_ONLN) && \
-    make install
-
-RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
-    tar -xf yasm-1.3.0.tar.gz && \
-    cd yasm-1.3.0 && \
-    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
-    make -j$(getconf _NPROCESSORS_ONLN) && \
-    make install
-
-RUN cd ~/ffmpeg_sources && \
-    git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
-    cd libvpx && \
-    ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
-    make -j$(getconf _NPROCESSORS_ONLN) && \
-    make install
-
-RUN cd ~/ffmpeg_sources && \
-    curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
-    tar -xf ffmpeg-snapshot.tar.bz2 && \
-    cd ffmpeg && \
-    PATH=~/bin:$PATH && \
-    PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
-    make -j$(getconf _NPROCESSORS_ONLN) && \
-    make install && \
-    echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
-    ldconfig && \
-    rm -rf ~/ffmpeg_sources
-
-<<<<<<< HEAD
-=======
-RUN curl -O -L https://github.com/ccache/ccache/releases/download/v3.7.9/ccache-3.7.9.tar.gz && \
-    tar -xf ccache-3.7.9.tar.gz && \
-    cd ccache-3.7.9 && \
-    linux32 ./configure && \
-    make -j$(getconf _NPROCESSORS_ONLN) && \
-    make install
-
-RUN curl -O -L https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-3.17.0.tar.gz && \
-    tar -xf cmake-3.17.0.tar.gz && \
-    cd cmake-3.17.0 && \
-    export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
-    ./configure --system-curl && \
-    make && \
-    make install && \
-    cd .. && \
-    rm -rf cmake-3.17.0*
-
->>>>>>> master
-ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
-ENV LDFLAGS -L/root/ffmpeg_build/lib
-ENV PATH "$HOME/bin:$PATH"

From f179cd18e9d7d6e4b3c153238fef37e8994843a9 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 6 Oct 2020 17:36:15 +0300
Subject: [PATCH 451/566] Python 3.9 preparations

---
 .travis.yml    | 128 ++++++++++++++++++++++++++++++++++++++++++++++++-
 appveyor.yml   |  32 +++++++++++++
 multibuild     |   2 +-
 pyproject.toml |   4 +-
 setup.py       |   2 +
 5 files changed, 163 insertions(+), 5 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index f79e1907..9b583ed7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -133,6 +133,16 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
       workspaces:
         use: brew_cache
+    - os: osx
+      language: generic
+      osx_image: xcode9.4
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.3
+      workspaces:
+        use: brew_cache
 
     # headless builds for MacOS
     - os: osx
@@ -165,6 +175,16 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
       workspaces:
         use: brew_cache
+    - os: osx
+      language: generic
+      osx_image: xcode9.4
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.3
+      workspaces:
+        use: brew_cache
 
     # Contrib builds for MacOS
     - os: osx
@@ -197,6 +217,16 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
       workspaces:
         use: brew_cache
+    - os: osx
+      language: generic
+      osx_image: xcode9.4
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.3
+      workspaces:
+        use: brew_cache
 
     # headless contrib builds for MacOS
     - os: osx
@@ -229,6 +259,16 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
       workspaces:
         use: brew_cache
+    - os: osx
+      language: generic
+      osx_image: xcode9.4
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.3
+      workspaces:
+        use: brew_cache
 
     # default builds for Linux
     - os: linux
@@ -308,11 +348,23 @@ jobs:
       dist: xenial
       services: docker
       env:
-        - MB_PYTHON_VERSION=3.8
+        - MB_PYTHON_VERSION=3.9
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.3
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.17.3
+        - TEST_DEPENDS=numpy==1.19.3
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
@@ -390,6 +442,30 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.3
+      cache:
+        directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - PLAT=i686
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.3
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
 
     # contrib builds for Linux
     - os: linux
@@ -464,6 +540,30 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - TEST_DEPENDS=numpy==1.19.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - PLAT=i686
+        - TEST_DEPENDS=numpy==1.19.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
 
 
     # headless contrib builds for Linux
@@ -539,6 +639,30 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - TEST_DEPENDS=numpy==1.19.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - PLAT=i686
+        - TEST_DEPENDS=numpy==1.19.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
 
 # The first line is printed in the folding header in Travis output
 before_install: |
diff --git a/appveyor.yml b/appveyor.yml
index 3dde3d23..d203b1cf 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -30,6 +30,14 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
+    - PYTHON: "C:/Python39"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python39-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
@@ -54,6 +62,14 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
+    - PYTHON: "C:/Python39"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python39-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
@@ -78,6 +94,14 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
+    - PYTHON: "C:/Python39"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python39-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
@@ -102,6 +126,14 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
+    - PYTHON: "C:/Python39"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python39-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
 matrix:
     fast_finish: true
 
diff --git a/multibuild b/multibuild
index c2890dc8..8882150d 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit c2890dc8dc93f99b0eadd76f87aa181f6aea42da
+Subproject commit 8882150df6529658700b66bec124dfb77eefca26
diff --git a/pyproject.toml b/pyproject.toml
index 7522b5ef..ba577535 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,8 +1,8 @@
 [build-system]
 requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
-  "numpy==1.11.3; python_version=='3.5'",
   "numpy==1.13.3; python_version=='3.6'",
   "numpy==1.14.5; python_version=='3.7'",
-  "numpy==1.17.3; python_version>='3.8'"
+  "numpy==1.17.3; python_version>='3.8'",
+  "numpy==1.19.3; python_version>='3.8'"
 ]
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 86a7667a..7f52501f 100644
--- a/setup.py
+++ b/setup.py
@@ -235,9 +235,11 @@ def main():
             "Operating System :: Unix",
             "Programming Language :: Python",
             "Programming Language :: Python :: 3",
+            "Programming Language :: Python :: 3 :: Only",
             "Programming Language :: Python :: 3.6",
             "Programming Language :: Python :: 3.7",
             "Programming Language :: Python :: 3.8",
+            "Programming Language :: Python :: 3.9",
             "Programming Language :: C++",
             "Programming Language :: Python :: Implementation :: CPython",
             "Topic :: Scientific/Engineering",

From b743f47af4127fb461cc390cba4c1977379c7c81 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 6 Oct 2020 17:38:06 +0300
Subject: [PATCH 452/566] fix typo

---
 pyproject.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index ba577535..e20c59a6 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,5 +4,5 @@ requires = [
   "numpy==1.13.3; python_version=='3.6'",
   "numpy==1.14.5; python_version=='3.7'",
   "numpy==1.17.3; python_version>='3.8'",
-  "numpy==1.19.3; python_version>='3.8'"
+  "numpy==1.19.3; python_version>='3.9'"
 ]
\ No newline at end of file

From 5e46e96c92a0a76ba0f5169f728b89e823cdce87 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 7 Oct 2020 17:48:29 +0300
Subject: [PATCH 453/566] fix pyproject.toml

---
 pyproject.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index e20c59a6..b362f93f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,6 +3,6 @@ requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
   "numpy==1.13.3; python_version=='3.6'",
   "numpy==1.14.5; python_version=='3.7'",
-  "numpy==1.17.3; python_version>='3.8'",
+  "numpy==1.17.3; python_version=='3.8'",
   "numpy==1.19.3; python_version>='3.9'"
 ]
\ No newline at end of file

From 69a8f4c0bdab956bf3999196918396346e3619c4 Mon Sep 17 00:00:00 2001
From: Stefan Weil <sw@weilnetz.de>
Date: Sun, 11 Oct 2020 09:57:28 +0200
Subject: [PATCH 454/566] .gitignore: Ignore cv2/version.py

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 0367e1b0..15079e07 100644
--- a/.gitignore
+++ b/.gitignore
@@ -67,4 +67,5 @@ target/
 # Build temporary files
 /contrib.enabled
 /cv_version.py
+/cv2/version.py
 _skbuild/

From 58f0105b328ccd0f8fcc29529ab7e310fe47f98e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 6 Oct 2020 17:36:15 +0300
Subject: [PATCH 455/566] Python 3.9 preparations

---
 .travis.yml    | 128 ++++++++++++++++++++++++++++++++++++++++++++++++-
 appveyor.yml   |  32 +++++++++++++
 multibuild     |   2 +-
 pyproject.toml |   4 +-
 setup.py       |   2 +
 5 files changed, 163 insertions(+), 5 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index f79e1907..9b583ed7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -133,6 +133,16 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
       workspaces:
         use: brew_cache
+    - os: osx
+      language: generic
+      osx_image: xcode9.4
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.3
+      workspaces:
+        use: brew_cache
 
     # headless builds for MacOS
     - os: osx
@@ -165,6 +175,16 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
       workspaces:
         use: brew_cache
+    - os: osx
+      language: generic
+      osx_image: xcode9.4
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.3
+      workspaces:
+        use: brew_cache
 
     # Contrib builds for MacOS
     - os: osx
@@ -197,6 +217,16 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
       workspaces:
         use: brew_cache
+    - os: osx
+      language: generic
+      osx_image: xcode9.4
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.3
+      workspaces:
+        use: brew_cache
 
     # headless contrib builds for MacOS
     - os: osx
@@ -229,6 +259,16 @@ jobs:
         - TEST_DEPENDS=numpy==1.17.3
       workspaces:
         use: brew_cache
+    - os: osx
+      language: generic
+      osx_image: xcode9.4
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.3
+      workspaces:
+        use: brew_cache
 
     # default builds for Linux
     - os: linux
@@ -308,11 +348,23 @@ jobs:
       dist: xenial
       services: docker
       env:
-        - MB_PYTHON_VERSION=3.8
+        - MB_PYTHON_VERSION=3.9
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.3
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
         - PLAT=i686
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.17.3
+        - TEST_DEPENDS=numpy==1.19.3
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
@@ -390,6 +442,30 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.3
+      cache:
+        directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - PLAT=i686
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.3
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
 
     # contrib builds for Linux
     - os: linux
@@ -464,6 +540,30 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - TEST_DEPENDS=numpy==1.19.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+      cache:
+        directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - PLAT=i686
+        - TEST_DEPENDS=numpy==1.19.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
 
 
     # headless contrib builds for Linux
@@ -539,6 +639,30 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - TEST_DEPENDS=numpy==1.19.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+      cache:
+        directories: $HOME/.ccache
+    - os: linux
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - PLAT=i686
+        - TEST_DEPENDS=numpy==1.19.3
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
 
 # The first line is printed in the folding header in Travis output
 before_install: |
diff --git a/appveyor.yml b/appveyor.yml
index 3dde3d23..d203b1cf 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -30,6 +30,14 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
+    - PYTHON: "C:/Python39"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python39-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
@@ -54,6 +62,14 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
+    - PYTHON: "C:/Python39"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python39-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
@@ -78,6 +94,14 @@ environment:
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
+    - PYTHON: "C:/Python39"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python39-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
     - PYTHON: "C:/Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
@@ -102,6 +126,14 @@ environment:
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
+    - PYTHON: "C:/Python39"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python39-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
 matrix:
     fast_finish: true
 
diff --git a/multibuild b/multibuild
index c2890dc8..8882150d 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit c2890dc8dc93f99b0eadd76f87aa181f6aea42da
+Subproject commit 8882150df6529658700b66bec124dfb77eefca26
diff --git a/pyproject.toml b/pyproject.toml
index 7522b5ef..ba577535 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,8 +1,8 @@
 [build-system]
 requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
-  "numpy==1.11.3; python_version=='3.5'",
   "numpy==1.13.3; python_version=='3.6'",
   "numpy==1.14.5; python_version=='3.7'",
-  "numpy==1.17.3; python_version>='3.8'"
+  "numpy==1.17.3; python_version>='3.8'",
+  "numpy==1.19.3; python_version>='3.8'"
 ]
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 86a7667a..7f52501f 100644
--- a/setup.py
+++ b/setup.py
@@ -235,9 +235,11 @@ def main():
             "Operating System :: Unix",
             "Programming Language :: Python",
             "Programming Language :: Python :: 3",
+            "Programming Language :: Python :: 3 :: Only",
             "Programming Language :: Python :: 3.6",
             "Programming Language :: Python :: 3.7",
             "Programming Language :: Python :: 3.8",
+            "Programming Language :: Python :: 3.9",
             "Programming Language :: C++",
             "Programming Language :: Python :: Implementation :: CPython",
             "Topic :: Scientific/Engineering",

From c4f8e26297b24c5f4294ea3be2d563a4058f8305 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 6 Oct 2020 17:38:06 +0300
Subject: [PATCH 456/566] fix typo

---
 pyproject.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index ba577535..e20c59a6 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,5 +4,5 @@ requires = [
   "numpy==1.13.3; python_version=='3.6'",
   "numpy==1.14.5; python_version=='3.7'",
   "numpy==1.17.3; python_version>='3.8'",
-  "numpy==1.19.3; python_version>='3.8'"
+  "numpy==1.19.3; python_version>='3.9'"
 ]
\ No newline at end of file

From 2d445e7e8f8e8b21ac67e267b26c9c306908c9a1 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 7 Oct 2020 17:48:29 +0300
Subject: [PATCH 457/566] fix pyproject.toml

---
 pyproject.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index e20c59a6..b362f93f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,6 +3,6 @@ requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
   "numpy==1.13.3; python_version=='3.6'",
   "numpy==1.14.5; python_version=='3.7'",
-  "numpy==1.17.3; python_version>='3.8'",
+  "numpy==1.17.3; python_version=='3.8'",
   "numpy==1.19.3; python_version>='3.9'"
 ]
\ No newline at end of file

From 6ee82a398e1f4b02d86b8966c49f9278c348eaf8 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 11 Oct 2020 17:13:29 +0300
Subject: [PATCH 458/566] fix line endings

---
 appveyor.yml    | 382 ++++++++++----------
 cv2/__init__.py |  66 ++--
 find_version.py | 136 ++++----
 setup.py        | 900 ++++++++++++++++++++++++------------------------
 tests/test.py   |  34 +-
 5 files changed, 759 insertions(+), 759 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index d203b1cf..b658399a 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,191 +1,191 @@
-environment:
-  USER:
-    secure: fXgF9uyy6sT0JoVOR7BoqA==
-
-  PASS:
-    secure: 0bXSOVjf9x8L7nErTivu92TF1FwNosTjFJQPmxp8Dys=
-
-  matrix:
-    - PYTHON: "C:/Python36"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python36-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python37"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python37-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python38"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python38-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python39"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python39-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python36"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python36-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python37"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python37-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python38"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python38-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python39"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python39-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:/Python36"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python36-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python37"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python37-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python38"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python38-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python39"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python39-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python36"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python36-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python37"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python37-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python38"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python38-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python39"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:/Python39-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-matrix:
-    fast_finish: true
-
-build_script:
-- cmd: |
-    "%PYTHON%/python.exe" -m pip install --upgrade pip
-    "%PYTHON%/python.exe" -m pip install --upgrade setuptools
-    set "CI_BUILD=1" && "%PYTHON%/python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
-
-before_test:
-- ps: |
-
-    cd ${Env:APPVEYOR_BUILD_FOLDER}\tests
-    $env:PYTHONWARNINGS = "ignore:::pip._internal.cli.base_command"
-    &"${Env:PYTHON}/python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
-    if ($LastExitCode -ne 0) {throw $LastExitCode}
-
-test_script:
-- cmd: |
-
-    cd %APPVEYOR_BUILD_FOLDER%\tests
-    "%PYTHON%/python.exe" -m unittest test
-
-artifacts:
-- path: dist\opencv*.whl
-  name: wheels
-
-deploy_script:
-- ps: |
-
-    if (${Env:APPVEYOR_REPO_TAG} -eq "true") {
-      cd ${Env:APPVEYOR_BUILD_FOLDER}
-      if (${Env:ENABLE_CONTRIB} -eq 0) {
-        if (${Env:ENABLE_HEADLESS} -eq 0) {
-          echo "This is a default build. Deployment will be done to PyPI entry opencv-python."
-        }
-        else {
-          echo "This is a headless build. Deployment will be done to PyPI entry opencv-python-headless."
-        }
-      }
-      else {
-        if (${Env:ENABLE_HEADLESS} -eq 0) {
-          echo "This is a contrib build. Deployment will be done to PyPI entry opencv-contrib-python."
-        }
-        else {
-          echo "This is a headless contrib build. Deployment will be done to PyPI entry opencv-contrib-python-headless."
-        }
-      }
-
-      &"${Env:PYTHON}/python.exe" -m pip install twine
-      &"${Env:PYTHON}/python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv*
-    }
-    else {
-      echo "Tag not set, deployment skipped."
-    }
+environment:
+  USER:
+    secure: fXgF9uyy6sT0JoVOR7BoqA==
+
+  PASS:
+    secure: 0bXSOVjf9x8L7nErTivu92TF1FwNosTjFJQPmxp8Dys=
+
+  matrix:
+    - PYTHON: "C:/Python36"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python36-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python37"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python37-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python38"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python38-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python39"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python39-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python36"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python36-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python37"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python37-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python38"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python38-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python39"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python39-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 0
+
+    - PYTHON: "C:/Python36"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python36-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python37"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python37-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python38"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python38-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python39"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python39-x64"
+      ENABLE_CONTRIB: 0
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python36"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python36-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python37"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python37-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python38"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python38-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python39"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+    - PYTHON: "C:/Python39-x64"
+      ENABLE_CONTRIB: 1
+      ENABLE_HEADLESS: 1
+
+matrix:
+    fast_finish: true
+
+build_script:
+- cmd: |
+    "%PYTHON%/python.exe" -m pip install --upgrade pip
+    "%PYTHON%/python.exe" -m pip install --upgrade setuptools
+    set "CI_BUILD=1" && "%PYTHON%/python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
+
+before_test:
+- ps: |
+
+    cd ${Env:APPVEYOR_BUILD_FOLDER}\tests
+    $env:PYTHONWARNINGS = "ignore:::pip._internal.cli.base_command"
+    &"${Env:PYTHON}/python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
+    if ($LastExitCode -ne 0) {throw $LastExitCode}
+
+test_script:
+- cmd: |
+
+    cd %APPVEYOR_BUILD_FOLDER%\tests
+    "%PYTHON%/python.exe" -m unittest test
+
+artifacts:
+- path: dist\opencv*.whl
+  name: wheels
+
+deploy_script:
+- ps: |
+
+    if (${Env:APPVEYOR_REPO_TAG} -eq "true") {
+      cd ${Env:APPVEYOR_BUILD_FOLDER}
+      if (${Env:ENABLE_CONTRIB} -eq 0) {
+        if (${Env:ENABLE_HEADLESS} -eq 0) {
+          echo "This is a default build. Deployment will be done to PyPI entry opencv-python."
+        }
+        else {
+          echo "This is a headless build. Deployment will be done to PyPI entry opencv-python-headless."
+        }
+      }
+      else {
+        if (${Env:ENABLE_HEADLESS} -eq 0) {
+          echo "This is a contrib build. Deployment will be done to PyPI entry opencv-contrib-python."
+        }
+        else {
+          echo "This is a headless contrib build. Deployment will be done to PyPI entry opencv-contrib-python-headless."
+        }
+      }
+
+      &"${Env:PYTHON}/python.exe" -m pip install twine
+      &"${Env:PYTHON}/python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv*
+    }
+    else {
+      echo "Tag not set, deployment skipped."
+    }
diff --git a/cv2/__init__.py b/cv2/__init__.py
index 7f7c1261..d665b75c 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -1,33 +1,33 @@
-import importlib
-import os
-import sys
-
-from .cv2 import *
-from .data import *
-
-# wildcard import above does not import "private" variables like __version__
-# this makes them available
-globals().update(importlib.import_module("cv2.cv2").__dict__)
-
-ci_and_not_headless = False
-
-try:
-    from .version import ci_build, headless
-
-    ci_and_not_headless = ci_build and not headless
-except:
-    pass
-
-# the Qt plugin is included currently only in the pre-built wheels
-if (
-    sys.platform == "darwin" or sys.platform.startswith("linux")
-) and ci_and_not_headless:
-    os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.path.join(
-        os.path.dirname(os.path.abspath(__file__)), "qt", "plugins"
-    )
-
-# Qt will throw warning on Linux if fonts are not found
-if sys.platform.startswith("linux") and ci_and_not_headless:
-    os.environ["QT_QPA_FONTDIR"] = os.path.join(
-        os.path.dirname(os.path.abspath(__file__)), "qt", "fonts"
-    )
+import importlib
+import os
+import sys
+
+from .cv2 import *
+from .data import *
+
+# wildcard import above does not import "private" variables like __version__
+# this makes them available
+globals().update(importlib.import_module("cv2.cv2").__dict__)
+
+ci_and_not_headless = False
+
+try:
+    from .version import ci_build, headless
+
+    ci_and_not_headless = ci_build and not headless
+except:
+    pass
+
+# the Qt plugin is included currently only in the pre-built wheels
+if (
+    sys.platform == "darwin" or sys.platform.startswith("linux")
+) and ci_and_not_headless:
+    os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.path.join(
+        os.path.dirname(os.path.abspath(__file__)), "qt", "plugins"
+    )
+
+# Qt will throw warning on Linux if fonts are not found
+if sys.platform.startswith("linux") and ci_and_not_headless:
+    os.environ["QT_QPA_FONTDIR"] = os.path.join(
+        os.path.dirname(os.path.abspath(__file__)), "qt", "fonts"
+    )
diff --git a/find_version.py b/find_version.py
index 80ae522b..6c676b23 100644
--- a/find_version.py
+++ b/find_version.py
@@ -1,68 +1,68 @@
-import sys
-import os
-import subprocess
-
-if __name__ == "__main__":
-    contrib = sys.argv[1]
-    headless = sys.argv[2]
-    ci_build = sys.argv[3]
-
-    opencv_version = ""
-    # dig out the version from OpenCV sources
-    version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp"
-
-    with open(version_file_path, "r") as f:
-        for line in f:
-            words = line.split()
-
-            if "CV_VERSION_MAJOR" in words:
-                opencv_version += words[2]
-                opencv_version += "."
-
-            if "CV_VERSION_MINOR" in words:
-                opencv_version += words[2]
-                opencv_version += "."
-
-            if "CV_VERSION_REVISION" in words:
-                opencv_version += words[2]
-                break
-
-    # used in local dev releases
-    git_hash = (
-        subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
-        .splitlines()[0]
-        .decode()
-    )
-    # this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
-    try:
-        tag = (
-            subprocess.check_output(
-                ["git", "describe", "--tags"], stderr=subprocess.STDOUT
-            )
-            .splitlines()[0]
-            .decode()
-            .split("-")
-        )
-    except subprocess.CalledProcessError as e:
-        # no tags reachable (e.g. on a topic branch in a fork), see
-        # https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
-        if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
-            tag = []
-        else:
-            print(e.output)
-            raise
-
-    if len(tag) == 1:
-        # tag identifies the build and should be a sequential revision number
-        version = tag[0]
-        opencv_version += ".{}".format(version)
-    else:
-        # local version identifier, not to be published on PyPI
-        version = git_hash
-        opencv_version += "+{}".format(version)
-
-    with open("cv2/version.py", "w") as f:
-        f.write('opencv_version = "{}"\n'.format(opencv_version))
-        f.write("contrib = {}\n".format(contrib))
-        f.write("headless = {}\n".format(headless))
-        f.write("ci_build = {}".format(ci_build))
+import sys
+import os
+import subprocess
+
+if __name__ == "__main__":
+    contrib = sys.argv[1]
+    headless = sys.argv[2]
+    ci_build = sys.argv[3]
+
+    opencv_version = ""
+    # dig out the version from OpenCV sources
+    version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp"
+
+    with open(version_file_path, "r") as f:
+        for line in f:
+            words = line.split()
+
+            if "CV_VERSION_MAJOR" in words:
+                opencv_version += words[2]
+                opencv_version += "."
+
+            if "CV_VERSION_MINOR" in words:
+                opencv_version += words[2]
+                opencv_version += "."
+
+            if "CV_VERSION_REVISION" in words:
+                opencv_version += words[2]
+                break
+
+    # used in local dev releases
+    git_hash = (
+        subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
+        .splitlines()[0]
+        .decode()
+    )
+    # this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
+    try:
+        tag = (
+            subprocess.check_output(
+                ["git", "describe", "--tags"], stderr=subprocess.STDOUT
+            )
+            .splitlines()[0]
+            .decode()
+            .split("-")
+        )
+    except subprocess.CalledProcessError as e:
+        # no tags reachable (e.g. on a topic branch in a fork), see
+        # https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
+        if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
+            tag = []
+        else:
+            print(e.output)
+            raise
+
+    if len(tag) == 1:
+        # tag identifies the build and should be a sequential revision number
+        version = tag[0]
+        opencv_version += ".{}".format(version)
+    else:
+        # local version identifier, not to be published on PyPI
+        version = git_hash
+        opencv_version += "+{}".format(version)
+
+    with open("cv2/version.py", "w") as f:
+        f.write('opencv_version = "{}"\n'.format(opencv_version))
+        f.write("contrib = {}\n".format(contrib))
+        f.write("headless = {}\n".format(headless))
+        f.write("ci_build = {}".format(ci_build))
diff --git a/setup.py b/setup.py
index 7f52501f..3ba72442 100644
--- a/setup.py
+++ b/setup.py
@@ -1,450 +1,450 @@
-import io
-import os
-import os.path
-import sys
-import runpy
-import subprocess
-import re
-import sysconfig
-import skbuild
-from skbuild import cmaker
-
-
-def main():
-    os.chdir(os.path.dirname(os.path.abspath(__file__)))
-
-    CI_BUILD = os.environ.get("CI_BUILD", "False")
-    is_CI_build = True if CI_BUILD == "1" else False
-    cmake_source_dir = "opencv"
-    minimum_supported_numpy = "1.13.1"
-    build_contrib = get_build_env_var_by_name("contrib")
-    build_headless = get_build_env_var_by_name("headless")
-    build_java = "ON" if get_build_env_var_by_name("java") else "OFF"
-
-    if sys.version_info[:2] >= (3, 6):
-        minimum_supported_numpy = "1.13.3"
-    if sys.version_info[:2] >= (3, 7):
-        minimum_supported_numpy = "1.14.5"
-    if sys.version_info[:2] >= (3, 8):
-        minimum_supported_numpy = "1.17.3"
-
-    numpy_version = "numpy>=%s" % minimum_supported_numpy
-
-    python_version = cmaker.CMaker.get_python_version()
-    python_lib_path = cmaker.CMaker.get_python_library(python_version).replace(
-        "\\", "/"
-    )
-    python_include_dir = cmaker.CMaker.get_python_include_dir(python_version).replace(
-        "\\", "/"
-    )
-
-    if os.path.exists(".git"):
-        import pip._internal.vcs.git as git
-
-        g = git.Git()  # NOTE: pip API's are internal, this has to be refactored
-
-        g.run_command(["submodule", "sync"])
-        g.run_command(
-            ["submodule", "update", "--init", "--recursive", cmake_source_dir]
-        )
-
-        if build_contrib:
-            g.run_command(
-                ["submodule", "update", "--init", "--recursive", "opencv_contrib"]
-            )
-
-    package_version, build_contrib, build_headless = get_and_set_info(
-        build_contrib, build_headless, is_CI_build
-    )
-
-    # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
-    x64 = sys.maxsize > 2 ** 32
-
-    package_name = "opencv-python"
-
-    if build_contrib and not build_headless:
-        package_name = "opencv-contrib-python"
-
-    if build_contrib and build_headless:
-        package_name = "opencv-contrib-python-headless"
-
-    if build_headless and not build_contrib:
-        package_name = "opencv-python-headless"
-
-    long_description = io.open("README.md", encoding="utf-8").read()
-
-    packages = ["cv2", "cv2.data"]
-
-    package_data = {
-        "cv2": ["*%s" % sysconfig.get_config_vars().get("SO"), "version.py"]
-        + (["*.dll"] if os.name == "nt" else [])
-        + ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
-        "cv2.data": ["*.xml"],
-    }
-
-    # Files from CMake output to copy to package.
-    # Path regexes with forward slashes relative to CMake install dir.
-    rearrange_cmake_output_data = {
-        "cv2": (
-            [r"bin/opencv_videoio_ffmpeg\d{3}%s\.dll" % ("_64" if x64 else "")]
-            if os.name == "nt"
-            else []
-        )
-        +
-        # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
-        # Naming conventions vary so widely between versions and OSes
-        # had to give up on checking them.
-        [
-            "python/cv2[^/]*%(ext)s"
-            % {"ext": re.escape(sysconfig.get_config_var("EXT_SUFFIX"))}
-        ],
-        "cv2.data": [  # OPENCV_OTHER_INSTALL_PATH
-            ("etc" if os.name == "nt" else "share/opencv4") + r"/haarcascades/.*\.xml"
-        ],
-    }
-
-    # Files in sourcetree outside package dir that should be copied to package.
-    # Raw paths relative to sourcetree root.
-    files_outside_package_dir = {"cv2": ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"]}
-
-    ci_cmake_generator = (
-        ["-G", "Visual Studio 14" + (" Win64" if x64 else "")]
-        if os.name == "nt"
-        else ["-G", "Unix Makefiles"]
-    )
-
-    cmake_args = (
-        (ci_cmake_generator if is_CI_build else [])
-        + [
-            # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
-            "-DPYTHON3_EXECUTABLE=%s" % sys.executable,
-            "-DPYTHON3_INCLUDE_DIR=%s" % python_include_dir,
-            "-DPYTHON3_LIBRARY=%s" % python_lib_path,
-            "-DBUILD_opencv_python3=ON",
-            "-DBUILD_opencv_python2=OFF",
-            # Disable the Java build by default as it is not needed
-            "-DBUILD_opencv_java=%s" % build_java,
-            # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
-            "-DOPENCV_SKIP_PYTHON_LOADER=ON",
-            # Relative dir to install the built module to in the build tree.
-            # The default is generated from sysconfig, we'd rather have a constant for simplicity
-            "-DOPENCV_PYTHON3_INSTALL_PATH=python",
-            # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
-            # and skbuild bails out on seeing that
-            "-DINSTALL_CREATE_DISTRIB=ON",
-            # See opencv/CMakeLists.txt for options and defaults
-            "-DBUILD_opencv_apps=OFF",
-            "-DBUILD_SHARED_LIBS=OFF",
-            "-DBUILD_TESTS=OFF",
-            "-DBUILD_PERF_TESTS=OFF",
-            "-DBUILD_DOCS=OFF",
-        ]
-        + (
-            ["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")]
-            if build_contrib
-            else []
-        )
-    )
-
-    if build_headless:
-        # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
-        cmake_args.append("-DWITH_WIN32UI=OFF")
-        cmake_args.append("-DWITH_QT=OFF")
-        cmake_args.append("-DWITH_GTK=OFF")
-        if is_CI_build:
-            cmake_args.append(
-                "-DWITH_MSMF=OFF"
-            )  # see: https://github.com/skvark/opencv-python/issues/263
-
-    if sys.platform.startswith("linux") and not x64 and "bdist_wheel" in sys.argv:
-        subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
-
-    # OS-specific components during CI builds
-    if is_CI_build:
-
-        if (
-            not build_headless
-            and "bdist_wheel" in sys.argv
-            and (sys.platform == "darwin" or sys.platform.startswith("linux"))
-        ):
-            cmake_args.append("-DWITH_QT=5")
-            subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
-
-            if sys.platform.startswith("linux"):
-                rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
-                    (r"lib/qt/plugins/platforms/libqxcb\.so")
-                ]
-
-                # add fonts for Qt5
-                fonts = []
-                for file in os.listdir("/usr/share/fonts/dejavu"):
-                    if file.endswith(".ttf"):
-                        fonts.append(
-                            (r"lib/qt/fonts/dejavu/%s\.ttf" % file.split(".")[0])
-                        )
-
-                rearrange_cmake_output_data["cv2.qt.fonts"] = fonts
-
-            if sys.platform == "darwin":
-                rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
-                    (r"lib/qt/plugins/platforms/libqcocoa\.dylib")
-                ]
-
-        if sys.platform.startswith("linux"):
-            cmake_args.append("-DWITH_V4L=ON")
-            cmake_args.append("-DWITH_LAPACK=ON")
-            cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
-
-    # https://github.com/scikit-build/scikit-build/issues/479
-    if "CMAKE_ARGS" in os.environ:
-        import shlex
-
-        cmake_args.extend(shlex.split(os.environ["CMAKE_ARGS"]))
-        del shlex
-
-    # works via side effect
-    RearrangeCMakeOutput(
-        rearrange_cmake_output_data, files_outside_package_dir, package_data.keys()
-    )
-
-    skbuild.setup(
-        name=package_name,
-        version=package_version,
-        url="https://github.com/skvark/opencv-python",
-        license="MIT",
-        description="Wrapper package for OpenCV python bindings.",
-        long_description=long_description,
-        long_description_content_type="text/markdown",
-        packages=packages,
-        package_data=package_data,
-        maintainer="Olli-Pekka Heinisuo",
-        ext_modules=EmptyListWithLength(),
-        install_requires=numpy_version,
-        python_requires=">=3.6",
-        classifiers=[
-            "Development Status :: 5 - Production/Stable",
-            "Environment :: Console",
-            "Intended Audience :: Developers",
-            "Intended Audience :: Education",
-            "Intended Audience :: Information Technology",
-            "Intended Audience :: Science/Research",
-            "License :: OSI Approved :: MIT License",
-            "Operating System :: MacOS",
-            "Operating System :: Microsoft :: Windows",
-            "Operating System :: POSIX",
-            "Operating System :: Unix",
-            "Programming Language :: Python",
-            "Programming Language :: Python :: 3",
-            "Programming Language :: Python :: 3 :: Only",
-            "Programming Language :: Python :: 3.6",
-            "Programming Language :: Python :: 3.7",
-            "Programming Language :: Python :: 3.8",
-            "Programming Language :: Python :: 3.9",
-            "Programming Language :: C++",
-            "Programming Language :: Python :: Implementation :: CPython",
-            "Topic :: Scientific/Engineering",
-            "Topic :: Scientific/Engineering :: Image Recognition",
-            "Topic :: Software Development",
-        ],
-        cmake_args=cmake_args,
-        cmake_source_dir=cmake_source_dir,
-    )
-
-
-class RearrangeCMakeOutput(object):
-    """
-        Patch SKBuild logic to only take files related to the Python package
-        and construct a file hierarchy that SKBuild expects (see below)
-    """
-
-    _setuptools_wrap = None
-
-    # Have to wrap a function reference, or it's converted
-    # into an instance method on attr assignment
-    import argparse
-
-    wraps = argparse.Namespace(_classify_installed_files=None)
-    del argparse
-
-    package_paths_re = None
-    packages = None
-    files_outside_package = None
-
-    def __init__(self, package_paths_re, files_outside_package, packages):
-        cls = self.__class__
-        assert not cls.wraps._classify_installed_files, "Singleton object"
-        import skbuild.setuptools_wrap
-
-        cls._setuptools_wrap = skbuild.setuptools_wrap
-        cls.wraps._classify_installed_files = (
-            cls._setuptools_wrap._classify_installed_files
-        )
-        cls._setuptools_wrap._classify_installed_files = (
-            self._classify_installed_files_override
-        )
-
-        cls.package_paths_re = package_paths_re
-        cls.files_outside_package = files_outside_package
-        cls.packages = packages
-
-    def __del__(self):
-        cls = self.__class__
-        cls._setuptools_wrap._classify_installed_files = (
-            cls.wraps._classify_installed_files
-        )
-        cls.wraps._classify_installed_files = None
-        cls._setuptools_wrap = None
-
-    def _classify_installed_files_override(
-        self,
-        install_paths,
-        package_data,
-        package_prefixes,
-        py_modules,
-        new_py_modules,
-        scripts,
-        new_scripts,
-        data_files,
-        cmake_source_dir,
-        cmake_install_reldir,
-    ):
-        """
-            From all CMake output, we're only interested in a few files
-            and must place them into CMake install dir according
-            to Python conventions for SKBuild to find them:
-                package\
-                    file
-                    subpackage\
-                        etc.
-        """
-
-        cls = self.__class__
-
-        # 'relpath'/'reldir' = relative to CMAKE_INSTALL_DIR/cmake_install_dir
-        # 'path'/'dir' = relative to sourcetree root
-        cmake_install_dir = os.path.join(
-            cls._setuptools_wrap.CMAKE_INSTALL_DIR(), cmake_install_reldir
-        )
-        install_relpaths = [
-            os.path.relpath(p, cmake_install_dir) for p in install_paths
-        ]
-        fslash_install_relpaths = [
-            p.replace(os.path.sep, "/") for p in install_relpaths
-        ]
-        relpaths_zip = list(zip(fslash_install_relpaths, install_relpaths))
-        del install_relpaths, fslash_install_relpaths
-
-        final_install_relpaths = []
-
-        print("Copying files from CMake output")
-
-        for package_name, relpaths_re in cls.package_paths_re.items():
-            package_dest_reldir = package_name.replace(".", os.path.sep)
-            for relpath_re in relpaths_re:
-                found = False
-                r = re.compile(relpath_re + "$")
-                for fslash_relpath, relpath in relpaths_zip:
-                    m = r.match(fslash_relpath)
-                    if not m:
-                        continue
-                    found = True
-                    new_install_relpath = os.path.join(
-                        package_dest_reldir, os.path.basename(relpath)
-                    )
-                    cls._setuptools_wrap._copy_file(
-                        os.path.join(cmake_install_dir, relpath),
-                        os.path.join(cmake_install_dir, new_install_relpath),
-                        hide_listing=False,
-                    )
-                    final_install_relpaths.append(new_install_relpath)
-                    del m, fslash_relpath, new_install_relpath
-                else:
-                    if not found:
-                        raise Exception("Not found: '%s'" % relpath_re)
-                del r, found
-
-        del relpaths_zip
-
-        print("Copying files from non-default sourcetree locations")
-
-        for package_name, paths in cls.files_outside_package.items():
-            package_dest_reldir = package_name.replace(".", os.path.sep)
-            for path in paths:
-                new_install_relpath = os.path.join(
-                    package_dest_reldir,
-                    # Don't yet have a need to copy
-                    # to subdirectories of package dir
-                    os.path.basename(path),
-                )
-                cls._setuptools_wrap._copy_file(
-                    path,
-                    os.path.join(cmake_install_dir, new_install_relpath),
-                    hide_listing=False,
-                )
-                final_install_relpaths.append(new_install_relpath)
-
-        final_install_paths = [
-            os.path.join(cmake_install_dir, p) for p in final_install_relpaths
-        ]
-
-        return (cls.wraps._classify_installed_files)(
-            final_install_paths,
-            package_data,
-            package_prefixes,
-            py_modules,
-            new_py_modules,
-            scripts,
-            new_scripts,
-            data_files,
-            # To get around a check that prepends source dir to paths and breaks package detection code.
-            cmake_source_dir="",
-            cmake_install_dir=cmake_install_reldir,
-        )
-
-
-def get_and_set_info(contrib, headless, ci_build):
-    # cv2/version.py should be generated by running find_version.py
-    version = {}
-    here = os.path.abspath(os.path.dirname(__file__))
-    version_file = os.path.join(here, "cv2", "version.py")
-
-    # generate a fresh version.py always when Git repository exists
-    # (in sdists the version.py file already exists)
-    if os.path.exists(".git"):
-        old_args = sys.argv.copy()
-        sys.argv = ["", str(contrib), str(headless), str(ci_build)]
-        runpy.run_path("find_version.py", run_name="__main__")
-        sys.argv = old_args
-
-    with open(version_file) as fp:
-        exec(fp.read(), version)
-
-    return version["opencv_version"], version["contrib"], version["headless"]
-
-
-def get_build_env_var_by_name(flag_name):
-    flag_set = False
-
-    try:
-        flag_set = bool(int(os.getenv("ENABLE_" + flag_name.upper(), None)))
-    except Exception:
-        pass
-
-    if not flag_set:
-        try:
-            flag_set = bool(int(open(flag_name + ".enabled").read(1)))
-        except Exception:
-            pass
-
-    return flag_set
-
-
-# This creates a list which is empty but returns a length of 1.
-# Should make the wheel a binary distribution and platlib compliant.
-class EmptyListWithLength(list):
-    def __len__(self):
-        return 1
-
-
-if __name__ == "__main__":
-    main()
+import io
+import os
+import os.path
+import sys
+import runpy
+import subprocess
+import re
+import sysconfig
+import skbuild
+from skbuild import cmaker
+
+
+def main():
+    os.chdir(os.path.dirname(os.path.abspath(__file__)))
+
+    CI_BUILD = os.environ.get("CI_BUILD", "False")
+    is_CI_build = True if CI_BUILD == "1" else False
+    cmake_source_dir = "opencv"
+    minimum_supported_numpy = "1.13.1"
+    build_contrib = get_build_env_var_by_name("contrib")
+    build_headless = get_build_env_var_by_name("headless")
+    build_java = "ON" if get_build_env_var_by_name("java") else "OFF"
+
+    if sys.version_info[:2] >= (3, 6):
+        minimum_supported_numpy = "1.13.3"
+    if sys.version_info[:2] >= (3, 7):
+        minimum_supported_numpy = "1.14.5"
+    if sys.version_info[:2] >= (3, 8):
+        minimum_supported_numpy = "1.17.3"
+
+    numpy_version = "numpy>=%s" % minimum_supported_numpy
+
+    python_version = cmaker.CMaker.get_python_version()
+    python_lib_path = cmaker.CMaker.get_python_library(python_version).replace(
+        "\\", "/"
+    )
+    python_include_dir = cmaker.CMaker.get_python_include_dir(python_version).replace(
+        "\\", "/"
+    )
+
+    if os.path.exists(".git"):
+        import pip._internal.vcs.git as git
+
+        g = git.Git()  # NOTE: pip API's are internal, this has to be refactored
+
+        g.run_command(["submodule", "sync"])
+        g.run_command(
+            ["submodule", "update", "--init", "--recursive", cmake_source_dir]
+        )
+
+        if build_contrib:
+            g.run_command(
+                ["submodule", "update", "--init", "--recursive", "opencv_contrib"]
+            )
+
+    package_version, build_contrib, build_headless = get_and_set_info(
+        build_contrib, build_headless, is_CI_build
+    )
+
+    # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
+    x64 = sys.maxsize > 2 ** 32
+
+    package_name = "opencv-python"
+
+    if build_contrib and not build_headless:
+        package_name = "opencv-contrib-python"
+
+    if build_contrib and build_headless:
+        package_name = "opencv-contrib-python-headless"
+
+    if build_headless and not build_contrib:
+        package_name = "opencv-python-headless"
+
+    long_description = io.open("README.md", encoding="utf-8").read()
+
+    packages = ["cv2", "cv2.data"]
+
+    package_data = {
+        "cv2": ["*%s" % sysconfig.get_config_vars().get("SO"), "version.py"]
+        + (["*.dll"] if os.name == "nt" else [])
+        + ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
+        "cv2.data": ["*.xml"],
+    }
+
+    # Files from CMake output to copy to package.
+    # Path regexes with forward slashes relative to CMake install dir.
+    rearrange_cmake_output_data = {
+        "cv2": (
+            [r"bin/opencv_videoio_ffmpeg\d{3}%s\.dll" % ("_64" if x64 else "")]
+            if os.name == "nt"
+            else []
+        )
+        +
+        # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
+        # Naming conventions vary so widely between versions and OSes
+        # had to give up on checking them.
+        [
+            "python/cv2[^/]*%(ext)s"
+            % {"ext": re.escape(sysconfig.get_config_var("EXT_SUFFIX"))}
+        ],
+        "cv2.data": [  # OPENCV_OTHER_INSTALL_PATH
+            ("etc" if os.name == "nt" else "share/opencv4") + r"/haarcascades/.*\.xml"
+        ],
+    }
+
+    # Files in sourcetree outside package dir that should be copied to package.
+    # Raw paths relative to sourcetree root.
+    files_outside_package_dir = {"cv2": ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"]}
+
+    ci_cmake_generator = (
+        ["-G", "Visual Studio 14" + (" Win64" if x64 else "")]
+        if os.name == "nt"
+        else ["-G", "Unix Makefiles"]
+    )
+
+    cmake_args = (
+        (ci_cmake_generator if is_CI_build else [])
+        + [
+            # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
+            "-DPYTHON3_EXECUTABLE=%s" % sys.executable,
+            "-DPYTHON3_INCLUDE_DIR=%s" % python_include_dir,
+            "-DPYTHON3_LIBRARY=%s" % python_lib_path,
+            "-DBUILD_opencv_python3=ON",
+            "-DBUILD_opencv_python2=OFF",
+            # Disable the Java build by default as it is not needed
+            "-DBUILD_opencv_java=%s" % build_java,
+            # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
+            "-DOPENCV_SKIP_PYTHON_LOADER=ON",
+            # Relative dir to install the built module to in the build tree.
+            # The default is generated from sysconfig, we'd rather have a constant for simplicity
+            "-DOPENCV_PYTHON3_INSTALL_PATH=python",
+            # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
+            # and skbuild bails out on seeing that
+            "-DINSTALL_CREATE_DISTRIB=ON",
+            # See opencv/CMakeLists.txt for options and defaults
+            "-DBUILD_opencv_apps=OFF",
+            "-DBUILD_SHARED_LIBS=OFF",
+            "-DBUILD_TESTS=OFF",
+            "-DBUILD_PERF_TESTS=OFF",
+            "-DBUILD_DOCS=OFF",
+        ]
+        + (
+            ["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")]
+            if build_contrib
+            else []
+        )
+    )
+
+    if build_headless:
+        # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
+        cmake_args.append("-DWITH_WIN32UI=OFF")
+        cmake_args.append("-DWITH_QT=OFF")
+        cmake_args.append("-DWITH_GTK=OFF")
+        if is_CI_build:
+            cmake_args.append(
+                "-DWITH_MSMF=OFF"
+            )  # see: https://github.com/skvark/opencv-python/issues/263
+
+    if sys.platform.startswith("linux") and not x64 and "bdist_wheel" in sys.argv:
+        subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
+
+    # OS-specific components during CI builds
+    if is_CI_build:
+
+        if (
+            not build_headless
+            and "bdist_wheel" in sys.argv
+            and (sys.platform == "darwin" or sys.platform.startswith("linux"))
+        ):
+            cmake_args.append("-DWITH_QT=5")
+            subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
+
+            if sys.platform.startswith("linux"):
+                rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
+                    (r"lib/qt/plugins/platforms/libqxcb\.so")
+                ]
+
+                # add fonts for Qt5
+                fonts = []
+                for file in os.listdir("/usr/share/fonts/dejavu"):
+                    if file.endswith(".ttf"):
+                        fonts.append(
+                            (r"lib/qt/fonts/dejavu/%s\.ttf" % file.split(".")[0])
+                        )
+
+                rearrange_cmake_output_data["cv2.qt.fonts"] = fonts
+
+            if sys.platform == "darwin":
+                rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
+                    (r"lib/qt/plugins/platforms/libqcocoa\.dylib")
+                ]
+
+        if sys.platform.startswith("linux"):
+            cmake_args.append("-DWITH_V4L=ON")
+            cmake_args.append("-DWITH_LAPACK=ON")
+            cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
+
+    # https://github.com/scikit-build/scikit-build/issues/479
+    if "CMAKE_ARGS" in os.environ:
+        import shlex
+
+        cmake_args.extend(shlex.split(os.environ["CMAKE_ARGS"]))
+        del shlex
+
+    # works via side effect
+    RearrangeCMakeOutput(
+        rearrange_cmake_output_data, files_outside_package_dir, package_data.keys()
+    )
+
+    skbuild.setup(
+        name=package_name,
+        version=package_version,
+        url="https://github.com/skvark/opencv-python",
+        license="MIT",
+        description="Wrapper package for OpenCV python bindings.",
+        long_description=long_description,
+        long_description_content_type="text/markdown",
+        packages=packages,
+        package_data=package_data,
+        maintainer="Olli-Pekka Heinisuo",
+        ext_modules=EmptyListWithLength(),
+        install_requires=numpy_version,
+        python_requires=">=3.6",
+        classifiers=[
+            "Development Status :: 5 - Production/Stable",
+            "Environment :: Console",
+            "Intended Audience :: Developers",
+            "Intended Audience :: Education",
+            "Intended Audience :: Information Technology",
+            "Intended Audience :: Science/Research",
+            "License :: OSI Approved :: MIT License",
+            "Operating System :: MacOS",
+            "Operating System :: Microsoft :: Windows",
+            "Operating System :: POSIX",
+            "Operating System :: Unix",
+            "Programming Language :: Python",
+            "Programming Language :: Python :: 3",
+            "Programming Language :: Python :: 3 :: Only",
+            "Programming Language :: Python :: 3.6",
+            "Programming Language :: Python :: 3.7",
+            "Programming Language :: Python :: 3.8",
+            "Programming Language :: Python :: 3.9",
+            "Programming Language :: C++",
+            "Programming Language :: Python :: Implementation :: CPython",
+            "Topic :: Scientific/Engineering",
+            "Topic :: Scientific/Engineering :: Image Recognition",
+            "Topic :: Software Development",
+        ],
+        cmake_args=cmake_args,
+        cmake_source_dir=cmake_source_dir,
+    )
+
+
+class RearrangeCMakeOutput(object):
+    """
+        Patch SKBuild logic to only take files related to the Python package
+        and construct a file hierarchy that SKBuild expects (see below)
+    """
+
+    _setuptools_wrap = None
+
+    # Have to wrap a function reference, or it's converted
+    # into an instance method on attr assignment
+    import argparse
+
+    wraps = argparse.Namespace(_classify_installed_files=None)
+    del argparse
+
+    package_paths_re = None
+    packages = None
+    files_outside_package = None
+
+    def __init__(self, package_paths_re, files_outside_package, packages):
+        cls = self.__class__
+        assert not cls.wraps._classify_installed_files, "Singleton object"
+        import skbuild.setuptools_wrap
+
+        cls._setuptools_wrap = skbuild.setuptools_wrap
+        cls.wraps._classify_installed_files = (
+            cls._setuptools_wrap._classify_installed_files
+        )
+        cls._setuptools_wrap._classify_installed_files = (
+            self._classify_installed_files_override
+        )
+
+        cls.package_paths_re = package_paths_re
+        cls.files_outside_package = files_outside_package
+        cls.packages = packages
+
+    def __del__(self):
+        cls = self.__class__
+        cls._setuptools_wrap._classify_installed_files = (
+            cls.wraps._classify_installed_files
+        )
+        cls.wraps._classify_installed_files = None
+        cls._setuptools_wrap = None
+
+    def _classify_installed_files_override(
+        self,
+        install_paths,
+        package_data,
+        package_prefixes,
+        py_modules,
+        new_py_modules,
+        scripts,
+        new_scripts,
+        data_files,
+        cmake_source_dir,
+        cmake_install_reldir,
+    ):
+        """
+            From all CMake output, we're only interested in a few files
+            and must place them into CMake install dir according
+            to Python conventions for SKBuild to find them:
+                package\
+                    file
+                    subpackage\
+                        etc.
+        """
+
+        cls = self.__class__
+
+        # 'relpath'/'reldir' = relative to CMAKE_INSTALL_DIR/cmake_install_dir
+        # 'path'/'dir' = relative to sourcetree root
+        cmake_install_dir = os.path.join(
+            cls._setuptools_wrap.CMAKE_INSTALL_DIR(), cmake_install_reldir
+        )
+        install_relpaths = [
+            os.path.relpath(p, cmake_install_dir) for p in install_paths
+        ]
+        fslash_install_relpaths = [
+            p.replace(os.path.sep, "/") for p in install_relpaths
+        ]
+        relpaths_zip = list(zip(fslash_install_relpaths, install_relpaths))
+        del install_relpaths, fslash_install_relpaths
+
+        final_install_relpaths = []
+
+        print("Copying files from CMake output")
+
+        for package_name, relpaths_re in cls.package_paths_re.items():
+            package_dest_reldir = package_name.replace(".", os.path.sep)
+            for relpath_re in relpaths_re:
+                found = False
+                r = re.compile(relpath_re + "$")
+                for fslash_relpath, relpath in relpaths_zip:
+                    m = r.match(fslash_relpath)
+                    if not m:
+                        continue
+                    found = True
+                    new_install_relpath = os.path.join(
+                        package_dest_reldir, os.path.basename(relpath)
+                    )
+                    cls._setuptools_wrap._copy_file(
+                        os.path.join(cmake_install_dir, relpath),
+                        os.path.join(cmake_install_dir, new_install_relpath),
+                        hide_listing=False,
+                    )
+                    final_install_relpaths.append(new_install_relpath)
+                    del m, fslash_relpath, new_install_relpath
+                else:
+                    if not found:
+                        raise Exception("Not found: '%s'" % relpath_re)
+                del r, found
+
+        del relpaths_zip
+
+        print("Copying files from non-default sourcetree locations")
+
+        for package_name, paths in cls.files_outside_package.items():
+            package_dest_reldir = package_name.replace(".", os.path.sep)
+            for path in paths:
+                new_install_relpath = os.path.join(
+                    package_dest_reldir,
+                    # Don't yet have a need to copy
+                    # to subdirectories of package dir
+                    os.path.basename(path),
+                )
+                cls._setuptools_wrap._copy_file(
+                    path,
+                    os.path.join(cmake_install_dir, new_install_relpath),
+                    hide_listing=False,
+                )
+                final_install_relpaths.append(new_install_relpath)
+
+        final_install_paths = [
+            os.path.join(cmake_install_dir, p) for p in final_install_relpaths
+        ]
+
+        return (cls.wraps._classify_installed_files)(
+            final_install_paths,
+            package_data,
+            package_prefixes,
+            py_modules,
+            new_py_modules,
+            scripts,
+            new_scripts,
+            data_files,
+            # To get around a check that prepends source dir to paths and breaks package detection code.
+            cmake_source_dir="",
+            cmake_install_dir=cmake_install_reldir,
+        )
+
+
+def get_and_set_info(contrib, headless, ci_build):
+    # cv2/version.py should be generated by running find_version.py
+    version = {}
+    here = os.path.abspath(os.path.dirname(__file__))
+    version_file = os.path.join(here, "cv2", "version.py")
+
+    # generate a fresh version.py always when Git repository exists
+    # (in sdists the version.py file already exists)
+    if os.path.exists(".git"):
+        old_args = sys.argv.copy()
+        sys.argv = ["", str(contrib), str(headless), str(ci_build)]
+        runpy.run_path("find_version.py", run_name="__main__")
+        sys.argv = old_args
+
+    with open(version_file) as fp:
+        exec(fp.read(), version)
+
+    return version["opencv_version"], version["contrib"], version["headless"]
+
+
+def get_build_env_var_by_name(flag_name):
+    flag_set = False
+
+    try:
+        flag_set = bool(int(os.getenv("ENABLE_" + flag_name.upper(), None)))
+    except Exception:
+        pass
+
+    if not flag_set:
+        try:
+            flag_set = bool(int(open(flag_name + ".enabled").read(1)))
+        except Exception:
+            pass
+
+    return flag_set
+
+
+# This creates a list which is empty but returns a length of 1.
+# Should make the wheel a binary distribution and platlib compliant.
+class EmptyListWithLength(list):
+    def __len__(self):
+        return 1
+
+
+if __name__ == "__main__":
+    main()
diff --git a/tests/test.py b/tests/test.py
index 54ee19dc..6411ff39 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -1,17 +1,17 @@
-import unittest
-import sys
-
-
-class OpenCVTest(unittest.TestCase):
-    """ Simple functionality tests. """
-
-    def test_import(self):
-        """ Test that the cv2 module can be imported. """
-        import cv2
-
-    def test_video_capture(self):
-
-        import cv2
-
-        cap = cv2.VideoCapture("SampleVideo_1280x720_1mb.mp4")
-        self.assertTrue(cap.isOpened())
+import unittest
+import sys
+
+
+class OpenCVTest(unittest.TestCase):
+    """ Simple functionality tests. """
+
+    def test_import(self):
+        """ Test that the cv2 module can be imported. """
+        import cv2
+
+    def test_video_capture(self):
+
+        import cv2
+
+        cap = cv2.VideoCapture("SampleVideo_1280x720_1mb.mp4")
+        self.assertTrue(cap.isOpened())

From e225c615d8741dfd78cfae05470aa5af60cb7c8b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 30 Oct 2020 17:10:50 +0200
Subject: [PATCH 459/566] fix auditwheel patching

---
 travis_config.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index 6f9f6511..910e365f 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -17,7 +17,11 @@ function bdist_wheel_cmd {
     CI_BUILD=1 pip wheel --verbose --wheel-dir="$PWD/dist" . $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
     if [ -z "$IS_OSX" ]; then
-      /opt/python/cp37-cp37m/bin/python patch_auditwheel_whitelist.py
+      TOOLS_PATH=/opt/_internal/tools
+      /opt/python/cp37-cp37m/bin/python -m venv $TOOLS_PATH
+      source $TOOLS_PATH/bin/activate
+      python patch_auditwheel_whitelist.py
+      deactivate
     fi
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }

From ed8acbccb8a1c0dda9cb30de325fd86fe47105ef Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 30 Oct 2020 22:55:24 +0200
Subject: [PATCH 460/566] fix py39 entry

---
 .travis.yml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 9b583ed7..406a0797 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -352,7 +352,6 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.19.3
-        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux

From 649cfc1d98a30690acfd10a47b11f1ac8da21b51 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 30 Oct 2020 22:55:24 +0200
Subject: [PATCH 461/566] fix py39 entry

---
 .travis.yml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 9b583ed7..406a0797 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -352,7 +352,6 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.19.3
-        - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
     - os: linux

From 7e104646a3984b1d151781553240937947189212 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 1 Nov 2020 16:06:27 +0200
Subject: [PATCH 462/566] fix min numpy version

---
 setup.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/setup.py b/setup.py
index 3ba72442..12f45c95 100644
--- a/setup.py
+++ b/setup.py
@@ -27,6 +27,8 @@ def main():
         minimum_supported_numpy = "1.14.5"
     if sys.version_info[:2] >= (3, 8):
         minimum_supported_numpy = "1.17.3"
+    if sys.version_info[:2] >= (3, 9):
+        minimum_supported_numpy = "1.19.3"
 
     numpy_version = "numpy>=%s" % minimum_supported_numpy
 

From 285348bc19c7e31ec7974f9c8febbb6fbc12ef17 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 1 Nov 2020 16:06:27 +0200
Subject: [PATCH 463/566] fix min numpy version

---
 setup.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/setup.py b/setup.py
index 55fcbccd..b58ea894 100644
--- a/setup.py
+++ b/setup.py
@@ -27,6 +27,8 @@ def main():
         minimum_supported_numpy = "1.14.5"
     if sys.version_info[:2] >= (3, 8):
         minimum_supported_numpy = "1.17.3"
+    if sys.version_info[:2] >= (3, 9):
+        minimum_supported_numpy = "1.19.3"
 
     numpy_version = "numpy>=%s" % minimum_supported_numpy
 

From ea7c4164a5b1ae316a219935b69f24947ff7fd9f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 1 Nov 2020 16:13:15 +0200
Subject: [PATCH 464/566] download Python 3.9 manually

---
 appveyor.yml | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/appveyor.yml b/appveyor.yml
index b658399a..3e5d8053 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -137,6 +137,16 @@ environment:
 matrix:
     fast_finish: true
 
+install:
+  - ps: |
+      if (-not (Test-Path $env:PYTHON)) {
+        curl -o install_python.ps1 https://raw.githubusercontent.com/matthew-brett/multibuild/devel/install_python.ps1
+        .\install_python.ps1
+      }
+  - ps: if (-not (Test-Path $env:PYTHON)) { throw "No $env:PYTHON" }
+  - "set PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
+  - python --version
+
 build_script:
 - cmd: |
     "%PYTHON%/python.exe" -m pip install --upgrade pip

From 23d3a09dae68d6f99615bcac8b6bca60489967f0 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 1 Nov 2020 16:13:15 +0200
Subject: [PATCH 465/566] download Python 3.9 manually

---
 appveyor.yml | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/appveyor.yml b/appveyor.yml
index b658399a..3e5d8053 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -137,6 +137,16 @@ environment:
 matrix:
     fast_finish: true
 
+install:
+  - ps: |
+      if (-not (Test-Path $env:PYTHON)) {
+        curl -o install_python.ps1 https://raw.githubusercontent.com/matthew-brett/multibuild/devel/install_python.ps1
+        .\install_python.ps1
+      }
+  - ps: if (-not (Test-Path $env:PYTHON)) { throw "No $env:PYTHON" }
+  - "set PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
+  - python --version
+
 build_script:
 - cmd: |
     "%PYTHON%/python.exe" -m pip install --upgrade pip

From 86414ec4c72ee2d272e8d9a5a4500b869ddc6d9e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 1 Nov 2020 18:43:24 +0200
Subject: [PATCH 466/566] fix slashes

---
 appveyor.yml | 78 ++++++++++++++++++++++++++--------------------------
 1 file changed, 39 insertions(+), 39 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index 3e5d8053..30646669 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -6,131 +6,131 @@ environment:
     secure: 0bXSOVjf9x8L7nErTivu92TF1FwNosTjFJQPmxp8Dys=
 
   matrix:
-    - PYTHON: "C:/Python36"
+    - PYTHON: "C:\Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python36-x64"
+    - PYTHON: "C:\Python36-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python37"
+    - PYTHON: "C:\Python37"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python37-x64"
+    - PYTHON: "C:\Python37-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python38"
+    - PYTHON: "C:\Python38"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python38-x64"
+    - PYTHON: "C:\Python38-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python39"
+    - PYTHON: "C:\Python39"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python39-x64"
+    - PYTHON: "C:\Python39-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python36"
+    - PYTHON: "C:\Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python36-x64"
+    - PYTHON: "C:\Python36-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python37"
+    - PYTHON: "C:\Python37"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python37-x64"
+    - PYTHON: "C:\Python37-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python38"
+    - PYTHON: "C:\Python38"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python38-x64"
+    - PYTHON: "C:\Python38-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python39"
+    - PYTHON: "C:\Python39"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python39-x64"
+    - PYTHON: "C:\Python39-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python36"
+    - PYTHON: "C:\Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python36-x64"
+    - PYTHON: "C:\Python36-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python37"
+    - PYTHON: "C:\Python37"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python37-x64"
+    - PYTHON: "C:\Python37-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python38"
+    - PYTHON: "C:\Python38"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python38-x64"
+    - PYTHON: "C:\Python38-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python39"
+    - PYTHON: "C:\Python39"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python39-x64"
+    - PYTHON: "C:\Python39-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python36"
+    - PYTHON: "C:\Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python36-x64"
+    - PYTHON: "C:\Python36-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python37"
+    - PYTHON: "C:\Python37"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python37-x64"
+    - PYTHON: "C:\Python37-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python38"
+    - PYTHON: "C:\Python38"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python38-x64"
+    - PYTHON: "C:\Python38-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python39"
+    - PYTHON: "C:\Python39"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python39-x64"
+    - PYTHON: "C:\Python39-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
@@ -149,23 +149,23 @@ install:
 
 build_script:
 - cmd: |
-    "%PYTHON%/python.exe" -m pip install --upgrade pip
-    "%PYTHON%/python.exe" -m pip install --upgrade setuptools
-    set "CI_BUILD=1" && "%PYTHON%/python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
+    "%PYTHON%\python.exe" -m pip install --upgrade pip
+    "%PYTHON%\python.exe" -m pip install --upgrade setuptools
+    set "CI_BUILD=1" && "%PYTHON%\python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
 
 before_test:
 - ps: |
 
     cd ${Env:APPVEYOR_BUILD_FOLDER}\tests
     $env:PYTHONWARNINGS = "ignore:::pip._internal.cli.base_command"
-    &"${Env:PYTHON}/python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
+    &"${Env:PYTHON}\python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
     if ($LastExitCode -ne 0) {throw $LastExitCode}
 
 test_script:
 - cmd: |
 
     cd %APPVEYOR_BUILD_FOLDER%\tests
-    "%PYTHON%/python.exe" -m unittest test
+    "%PYTHON%\python.exe" -m unittest test
 
 artifacts:
 - path: dist\opencv*.whl
@@ -193,8 +193,8 @@ deploy_script:
         }
       }
 
-      &"${Env:PYTHON}/python.exe" -m pip install twine
-      &"${Env:PYTHON}/python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv*
+      &"${Env:PYTHON}\python.exe" -m pip install twine
+      &"${Env:PYTHON}\python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv*
     }
     else {
       echo "Tag not set, deployment skipped."

From 603e2a329cd0cc1ba0171999475c97d9e4dfcf8e Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 1 Nov 2020 18:43:24 +0200
Subject: [PATCH 467/566] fix slashes

---
 appveyor.yml | 78 ++++++++++++++++++++++++++--------------------------
 1 file changed, 39 insertions(+), 39 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index 3e5d8053..30646669 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -6,131 +6,131 @@ environment:
     secure: 0bXSOVjf9x8L7nErTivu92TF1FwNosTjFJQPmxp8Dys=
 
   matrix:
-    - PYTHON: "C:/Python36"
+    - PYTHON: "C:\Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python36-x64"
+    - PYTHON: "C:\Python36-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python37"
+    - PYTHON: "C:\Python37"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python37-x64"
+    - PYTHON: "C:\Python37-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python38"
+    - PYTHON: "C:\Python38"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python38-x64"
+    - PYTHON: "C:\Python38-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python39"
+    - PYTHON: "C:\Python39"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python39-x64"
+    - PYTHON: "C:\Python39-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python36"
+    - PYTHON: "C:\Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python36-x64"
+    - PYTHON: "C:\Python36-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python37"
+    - PYTHON: "C:\Python37"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python37-x64"
+    - PYTHON: "C:\Python37-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python38"
+    - PYTHON: "C:\Python38"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python38-x64"
+    - PYTHON: "C:\Python38-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python39"
+    - PYTHON: "C:\Python39"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python39-x64"
+    - PYTHON: "C:\Python39-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:/Python36"
+    - PYTHON: "C:\Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python36-x64"
+    - PYTHON: "C:\Python36-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python37"
+    - PYTHON: "C:\Python37"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python37-x64"
+    - PYTHON: "C:\Python37-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python38"
+    - PYTHON: "C:\Python38"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python38-x64"
+    - PYTHON: "C:\Python38-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python39"
+    - PYTHON: "C:\Python39"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python39-x64"
+    - PYTHON: "C:\Python39-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python36"
+    - PYTHON: "C:\Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python36-x64"
+    - PYTHON: "C:\Python36-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python37"
+    - PYTHON: "C:\Python37"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python37-x64"
+    - PYTHON: "C:\Python37-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python38"
+    - PYTHON: "C:\Python38"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python38-x64"
+    - PYTHON: "C:\Python38-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python39"
+    - PYTHON: "C:\Python39"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:/Python39-x64"
+    - PYTHON: "C:\Python39-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
@@ -149,23 +149,23 @@ install:
 
 build_script:
 - cmd: |
-    "%PYTHON%/python.exe" -m pip install --upgrade pip
-    "%PYTHON%/python.exe" -m pip install --upgrade setuptools
-    set "CI_BUILD=1" && "%PYTHON%/python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
+    "%PYTHON%\python.exe" -m pip install --upgrade pip
+    "%PYTHON%\python.exe" -m pip install --upgrade setuptools
+    set "CI_BUILD=1" && "%PYTHON%\python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
 
 before_test:
 - ps: |
 
     cd ${Env:APPVEYOR_BUILD_FOLDER}\tests
     $env:PYTHONWARNINGS = "ignore:::pip._internal.cli.base_command"
-    &"${Env:PYTHON}/python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
+    &"${Env:PYTHON}\python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
     if ($LastExitCode -ne 0) {throw $LastExitCode}
 
 test_script:
 - cmd: |
 
     cd %APPVEYOR_BUILD_FOLDER%\tests
-    "%PYTHON%/python.exe" -m unittest test
+    "%PYTHON%\python.exe" -m unittest test
 
 artifacts:
 - path: dist\opencv*.whl
@@ -193,8 +193,8 @@ deploy_script:
         }
       }
 
-      &"${Env:PYTHON}/python.exe" -m pip install twine
-      &"${Env:PYTHON}/python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv*
+      &"${Env:PYTHON}\python.exe" -m pip install twine
+      &"${Env:PYTHON}\python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv*
     }
     else {
       echo "Tag not set, deployment skipped."

From 6f8c817a028264eed681ec8527f39bd276919324 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 1 Nov 2020 19:12:54 +0200
Subject: [PATCH 468/566] another fix for slashes

---
 appveyor.yml | 78 ++++++++++++++++++++++++++--------------------------
 1 file changed, 39 insertions(+), 39 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index 30646669..c79e7de4 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -6,131 +6,131 @@ environment:
     secure: 0bXSOVjf9x8L7nErTivu92TF1FwNosTjFJQPmxp8Dys=
 
   matrix:
-    - PYTHON: "C:\Python36"
+    - PYTHON: "C:\\Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python36-x64"
+    - PYTHON: "C:\\Python36-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python37"
+    - PYTHON: "C:\\Python37"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python37-x64"
+    - PYTHON: "C:\\Python37-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python38"
+    - PYTHON: "C:\\Python38"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python38-x64"
+    - PYTHON: "C:\\Python38-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python39"
+    - PYTHON: "C:\\Python39"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python39-x64"
+    - PYTHON: "C:\\Python39-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python36"
+    - PYTHON: "C:\\Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python36-x64"
+    - PYTHON: "C:\\Python36-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python37"
+    - PYTHON: "C:\\Python37"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python37-x64"
+    - PYTHON: "C:\\Python37-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python38"
+    - PYTHON: "C:\\Python38"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python38-x64"
+    - PYTHON: "C:\\Python38-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python39"
+    - PYTHON: "C:\\Python39"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python39-x64"
+    - PYTHON: "C:\\Python39-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python36"
+    - PYTHON: "C:\\Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python36-x64"
+    - PYTHON: "C:\\Python36-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python37"
+    - PYTHON: "C:\\Python37"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python37-x64"
+    - PYTHON: "C:\\Python37-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python38"
+    - PYTHON: "C:\\Python38"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python38-x64"
+    - PYTHON: "C:\\Python38-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python39"
+    - PYTHON: "C:\\Python39"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python39-x64"
+    - PYTHON: "C:\\Python39-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python36"
+    - PYTHON: "C:\\Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python36-x64"
+    - PYTHON: "C:\\Python36-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python37"
+    - PYTHON: "C:\\Python37"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python37-x64"
+    - PYTHON: "C:\\Python37-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python38"
+    - PYTHON: "C:\\Python38"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python38-x64"
+    - PYTHON: "C:\\Python38-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python39"
+    - PYTHON: "C:\\Python39"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python39-x64"
+    - PYTHON: "C:\\Python39-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
@@ -149,23 +149,23 @@ install:
 
 build_script:
 - cmd: |
-    "%PYTHON%\python.exe" -m pip install --upgrade pip
-    "%PYTHON%\python.exe" -m pip install --upgrade setuptools
-    set "CI_BUILD=1" && "%PYTHON%\python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
+    "%PYTHON%\\python.exe" -m pip install --upgrade pip
+    "%PYTHON%\\python.exe" -m pip install --upgrade setuptools
+    set "CI_BUILD=1" && "%PYTHON%\\python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
 
 before_test:
 - ps: |
 
     cd ${Env:APPVEYOR_BUILD_FOLDER}\tests
     $env:PYTHONWARNINGS = "ignore:::pip._internal.cli.base_command"
-    &"${Env:PYTHON}\python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
+    &"${Env:PYTHON}\\python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
     if ($LastExitCode -ne 0) {throw $LastExitCode}
 
 test_script:
 - cmd: |
 
     cd %APPVEYOR_BUILD_FOLDER%\tests
-    "%PYTHON%\python.exe" -m unittest test
+    "%PYTHON%\\python.exe" -m unittest test
 
 artifacts:
 - path: dist\opencv*.whl
@@ -193,8 +193,8 @@ deploy_script:
         }
       }
 
-      &"${Env:PYTHON}\python.exe" -m pip install twine
-      &"${Env:PYTHON}\python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv*
+      &"${Env:PYTHON}\\python.exe" -m pip install twine
+      &"${Env:PYTHON}\\python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv*
     }
     else {
       echo "Tag not set, deployment skipped."

From 6b377bade9e8127188ab748c1b8ac14efa87374a Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sun, 1 Nov 2020 19:12:54 +0200
Subject: [PATCH 469/566] another fix for slashes

---
 appveyor.yml | 78 ++++++++++++++++++++++++++--------------------------
 1 file changed, 39 insertions(+), 39 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index 30646669..c79e7de4 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -6,131 +6,131 @@ environment:
     secure: 0bXSOVjf9x8L7nErTivu92TF1FwNosTjFJQPmxp8Dys=
 
   matrix:
-    - PYTHON: "C:\Python36"
+    - PYTHON: "C:\\Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python36-x64"
+    - PYTHON: "C:\\Python36-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python37"
+    - PYTHON: "C:\\Python37"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python37-x64"
+    - PYTHON: "C:\\Python37-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python38"
+    - PYTHON: "C:\\Python38"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python38-x64"
+    - PYTHON: "C:\\Python38-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python39"
+    - PYTHON: "C:\\Python39"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python39-x64"
+    - PYTHON: "C:\\Python39-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python36"
+    - PYTHON: "C:\\Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python36-x64"
+    - PYTHON: "C:\\Python36-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python37"
+    - PYTHON: "C:\\Python37"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python37-x64"
+    - PYTHON: "C:\\Python37-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python38"
+    - PYTHON: "C:\\Python38"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python38-x64"
+    - PYTHON: "C:\\Python38-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python39"
+    - PYTHON: "C:\\Python39"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python39-x64"
+    - PYTHON: "C:\\Python39-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 0
 
-    - PYTHON: "C:\Python36"
+    - PYTHON: "C:\\Python36"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python36-x64"
+    - PYTHON: "C:\\Python36-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python37"
+    - PYTHON: "C:\\Python37"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python37-x64"
+    - PYTHON: "C:\\Python37-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python38"
+    - PYTHON: "C:\\Python38"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python38-x64"
+    - PYTHON: "C:\\Python38-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python39"
+    - PYTHON: "C:\\Python39"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python39-x64"
+    - PYTHON: "C:\\Python39-x64"
       ENABLE_CONTRIB: 0
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python36"
+    - PYTHON: "C:\\Python36"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python36-x64"
+    - PYTHON: "C:\\Python36-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python37"
+    - PYTHON: "C:\\Python37"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python37-x64"
+    - PYTHON: "C:\\Python37-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python38"
+    - PYTHON: "C:\\Python38"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python38-x64"
+    - PYTHON: "C:\\Python38-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python39"
+    - PYTHON: "C:\\Python39"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
-    - PYTHON: "C:\Python39-x64"
+    - PYTHON: "C:\\Python39-x64"
       ENABLE_CONTRIB: 1
       ENABLE_HEADLESS: 1
 
@@ -149,23 +149,23 @@ install:
 
 build_script:
 - cmd: |
-    "%PYTHON%\python.exe" -m pip install --upgrade pip
-    "%PYTHON%\python.exe" -m pip install --upgrade setuptools
-    set "CI_BUILD=1" && "%PYTHON%\python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
+    "%PYTHON%\\python.exe" -m pip install --upgrade pip
+    "%PYTHON%\\python.exe" -m pip install --upgrade setuptools
+    set "CI_BUILD=1" && "%PYTHON%\\python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
 
 before_test:
 - ps: |
 
     cd ${Env:APPVEYOR_BUILD_FOLDER}\tests
     $env:PYTHONWARNINGS = "ignore:::pip._internal.cli.base_command"
-    &"${Env:PYTHON}\python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
+    &"${Env:PYTHON}\\python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
     if ($LastExitCode -ne 0) {throw $LastExitCode}
 
 test_script:
 - cmd: |
 
     cd %APPVEYOR_BUILD_FOLDER%\tests
-    "%PYTHON%\python.exe" -m unittest test
+    "%PYTHON%\\python.exe" -m unittest test
 
 artifacts:
 - path: dist\opencv*.whl
@@ -193,8 +193,8 @@ deploy_script:
         }
       }
 
-      &"${Env:PYTHON}\python.exe" -m pip install twine
-      &"${Env:PYTHON}\python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv*
+      &"${Env:PYTHON}\\python.exe" -m pip install twine
+      &"${Env:PYTHON}\\python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv*
     }
     else {
       echo "Tag not set, deployment skipped."

From e98379369e0dcf3f4b636d6b42b5a0815182416c Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 2 Nov 2020 18:15:44 +0200
Subject: [PATCH 470/566] update README

---
 README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.md b/README.md
index 94a30d4b..98bbfa3b 100644
--- a/README.md
+++ b/README.md
@@ -200,6 +200,7 @@ Python 3.x compatible pre-built wheels are provided for the officially supported
 - 3.6
 - 3.7
 - 3.8
+- 3.9
 
 ### Backward compatibility
 

From 98fa4b18da0813c1a0ce6ea224485c724e50b60b Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 2 Nov 2020 18:15:44 +0200
Subject: [PATCH 471/566] update README

---
 README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.md b/README.md
index 94a30d4b..98bbfa3b 100644
--- a/README.md
+++ b/README.md
@@ -200,6 +200,7 @@ Python 3.x compatible pre-built wheels are provided for the officially supported
 - 3.6
 - 3.7
 - 3.8
+- 3.9
 
 ### Backward compatibility
 

From 83ace3c0ce52bbc64292baaa7642ba99cdc7b221 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 21 Aug 2020 21:42:27 +0300
Subject: [PATCH 472/566] try with new images

---
 .travis.yml | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 406a0797..5cebcd93 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -367,7 +367,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - PLAT=aarch64
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.17.3
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
+        
     # headless builds for Linux
     - os: linux
       language: generic

From 58920f641df7a0433a9773011956a23b6eaabe4f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 21 Aug 2020 22:00:16 +0300
Subject: [PATCH 473/566] add env markers for aarch64

---
 pyproject.toml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index b362f93f..4e53a159 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -2,7 +2,8 @@
 requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
   "numpy==1.13.3; python_version=='3.6'",
+  "numpy==1.19.0; python_version>='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
   "numpy==1.14.5; python_version=='3.7'",
   "numpy==1.17.3; python_version=='3.8'",
   "numpy==1.19.3; python_version>='3.9'"
-]
\ No newline at end of file
+]

From 0fc0d4b5c80035949f6f0265b8dd4a4de811a6dd Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 21 Aug 2020 22:04:17 +0300
Subject: [PATCH 474/566] add numpy version to setup.py

---
 setup.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/setup.py b/setup.py
index 12f45c95..528019cd 100644
--- a/setup.py
+++ b/setup.py
@@ -6,6 +6,7 @@
 import subprocess
 import re
 import sysconfig
+import platform
 import skbuild
 from skbuild import cmaker
 
@@ -23,6 +24,8 @@ def main():
 
     if sys.version_info[:2] >= (3, 6):
         minimum_supported_numpy = "1.13.3"
+    if sys.version_info[:2] >= (3, 6) and platform.machine() == "aarch64":
+        minimum_supported_numpy = "1.19.0"
     if sys.version_info[:2] >= (3, 7):
         minimum_supported_numpy = "1.14.5"
     if sys.version_info[:2] >= (3, 8):

From 8cc5da85711a24a15715f93fb49ed532aef5a8e2 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Fri, 21 Aug 2020 22:14:01 +0300
Subject: [PATCH 475/566] test depends, more specific pyproject.toml

---
 .travis.yml    | 4 ++--
 pyproject.toml | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 5cebcd93..c29a8d9d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -377,11 +377,11 @@ jobs:
         - PLAT=aarch64
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.17.3
+        - TEST_DEPENDS=numpy==1.19.0
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-        
+
     # headless builds for Linux
     - os: linux
       language: generic
diff --git a/pyproject.toml b/pyproject.toml
index 4e53a159..b2efd1bd 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,9 +1,9 @@
 [build-system]
 requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
-  "numpy==1.13.3; python_version=='3.6'",
+  "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64'",
   "numpy==1.19.0; python_version>='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
-  "numpy==1.14.5; python_version=='3.7'",
-  "numpy==1.17.3; python_version=='3.8'",
-  "numpy==1.19.3; python_version>='3.9'"
+  "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64'",
+  "numpy==1.17.3; python_version=='3.8' and platform_machine != 'aarch64'",
+  "numpy==1.19.3; python_version>='3.9' and platform_machine != 'aarch64'"
 ]

From 16ac6e7655750ea23f7a756700be9262b6e912f0 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Thu, 12 Nov 2020 21:30:45 +0200
Subject: [PATCH 476/566] add test image

---
 .travis.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.travis.yml b/.travis.yml
index c29a8d9d..8c1c0b80 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -375,6 +375,7 @@ jobs:
       env:
         - MB_PYTHON_VERSION=3.8
         - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.19.0

From 37a96dac620aa72751936560f430756a1a099451 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 16 Nov 2020 16:48:00 +0200
Subject: [PATCH 477/566] add arm64 matrix entries and update Dockerfile

---
 .travis.yml                             | 225 ++++++++++++++++++++++++
 docker/manylinux2014/Dockerfile_aarch64 |  10 --
 2 files changed, 225 insertions(+), 10 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 8c1c0b80..30a0ff0d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -295,6 +295,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.6
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -319,6 +334,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -343,6 +373,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -408,6 +453,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.6
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -432,6 +492,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -456,6 +531,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -480,6 +570,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=0
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
 
     # contrib builds for Linux
     - os: linux
@@ -506,6 +611,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.6
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -530,6 +650,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -554,6 +689,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -578,6 +728,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=0
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
 
 
     # headless contrib builds for Linux
@@ -605,6 +770,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.6
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -629,6 +809,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.7
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -653,6 +848,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.8
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
     - os: linux
       language: generic
       dist: xenial
@@ -677,6 +887,21 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
+    - os: linux
+      arch: arm64
+      language: generic
+      dist: xenial
+      services: docker
+      env:
+        - MB_PYTHON_VERSION=3.9
+        - PLAT=aarch64
+        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
+        - ENABLE_CONTRIB=1
+        - ENABLE_HEADLESS=1
+        - TEST_DEPENDS=numpy==1.19.0
+        - USE_CCACHE=0
+      cache:
+        directories: $HOME/.ccache
 
 # The first line is printed in the folding header in Travis output
 before_install: |
diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
index 5fb47264..e8920770 100644
--- a/docker/manylinux2014/Dockerfile_aarch64
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -68,16 +68,6 @@ RUN curl -O -L https://github.com/ccache/ccache/releases/download/v3.7.9/ccache-
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
 
-RUN curl -O -L https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-3.17.0.tar.gz && \
-    tar -xf cmake-3.17.0.tar.gz && \
-    cd cmake-3.17.0 && \
-    export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
-    ./configure --system-curl && \
-    make && \
-    make install && \
-    cd .. && \
-    rm -rf cmake-3.17.0*
-
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 ENV PATH "$HOME/bin:$PATH"

From f76794273354b316195e3beac0a6216ff22445d6 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 16 Nov 2020 16:51:31 +0200
Subject: [PATCH 478/566] fix py version

---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 30a0ff0d..a4c8227e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -418,7 +418,7 @@ jobs:
       dist: xenial
       services: docker
       env:
-        - MB_PYTHON_VERSION=3.8
+        - MB_PYTHON_VERSION=3.9
         - PLAT=aarch64
         - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
         - ENABLE_CONTRIB=0

From 39ca0fdafb0e7ba9a34491a48e0eddc549e87491 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 16 Nov 2020 18:06:55 +0200
Subject: [PATCH 479/566] use numpy 1.19.3

---
 pyproject.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index b2efd1bd..d7c5527d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -2,7 +2,7 @@
 requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
   "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64'",
-  "numpy==1.19.0; python_version>='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
+  "numpy==1.19.3; python_version>='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
   "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64'",
   "numpy==1.17.3; python_version=='3.8' and platform_machine != 'aarch64'",
   "numpy==1.19.3; python_version>='3.9' and platform_machine != 'aarch64'"

From 7701ec78577301c235ad53ce613b4fa04a589963 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 16 Nov 2020 18:06:55 +0200
Subject: [PATCH 480/566] use numpy 1.19.3

---
 pyproject.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index b2efd1bd..d7c5527d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -2,7 +2,7 @@
 requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
   "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64'",
-  "numpy==1.19.0; python_version>='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
+  "numpy==1.19.3; python_version>='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
   "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64'",
   "numpy==1.17.3; python_version=='3.8' and platform_machine != 'aarch64'",
   "numpy==1.19.3; python_version>='3.9' and platform_machine != 'aarch64'"

From a5fc2953c61ebfd6c4b0b025abbe3890edbc5a3f Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 17 Nov 2020 16:27:53 +0200
Subject: [PATCH 481/566] fix min supported numpy

---
 setup.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/setup.py b/setup.py
index 528019cd..a4f9f729 100644
--- a/setup.py
+++ b/setup.py
@@ -17,15 +17,13 @@ def main():
     CI_BUILD = os.environ.get("CI_BUILD", "False")
     is_CI_build = True if CI_BUILD == "1" else False
     cmake_source_dir = "opencv"
-    minimum_supported_numpy = "1.13.1"
+    minimum_supported_numpy = "1.13.3"
     build_contrib = get_build_env_var_by_name("contrib")
     build_headless = get_build_env_var_by_name("headless")
     build_java = "ON" if get_build_env_var_by_name("java") else "OFF"
 
     if sys.version_info[:2] >= (3, 6):
         minimum_supported_numpy = "1.13.3"
-    if sys.version_info[:2] >= (3, 6) and platform.machine() == "aarch64":
-        minimum_supported_numpy = "1.19.0"
     if sys.version_info[:2] >= (3, 7):
         minimum_supported_numpy = "1.14.5"
     if sys.version_info[:2] >= (3, 8):
@@ -33,6 +31,10 @@ def main():
     if sys.version_info[:2] >= (3, 9):
         minimum_supported_numpy = "1.19.3"
 
+    # arm64 is a special case
+    if sys.version_info[:2] >= (3, 6) and platform.machine() == "aarch64":
+        minimum_supported_numpy = "1.19.3"
+
     numpy_version = "numpy>=%s" % minimum_supported_numpy
 
     python_version = cmaker.CMaker.get_python_version()

From 54294dda82192b40f85061e2f3c6733de17e62d0 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Tue, 17 Nov 2020 16:27:53 +0200
Subject: [PATCH 482/566] fix min supported numpy

---
 setup.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/setup.py b/setup.py
index 4ad06197..7b106847 100644
--- a/setup.py
+++ b/setup.py
@@ -17,15 +17,13 @@ def main():
     CI_BUILD = os.environ.get("CI_BUILD", "False")
     is_CI_build = True if CI_BUILD == "1" else False
     cmake_source_dir = "opencv"
-    minimum_supported_numpy = "1.13.1"
+    minimum_supported_numpy = "1.13.3"
     build_contrib = get_build_env_var_by_name("contrib")
     build_headless = get_build_env_var_by_name("headless")
     build_java = "ON" if get_build_env_var_by_name("java") else "OFF"
 
     if sys.version_info[:2] >= (3, 6):
         minimum_supported_numpy = "1.13.3"
-    if sys.version_info[:2] >= (3, 6) and platform.machine() == "aarch64":
-        minimum_supported_numpy = "1.19.0"
     if sys.version_info[:2] >= (3, 7):
         minimum_supported_numpy = "1.14.5"
     if sys.version_info[:2] >= (3, 8):
@@ -33,6 +31,10 @@ def main():
     if sys.version_info[:2] >= (3, 9):
         minimum_supported_numpy = "1.19.3"
 
+    # arm64 is a special case
+    if sys.version_info[:2] >= (3, 6) and platform.machine() == "aarch64":
+        minimum_supported_numpy = "1.19.3"
+
     numpy_version = "numpy>=%s" % minimum_supported_numpy
 
     python_version = cmaker.CMaker.get_python_version()

From 1e85f5e48571923bb8dcd417294a16898ab96b39 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 28 Nov 2020 14:02:25 +0200
Subject: [PATCH 483/566] update OpenCV licensing

---
 LICENSE-3RD-PARTY.txt | 242 +++++++++++++++++++++++++++++++++++-------
 README.md             |   2 +-
 2 files changed, 202 insertions(+), 42 deletions(-)

diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index 60c34bc0..20f4fb37 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -1,48 +1,208 @@
 OpenCV library is redistributed within opencv-python package.
 This license applies to OpenCV binary in the directory cv2/.
 
-By downloading, copying, installing or using the software you agree to this license.
-If you do not agree to this license, do not download, install,
-copy or use the software.
 
-
-                          License Agreement
-               For Open Source Computer Vision Library
-                       (3-clause BSD License)
-
-Copyright (C) 2000-2020, Intel Corporation, all rights reserved.
-Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
-Copyright (C) 2009-2016, NVIDIA Corporation, all rights reserved.
-Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
-Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
-Copyright (C) 2015-2016, Itseez Inc., all rights reserved.
-Copyright (C) 2019-2020, Xperience AI, all rights reserved.
-Third party copyrights are property of their respective owners.
-
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-
-  * Redistributions of source code must retain the above copyright notice,
-    this list of conditions and the following disclaimer.
-
-  * Redistributions in binary form must reproduce the above copyright notice,
-    this list of conditions and the following disclaimer in the documentation
-    and/or other materials provided with the distribution.
-
-  * Neither the names of the copyright holders nor the names of the contributors
-    may be used to endorse or promote products derived from this software
-    without specific prior written permission.
-
-This software is provided by the copyright holders and contributors "as is" and
-any express or implied warranties, including, but not limited to, the implied
-warranties of merchantability and fitness for a particular purpose are disclaimed.
-In no event shall copyright holders or contributors be liable for any direct,
-indirect, incidental, special, exemplary, or consequential damages
-(including, but not limited to, procurement of substitute goods or services;
-loss of use, data, or profits; or business interruption) however caused
-and on any theory of liability, whether in contract, strict liability,
-or tort (including negligence or otherwise) arising in any way out of
-the use of this software, even if advised of the possibility of such damage.
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
 
 ------------------------------------------------------------------------------
 libvpx is redistributed within all opencv-python Linux packages.
diff --git a/README.md b/README.md
index 98bbfa3b..6c6022ba 100644
--- a/README.md
+++ b/README.md
@@ -157,7 +157,7 @@ On slow systems such as Raspberry Pi the full build may take several hours. On a
 
 Opencv-python package (scripts in this repository) is available under MIT license.
 
-OpenCV itself is available under [3-clause BSD License](https://github.com/opencv/opencv/blob/master/LICENSE).
+OpenCV itself is available under [Apache 2](https://github.com/opencv/opencv/blob/master/LICENSE) license.
 
 Third party package licenses are at [LICENSE-3RD-PARTY.txt](https://github.com/skvark/opencv-python/blob/master/LICENSE-3RD-PARTY.txt).
 

From bb77a8a8f763a1ac7f12a7262397375e835a8ca5 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 28 Nov 2020 14:03:46 +0200
Subject: [PATCH 484/566] OpenCV 3.4.12

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index e8d4259f..dc15187f 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit e8d4259f9ab787b512b9aa1203fc816fb9f19231
+Subproject commit dc15187f1b6784ef2ece30dae223570811eaddff
diff --git a/opencv_contrib b/opencv_contrib
index 3ce9ec6c..b8eca416 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 3ce9ec6c827b7b715ba9f7282f5670925c903b56
+Subproject commit b8eca4161439f361ae4d5a398aab1495136c704b

From f33e65ddfc206d9169136b99d972f3014ee1afdc Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 28 Nov 2020 14:05:37 +0200
Subject: [PATCH 485/566] OpenCV 4.5.0

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index c3bb57af..d5fd2f01 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit c3bb57afeaf030f10939204d48d7c2a3842f4293
+Subproject commit d5fd2f0155ffad366f9ac912dfd6d189a7a6a98e
diff --git a/opencv_contrib b/opencv_contrib
index 5fae4082..37315bab 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 5fae4082cc493efa5cb7a7486f9e009618a5198b
+Subproject commit 37315babf9984a5b6aa981644a20dd8df1a5ff02

From 3137b3e570d2b78e16a2c2def094d125b16dadbd Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Sat, 28 Nov 2020 14:02:25 +0200
Subject: [PATCH 486/566] update OpenCV licensing

---
 LICENSE-3RD-PARTY.txt | 242 +++++++++++++++++++++++++++++++++++-------
 README.md             |   2 +-
 2 files changed, 202 insertions(+), 42 deletions(-)

diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index 60c34bc0..20f4fb37 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -1,48 +1,208 @@
 OpenCV library is redistributed within opencv-python package.
 This license applies to OpenCV binary in the directory cv2/.
 
-By downloading, copying, installing or using the software you agree to this license.
-If you do not agree to this license, do not download, install,
-copy or use the software.
 
-
-                          License Agreement
-               For Open Source Computer Vision Library
-                       (3-clause BSD License)
-
-Copyright (C) 2000-2020, Intel Corporation, all rights reserved.
-Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
-Copyright (C) 2009-2016, NVIDIA Corporation, all rights reserved.
-Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
-Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
-Copyright (C) 2015-2016, Itseez Inc., all rights reserved.
-Copyright (C) 2019-2020, Xperience AI, all rights reserved.
-Third party copyrights are property of their respective owners.
-
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-
-  * Redistributions of source code must retain the above copyright notice,
-    this list of conditions and the following disclaimer.
-
-  * Redistributions in binary form must reproduce the above copyright notice,
-    this list of conditions and the following disclaimer in the documentation
-    and/or other materials provided with the distribution.
-
-  * Neither the names of the copyright holders nor the names of the contributors
-    may be used to endorse or promote products derived from this software
-    without specific prior written permission.
-
-This software is provided by the copyright holders and contributors "as is" and
-any express or implied warranties, including, but not limited to, the implied
-warranties of merchantability and fitness for a particular purpose are disclaimed.
-In no event shall copyright holders or contributors be liable for any direct,
-indirect, incidental, special, exemplary, or consequential damages
-(including, but not limited to, procurement of substitute goods or services;
-loss of use, data, or profits; or business interruption) however caused
-and on any theory of liability, whether in contract, strict liability,
-or tort (including negligence or otherwise) arising in any way out of
-the use of this software, even if advised of the possibility of such damage.
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
 
 ------------------------------------------------------------------------------
 libvpx is redistributed within all opencv-python Linux packages.
diff --git a/README.md b/README.md
index 98bbfa3b..6c6022ba 100644
--- a/README.md
+++ b/README.md
@@ -157,7 +157,7 @@ On slow systems such as Raspberry Pi the full build may take several hours. On a
 
 Opencv-python package (scripts in this repository) is available under MIT license.
 
-OpenCV itself is available under [3-clause BSD License](https://github.com/opencv/opencv/blob/master/LICENSE).
+OpenCV itself is available under [Apache 2](https://github.com/opencv/opencv/blob/master/LICENSE) license.
 
 Third party package licenses are at [LICENSE-3RD-PARTY.txt](https://github.com/skvark/opencv-python/blob/master/LICENSE-3RD-PARTY.txt).
 

From 9c8ebecac062befd1472fbc730296ac145e6c1fa Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 2 Dec 2020 17:11:52 +0200
Subject: [PATCH 487/566] check if there is enough time to build FFmpeg without
 cache

---
 .travis.yml      | 107 +++++++----------------------------------------
 README.md        |   4 --
 travis_config.sh |   1 +
 3 files changed, 17 insertions(+), 95 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index a4c8227e..42623a59 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -32,32 +32,6 @@ jobs:
   exclude:
     - language: ruby
   include:
-    - os: osx
-      env:
-        - MB_PYTHON_VERSION=3.8
-      language: generic
-      osx_image: xcode9.4
-      stage: s1
-      workspaces:
-        create:
-          name: brew_cache
-          paths:
-            # https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
-            - $HOME/Library/Caches/Homebrew
-            - /usr/local/Homebrew/
-            # used in OSX custom build script dealing with local bottle caching
-            - $HOME/local_bottle_metadata
-      #workspaces share within the same build, cache shares between builds
-      cache:
-        directories:
-          # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
-          - $HOME/.ccache
-          # https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
-          - $HOME/Library/Caches/Homebrew
-          - /usr/local/Homebrew/
-          # used in OSX custom build script dealing with local bottle caching
-          - $HOME/local_bottle_metadata
-
     # source distributions
     - os: linux
       stage: s1
@@ -111,8 +85,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.13.3
-      workspaces:
-        use: brew_cache
+
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -121,8 +94,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
-      workspaces:
-        use: brew_cache
+
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -131,8 +103,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.17.3
-      workspaces:
-        use: brew_cache
+
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -141,8 +112,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.19.3
-      workspaces:
-        use: brew_cache
+
 
     # headless builds for MacOS
     - os: osx
@@ -153,8 +123,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.13.3
-      workspaces:
-        use: brew_cache
+
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -163,8 +132,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
-      workspaces:
-        use: brew_cache
+
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -173,8 +141,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.17.3
-      workspaces:
-        use: brew_cache
+
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -183,8 +150,7 @@ jobs:
         - ENABLE_CONTRIB=0
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.19.3
-      workspaces:
-        use: brew_cache
+
 
     # Contrib builds for MacOS
     - os: osx
@@ -195,8 +161,7 @@ jobs:
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.13.3
-      workspaces:
-        use: brew_cache
+
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -205,8 +170,7 @@ jobs:
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.14.5
-      workspaces:
-        use: brew_cache
+
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -215,8 +179,7 @@ jobs:
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.17.3
-      workspaces:
-        use: brew_cache
+
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -225,8 +188,7 @@ jobs:
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=0
         - TEST_DEPENDS=numpy==1.19.3
-      workspaces:
-        use: brew_cache
+
 
     # headless contrib builds for MacOS
     - os: osx
@@ -237,8 +199,7 @@ jobs:
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.13.3
-      workspaces:
-        use: brew_cache
+
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -247,8 +208,7 @@ jobs:
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.14.5
-      workspaces:
-        use: brew_cache
+
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -257,8 +217,7 @@ jobs:
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.17.3
-      workspaces:
-        use: brew_cache
+
     - os: osx
       language: generic
       osx_image: xcode9.4
@@ -267,8 +226,7 @@ jobs:
         - ENABLE_CONTRIB=1
         - ENABLE_HEADLESS=1
         - TEST_DEPENDS=numpy==1.19.3
-      workspaces:
-        use: brew_cache
+
 
     # default builds for Linux
     - os: linux
@@ -925,24 +883,6 @@ before_install: |
       echo $ENABLE_CONTRIB > contrib.enabled
       echo $ENABLE_HEADLESS > headless.enabled
 
-      if [ -n "$IS_OSX" ]; then
-        export PATH="/usr/local/sbin:$PATH"
-        TAPS="$(brew --repository)/Library/Taps"
-        if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
-            rm -rf "$TAPS/caskroom/homebrew-cask"
-        fi
-        find "$TAPS" -type d -name .git -exec \
-                bash -xec '
-                    cd $(dirname '\''{}'\'') || echo "status: $?"
-                    git clean -fxd || echo "status: $?"
-                    sleep 1 || echo "status: $?"
-                    git status || echo "status: $?"' \; || echo "status: $?"
-        brew_cache_cleanup
-      fi
-      echo "end"
-      # Not interested in travis internal scripts' output
-    fi
-
     set +x
 
 install: |
@@ -975,21 +915,6 @@ script: |
     trap ERR
     test "$rc" -eq 0
 
-before_cache: |
-    # Cleanup dirs to be cached
-    set -e; set -x
-    if [ -n "$IS_OSX" ]; then
-
-      # When Taps is cached, this dir causes "Error: file exists" on `brew update`
-      if [ -e "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask" ]; then
-        rm -rf "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask"
-      fi
-
-      brew_cache_cleanup
-
-    fi
-    set +x; set +e
-
 after_success: |
     # Upload wheels to pypi if tag is set
 
diff --git a/README.md b/README.md
index 6c6022ba..2352d2e8 100644
--- a/README.md
+++ b/README.md
@@ -49,10 +49,6 @@ A: No, the packages are special wheel binary packages and they already contain s
 
 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: Pip install 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](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.
diff --git a/travis_config.sh b/travis_config.sh
index 910e365f..063baf8a 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -111,6 +111,7 @@ function pre_build {
         brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
     else
         brew unlink python@2
+        generate_ffmpeg_formula
         brew install ffmpeg_opencv
     fi
 

From b023344cf6c64fe50d840c2c9b36cb1608e073ac Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Wed, 2 Dec 2020 17:17:09 +0200
Subject: [PATCH 488/566] fix syntax

---
 .travis.yml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index 42623a59..531c2627 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -883,6 +883,10 @@ before_install: |
       echo $ENABLE_CONTRIB > contrib.enabled
       echo $ENABLE_HEADLESS > headless.enabled
 
+      echo "end"
+      # Not interested in travis internal scripts' output
+    fi
+
     set +x
 
 install: |

From e83bc139980262fcb09158a88597a66324ee447a Mon Sep 17 00:00:00 2001
From: Thomas Nyberg <twn@thomasnyberg.com>
Date: Fri, 11 Dec 2020 11:11:24 +0100
Subject: [PATCH 489/566] Add docs for debug build

---
 README.md | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/README.md b/README.md
index 6c6022ba..bc97db72 100644
--- a/README.md
+++ b/README.md
@@ -140,6 +140,24 @@ If some dependency is not enabled in the pre-built wheels, you can also run the
     - 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: https://github.com/skvark/opencv-python/issues/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.

From 7d1e48ca7bcf651c7ddc13d30a452e14d06db0dc Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 28 Dec 2020 19:56:24 +0200
Subject: [PATCH 490/566] arm64 azure cli does not work

---
 .travis.yml | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 531c2627..3c2efde8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -971,18 +971,20 @@ after_success: |
 
     # Save to Azure storage always
 
-    if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-      curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
-    else
-      brew install azure-cli
-    fi
+    if [[ $TRAVIS_CPU_ARCH != "arm64" ]]; then
+      if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
+        curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
+      else
+        brew install azure-cli
+      fi
 
-    az storage container create -n ${TRAVIS_COMMIT} --public-access blob
+      az storage container create -n ${TRAVIS_COMMIT} --public-access blob
 
-    if [[ $SDIST == 1 ]]; then
-      az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/dist --pattern *.gz
-    else
-      az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern opencv*.whl
+      if [[ $SDIST == 1 ]]; then
+        az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/dist --pattern *.gz
+      else
+        az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern opencv*.whl
+      fi
     fi
 
     set +x

From fed2178dfc28dfb034e8111579293affb77b2cf1 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 28 Dec 2020 20:02:34 +0200
Subject: [PATCH 491/566] fix paths

---
 setup.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index 7b106847..a4f9f729 100644
--- a/setup.py
+++ b/setup.py
@@ -93,7 +93,7 @@ def main():
     # Path regexes with forward slashes relative to CMake install dir.
     rearrange_cmake_output_data = {
         "cv2": (
-            [r"bin/opencv_ffmpeg\d{3,4}%s\.dll" % ("_64" if x64 else "")]
+            [r"bin/opencv_videoio_ffmpeg\d{3}%s\.dll" % ("_64" if x64 else "")]
             if os.name == "nt"
             else []
         )
@@ -106,7 +106,7 @@ def main():
             % {"ext": re.escape(sysconfig.get_config_var("EXT_SUFFIX"))}
         ],
         "cv2.data": [  # OPENCV_OTHER_INSTALL_PATH
-            ("etc" if os.name == "nt" else "share/OpenCV") + r"/haarcascades/.*\.xml"
+            ("etc" if os.name == "nt" else "share/opencv4") + r"/haarcascades/.*\.xml"
         ],
     }
 

From 5f56caf2c33cca711ae5c361b78a684990f85aac Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 28 Dec 2020 20:05:41 +0200
Subject: [PATCH 492/566] OpenCV 4.5.1

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index d5fd2f01..1363496c 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit d5fd2f0155ffad366f9ac912dfd6d189a7a6a98e
+Subproject commit 1363496c1106606684d40447f5d1149b2c66a9f8
diff --git a/opencv_contrib b/opencv_contrib
index 37315bab..b91a781c 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 37315babf9984a5b6aa981644a20dd8df1a5ff02
+Subproject commit b91a781cbc1285d441aa682926d93d8c23678b0b

From fd4e6040af94d9db3da25874132ca092b4c9e3a1 Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <op.heinisuo@gmail.com>
Date: Mon, 28 Dec 2020 20:40:12 +0200
Subject: [PATCH 493/566] disable Qt on macOS for now due to multiple issues

---
 cv2/__init__.py  |  4 +---
 setup.py         |  2 +-
 travis_config.sh | 16 ++++++++--------
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/cv2/__init__.py b/cv2/__init__.py
index d665b75c..0c080d52 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -19,9 +19,7 @@
     pass
 
 # the Qt plugin is included currently only in the pre-built wheels
-if (
-    sys.platform == "darwin" or sys.platform.startswith("linux")
-) and ci_and_not_headless:
+if sys.platform.startswith("linux") and ci_and_not_headless:
     os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), "qt", "plugins"
     )
diff --git a/setup.py b/setup.py
index a4f9f729..67f22c60 100644
--- a/setup.py
+++ b/setup.py
@@ -172,7 +172,7 @@ def main():
         if (
             not build_headless
             and "bdist_wheel" in sys.argv
-            and (sys.platform == "darwin" or sys.platform.startswith("linux"))
+            and sys.platform.startswith("linux")
         ):
             cmake_args.append("-DWITH_QT=5")
             subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
diff --git a/travis_config.sh b/travis_config.sh
index 063baf8a..9ba0bb11 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -115,15 +115,15 @@ function pre_build {
         brew install ffmpeg_opencv
     fi
 
-    echo 'Installing qt5'
+    # echo 'Installing qt5'
     
-    if [ -n "$CACHE_STAGE" ]; then
-        echo "Qt5 has bottle, no caching needed"
-    else
-        brew switch qt 5.13.2
-        brew pin qt
-        export PATH="/usr/local/opt/qt/bin:$PATH"
-    fi
+    # if [ -n "$CACHE_STAGE" ]; then
+    #    echo "Qt5 has bottle, no caching needed"
+    # else
+    #    brew switch qt 5.13.2
+    #    brew pin qt
+    #    export PATH="/usr/local/opt/qt/bin:$PATH"
+    # fi
 
     if [ -n "$CACHE_STAGE" ]; then
         brew_go_bootstrap_mode 0

From 89ca6a4ac9079c72d4d86d1c0f3141eeb0ca1bd6 Mon Sep 17 00:00:00 2001
From: Grigory Serebryakov <sergregory@users.noreply.github.com>
Date: Fri, 30 Apr 2021 20:16:59 +0300
Subject: [PATCH 494/566] Add GitHub actions setup for CI instead of Travis &
 Appveyour (where possible) (#470)

* Add initial config for github actions

* Allow actions for all branches and PRs to master by default

* Fix typo

* Do not set docker image info for multibuild, as we do it in github actions

* Do not run github action in docker as multiduild will do it for us

* Remove error steps - somehow I've missed them when cleaned for the build

* Merge all build logic into one step as somehow build wheel is not known when sourced and used in different steps

* Debug: try to change directory to get inside the repo sources

* Adjust env variables to enable build

* Specify docker image to use in github builds

* Enable back all python versions in build matrix

* Remove numpy as build dependency as prebuilt docker should handle it for us

* Make linux build matrix wider - enable contrib, headless/gui, source/binary distribution

* Fix return code setting for skipped tests in case of sdist

* Build source distribution with only one version of python - as we do not care abnout python version when doing the source distribution

* Try to fix config

* Try to fix config

* Enable OSX builds

* Quickfix to enable OSX build

* Temporary disable linux and all pythons execpt one to reduce the build matrix size

* Disable cache stage that was implemented for travis

* Do not unlink python2 for github osx builds

* Fix ffmpeg bottle build command

* Disable travis cache stage

* Changed build_wheels to Windows platform

* Try new pipeline

* Try windows with a new configuration

* Try bash on Windows

* Added ubuntu and macos into pipeline

* Fix if condition for windows

* Turned on all python versions, uploading artifacts

* Fixed Windows and created Release job

* Add missed source distribution build

* Move x86 python builds to github actions. Travis does only aarch64 now

* Split linux and OSX builds to exclude x86 OSX builds from build matrix

* Reduce architectures to x64 for both OSX and Ubuntu as x86 is supported for windows only

* Add PyPI secrets usage

* Publish packages built in PRs to testPyPI

* Push to test PyPI on each package build. Remove unneded build on push to master

* Apply review comments

* Combine all release steps into one job

Co-authored-by: Andrey Senyaev <andrey.senyaev@xperience.ai>
Co-authored-by: Andrey Senyaev <76472231+asenyaev@users.noreply.github.com>
---
 .github/workflows/build_wheels.yml | 279 +++++++++++++
 .travis.yml                        | 609 +----------------------------
 opencv                             |   2 +-
 travis_config.sh                   |  29 +-
 travis_osx_brew_cache.sh           |  95 ++---
 5 files changed, 359 insertions(+), 655 deletions(-)
 create mode 100644 .github/workflows/build_wheels.yml

diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml
new file mode 100644
index 00000000..cbed8b6c
--- /dev/null
+++ b/.github/workflows/build_wheels.yml
@@ -0,0 +1,279 @@
+name: Build PYPI wheels for opencv-python
+
+on:
+  pull_request:
+    branches:
+      - master
+  release:
+    types: [published, edited]
+
+
+jobs:
+  build-windows-x86_64:
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        shell: powershell
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [windows-latest]
+        python-version: [3.6, 3.7, 3.8, 3.9]
+        platform: [x86, x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [0]
+
+    env:
+      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+      SDIST: ${{ matrix.build_sdist || 0}}
+      ENABLE_HEADLESS: ${{ matrix.without_gui }}
+      ENABLE_CONTRIB: ${{ matrix.with_contrib }}
+
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: true
+        fetch-depth: 0
+
+    - name: Update submodules
+      run: |
+        git submodule update --remote
+
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v2
+      with:
+        python-version: ${{ matrix.python-version }}
+        architecture: ${{ matrix.platform }}
+
+    - name: Setup MSBuild.exe
+      uses: warrenbuckley/Setup-MSBuild@v1
+
+    - name: build script
+      run: |
+        python --version
+        python -m pip install --upgrade pip
+        python -m pip install --upgrade setuptools
+        set "CI_BUILD=1" && python -m pip wheel --wheel-dir=%cd%\wheelhouse . --verbose
+      shell: cmd
+
+    - name: before test
+      run: |
+        cd ${{ github.workspace }}/tests
+        &python -m pip install --user --no-warn-script-location (ls "../wheelhouse/opencv*.whl")
+        if ($LastExitCode -ne 0) {throw $LastExitCode}
+      shell: powershell
+
+    - name: run test
+      run: |
+        cd ${{ github.workspace }}/tests
+        python -m unittest test
+      shell: cmd
+
+    - name: saving artifacts
+      uses: actions/upload-artifact@v2
+      with:
+        name: wheels
+        path: wheelhouse/opencv*.whl
+
+  build:
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        shell: bash
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ubuntu-latest, macos-latest]
+        python-version: [3.6, 3.7, 3.8, 3.9]
+        platform: [x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [0]
+
+    env:
+      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+      REPO_DIR: .
+      BUILD_COMMIT: master
+      PROJECT_SPEC: opencv-python
+      MB_PYTHON_VERSION: ${{ matrix.python-version }}
+      TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
+      MB_ML_VER: 2014
+      NP_TEST_DEP: numpy
+      TRAVIS_BUILD_DIR: ${{ github.workspace }}
+      CONFIG_PATH: travis_config.sh
+      DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
+      USE_CCACHE: 1
+      UNICODE_WIDTH: 32
+      SDIST: ${{ matrix.build_sdist || 0}}
+      ENABLE_HEADLESS: ${{ matrix.without_gui }}
+      ENABLE_CONTRIB: ${{ matrix.with_contrib }}
+
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: true
+        fetch-depth: 0
+
+    - name: Update submodules
+      run: |
+        git submodule update --remote
+
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v2
+      if: ${{ 'macos-latest' == matrix.os }}
+      with:
+        python-version: ${{ matrix.python-version }}
+        architecture: ${{ matrix.platform }}
+
+    - name: Setup Environment variables
+      run: |
+        if [ "macos-latest" == "${{ matrix.os }}" ]; then echo "TRAVIS_OS_NAME=osx" >> $GITHUB_ENV; else echo "TRAVIS_OS_NAME=${{ matrix.os }}" >> $GITHUB_ENV; fi
+        if [ "schedule" == "${{ github.event_name }}" ]; then echo "TRAVIS_EVENT_TYPE=cron" >> $GITHUB_ENV; else echo "TRAVIS_EVENT_TYPE=${{ github.event_name }}" >> $GITHUB_ENV; fi
+        if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
+        if [ "x64" == "${{ matrix.platform }}" ]; then echo "PLAT=x86_64" >> $GITHUB_ENV; fi
+        if [ "x86" == "${{ matrix.platform }}" ]; then echo "PLAT=i686" >> $GITHUB_ENV; fi
+        echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
+        echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
+
+    - name: before install
+      run: |
+        set -e
+        # Check out and prepare the source
+        # Multibuild doesn't have releases, so --depth would break eventually (see
+        # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+        git submodule update --init multibuild
+        source multibuild/common_utils.sh
+        # https://github.com/matthew-brett/multibuild/issues/116
+        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+        source multibuild/travis_steps.sh
+        # This sets -x
+        # source travis_multibuild_customize.sh
+        echo $ENABLE_CONTRIB > contrib.enabled
+        echo $ENABLE_HEADLESS > headless.enabled
+        set -x
+        build_wheel $REPO_DIR $PLAT
+        install_run $PLAT
+        set +x
+    - name: saving artifacts
+      uses: actions/upload-artifact@v2
+      with:
+        name: wheels
+        path: wheelhouse/opencv*.whl
+
+
+  build_sdist:
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        shell: bash
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ubuntu-latest]
+        python-version: [3.8]
+        platform: [x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [1]
+
+    env:
+      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+      REPO_DIR: .
+      BUILD_COMMIT: master
+      PROJECT_SPEC: opencv-python
+      PLAT: x86_64
+      MB_PYTHON_VERSION: ${{ matrix.python-version }}
+      TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
+      MB_ML_VER: 2014
+      NP_TEST_DEP: numpy
+      TRAVIS_BUILD_DIR: ${{ github.workspace }}
+      CONFIG_PATH: travis_config.sh
+      DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
+      USE_CCACHE: 1
+      UNICODE_WIDTH: 32
+      SDIST: ${{ matrix.build_sdist || 0}}
+      ENABLE_HEADLESS: ${{ matrix.without_gui || 0 }}
+      ENABLE_CONTRIB: ${{ matrix.with_contrib || 0}}
+
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: true
+        fetch-depth: 0
+
+    - name: Update submodules
+      run: |
+        git submodule update --remote
+
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v2
+      with:
+        python-version: ${{ matrix.python-version }}
+        architecture: ${{ matrix.platform }}
+
+    - name: Setup Environment variables
+      run: |
+        if [ "macos-latest" == "${{ matrix.os }}" ]; then echo "TRAVIS_OS_NAME=osx" >> $GITHUB_ENV; else echo "TRAVIS_OS_NAME=${{ matrix.os }}" >> $GITHUB_ENV; fi
+        if [ "schedule" == "${{ github.event_name }}" ]; then echo "TRAVIS_EVENT_TYPE=cron" >> $GITHUB_ENV; else echo "TRAVIS_EVENT_TYPE=${{ github.event_name }}" >> $GITHUB_ENV; fi
+        if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
+        echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
+        echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
+
+    - name: before install
+      run: |
+        set -e
+        # Build and package
+        set -x
+          python -m pip install --upgrade pip
+          python -m pip install scikit-build
+          python setup.py sdist
+        set +x
+        # Install and run tests
+        set -x
+        echo "skipping tests because of sdist"
+    - name: saving artifacts
+      uses: actions/upload-artifact@v2
+      with:
+        name: wheels
+        path: dist/opencv*.tar.gz
+
+  release_opencv_python:
+    if: startsWith(github.ref, 'refs/tags/v')
+    needs: [build, build-windows-x86_64, build_sdist]
+    runs-on: ubuntu-latest
+    environment: opencv-python-release
+    defaults:
+      run:
+        shell: bash
+    steps:
+      - uses: actions/download-artifact@v2
+        with:
+          name: wheels
+          path: wheelhouse/
+      - name: Upload wheels for opencv_python
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-*
+
+      - name: Upload wheels for opencv_contrib_python
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-*
+
+      - name: Upload wheels for opencv_python_headless
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-*
+
+      - name: Upload wheels for opencv_contrib_python_headless
+
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_headless-*
diff --git a/.travis.yml b/.travis.yml
index 3c2efde8..6ba06d4c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -23,7 +23,6 @@ cache:
 # Add more cache stages (s2 etc) and corresponding OSX jobs like s1
 # if brew builds start to take longer than one Travis time limit
 stages:
-  - s1
   - final
 
 jobs:
@@ -32,227 +31,7 @@ jobs:
   exclude:
     - language: ruby
   include:
-    # source distributions
-    - os: linux
-      stage: s1
-      script: skip
-      env:
-        - SDIST=1
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-      python: "3.8"
-      language: python
-      dist: xenial
-    - os: linux
-      stage: s1
-      script: skip
-      env:
-        - SDIST=1
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-      python: "3.8"
-      language: python
-      dist: xenial
-    - os: linux
-      stage: s1
-      script: skip
-      env:
-        - SDIST=1
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      python: "3.8"
-      language: python
-      dist: xenial
-    - os: linux
-      stage: s1
-      script: skip
-      env:
-        - SDIST=1
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      python: "3.8"
-      language: python
-      dist: xenial
-
-    # default builds for MacOS
-      #further jobs in the list will use the same stage until the next assignment
-    - stage: final
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.13.3
-
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.14.5
-
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.17.3
-
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.19.3
-
-
-    # headless builds for MacOS
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.13.3
-
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.14.5
-
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.17.3
-
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.19.3
-
-
-    # Contrib builds for MacOS
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.13.3
-
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.14.5
-
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.17.3
-
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.19.3
-
-
-    # headless contrib builds for MacOS
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.13.3
-
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.14.5
-
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.17.3
-
-    - os: osx
-      language: generic
-      osx_image: xcode9.4
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.19.3
-
-
     # default builds for Linux
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.13.3
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.13.3
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -268,30 +47,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.14.5
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.14.5
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -307,30 +62,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.17.3
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.17.3
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -346,30 +77,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.19.3
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.19.3
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -387,30 +94,6 @@ jobs:
         directories: $HOME/.ccache
 
     # headless builds for Linux
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.13.3
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.13.3
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -426,30 +109,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.14.5
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.14.5
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -465,30 +124,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.17.3
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.17.3
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -504,30 +139,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.19.3
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - PLAT=i686
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.19.3
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -545,30 +156,6 @@ jobs:
         directories: $HOME/.ccache
 
     # contrib builds for Linux
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - TEST_DEPENDS=numpy==1.13.3
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - PLAT=i686
-        - TEST_DEPENDS=numpy==1.13.3
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -584,30 +171,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - TEST_DEPENDS=numpy==1.14.5
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - PLAT=i686
-        - TEST_DEPENDS=numpy==1.14.5
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -623,30 +186,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - TEST_DEPENDS=numpy==1.17.3
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - PLAT=i686
-        - TEST_DEPENDS=numpy==1.17.3
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -662,30 +201,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - TEST_DEPENDS=numpy==1.19.3
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - PLAT=i686
-        - TEST_DEPENDS=numpy==1.19.3
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -704,30 +219,6 @@ jobs:
 
 
     # headless contrib builds for Linux
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - TEST_DEPENDS=numpy==1.13.3
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - PLAT=i686
-        - TEST_DEPENDS=numpy==1.13.3
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -743,30 +234,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - TEST_DEPENDS=numpy==1.14.5
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - PLAT=i686
-        - TEST_DEPENDS=numpy==1.14.5
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -782,30 +249,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - TEST_DEPENDS=numpy==1.17.3
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - PLAT=i686
-        - TEST_DEPENDS=numpy==1.17.3
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -821,30 +264,6 @@ jobs:
         - USE_CCACHE=0
       cache:
         directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - TEST_DEPENDS=numpy==1.19.3
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - PLAT=i686
-        - TEST_DEPENDS=numpy==1.19.3
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
     - os: linux
       arch: arm64
       language: generic
@@ -969,23 +388,23 @@ after_success: |
 
     fi
 
-    # Save to Azure storage always
+    # # Save to Azure storage always
 
-    if [[ $TRAVIS_CPU_ARCH != "arm64" ]]; then
-      if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-        curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
-      else
-        brew install azure-cli
-      fi
+    # if [[ $TRAVIS_CPU_ARCH != "arm64" ]]; then
+    #   if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
+    #     curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
+    #   else
+    #     brew install azure-cli
+    #   fi
 
-      az storage container create -n ${TRAVIS_COMMIT} --public-access blob
+    #   az storage container create -n ${TRAVIS_COMMIT} --public-access blob
 
-      if [[ $SDIST == 1 ]]; then
-        az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/dist --pattern *.gz
-      else
-        az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern opencv*.whl
-      fi
-    fi
+    #   if [[ $SDIST == 1 ]]; then
+    #     az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/dist --pattern *.gz
+    #   else
+    #     az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern opencv*.whl
+    #   fi
+    # fi
 
     set +x
 
diff --git a/opencv b/opencv
index 1363496c..b19f8603 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 1363496c1106606684d40447f5d1149b2c66a9f8
+Subproject commit b19f8603843ac63274379c9e36331db6d4917001
diff --git a/travis_config.sh b/travis_config.sh
index 9ba0bb11..aac66317 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -95,28 +95,31 @@ function pre_build {
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
 
-    local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
+    local CACHE_STAGE;# (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
+    CACHE_STAGE=
     export HOMEBREW_NO_AUTO_UPDATE=1
 
     #after the cache stage, all bottles and Homebrew metadata should be already cached locally
-    if [ -n "$CACHE_STAGE" ]; then
-        brew update
-        generate_ffmpeg_formula
-        brew_add_local_bottles
-    fi
+    # if [ -n "$CACHE_STAGE" ]; then
+    #     brew update
+    #     generate_ffmpeg_formula
+    #     brew_add_local_bottles
+    # fi
 
     echo 'Installing FFmpeg'
 
-    if [ -n "$CACHE_STAGE" ]; then
-        brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
-    else
-        brew unlink python@2
+    # if [ -n "$CACHE_STAGE" ]; then
+    #     brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
+    # else
+        brew update
         generate_ffmpeg_formula
-        brew install ffmpeg_opencv
-    fi
+        brew_add_local_bottles
+        # brew unlink python@2
+        brew install --build-bottle ffmpeg_opencv
+    # fi
 
     # echo 'Installing qt5'
-    
+
     # if [ -n "$CACHE_STAGE" ]; then
     #    echo "Qt5 has bottle, no caching needed"
     # else
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index e3a69cc3..401265f2 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -4,6 +4,9 @@
 #Should be in Travis' cache
 BREW_LOCAL_BOTTLE_METADATA="$HOME/local_bottle_metadata"
 
+#FIXME: temporary fix to enable the build, should be replaced with the proper path to the cache dir
+mkdir -p $BREW_LOCAL_BOTTLE_METADATA
+
 # Starting reference point for elapsed build time; seconds since the epoch.
 #TRAVIS_TIMER_START_TIME is set at the start of a log fold, in nanoseconds since the epoch
 BREW_TIME_START=$(($TRAVIS_TIMER_START_TIME/10**9))
@@ -48,33 +51,33 @@ function brew_add_local_bottles {
     #  so that `brew` commands can find them.
     # If the package was updated, removes the corresponding files
     #  and the bottle's entry in the formula, if any.
-    
-    # Bottle entry in formula: 
+
+    # Bottle entry in formula:
     #   bottle do
     #     <...>
     #     sha256 "<sha256>" => :<os_codename>
     #     <...>
-    #   end 
-    
+    #   end
+
     echo "Cached bottles:"
     ls "$(brew --cache)/downloads" || true  #may not exist initially since it's "$(brew --cache)" that is in Travis cache
     echo "Saved .json's and links:"
     ls "$BREW_LOCAL_BOTTLE_METADATA"
-    
+
     for JSON in "$BREW_LOCAL_BOTTLE_METADATA"/*.json; do
         [ -e "$JSON" ] || break    # OSX 10.11 bash has no nullglob
         local PACKAGE JSON_VERSION JSON_REBUILD OS_CODENAME BOTTLE_HASH
-        
+
         _brew_parse_bottle_json "$JSON" PACKAGE JSON_VERSION JSON_REBUILD OS_CODENAME BOTTLE_HASH
 
         echo "Adding local bottle: $PACKAGE ${JSON_VERSION}_${JSON_REBUILD}"
-        
+
         local FORMULA_VERSION FORMULA_REBUILD FORMULA_BOTTLE_HASH
-        
+
         _brew_parse_package_info "$PACKAGE" "$OS_CODENAME" FORMULA_VERSION FORMULA_REBUILD FORMULA_BOTTLE_HASH
 
         local FORMULA_HAS_BOTTLE; [ -n "$FORMULA_BOTTLE_HASH" ] && FORMULA_HAS_BOTTLE=1 || true
-        
+
 
         local BOTTLE_LINK BOTTLE=""; BOTTLE_LINK="${JSON}.bottle.lnk";
         local BOTTLE_EXISTS= BOTTLE_MISMATCH= VERSION_MISMATCH=
@@ -88,10 +91,10 @@ function brew_add_local_bottles {
         if [ -f "$BOTTLE_LINK" ]; then
             BOTTLE=$(cat "$BOTTLE_LINK");
             BOTTLE=$(cd "$(dirname "$BOTTLE")"; pwd)/$(basename "$BOTTLE")
-            
+
             if [ -e "$BOTTLE" ]; then
                 BOTTLE_EXISTS=1;
-                
+
                 # The hash in `brew --cache $PACKAGE` entry is generated from download URL,
                 #  which itself is generated from base URL and version
                 # (see Homebrew/Library/Homebrew/download_strategy.rb:cached_location).
@@ -110,7 +113,7 @@ function brew_add_local_bottles {
         else
             echo "Link file is missing or of invalid type!" >&2
         fi
-                    
+
         # Delete cached bottle and all metadata if invalid
         if [[ -z "$BOTTLE_EXISTS" || -n "$VERSION_MISMATCH" || -n "$BOTTLE_MISMATCH" ]]; then
             echo "Deleting the cached bottle and all metadata"
@@ -133,11 +136,11 @@ function brew_add_local_bottles {
                     git commit -m "Removed obsolete local bottle ${JSON_VERSION}_${JSON_REBUILD} :${OS_CODENAME}" "$FORMULA"
                 )
             fi
-            
+
             if [ -n "$BOTTLE" -a -n "$BOTTLE_EXISTS" ]; then rm "$BOTTLE"; fi
             rm -f "$BOTTLE_LINK"
             rm "$JSON"
-            
+
         #(Re)add metadata to the formula otherwise
         else
             if [ "$FORMULA_BOTTLE_HASH" == "$BOTTLE_HASH" ]; then
@@ -156,7 +159,7 @@ function brew_cache_cleanup {
 
     #Lefovers from some failure probably
     rm -f "$BREW_LOCAL_BOTTLE_METADATA"/*.tar.gz
-    
+
     #`brew cleanup` may delete locally-built bottles that weren't needed this time
     # so we're saving and restoring them
     local BOTTLE_LINK BOTTLE
@@ -187,16 +190,16 @@ function brew_go_bootstrap_mode {
     local EXIT_CODE=${1:-1}
 
     echo "Going into cache bootstrap mode"
-    
+
     BREW_BOOTSTRAP_MODE=1
-        
+
     #Can't just `exit` because that would terminate the build without saving the cache
     #Have to replace further actions with no-ops
-    
+
     local MESSAGE=""; if [ "$EXIT_CODE" -ne 0 ]; then
         MESSAGE='Building dependencies took too long. Restart the build in Travis UI to continue from cache.';
     fi
-    
+
     eval '
     function '"$cmd"' { return 0; }
     function repair_wheelhouse { return 0; }
@@ -205,11 +208,11 @@ function brew_go_bootstrap_mode {
             echo \
         '        echo -e "\n'"$MESSAGE"'\n"'
         fi)"\
-    '    
+    '
         # Travis runs user scripts via `eval` i.e. in the same shell process.
         # So have to unset errexit in order to get to cache save stage
         set +e; return '"$EXIT_CODE"'
-    }'    
+    }'
 }
 
 
@@ -228,15 +231,15 @@ function _brew_install_and_cache_within_time_limit {
     if grep -qxFf <(cat <<<"$_BREW_ALREADY_INSTALLED") <<<"$PACKAGE"; then
         MARKED_INSTALLED=1
     fi
-        
+
     if [ -n "$MARKED_INSTALLED" ] || (brew list --versions "$PACKAGE" >/dev/null && ! (brew outdated | grep -qxF "$PACKAGE")); then
         echo "Already installed and the latest version: $PACKAGE"
         if [ -z "$MARKED_INSTALLED" ]; then _brew_mark_installed "$PACKAGE"; fi
         return 0
     fi
-    
+
     local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
-    
+
     _brew_is_bottle_available "$PACKAGE" KEG_ONLY || BUILD_FROM_SOURCE=1
     [ -n "$BUILD_FROM_SOURCE" ] && INCLUDE_BUILD="--include-build" || true
 
@@ -254,7 +257,7 @@ function _brew_install_and_cache_within_time_limit {
     _brew_install_and_cache "$PACKAGE" "$([[ -z "$BUILD_FROM_SOURCE" ]] && echo 1 || echo 0)" "$KEG_ONLY" || return 2
     _brew_check_elapsed_build_time "$TIME_START" "$TIME_LIMIT" || return $?
 }
-    
+
 
 function _brew_parse_bottle_json {
     # Parse JSON file resulting from `brew bottle --json`
@@ -271,9 +274,9 @@ function _brew_parse_bottle_json {
     print tag_name
     print tag_dict["sha256"]
     ' "$JSON")
-    
+
     unset JSON
-    
+
     { local i v; for i in {1..5}; do
         read -r v
         eval "${1:?}=\"$v\""
@@ -284,7 +287,7 @@ function _brew_parse_bottle_json {
 function _brew_parse_package_info {
     # Get and parse `brew info --json` about a package
     # and save data into specified variables
-    
+
     local PACKAGE OS_CODENAME
     PACKAGE="${1:?}"; shift
     OS_CODENAME="${1:?}"; shift
@@ -300,9 +303,9 @@ function _brew_parse_package_info {
     print bottle_data["files"].get(sys.argv[2],{"sha256":"!?"})["sha256"]     #prevent losing trailing blank line to command substitution
     ' \
     "$PACKAGE" "$OS_CODENAME"); JSON_DATA="${JSON_DATA%\!\?}"  #!? can't occur in a hash
-    
+
     unset PACKAGE OS_CODENAME
-    
+
     { local i v; for i in {1..3}; do
         read -r v
         eval "${1:?}=\"$v\""
@@ -346,13 +349,13 @@ function _brew_install_and_cache {
     # Install bottle or make and cache bottle.
     # assumes that deps were already installed
     # and not already the latest version
-    
+
     local PACKAGE USE_BOTTLE KEG_ONLY
     PACKAGE="${1:?}"
     USE_BOTTLE="${2:?}"
     KEG_ONLY="${3:?}"
     local VERB
-    
+
     if brew list --versions "$PACKAGE"; then
         # Install alongside the old version to avoid to have to update "runtime dependents"
         # https://discourse.brew.sh/t/can-i-install-a-new-version-without-having-to-upgrade-runtime-dependents/4443
@@ -363,7 +366,7 @@ function _brew_install_and_cache {
     else
         VERB=install
     fi
-    
+
     if [[ "$USE_BOTTLE" -gt 0 ]]; then
         echo "Installing bottle for: $PACKAGE"
         brew $VERB "$PACKAGE"
@@ -380,12 +383,12 @@ function _brew_install_and_cache {
         #proper procedure as per https://discourse.brew.sh/t/how-are-bottle-and-postinstall-related-is-it-safe-to-run-bottle-after-postinstall/3410/4
         brew uninstall --ignore-dependencies "$PACKAGE"
         brew $VERB "$BOTTLE"
-        
+
         local JSON; JSON=$(sed -E 's/bottle(.[[:digit:]]+)?\.tar\.gz$/bottle.json/' <<<"$BOTTLE")
-        
+
         #`brew bottle --merge` doesn't return nonzero on nonexisting json file
         test -f "$JSON" -a -f "$BOTTLE"
-        
+
         brew bottle --merge --write "$JSON"
         local CACHED_BOTTLE; CACHED_BOTTLE="$(brew --cache "$PACKAGE")"
         mv "$BOTTLE" "$CACHED_BOTTLE";
@@ -394,9 +397,9 @@ function _brew_install_and_cache {
         #Symlinks aren't cached by Travis. Will just save paths in files then.
         local BOTTLE_LINK; BOTTLE_LINK="${CACHED_JSON}.bottle.lnk"
         echo "$CACHED_BOTTLE" >"$BOTTLE_LINK"
-        
+
     fi
-    
+
     _brew_mark_installed "$PACKAGE"
 }
 
@@ -411,11 +414,11 @@ function _brew_check_elapsed_build_time {
     local TIME_START TIME_LIMIT ELAPSED_TIME
     TIME_START="${1:?}"
     TIME_LIMIT="${2:?}"
-    
+
     ELAPSED_TIME=$(($(date +%s) - $TIME_START))
     echo "Elapsed time: "$(($ELAPSED_TIME/60))"m (${ELAPSED_TIME}s)"
-    
-    if [[ "$ELAPSED_TIME" -gt $TIME_LIMIT ]]; then 
+
+    if [[ "$ELAPSED_TIME" -gt $TIME_LIMIT ]]; then
         brew_go_bootstrap_mode
         return 1
     fi
@@ -426,19 +429,19 @@ function _brew_check_slow_building_ahead {
 
     #If the package's projected build completion is higher than hard limit,
     # skip it and arrange for further build to be skipped and return 1
-    
+
     local PACKAGE TIME_START TIME_HARD_LIMIT
     PACKAGE="${1:?}"
     TIME_START="${2:?}"
     TIME_HARD_LIMIT="${3:?}"
-    
-    local PROJECTED_BUILD_TIME 
+
+    local PROJECTED_BUILD_TIME
     PROJECTED_BUILD_TIME=$(echo "$BREW_SLOW_BUILIDING_PACKAGES" | awk '$1=="'"$PACKAGE"'"{print $2}')
     [ -z "$PROJECTED_BUILD_TIME" ] && return 0 || true
-    
+
     local PROJECTED_BUILD_END_ELAPSED_TIME
     PROJECTED_BUILD_END_ELAPSED_TIME=$(( $(date +%s) - TIME_START + PROJECTED_BUILD_TIME * 60))
-    
+
     if [[ "$PROJECTED_BUILD_END_ELAPSED_TIME" -ge "$TIME_HARD_LIMIT" ]]; then
         echo -e "\nProjected build end elapsed time for $PACKAGE: $((PROJECTED_BUILD_END_ELAPSED_TIME/60))m ($PROJECTED_BUILD_END_ELAPSED_TIMEs)"
         brew_go_bootstrap_mode

From 4262df8adb5074ee03309fd7541fb1b12b99da66 Mon Sep 17 00:00:00 2001
From: Grigory Serebryakov <serebryakovgr@gmail.com>
Date: Fri, 30 Apr 2021 20:49:24 +0300
Subject: [PATCH 495/566] Update opencv to 4.5.2

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opencv b/opencv
index b19f8603..69357b1e 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit b19f8603843ac63274379c9e36331db6d4917001
+Subproject commit 69357b1e88680658a07cffde7678a4d697469f03
diff --git a/opencv_contrib b/opencv_contrib
index b91a781c..f5d7f671 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit b91a781cbc1285d441aa682926d93d8c23678b0b
+Subproject commit f5d7f6712d4ff229ba4f45cf79dfd11c557d56fd

From aa26990977aa021b7d9559666b5674b5ca76c2ec Mon Sep 17 00:00:00 2001
From: Olli-Pekka Heinisuo <skvark@users.noreply.github.com>
Date: Sat, 1 May 2021 23:40:51 +0300
Subject: [PATCH 496/566] make it possible to compile from sources against
 numpy on macOS aarch64 (#475)

---
 pyproject.toml | 1 +
 setup.py       | 8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index d7c5527d..07bcc4bb 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,6 +3,7 @@ requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
   "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64'",
   "numpy==1.19.3; python_version>='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
+  "numpy==1.20.1; python_version>='3.6' and sys_platform == 'darwin' and platform_machine == 'aarch64'",
   "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64'",
   "numpy==1.17.3; python_version=='3.8' and platform_machine != 'aarch64'",
   "numpy==1.19.3; python_version>='3.9' and platform_machine != 'aarch64'"
diff --git a/setup.py b/setup.py
index 67f22c60..a3265206 100644
--- a/setup.py
+++ b/setup.py
@@ -31,10 +31,14 @@ def main():
     if sys.version_info[:2] >= (3, 9):
         minimum_supported_numpy = "1.19.3"
 
-    # arm64 is a special case
-    if sys.version_info[:2] >= (3, 6) and platform.machine() == "aarch64":
+    # linux arm64 is a special case
+    if sys.platform.startswith("linux") and sys.version_info[:2] >= (3, 6) and platform.machine() == "aarch64":
         minimum_supported_numpy = "1.19.3"
 
+    # macos arm64 is a special case
+    if sys.platform == "darwin" and sys.version_info[:2] >= (3, 6) and platform.machine() == "aarch64":
+        minimum_supported_numpy = "1.20.1"
+
     numpy_version = "numpy>=%s" % minimum_supported_numpy
 
     python_version = cmaker.CMaker.get_python_version()

From 42baf3cc06df377c63393a0e204be2e18ec69cb2 Mon Sep 17 00:00:00 2001
From: Alexander Smorkalov <alexander.smorkalov@xperience.ai>
Date: Thu, 6 May 2021 10:27:20 +0300
Subject: [PATCH 497/566] Documentation update after migration to OpenCV
 organization on Github.

---
 CONTRIBUTING.md |  7 +++++--
 README.md       | 28 ++++++++++++++++------------
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 6a843f0e..07ac1259 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -6,9 +6,12 @@ Thank you for considering contributing to opencv-python.
 
 If you've noticed a bug or have a question that doesn't belong on
 [Stack Overflow](http://stackoverflow.com/questions/tagged/opencv-python),
-[search the issue tracker](https://github.com/skvark/opencv-python/issues?q=something)
+[search the project issue tracker](https://github.com/opencv/opencv-python/issues?q=something) or
+[search OpenCV issue tracker](https://github.com/opencv/opencv/issues?q=is%3Aissue+is%3Aopen+label%3A%22category%3A+python+bindings%22)
 to see if someone else in the community has already created a ticket.
-If not, go ahead and [make one](https://github.com/skvark/opencv-python/issues/new)!
+If not, go ahead and:
+- [make new one for opencv-python](https://github.com/opencv/opencv-python/issues/new) if you cannot load package or some functionality is not available!
+- [make new one for OpenCV](https://github.com/opencv/opencv-python/issues/new) if something went wrong with some function, class  or method in code!
 
 ### 2. Fork & create a branch
 
diff --git a/README.md b/README.md
index 232aa318..9629aae0 100644
--- a/README.md
+++ b/README.md
@@ -2,9 +2,9 @@
 
 ## OpenCV on Wheels
 
-**Unofficial** pre-built CPU-only OpenCV packages for Python.
+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. 
+Check the manual build section if you wish to compile the bindings from source to enable additional modules such as CUDA.
 
 ### Installation and Usage
 
@@ -30,7 +30,7 @@ Check the manual build section if you wish to compile the bindings from source t
 
     ``import cv2``
 
-    All packages contain haarcascade files. ``cv2.data.haarcascades`` can be used as a shortcut to the data folder. For example:
+    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")``
 
@@ -57,7 +57,7 @@ Windows N and KN editions do not include Media Feature Pack which is required by
 
 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](https://github.com/skvark/opencv-python/issues/36) for a manual fix.
+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](https://github.com/opencv/opencv-python/issues/36) for a manual fix.
 
 If you still encounter the error after you have checked all the previous solutions, download [Dependencies](https://github.com/lucasg/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.
 
@@ -65,6 +65,10 @@ If you still encounter the error after you have checked all the previous solutio
 
 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 interpriter. 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](https://github.com/opencv/opencv/wiki) and [the fficial OpenCV forum](https://forum.opencv.org/) 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: https://github.com/skvark/opencv-python/issues/126
@@ -100,7 +104,7 @@ The build process for a single entry in the build matrices is as follows (see fo
    -  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 
+   -  source distributions are separate entries in the build matrix
 
 4. Rearrange OpenCV's build result, add our custom files and generate wheel
 
@@ -117,7 +121,7 @@ The build can be customized with environment variables. In addition to any varia
 - ``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. 
+- ``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.
 
@@ -125,7 +129,7 @@ See the next section for more info about manual builds outside the CI environmen
 
 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/skvark/opencv-python.git`
+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)
@@ -152,18 +156,18 @@ export VERBOSE=1
 python3 setup.py bdist_wheel --build-type=Debug
 ```
 
-See this issue for more discussion: https://github.com/skvark/opencv-python/issues/424
+See this issue for more discussion: https://github.com/opencv/opencv-python/issues/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: 
+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. 
+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.
 
@@ -173,13 +177,13 @@ Opencv-python package (scripts in this repository) is available under MIT licens
 
 OpenCV itself is available under [Apache 2](https://github.com/opencv/opencv/blob/master/LICENSE) license.
 
-Third party package licenses are at [LICENSE-3RD-PARTY.txt](https://github.com/skvark/opencv-python/blob/master/LICENSE-3RD-PARTY.txt).
+Third party package licenses are at [LICENSE-3RD-PARTY.txt](https://github.com/opencv/opencv-python/blob/master/LICENSE-3RD-PARTY.txt).
 
 All wheels ship with [FFmpeg](http://ffmpeg.org) licensed under the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
 
 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).
 
-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).
+The packages include also other binaries. Full list of licenses can be found from [LICENSE-3RD-PARTY.txt](https://github.com/opencv/opencv-python/blob/master/LICENSE-3RD-PARTY.txt).
 
 ### Versioning
 

From 88c1735deff42f2b2eacf66bf59aafc5c0f25763 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <76472231+asenyaev@users.noreply.github.com>
Date: Thu, 6 May 2021 22:37:49 +0300
Subject: [PATCH 498/566] Fixed if condition for release job (#478)

* Fixed if condition for release job

* Added the test release job, changed if condition

* Merged all upload steps into one for pre-release
---
 .github/workflows/build_wheels.yml | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml
index cbed8b6c..67f7ad8d 100644
--- a/.github/workflows/build_wheels.yml
+++ b/.github/workflows/build_wheels.yml
@@ -244,8 +244,27 @@ jobs:
         name: wheels
         path: dist/opencv*.tar.gz
 
+  test_release_opencv_python:
+    if: github.event_name == 'release' && github.event.release.prerelease
+    needs: [build, build-windows-x86_64, build_sdist]
+    runs-on: ubuntu-latest
+    environment: test-opencv-python-release
+    defaults:
+      run:
+        shell: bash
+    steps:
+      - uses: actions/download-artifact@v2
+        with:
+          name: wheels
+          path: wheelhouse/
+
+      - name: Upload all wheels
+        run: |
+          python -m pip install twine
+          python -m twine upload --repository testpypi -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} --skip-existing wheelhouse/opencv_*
+
   release_opencv_python:
-    if: startsWith(github.ref, 'refs/tags/v')
+    if: github.event_name == 'release' && !github.event.release.prerelease
     needs: [build, build-windows-x86_64, build_sdist]
     runs-on: ubuntu-latest
     environment: opencv-python-release
@@ -257,6 +276,7 @@ jobs:
         with:
           name: wheels
           path: wheelhouse/
+
       - name: Upload wheels for opencv_python
         run: |
           python -m pip install twine
@@ -273,7 +293,6 @@ jobs:
           python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-*
 
       - name: Upload wheels for opencv_contrib_python_headless
-
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_headless-*

From c34cbfa3cb627ee40d83e719a539369645015356 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Tue, 11 May 2021 18:38:41 +0300
Subject: [PATCH 499/566] Added arm build

---
 .github/workflows/build_wheels.yml | 110 ++++++++++++++++++++++++++++-
 .gitmodules                        |   3 +
 opencv_extra                       |   1 +
 travis_config.sh                   |  15 ++--
 4 files changed, 123 insertions(+), 6 deletions(-)
 create mode 160000 opencv_extra

diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml
index 67f7ad8d..8d368f22 100644
--- a/.github/workflows/build_wheels.yml
+++ b/.github/workflows/build_wheels.yml
@@ -159,6 +159,7 @@ jobs:
         build_wheel $REPO_DIR $PLAT
         install_run $PLAT
         set +x
+
     - name: saving artifacts
       uses: actions/upload-artifact@v2
       with:
@@ -238,15 +239,120 @@ jobs:
         # Install and run tests
         set -x
         echo "skipping tests because of sdist"
+
     - name: saving artifacts
       uses: actions/upload-artifact@v2
       with:
         name: wheels
         path: dist/opencv*.tar.gz
 
+  build_arm:
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        shell: bash
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [jetson]
+        python-version: [3.6, 3.7, 3.8, 3.9]
+        platform: [x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [0]
+
+    env:
+      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+      REPO_DIR: .
+      BUILD_COMMIT: master
+      PROJECT_SPEC: opencv-python
+      MB_PYTHON_VERSION: ${{ matrix.python-version }}
+      TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
+      PLAT: aarch64
+      MB_ML_VER: 2014
+      NP_TEST_DEP: numpy
+      TRAVIS_BUILD_DIR: ${{ github.workspace }}
+      CONFIG_PATH: travis_config.sh
+      DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
+      DOCKER_TEST_IMAGE: multibuild/xenial_arm64v8
+      USE_CCACHE: 0
+      UNICODE_WIDTH: 32
+      SDIST: ${{ matrix.build_sdist || 0}}
+      ENABLE_HEADLESS: ${{ matrix.without_gui }}
+      ENABLE_CONTRIB: ${{ matrix.with_contrib }}
+
+    steps:
+    - name: Cleanup
+      if: always()
+      uses: AutoModality/action-clean@v1
+
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: true
+        fetch-depth: 0
+
+    - name: Setup Environment variables
+      run: |
+        if [ "jetson" == "${{ matrix.os }}" ]; then echo "PLAT=aarch64" >> $GITHUB_ENV; fi
+        echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
+        echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
+
+    - name: before install
+      run: |
+        set -e
+        if [[ $SDIST == 0 ]]; then
+          # Check out and prepare the source
+          # Multibuild doesn't have releases, so --depth would break eventually (see
+          # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+          git submodule update --init multibuild
+          source multibuild/common_utils.sh
+          # https://github.com/matthew-brett/multibuild/issues/116
+          if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+          source multibuild/travis_steps.sh
+          # This sets -x
+          # source travis_multibuild_customize.sh
+          echo $ENABLE_CONTRIB > contrib.enabled
+          echo $ENABLE_HEADLESS > headless.enabled
+          echo "end"
+          # Not interested in travis internal scripts' output
+        fi
+        set +x
+        # Build and package
+        set -x
+        ls
+        if [[ $SDIST == 1 ]]; then
+          python -m pip install --upgrade pip
+          python -m pip install scikit-build
+          python setup.py sdist
+        else
+          build_wheel $REPO_DIR $PLAT
+        fi
+        set +x
+        # Install and run tests
+        set -x
+        if [[ $SDIST == 1 ]]; then
+          echo "skipping tests because of sdist"
+          rc=0
+        else
+          install_run $PLAT && rc=$? || rc=$?
+        fi
+        set +x
+        #otherwise, Travis logic terminates prematurely
+        #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
+        trap ERR
+        test "$rc" -eq 0
+
+    - name: saving artifacts
+      uses: actions/upload-artifact@v2
+      with:
+        name: wheels
+        path: wheelhouse/opencv*.whl
+
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
-    needs: [build, build-windows-x86_64, build_sdist]
+    needs: [build, build-windows-x86_64, build_sdist, build_arm]
     runs-on: ubuntu-latest
     environment: test-opencv-python-release
     defaults:
@@ -265,7 +371,7 @@ jobs:
 
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
-    needs: [build, build-windows-x86_64, build_sdist]
+    needs: [build, build-windows-x86_64, build_sdist, build_arm]
     runs-on: ubuntu-latest
     environment: opencv-python-release
     defaults:
diff --git a/.gitmodules b/.gitmodules
index f2e0d283..655467e8 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -7,3 +7,6 @@
 [submodule "multibuild"]
 	path = multibuild
 	url = https://github.com/matthew-brett/multibuild.git
+[submodule "opencv_extra"]
+	path = opencv_extra
+	url = https://github.com/opencv/opencv_extra.git
diff --git a/opencv_extra b/opencv_extra
new file mode 160000
index 00000000..3b033d09
--- /dev/null
+++ b/opencv_extra
@@ -0,0 +1 @@
+Subproject commit 3b033d09cab1894d6452707df723789fe98c8663
diff --git a/travis_config.sh b/travis_config.sh
index aac66317..b1a991a4 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -146,24 +146,31 @@ function run_tests {
     echo "Run tests..."
     echo $PWD
 
+    PYTHON=python$PYTHON_VERSION
+
     if [ -n "$IS_OSX" ]; then
       echo "Running for OS X"
-      cd ../tests/
+      cd ../opencv/
+      export OPENCV_TEST_DATA_PATH=../opencv_extra/testdata
     else
       echo "Running for linux"
-      cd /io/tests/
+
+      if [ $PYTHON == "python3.6" ]; then
+        $PYTHON -m pip install -U numpy==1.19.4
+      fi
+      cd /io/opencv
+      export OPENCV_TEST_DATA_PATH=/io/opencv_extra/testdata
     fi
 
     test_wheels
 }
 
 function test_wheels {
-    PYTHON=python$PYTHON_VERSION
 
     echo "Starting tests..."
 
     #Test package
-    $PYTHON -m unittest test
+    $PYTHON modules/python/test/test.py -v --repo .
 }
 
 export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'

From 5d274516839ae170bd863773155ba154894e41fc Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Wed, 12 May 2021 09:58:59 +0300
Subject: [PATCH 500/566] Changed the label for a runner

---
 .github/workflows/build_wheels.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml
index 8d368f22..e13e803e 100644
--- a/.github/workflows/build_wheels.yml
+++ b/.github/workflows/build_wheels.yml
@@ -255,7 +255,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        os: [jetson]
+        os: [ARM64]
         python-version: [3.6, 3.7, 3.8, 3.9]
         platform: [x64]
         with_contrib: [0, 1]
@@ -295,7 +295,7 @@ jobs:
 
     - name: Setup Environment variables
       run: |
-        if [ "jetson" == "${{ matrix.os }}" ]; then echo "PLAT=aarch64" >> $GITHUB_ENV; fi
+        if [ "ARM64" == "${{ matrix.os }}" ]; then echo "PLAT=aarch64" >> $GITHUB_ENV; fi
         echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
         echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
 

From 6336ca866644dc5daf64831a4352c23479e1d248 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Tue, 18 May 2021 17:24:18 +0300
Subject: [PATCH 501/566] Split workflows according to platforms

---
 ...uild_wheels.yml => build_wheels_linux.yml} | 181 +-----------------
 .github/workflows/build_wheels_linux_arm.yml  | 167 ++++++++++++++++
 .github/workflows/build_wheels_macos.yml      | 151 +++++++++++++++
 .github/workflows/build_wheels_windows.yml    | 132 +++++++++++++
 4 files changed, 454 insertions(+), 177 deletions(-)
 rename .github/workflows/{build_wheels.yml => build_wheels_linux.yml} (59%)
 create mode 100644 .github/workflows/build_wheels_linux_arm.yml
 create mode 100644 .github/workflows/build_wheels_macos.yml
 create mode 100644 .github/workflows/build_wheels_windows.yml

diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels_linux.yml
similarity index 59%
rename from .github/workflows/build_wheels.yml
rename to .github/workflows/build_wheels_linux.yml
index e13e803e..c371b774 100644
--- a/.github/workflows/build_wheels.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -1,4 +1,4 @@
-name: Build PYPI wheels for opencv-python
+name: Build PYPI wheels for opencv-python on Linux x86_64
 
 on:
   pull_request:
@@ -9,75 +9,6 @@ on:
 
 
 jobs:
-  build-windows-x86_64:
-    runs-on: ${{ matrix.os }}
-    defaults:
-      run:
-        shell: powershell
-
-    strategy:
-      fail-fast: false
-      matrix:
-        os: [windows-latest]
-        python-version: [3.6, 3.7, 3.8, 3.9]
-        platform: [x86, x64]
-        with_contrib: [0, 1]
-        without_gui: [0, 1]
-        build_sdist: [0]
-
-    env:
-      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
-      SDIST: ${{ matrix.build_sdist || 0}}
-      ENABLE_HEADLESS: ${{ matrix.without_gui }}
-      ENABLE_CONTRIB: ${{ matrix.with_contrib }}
-
-    steps:
-    - name: Checkout
-      uses: actions/checkout@v2
-      with:
-        submodules: true
-        fetch-depth: 0
-
-    - name: Update submodules
-      run: |
-        git submodule update --remote
-
-    - name: Set up Python ${{ matrix.python-version }}
-      uses: actions/setup-python@v2
-      with:
-        python-version: ${{ matrix.python-version }}
-        architecture: ${{ matrix.platform }}
-
-    - name: Setup MSBuild.exe
-      uses: warrenbuckley/Setup-MSBuild@v1
-
-    - name: build script
-      run: |
-        python --version
-        python -m pip install --upgrade pip
-        python -m pip install --upgrade setuptools
-        set "CI_BUILD=1" && python -m pip wheel --wheel-dir=%cd%\wheelhouse . --verbose
-      shell: cmd
-
-    - name: before test
-      run: |
-        cd ${{ github.workspace }}/tests
-        &python -m pip install --user --no-warn-script-location (ls "../wheelhouse/opencv*.whl")
-        if ($LastExitCode -ne 0) {throw $LastExitCode}
-      shell: powershell
-
-    - name: run test
-      run: |
-        cd ${{ github.workspace }}/tests
-        python -m unittest test
-      shell: cmd
-
-    - name: saving artifacts
-      uses: actions/upload-artifact@v2
-      with:
-        name: wheels
-        path: wheelhouse/opencv*.whl
-
   build:
     runs-on: ${{ matrix.os }}
     defaults:
@@ -87,7 +18,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        os: [ubuntu-latest, macos-latest]
+        os: [ubuntu-latest]
         python-version: [3.6, 3.7, 3.8, 3.9]
         platform: [x64]
         with_contrib: [0, 1]
@@ -246,113 +177,9 @@ jobs:
         name: wheels
         path: dist/opencv*.tar.gz
 
-  build_arm:
-    runs-on: ${{ matrix.os }}
-    defaults:
-      run:
-        shell: bash
-
-    strategy:
-      fail-fast: false
-      matrix:
-        os: [ARM64]
-        python-version: [3.6, 3.7, 3.8, 3.9]
-        platform: [x64]
-        with_contrib: [0, 1]
-        without_gui: [0, 1]
-        build_sdist: [0]
-
-    env:
-      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
-      REPO_DIR: .
-      BUILD_COMMIT: master
-      PROJECT_SPEC: opencv-python
-      MB_PYTHON_VERSION: ${{ matrix.python-version }}
-      TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
-      PLAT: aarch64
-      MB_ML_VER: 2014
-      NP_TEST_DEP: numpy
-      TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
-      DOCKER_TEST_IMAGE: multibuild/xenial_arm64v8
-      USE_CCACHE: 0
-      UNICODE_WIDTH: 32
-      SDIST: ${{ matrix.build_sdist || 0}}
-      ENABLE_HEADLESS: ${{ matrix.without_gui }}
-      ENABLE_CONTRIB: ${{ matrix.with_contrib }}
-
-    steps:
-    - name: Cleanup
-      if: always()
-      uses: AutoModality/action-clean@v1
-
-    - name: Checkout
-      uses: actions/checkout@v2
-      with:
-        submodules: true
-        fetch-depth: 0
-
-    - name: Setup Environment variables
-      run: |
-        if [ "ARM64" == "${{ matrix.os }}" ]; then echo "PLAT=aarch64" >> $GITHUB_ENV; fi
-        echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
-        echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
-
-    - name: before install
-      run: |
-        set -e
-        if [[ $SDIST == 0 ]]; then
-          # Check out and prepare the source
-          # Multibuild doesn't have releases, so --depth would break eventually (see
-          # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
-          git submodule update --init multibuild
-          source multibuild/common_utils.sh
-          # https://github.com/matthew-brett/multibuild/issues/116
-          if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
-          source multibuild/travis_steps.sh
-          # This sets -x
-          # source travis_multibuild_customize.sh
-          echo $ENABLE_CONTRIB > contrib.enabled
-          echo $ENABLE_HEADLESS > headless.enabled
-          echo "end"
-          # Not interested in travis internal scripts' output
-        fi
-        set +x
-        # Build and package
-        set -x
-        ls
-        if [[ $SDIST == 1 ]]; then
-          python -m pip install --upgrade pip
-          python -m pip install scikit-build
-          python setup.py sdist
-        else
-          build_wheel $REPO_DIR $PLAT
-        fi
-        set +x
-        # Install and run tests
-        set -x
-        if [[ $SDIST == 1 ]]; then
-          echo "skipping tests because of sdist"
-          rc=0
-        else
-          install_run $PLAT && rc=$? || rc=$?
-        fi
-        set +x
-        #otherwise, Travis logic terminates prematurely
-        #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
-        trap ERR
-        test "$rc" -eq 0
-
-    - name: saving artifacts
-      uses: actions/upload-artifact@v2
-      with:
-        name: wheels
-        path: wheelhouse/opencv*.whl
-
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
-    needs: [build, build-windows-x86_64, build_sdist, build_arm]
+    needs: [build, build_sdist]
     runs-on: ubuntu-latest
     environment: test-opencv-python-release
     defaults:
@@ -371,7 +198,7 @@ jobs:
 
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
-    needs: [build, build-windows-x86_64, build_sdist, build_arm]
+    needs: [build, build_sdist]
     runs-on: ubuntu-latest
     environment: opencv-python-release
     defaults:
diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
new file mode 100644
index 00000000..de444d90
--- /dev/null
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -0,0 +1,167 @@
+name: Build PYPI wheels for opencv-python on Linux ARM
+
+on:
+  pull_request:
+    branches:
+      - master
+  release:
+    types: [published, edited]
+
+
+jobs:
+  build_arm:
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        shell: bash
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ARM64]
+        python-version: [3.6, 3.7, 3.8, 3.9]
+        platform: [x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [0]
+
+    env:
+      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+      REPO_DIR: .
+      BUILD_COMMIT: master
+      PROJECT_SPEC: opencv-python
+      MB_PYTHON_VERSION: ${{ matrix.python-version }}
+      TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
+      PLAT: aarch64
+      MB_ML_VER: 2014
+      NP_TEST_DEP: numpy
+      TRAVIS_BUILD_DIR: ${{ github.workspace }}
+      CONFIG_PATH: travis_config.sh
+      DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
+      DOCKER_TEST_IMAGE: multibuild/xenial_arm64v8
+      USE_CCACHE: 0
+      UNICODE_WIDTH: 32
+      SDIST: ${{ matrix.build_sdist || 0}}
+      ENABLE_HEADLESS: ${{ matrix.without_gui }}
+      ENABLE_CONTRIB: ${{ matrix.with_contrib }}
+
+    steps:
+    - name: Cleanup
+      if: always()
+      uses: AutoModality/action-clean@v1
+
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: true
+        fetch-depth: 0
+
+    - name: Setup Environment variables
+      run: |
+        if [ "ARM64" == "${{ matrix.os }}" ]; then echo "PLAT=aarch64" >> $GITHUB_ENV; fi
+        echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
+        echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
+
+    - name: before install
+      run: |
+        set -e
+        if [[ $SDIST == 0 ]]; then
+          # Check out and prepare the source
+          # Multibuild doesn't have releases, so --depth would break eventually (see
+          # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+          git submodule update --init multibuild
+          source multibuild/common_utils.sh
+          # https://github.com/matthew-brett/multibuild/issues/116
+          if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+          source multibuild/travis_steps.sh
+          # This sets -x
+          # source travis_multibuild_customize.sh
+          echo $ENABLE_CONTRIB > contrib.enabled
+          echo $ENABLE_HEADLESS > headless.enabled
+          echo "end"
+          # Not interested in travis internal scripts' output
+        fi
+        set +x
+        # Build and package
+        set -x
+        ls
+        if [[ $SDIST == 1 ]]; then
+          python -m pip install --upgrade pip
+          python -m pip install scikit-build
+          python setup.py sdist
+        else
+          build_wheel $REPO_DIR $PLAT
+        fi
+        set +x
+        # Install and run tests
+        set -x
+        if [[ $SDIST == 1 ]]; then
+          echo "skipping tests because of sdist"
+          rc=0
+        else
+          install_run $PLAT && rc=$? || rc=$?
+        fi
+        set +x
+        #otherwise, Travis logic terminates prematurely
+        #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
+        trap ERR
+        test "$rc" -eq 0
+
+    - name: saving artifacts
+      uses: actions/upload-artifact@v2
+      with:
+        name: wheels
+        path: wheelhouse/opencv*.whl
+
+  test_release_opencv_python:
+    if: github.event_name == 'release' && github.event.release.prerelease
+    needs: [build_arm]
+    runs-on: ubuntu-latest
+    environment: test-opencv-python-release
+    defaults:
+      run:
+        shell: bash
+    steps:
+      - uses: actions/download-artifact@v2
+        with:
+          name: wheels
+          path: wheelhouse/
+
+      - name: Upload all wheels
+        run: |
+          python -m pip install twine
+          python -m twine upload --repository testpypi -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} --skip-existing wheelhouse/opencv_*
+
+  release_opencv_python:
+    if: github.event_name == 'release' && !github.event.release.prerelease
+    needs: [build_arm]
+    runs-on: ubuntu-latest
+    environment: opencv-python-release
+    defaults:
+      run:
+        shell: bash
+    steps:
+      - uses: actions/download-artifact@v2
+        with:
+          name: wheels
+          path: wheelhouse/
+
+      - name: Upload wheels for opencv_python
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-*
+
+      - name: Upload wheels for opencv_contrib_python
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-*
+
+      - name: Upload wheels for opencv_python_headless
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-*
+
+      - name: Upload wheels for opencv_contrib_python_headless
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_headless-*
diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
new file mode 100644
index 00000000..d540f6c1
--- /dev/null
+++ b/.github/workflows/build_wheels_macos.yml
@@ -0,0 +1,151 @@
+name: Build PYPI wheels for opencv-python on Macos
+
+on:
+  pull_request:
+    branches:
+      - master
+  release:
+    types: [published, edited]
+
+
+jobs:
+  build:
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        shell: bash
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [macos-latest]
+        python-version: [3.6, 3.7, 3.8, 3.9]
+        platform: [x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [0]
+
+    env:
+      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+      REPO_DIR: .
+      BUILD_COMMIT: master
+      PROJECT_SPEC: opencv-python
+      MB_PYTHON_VERSION: ${{ matrix.python-version }}
+      TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
+      MB_ML_VER: 2014
+      NP_TEST_DEP: numpy
+      TRAVIS_BUILD_DIR: ${{ github.workspace }}
+      CONFIG_PATH: travis_config.sh
+      DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
+      USE_CCACHE: 1
+      UNICODE_WIDTH: 32
+      SDIST: ${{ matrix.build_sdist || 0}}
+      ENABLE_HEADLESS: ${{ matrix.without_gui }}
+      ENABLE_CONTRIB: ${{ matrix.with_contrib }}
+
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: true
+        fetch-depth: 0
+
+    - name: Update submodules
+      run: |
+        git submodule update --remote
+
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v2
+      if: ${{ 'macos-latest' == matrix.os }}
+      with:
+        python-version: ${{ matrix.python-version }}
+        architecture: ${{ matrix.platform }}
+
+    - name: Setup Environment variables
+      run: |
+        if [ "macos-latest" == "${{ matrix.os }}" ]; then echo "TRAVIS_OS_NAME=osx" >> $GITHUB_ENV; else echo "TRAVIS_OS_NAME=${{ matrix.os }}" >> $GITHUB_ENV; fi
+        if [ "schedule" == "${{ github.event_name }}" ]; then echo "TRAVIS_EVENT_TYPE=cron" >> $GITHUB_ENV; else echo "TRAVIS_EVENT_TYPE=${{ github.event_name }}" >> $GITHUB_ENV; fi
+        if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
+        if [ "x64" == "${{ matrix.platform }}" ]; then echo "PLAT=x86_64" >> $GITHUB_ENV; fi
+        if [ "x86" == "${{ matrix.platform }}" ]; then echo "PLAT=i686" >> $GITHUB_ENV; fi
+        echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
+        echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
+
+    - name: before install
+      run: |
+        set -e
+        # Check out and prepare the source
+        # Multibuild doesn't have releases, so --depth would break eventually (see
+        # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+        git submodule update --init multibuild
+        source multibuild/common_utils.sh
+        # https://github.com/matthew-brett/multibuild/issues/116
+        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+        source multibuild/travis_steps.sh
+        # This sets -x
+        # source travis_multibuild_customize.sh
+        echo $ENABLE_CONTRIB > contrib.enabled
+        echo $ENABLE_HEADLESS > headless.enabled
+        set -x
+        build_wheel $REPO_DIR $PLAT
+        install_run $PLAT
+        set +x
+
+    - name: saving artifacts
+      uses: actions/upload-artifact@v2
+      with:
+        name: wheels
+        path: wheelhouse/opencv*.whl
+
+  test_release_opencv_python:
+    if: github.event_name == 'release' && github.event.release.prerelease
+    needs: [build]
+    runs-on: ubuntu-latest
+    environment: test-opencv-python-release
+    defaults:
+      run:
+        shell: bash
+    steps:
+      - uses: actions/download-artifact@v2
+        with:
+          name: wheels
+          path: wheelhouse/
+
+      - name: Upload all wheels
+        run: |
+          python -m pip install twine
+          python -m twine upload --repository testpypi -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} --skip-existing wheelhouse/opencv_*
+
+  release_opencv_python:
+    if: github.event_name == 'release' && !github.event.release.prerelease
+    needs: [build]
+    runs-on: ubuntu-latest
+    environment: opencv-python-release
+    defaults:
+      run:
+        shell: bash
+    steps:
+      - uses: actions/download-artifact@v2
+        with:
+          name: wheels
+          path: wheelhouse/
+
+      - name: Upload wheels for opencv_python
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-*
+
+      - name: Upload wheels for opencv_contrib_python
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-*
+
+      - name: Upload wheels for opencv_python_headless
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-*
+
+      - name: Upload wheels for opencv_contrib_python_headless
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_headless-*
diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
new file mode 100644
index 00000000..76e6c35e
--- /dev/null
+++ b/.github/workflows/build_wheels_windows.yml
@@ -0,0 +1,132 @@
+name: Build PYPI wheels for opencv-python on Windows
+
+on:
+  pull_request:
+    branches:
+      - master
+  release:
+    types: [published, edited]
+
+
+jobs:
+  build-windows-x86_64:
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        shell: powershell
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [windows-latest]
+        python-version: [3.6, 3.7, 3.8, 3.9]
+        platform: [x86, x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [0]
+
+    env:
+      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+      SDIST: ${{ matrix.build_sdist || 0}}
+      ENABLE_HEADLESS: ${{ matrix.without_gui }}
+      ENABLE_CONTRIB: ${{ matrix.with_contrib }}
+
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: true
+        fetch-depth: 0
+
+    - name: Update submodules
+      run: |
+        git submodule update --remote
+
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v2
+      with:
+        python-version: ${{ matrix.python-version }}
+        architecture: ${{ matrix.platform }}
+
+    - name: Setup MSBuild.exe
+      uses: warrenbuckley/Setup-MSBuild@v1
+
+    - name: build script
+      run: |
+        python --version
+        python -m pip install --upgrade pip
+        python -m pip install --upgrade setuptools
+        set "CI_BUILD=1" && python -m pip wheel --wheel-dir=%cd%\wheelhouse . --verbose
+      shell: cmd
+
+    - name: before test
+      run: |
+        cd ${{ github.workspace }}/tests
+        &python -m pip install --user --no-warn-script-location (ls "../wheelhouse/opencv*.whl")
+        if ($LastExitCode -ne 0) {throw $LastExitCode}
+      shell: powershell
+
+    - name: run test
+      run: |
+        cd ${{ github.workspace }}/tests
+        python -m unittest test
+      shell: cmd
+
+    - name: saving artifacts
+      uses: actions/upload-artifact@v2
+      with:
+        name: wheels
+        path: wheelhouse/opencv*.whl
+
+  test_release_opencv_python:
+    if: github.event_name == 'release' && github.event.release.prerelease
+    needs: [build-windows-x86_64]
+    runs-on: ubuntu-latest
+    environment: test-opencv-python-release
+    defaults:
+      run:
+        shell: bash
+    steps:
+      - uses: actions/download-artifact@v2
+        with:
+          name: wheels
+          path: wheelhouse/
+
+      - name: Upload all wheels
+        run: |
+          python -m pip install twine
+          python -m twine upload --repository testpypi -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} --skip-existing wheelhouse/opencv_*
+
+  release_opencv_python:
+    if: github.event_name == 'release' && !github.event.release.prerelease
+    needs: [build-windows-x86_64]
+    runs-on: ubuntu-latest
+    environment: opencv-python-release
+    defaults:
+      run:
+        shell: bash
+    steps:
+      - uses: actions/download-artifact@v2
+        with:
+          name: wheels
+          path: wheelhouse/
+
+      - name: Upload wheels for opencv_python
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-*
+
+      - name: Upload wheels for opencv_contrib_python
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-*
+
+      - name: Upload wheels for opencv_python_headless
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-*
+
+      - name: Upload wheels for opencv_contrib_python_headless
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_headless-*

From 2bab1f58c70371b6f2e3108eebeb27311050aaea Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Thu, 27 May 2021 09:45:26 +0300
Subject: [PATCH 502/566] Split builds and tests for linux, update submodules
 only when a PR, turned off freetype because of issues, added get_build_info
 script

---
 .github/workflows/build_wheels_linux.yml     | 42 ++++++++++++--------
 .github/workflows/build_wheels_linux_arm.yml |  2 +-
 .github/workflows/build_wheels_macos.yml     |  6 +--
 .github/workflows/build_wheels_windows.yml   | 12 +++---
 setup.py                                     |  1 +
 tests/get_build_info.py                      |  3 ++
 travis_config.sh                             |  7 ++++
 7 files changed, 48 insertions(+), 25 deletions(-)
 create mode 100644 tests/get_build_info.py

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index c371b774..2b6f8efe 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -39,7 +39,7 @@ jobs:
       DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
-      SDIST: ${{ matrix.build_sdist || 0}}
+      SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
 
@@ -47,19 +47,12 @@ jobs:
     - name: Checkout
       uses: actions/checkout@v2
       with:
-        submodules: true
+        submodules: false
         fetch-depth: 0
 
     - name: Update submodules
-      run: |
-        git submodule update --remote
-
-    - name: Set up Python ${{ matrix.python-version }}
-      uses: actions/setup-python@v2
-      if: ${{ 'macos-latest' == matrix.os }}
-      with:
-        python-version: ${{ matrix.python-version }}
-        architecture: ${{ matrix.platform }}
+      if: github.event_name == 'pull_request'
+      run: git submodule update --remote
 
     - name: Setup Environment variables
       run: |
@@ -71,7 +64,7 @@ jobs:
         echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
         echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
 
-    - name: before install
+    - name: build
       run: |
         set -e
         # Check out and prepare the source
@@ -88,6 +81,23 @@ jobs:
         echo $ENABLE_HEADLESS > headless.enabled
         set -x
         build_wheel $REPO_DIR $PLAT
+
+    - name: install and test
+      run: |
+        set -e
+        # Check out and prepare the source
+        # Multibuild doesn't have releases, so --depth would break eventually (see
+        # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+        git submodule update --init --recursive
+        source multibuild/common_utils.sh
+        # https://github.com/matthew-brett/multibuild/issues/116
+        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+        source multibuild/travis_steps.sh
+        # This sets -x
+        # source travis_multibuild_customize.sh
+        echo $ENABLE_CONTRIB > contrib.enabled
+        echo $ENABLE_HEADLESS > headless.enabled
+        set -x
         install_run $PLAT
         set +x
 
@@ -129,9 +139,9 @@ jobs:
       DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
-      SDIST: ${{ matrix.build_sdist || 0}}
+      SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui || 0 }}
-      ENABLE_CONTRIB: ${{ matrix.with_contrib || 0}}
+      ENABLE_CONTRIB: ${{ matrix.with_contrib || 0 }}
 
     steps:
     - name: Checkout
@@ -141,8 +151,8 @@ jobs:
         fetch-depth: 0
 
     - name: Update submodules
-      run: |
-        git submodule update --remote
+      if: github.event_name == 'pull_request'
+      run: git submodule update --remote
 
     - name: Set up Python ${{ matrix.python-version }}
       uses: actions/setup-python@v2
diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index de444d90..a680401a 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -41,7 +41,7 @@ jobs:
       DOCKER_TEST_IMAGE: multibuild/xenial_arm64v8
       USE_CCACHE: 0
       UNICODE_WIDTH: 32
-      SDIST: ${{ matrix.build_sdist || 0}}
+      SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
 
diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index d540f6c1..bfce806f 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -39,7 +39,7 @@ jobs:
       DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
-      SDIST: ${{ matrix.build_sdist || 0}}
+      SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
 
@@ -51,8 +51,8 @@ jobs:
         fetch-depth: 0
 
     - name: Update submodules
-      run: |
-        git submodule update --remote
+      if: github.event_name == 'pull_request'
+      run: git submodule update --remote
 
     - name: Set up Python ${{ matrix.python-version }}
       uses: actions/setup-python@v2
diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index 76e6c35e..03a341e4 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -27,9 +27,10 @@ jobs:
 
     env:
       ACTIONS_ALLOW_UNSECURE_COMMANDS: true
-      SDIST: ${{ matrix.build_sdist || 0}}
+      SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
+      OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata
 
     steps:
     - name: Checkout
@@ -39,8 +40,8 @@ jobs:
         fetch-depth: 0
 
     - name: Update submodules
-      run: |
-        git submodule update --remote
+      if: github.event_name == 'pull_request'
+      run: git submodule update --remote
 
     - name: Set up Python ${{ matrix.python-version }}
       uses: actions/setup-python@v2
@@ -64,12 +65,13 @@ jobs:
         cd ${{ github.workspace }}/tests
         &python -m pip install --user --no-warn-script-location (ls "../wheelhouse/opencv*.whl")
         if ($LastExitCode -ne 0) {throw $LastExitCode}
+        python get_build_info.py
       shell: powershell
 
     - name: run test
       run: |
-        cd ${{ github.workspace }}/tests
-        python -m unittest test
+        cd ${{ github.workspace }}/opencv
+        python modules\python\test\test.py -v --repo .
       shell: cmd
 
     - name: saving artifacts
diff --git a/setup.py b/setup.py
index a3265206..a14825da 100644
--- a/setup.py
+++ b/setup.py
@@ -145,6 +145,7 @@ def main():
             "-DINSTALL_CREATE_DISTRIB=ON",
             # See opencv/CMakeLists.txt for options and defaults
             "-DBUILD_opencv_apps=OFF",
+            "-DBUILD_opencv_freetype=OFF",
             "-DBUILD_SHARED_LIBS=OFF",
             "-DBUILD_TESTS=OFF",
             "-DBUILD_PERF_TESTS=OFF",
diff --git a/tests/get_build_info.py b/tests/get_build_info.py
new file mode 100644
index 00000000..4714f2f4
--- /dev/null
+++ b/tests/get_build_info.py
@@ -0,0 +1,3 @@
+import cv2 as cv
+
+print(cv.getBuildInformation())
diff --git a/travis_config.sh b/travis_config.sh
index b1a991a4..a83fe141 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -150,6 +150,10 @@ function run_tests {
 
     if [ -n "$IS_OSX" ]; then
       echo "Running for OS X"
+
+      cd ../tests
+      $PYTHON get_build_info.py
+
       cd ../opencv/
       export OPENCV_TEST_DATA_PATH=../opencv_extra/testdata
     else
@@ -158,6 +162,9 @@ function run_tests {
       if [ $PYTHON == "python3.6" ]; then
         $PYTHON -m pip install -U numpy==1.19.4
       fi
+      cd /io/tests
+      $PYTHON get_build_info.py
+
       cd /io/opencv
       export OPENCV_TEST_DATA_PATH=/io/opencv_extra/testdata
     fi

From 83deed818f0f83fd193eb1d5bace23fac0f1eba0 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Thu, 3 Jun 2021 13:20:20 +0300
Subject: [PATCH 503/566] Extracted build and install+test steps into two
 different scripts and fixed issues

---
 .github/workflows/build_wheels_linux.yml     | 44 ++--------------
 .github/workflows/build_wheels_linux_arm.yml | 53 +++-----------------
 .github/workflows/build_wheels_macos.yml     |  5 +-
 .github/workflows/build_wheels_windows.yml   |  3 +-
 scripts/build.sh                             | 17 +++++++
 scripts/install.sh                           | 18 +++++++
 6 files changed, 52 insertions(+), 88 deletions(-)
 create mode 100755 scripts/build.sh
 create mode 100755 scripts/install.sh

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index 2b6f8efe..c9307d74 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -33,7 +33,7 @@ jobs:
       MB_PYTHON_VERSION: ${{ matrix.python-version }}
       TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
       MB_ML_VER: 2014
-      NP_TEST_DEP: numpy
+      NP_TEST_DEP: numpy==1.19.4
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
       DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
@@ -56,50 +56,17 @@ jobs:
 
     - name: Setup Environment variables
       run: |
-        if [ "macos-latest" == "${{ matrix.os }}" ]; then echo "TRAVIS_OS_NAME=osx" >> $GITHUB_ENV; else echo "TRAVIS_OS_NAME=${{ matrix.os }}" >> $GITHUB_ENV; fi
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "TRAVIS_EVENT_TYPE=cron" >> $GITHUB_ENV; else echo "TRAVIS_EVENT_TYPE=${{ github.event_name }}" >> $GITHUB_ENV; fi
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
         if [ "x64" == "${{ matrix.platform }}" ]; then echo "PLAT=x86_64" >> $GITHUB_ENV; fi
-        if [ "x86" == "${{ matrix.platform }}" ]; then echo "PLAT=i686" >> $GITHUB_ENV; fi
         echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
         echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
 
     - name: build
-      run: |
-        set -e
-        # Check out and prepare the source
-        # Multibuild doesn't have releases, so --depth would break eventually (see
-        # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
-        git submodule update --init multibuild
-        source multibuild/common_utils.sh
-        # https://github.com/matthew-brett/multibuild/issues/116
-        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
-        source multibuild/travis_steps.sh
-        # This sets -x
-        # source travis_multibuild_customize.sh
-        echo $ENABLE_CONTRIB > contrib.enabled
-        echo $ENABLE_HEADLESS > headless.enabled
-        set -x
-        build_wheel $REPO_DIR $PLAT
+      run: source scripts/build.sh
 
     - name: install and test
-      run: |
-        set -e
-        # Check out and prepare the source
-        # Multibuild doesn't have releases, so --depth would break eventually (see
-        # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
-        git submodule update --init --recursive
-        source multibuild/common_utils.sh
-        # https://github.com/matthew-brett/multibuild/issues/116
-        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
-        source multibuild/travis_steps.sh
-        # This sets -x
-        # source travis_multibuild_customize.sh
-        echo $ENABLE_CONTRIB > contrib.enabled
-        echo $ENABLE_HEADLESS > headless.enabled
-        set -x
-        install_run $PLAT
-        set +x
+      run: source scripts/install.sh
 
     - name: saving artifacts
       uses: actions/upload-artifact@v2
@@ -133,7 +100,7 @@ jobs:
       MB_PYTHON_VERSION: ${{ matrix.python-version }}
       TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
       MB_ML_VER: 2014
-      NP_TEST_DEP: numpy
+      NP_TEST_DEP: numpy==1.19.4
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
       DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
@@ -147,7 +114,7 @@ jobs:
     - name: Checkout
       uses: actions/checkout@v2
       with:
-        submodules: true
+        submodules: false
         fetch-depth: 0
 
     - name: Update submodules
@@ -162,7 +129,6 @@ jobs:
 
     - name: Setup Environment variables
       run: |
-        if [ "macos-latest" == "${{ matrix.os }}" ]; then echo "TRAVIS_OS_NAME=osx" >> $GITHUB_ENV; else echo "TRAVIS_OS_NAME=${{ matrix.os }}" >> $GITHUB_ENV; fi
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "TRAVIS_EVENT_TYPE=cron" >> $GITHUB_ENV; else echo "TRAVIS_EVENT_TYPE=${{ github.event_name }}" >> $GITHUB_ENV; fi
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
         echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index a680401a..7ad52cda 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -34,7 +34,7 @@ jobs:
       TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
       PLAT: aarch64
       MB_ML_VER: 2014
-      NP_TEST_DEP: numpy
+      NP_TEST_DEP: numpy==1.19.4
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
       DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
@@ -53,7 +53,7 @@ jobs:
     - name: Checkout
       uses: actions/checkout@v2
       with:
-        submodules: true
+        submodules: false
         fetch-depth: 0
 
     - name: Setup Environment variables
@@ -62,50 +62,11 @@ jobs:
         echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
         echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
 
-    - name: before install
-      run: |
-        set -e
-        if [[ $SDIST == 0 ]]; then
-          # Check out and prepare the source
-          # Multibuild doesn't have releases, so --depth would break eventually (see
-          # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
-          git submodule update --init multibuild
-          source multibuild/common_utils.sh
-          # https://github.com/matthew-brett/multibuild/issues/116
-          if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
-          source multibuild/travis_steps.sh
-          # This sets -x
-          # source travis_multibuild_customize.sh
-          echo $ENABLE_CONTRIB > contrib.enabled
-          echo $ENABLE_HEADLESS > headless.enabled
-          echo "end"
-          # Not interested in travis internal scripts' output
-        fi
-        set +x
-        # Build and package
-        set -x
-        ls
-        if [[ $SDIST == 1 ]]; then
-          python -m pip install --upgrade pip
-          python -m pip install scikit-build
-          python setup.py sdist
-        else
-          build_wheel $REPO_DIR $PLAT
-        fi
-        set +x
-        # Install and run tests
-        set -x
-        if [[ $SDIST == 1 ]]; then
-          echo "skipping tests because of sdist"
-          rc=0
-        else
-          install_run $PLAT && rc=$? || rc=$?
-        fi
-        set +x
-        #otherwise, Travis logic terminates prematurely
-        #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
-        trap ERR
-        test "$rc" -eq 0
+    - name: build
+      run: source scripts/build.sh
+
+    - name: install and test
+      run: source scripts/install.sh
 
     - name: saving artifacts
       uses: actions/upload-artifact@v2
diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index bfce806f..c2dc073f 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -33,7 +33,7 @@ jobs:
       MB_PYTHON_VERSION: ${{ matrix.python-version }}
       TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
       MB_ML_VER: 2014
-      NP_TEST_DEP: numpy
+      NP_TEST_DEP: numpy==1.19.4
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
       DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
@@ -47,7 +47,7 @@ jobs:
     - name: Checkout
       uses: actions/checkout@v2
       with:
-        submodules: true
+        submodules: false
         fetch-depth: 0
 
     - name: Update submodules
@@ -88,6 +88,7 @@ jobs:
         echo $ENABLE_HEADLESS > headless.enabled
         set -x
         build_wheel $REPO_DIR $PLAT
+        git submodule update --init --recursive
         install_run $PLAT
         set +x
 
diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index 03a341e4..c8811083 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -36,7 +36,7 @@ jobs:
     - name: Checkout
       uses: actions/checkout@v2
       with:
-        submodules: true
+        submodules: false
         fetch-depth: 0
 
     - name: Update submodules
@@ -62,6 +62,7 @@ jobs:
 
     - name: before test
       run: |
+        git submodule update --init --recursive
         cd ${{ github.workspace }}/tests
         &python -m pip install --user --no-warn-script-location (ls "../wheelhouse/opencv*.whl")
         if ($LastExitCode -ne 0) {throw $LastExitCode}
diff --git a/scripts/build.sh b/scripts/build.sh
new file mode 100755
index 00000000..f48ca066
--- /dev/null
+++ b/scripts/build.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+set -e
+# Check out and prepare the source
+# Multibuild doesn't have releases, so --depth would break eventually (see
+# https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+git submodule update --init multibuild
+source multibuild/common_utils.sh
+# https://github.com/matthew-brett/multibuild/issues/116
+if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+source multibuild/travis_steps.sh
+# This sets -x
+# source travis_multibuild_customize.sh
+echo $ENABLE_CONTRIB > contrib.enabled
+echo $ENABLE_HEADLESS > headless.enabled
+set -x
+build_wheel $REPO_DIR $PLAT
diff --git a/scripts/install.sh b/scripts/install.sh
new file mode 100755
index 00000000..6e019d1c
--- /dev/null
+++ b/scripts/install.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+set -e
+# Check out and prepare the source
+# Multibuild doesn't have releases, so --depth would break eventually (see
+# https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
+git submodule update --init --recursive
+source multibuild/common_utils.sh
+# https://github.com/matthew-brett/multibuild/issues/116
+if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
+source multibuild/travis_steps.sh
+# This sets -x
+# source travis_multibuild_customize.sh
+echo $ENABLE_CONTRIB > contrib.enabled
+echo $ENABLE_HEADLESS > headless.enabled
+set -x
+install_run $PLAT
+set +x

From 4fe9a58b2e7f317838c3a21cf1a1f065bdc72695 Mon Sep 17 00:00:00 2001
From: William Jackson <william@subtlecoolness.com>
Date: Wed, 9 Jun 2021 09:49:38 -0500
Subject: [PATCH 504/566] Include software distributions when uploading to PyPI

---
 .github/workflows/build_wheels_linux.yml | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index c9307d74..8ff86b1b 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -170,7 +170,7 @@ jobs:
       - name: Upload all wheels
         run: |
           python -m pip install twine
-          python -m twine upload --repository testpypi -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} --skip-existing wheelhouse/opencv_*
+          python -m twine upload --repository testpypi -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} --skip-existing wheelhouse/opencv_* wheelhouse/opencv-*
 
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
@@ -189,19 +189,19 @@ jobs:
       - name: Upload wheels for opencv_python
         run: |
           python -m pip install twine
-          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-*
+          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-* wheelhouse/opencv-python-[^h]*
 
       - name: Upload wheels for opencv_contrib_python
         run: |
           python -m pip install twine
-          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-*
+          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-* wheelhouse/opencv-contrib-python-[^h]*
 
       - name: Upload wheels for opencv_python_headless
         run: |
           python -m pip install twine
-          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-*
+          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-* wheelhouse/opencv-python-headless-*
 
       - name: Upload wheels for opencv_contrib_python_headless
         run: |
           python -m pip install twine
-          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_headless-*
+          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_headless-* wheelhouse/opencv-contrib-python-headless-*

From 9136e869fae07f086aa1dfaa202051e26b3ef1a0 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Wed, 30 Jun 2021 18:17:33 +0300
Subject: [PATCH 505/566] Added MacOS with M1 build

---
 .github/workflows/build_wheels_linux.yml     |   4 +
 .github/workflows/build_wheels_linux_arm.yml |   4 +
 .github/workflows/build_wheels_macos.yml     |   4 +
 .github/workflows/build_wheels_macos_m1.yml  | 117 +++++++++++++++++++
 .github/workflows/build_wheels_windows.yml   |   3 +
 pyproject.toml                               |  10 +-
 setup.py                                     |   4 +-
 7 files changed, 139 insertions(+), 7 deletions(-)
 create mode 100644 .github/workflows/build_wheels_macos_m1.yml

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index c9307d74..af8f1a06 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -4,6 +4,10 @@ on:
   pull_request:
     branches:
       - master
+    paths-ignore:
+      - '.github/workflows/build_wheels_linux_arm.yml'
+      - '.github/workflows/build_wheels_windows*'
+      - '.github/workflows/build_wheels_macos*'
   release:
     types: [published, edited]
 
diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index 7ad52cda..d71db231 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -4,6 +4,10 @@ on:
   pull_request:
     branches:
       - master
+    paths-ignore:
+      - '.github/workflows/build_wheels_linux.yml'
+      - '.github/workflows/build_wheels_windows*'
+      - '.github/workflows/build_wheels_macos*'
   release:
     types: [published, edited]
 
diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index c2dc073f..5b2b8066 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -4,6 +4,10 @@ on:
   pull_request:
     branches:
       - master
+    paths-ignore:
+      - '.github/workflows/build_wheels_linux*'
+      - '.github/workflows/build_wheels_windows*'
+      - '.github/workflows/build_wheels_macos_m1.yml'
   release:
     types: [published, edited]
 
diff --git a/.github/workflows/build_wheels_macos_m1.yml b/.github/workflows/build_wheels_macos_m1.yml
new file mode 100644
index 00000000..d3018497
--- /dev/null
+++ b/.github/workflows/build_wheels_macos_m1.yml
@@ -0,0 +1,117 @@
+name: Build PYPI wheels for opencv-python on Macos M1
+
+on:
+  pull_request:
+    branches:
+      - master
+    paths-ignore:
+      - '.github/workflows/build_wheels_linux*'
+      - '.github/workflows/build_wheels_windows*'
+      - '.github/workflows/build_wheels_macos.yml'
+  release:
+    types: [published, edited]
+
+
+jobs:
+  build:
+    runs-on: ${{ matrix.os }}
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [macOS-M1]
+        python-version: [3.7, 3.8, 3.9]
+        platform: [x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [0]
+
+    env:
+      SDIST: ${{ matrix.build_sdist || 0 }}
+      ENABLE_HEADLESS: ${{ matrix.without_gui }}
+      ENABLE_CONTRIB: ${{ matrix.with_contrib }}
+      OPENCV_TEST_DATA_PATH: ${{ github.workspace }}/opencv_extra/testdata
+
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: false
+        fetch-depth: 0
+
+    - name: Update submodules
+      if: github.event_name == 'pull_request'
+      run: git submodule update --remote
+
+    - name: build script
+      run: |
+        git submodule update --init multibuild
+        echo $ENABLE_CONTRIB > contrib.enabled
+        echo $ENABLE_HEADLESS > headless.enabled
+        export MACOSX_DEPLOYMENT_TARGET=11.0
+        arch -arm64 python${{ matrix.python-version }} -m pip wheel --wheel-dir=wheelhouse . --verbose
+    - name: before test
+      run: |
+        git submodule update --init --recursive
+        arch -arm64 python${{ matrix.python-version }} -m pip install --user --no-cache --force-reinstall wheelhouse/opencv*.whl
+        cd ${{ github.workspace }}/tests
+        arch -arm64 python${{ matrix.python-version }} get_build_info.py
+    - name: run test
+      run: |
+        cd ${{ github.workspace }}/opencv
+        arch -arm64 python${{ matrix.python-version }} modules/python/test/test.py -v --repo .
+    - name: saving artifacts
+      uses: actions/upload-artifact@v2
+      with:
+        name: wheels
+        path: wheelhouse/opencv*.whl
+
+  test_release_opencv_python:
+    if: github.event_name == 'release' && github.event.release.prerelease
+    needs: [build]
+    runs-on: ubuntu-latest
+    environment: test-opencv-python-release
+    defaults:
+      run:
+        shell: bash
+    steps:
+      - uses: actions/download-artifact@v2
+        with:
+          name: wheels
+          path: wheelhouse/
+
+      - name: Upload all wheels
+        run: |
+          python -m pip install twine
+          python -m twine upload --repository testpypi -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} --skip-existing wheelhouse/opencv_*
+
+  release_opencv_python:
+    if: github.event_name == 'release' && !github.event.release.prerelease
+    needs: [build]
+    runs-on: ubuntu-latest
+    environment: opencv-python-release
+    defaults:
+      run:
+        shell: bash
+    steps:
+      - uses: actions/download-artifact@v2
+        with:
+          name: wheels
+          path: wheelhouse/
+
+      - name: Upload wheels for opencv_python
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-*
+      - name: Upload wheels for opencv_contrib_python
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-*
+      - name: Upload wheels for opencv_python_headless
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-*
+      - name: Upload wheels for opencv_contrib_python_headless
+        run: |
+          python -m pip install twine
+          python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_headless-*
diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index c8811083..554f684c 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -4,6 +4,9 @@ on:
   pull_request:
     branches:
       - master
+    paths-ignore:
+      - '.github/workflows/build_wheels_linux*'
+      - '.github/workflows/build_wheels_macos*'
   release:
     types: [published, edited]
 
diff --git a/pyproject.toml b/pyproject.toml
index 07bcc4bb..5a2849f3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,10 +1,10 @@
 [build-system]
 requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
-  "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64'",
+  "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
   "numpy==1.19.3; python_version>='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
-  "numpy==1.20.1; python_version>='3.6' and sys_platform == 'darwin' and platform_machine == 'aarch64'",
-  "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64'",
-  "numpy==1.17.3; python_version=='3.8' and platform_machine != 'aarch64'",
-  "numpy==1.19.3; python_version>='3.9' and platform_machine != 'aarch64'"
+  "numpy==1.21.0; python_version>='3.6' and sys_platform == 'darwin' and platform_machine == 'arm64'",
+  "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
+  "numpy==1.17.3; python_version=='3.8' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
+  "numpy==1.19.3; python_version>='3.9' and platform_machine != 'aarch64' and platform_machine != 'arm64'"
 ]
diff --git a/setup.py b/setup.py
index a14825da..612a080c 100644
--- a/setup.py
+++ b/setup.py
@@ -36,8 +36,8 @@ def main():
         minimum_supported_numpy = "1.19.3"
 
     # macos arm64 is a special case
-    if sys.platform == "darwin" and sys.version_info[:2] >= (3, 6) and platform.machine() == "aarch64":
-        minimum_supported_numpy = "1.20.1"
+    if sys.platform == "darwin" and sys.version_info[:2] >= (3, 6) and platform.machine() == "arm64":
+        minimum_supported_numpy = "1.21.0"
 
     numpy_version = "numpy>=%s" % minimum_supported_numpy
 

From 2ff0d0e3a4b2152214f4f1fd8d0ee0f40497e6c7 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Wed, 7 Jul 2021 15:12:11 +0300
Subject: [PATCH 506/566] Updated submodules to 4.5.3 release

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 opencv_extra   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/opencv b/opencv
index 69357b1e..ad6e8294 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 69357b1e88680658a07cffde7678a4d697469f03
+Subproject commit ad6e82942b37be8ee2c71c1d9bc7fe79cd16f7ab
diff --git a/opencv_contrib b/opencv_contrib
index f5d7f671..d5317d62 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit f5d7f6712d4ff229ba4f45cf79dfd11c557d56fd
+Subproject commit d5317d6297a8129b66dba1a1f7cc784e94639da9
diff --git a/opencv_extra b/opencv_extra
index 3b033d09..d5c7212d 160000
--- a/opencv_extra
+++ b/opencv_extra
@@ -1 +1 @@
-Subproject commit 3b033d09cab1894d6452707df723789fe98c8663
+Subproject commit d5c7212d53f097c9fdf5e72c598ad051660599e8

From eb0efe2fa05e4ef1e596bad2509e870fc2c5377f Mon Sep 17 00:00:00 2001
From: Alexander Smorkalov <alexander.smorkalov@xperience.ai>
Date: Fri, 16 Jul 2021 15:58:54 +0300
Subject: [PATCH 507/566] Readme update after migration to Github Actions for
 CI.

---
 README.md | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 9629aae0..38789a8b 100644
--- a/README.md
+++ b/README.md
@@ -79,15 +79,16 @@ A: It's easier for users to understand ``opencv-python`` than ``cv2`` and it mak
 
 ## Documentation for opencv-python
 
-[![AppVeyor CI test status (Windows)](https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows)](https://ci.appveyor.com/project/skvark/opencv-python)
-[![Travis CI test status (Linux and macOS)](https://img.shields.io/travis/com/skvark/opencv-python/master?label=Linux%20%26%20macOS)](https://travis-ci.com/github/skvark/opencv-python/)
+[![Windows Buld Status](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_windows.yml/badge.svg)](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_windows.yml)
+[![(Linux Build status)](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_linux.yml/badge.svg)](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_linux.yml)
+[![(Mac OS Build status)](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_macos.yml/badge.svg)](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_macos.yml)
 
 The aim of this repository is to provide means to package each new [OpenCV release](https://github.com/opencv/opencv/releases) 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):
+The build process for a single entry in the build matrices is as follows (see for example `.github/workflows/build_wheels_linux.yml` file):
 
 0. In Linux and MacOS build: get OpenCV's optional C dependencies that we compile against
 
@@ -181,7 +182,7 @@ Third party package licenses are at [LICENSE-3RD-PARTY.txt](https://github.com/o
 
 All wheels ship with [FFmpeg](http://ffmpeg.org) licensed under the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
 
-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).
+Non-headless Linux 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).
 
 The packages include also other binaries. Full list of licenses can be found from [LICENSE-3RD-PARTY.txt](https://github.com/opencv/opencv-python/blob/master/LICENSE-3RD-PARTY.txt).
 

From ecd163ddef981f28278e7a1cd4a9056da204dd19 Mon Sep 17 00:00:00 2001
From: Aaron Gokaslan <aaronGokaslan@gmail.com>
Date: Fri, 17 Sep 2021 13:04:41 -0400
Subject: [PATCH 508/566] fix typo in Readme

Fixes a typo in Readme
---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 38789a8b..bb43bb99 100644
--- a/README.md
+++ b/README.md
@@ -67,7 +67,7 @@ A: Make sure you have removed old manual installations of OpenCV Python bindings
 
 **Q: Function foo() or method bar() returns wrong result, throws exception or crashes interpriter. 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](https://github.com/opencv/opencv/wiki) and [the fficial OpenCV forum](https://forum.opencv.org/) before file new bugs.
+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](https://github.com/opencv/opencv/wiki) and [the official OpenCV forum](https://forum.opencv.org/) before file new bugs.
 
 **Q: Why the packages do not include non-free algorithms?**
 

From 5fedf828ee2b985351747c8f6485475e033074b9 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <76472231+asenyaev@users.noreply.github.com>
Date: Tue, 21 Sep 2021 12:19:00 +0300
Subject: [PATCH 509/566] Added the lapack installation

---
 travis_config.sh | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/travis_config.sh b/travis_config.sh
index a83fe141..7026a021 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -26,6 +26,13 @@ function bdist_wheel_cmd {
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }
 
+if [ -n "$IS_OSX" ]; then
+  brew install lapack
+else
+  yum install -y atlas-devel blas-devel lapack-devel
+  cp /usr/include/lapacke/lapacke*.h /usr/include/
+fi
+
 if [ -n "$IS_OSX" ]; then
   echo "    > OSX environment "
   export MAKEFLAGS="-j$(sysctl -n hw.ncpu)"

From 3c1ea4402db35fa51c6804db7424bd30d561a51c Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Fri, 1 Oct 2021 11:35:33 +0300
Subject: [PATCH 510/566] Changed blas to openblas and fixed flow to a proper
 installation

---
 scripts/build.sh |  1 +
 travis_config.sh | 15 ++++++++-------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/scripts/build.sh b/scripts/build.sh
index f48ca066..aa9ff968 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -15,3 +15,4 @@ echo $ENABLE_CONTRIB > contrib.enabled
 echo $ENABLE_HEADLESS > headless.enabled
 set -x
 build_wheel $REPO_DIR $PLAT
+rm wheelhouse/numpy*
diff --git a/travis_config.sh b/travis_config.sh
index 7026a021..28fbb96f 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -26,13 +26,6 @@ function bdist_wheel_cmd {
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
 }
 
-if [ -n "$IS_OSX" ]; then
-  brew install lapack
-else
-  yum install -y atlas-devel blas-devel lapack-devel
-  cp /usr/include/lapacke/lapacke*.h /usr/include/
-fi
-
 if [ -n "$IS_OSX" ]; then
   echo "    > OSX environment "
   export MAKEFLAGS="-j$(sysctl -n hw.ncpu)"
@@ -99,6 +92,14 @@ function pre_build {
   echo "Starting pre-build"
   set -e -o pipefail
 
+  if [ -n "$IS_OSX" ]; then
+    brew install lapack
+  else
+    yum install -y lapack-devel openblas-devel
+    cp /usr/include/lapacke/lapacke*.h /usr/include/
+    curl https://raw.githubusercontent.com/xianyi/OpenBLAS/v0.3.3/cblas.h -o /usr/include/cblas.h
+  fi
+
   if [ -n "$IS_OSX" ]; then
     echo "Running for OSX"
 

From 40e0e3b8c235386c003f8ea5d0a9d9ea968a06cd Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Fri, 1 Oct 2021 13:51:43 +0300
Subject: [PATCH 511/566] Fixed aarch64 openblas installation

---
 travis_config.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/travis_config.sh b/travis_config.sh
index 28fbb96f..a387966c 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -95,7 +95,8 @@ function pre_build {
   if [ -n "$IS_OSX" ]; then
     brew install lapack
   else
-    yum install -y lapack-devel openblas-devel
+    # epel-release need for aarch64 to get openblas packages
+    yum install -y lapack-devel epel-release && yum install -y openblas-devel
     cp /usr/include/lapacke/lapacke*.h /usr/include/
     curl https://raw.githubusercontent.com/xianyi/OpenBLAS/v0.3.3/cblas.h -o /usr/include/cblas.h
   fi

From 1d6e03459e32a5effd27b7b86186b418f2bde437 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Fri, 1 Oct 2021 19:11:37 +0300
Subject: [PATCH 512/566] Fixed an issue when machine:X86 was defined on
 Windows x64

---
 setup.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/setup.py b/setup.py
index 612a080c..22b6561d 100644
--- a/setup.py
+++ b/setup.py
@@ -151,6 +151,12 @@ def main():
             "-DBUILD_PERF_TESTS=OFF",
             "-DBUILD_DOCS=OFF",
         ]
+        + (
+            # If it is not defined 'linker flags: /machine:X86' on Windows x64
+            ["-DCMAKE_GENERATOR_PLATFORM=x64"]
+            if x64 and sys.platform == "win32"
+            else []
+          )
         + (
             ["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")]
             if build_contrib

From 76a6fb2476b0f4610d6b8a827d3201cacab7daae Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Wed, 6 Oct 2021 19:52:12 +0300
Subject: [PATCH 513/566] Added fix for MacOS with M1

---
 .github/workflows/build_wheels_macos_m1.yml | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/build_wheels_macos_m1.yml b/.github/workflows/build_wheels_macos_m1.yml
index d3018497..fb4b7d1b 100644
--- a/.github/workflows/build_wheels_macos_m1.yml
+++ b/.github/workflows/build_wheels_macos_m1.yml
@@ -49,17 +49,21 @@ jobs:
         echo $ENABLE_CONTRIB > contrib.enabled
         echo $ENABLE_HEADLESS > headless.enabled
         export MACOSX_DEPLOYMENT_TARGET=11.0
-        arch -arm64 python${{ matrix.python-version }} -m pip wheel --wheel-dir=wheelhouse . --verbose
+        arch -arm64 -e SDIST=${{ matrix.build_sdist }} -e ENABLE_HEADLESS=${{ matrix.without_gui }} -e ENABLE_CONTRIB=${{ matrix.with_contrib }} python${{ matrix.python-version }} -m pip wheel --wheel-dir=wheelhouse . --verbose
+        delocate-wheel ${{ github.workspace }}/wheelhouse/opencv*
+
     - name: before test
       run: |
         git submodule update --init --recursive
         arch -arm64 python${{ matrix.python-version }} -m pip install --user --no-cache --force-reinstall wheelhouse/opencv*.whl
         cd ${{ github.workspace }}/tests
         arch -arm64 python${{ matrix.python-version }} get_build_info.py
+
     - name: run test
       run: |
         cd ${{ github.workspace }}/opencv
         arch -arm64 python${{ matrix.python-version }} modules/python/test/test.py -v --repo .
+
     - name: saving artifacts
       uses: actions/upload-artifact@v2
       with:

From 3f010892e3c7b947c6afba6af3b05c2cfca3515b Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Wed, 6 Oct 2021 22:45:47 +0300
Subject: [PATCH 514/566] Removed env variables and defined CI_BUILD variable
 globally

---
 .github/workflows/build_wheels_macos_m1.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/build_wheels_macos_m1.yml b/.github/workflows/build_wheels_macos_m1.yml
index fb4b7d1b..2c855874 100644
--- a/.github/workflows/build_wheels_macos_m1.yml
+++ b/.github/workflows/build_wheels_macos_m1.yml
@@ -27,6 +27,7 @@ jobs:
         build_sdist: [0]
 
     env:
+      CI_BUILD: 1
       SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
@@ -49,7 +50,7 @@ jobs:
         echo $ENABLE_CONTRIB > contrib.enabled
         echo $ENABLE_HEADLESS > headless.enabled
         export MACOSX_DEPLOYMENT_TARGET=11.0
-        arch -arm64 -e SDIST=${{ matrix.build_sdist }} -e ENABLE_HEADLESS=${{ matrix.without_gui }} -e ENABLE_CONTRIB=${{ matrix.with_contrib }} python${{ matrix.python-version }} -m pip wheel --wheel-dir=wheelhouse . --verbose
+        arch -arm64 python${{ matrix.python-version }} -m pip wheel --wheel-dir=wheelhouse . --verbose
         delocate-wheel ${{ github.workspace }}/wheelhouse/opencv*
 
     - name: before test

From d82a270ecfda961d1a9a12e525aac773b4dda234 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Fri, 8 Oct 2021 00:08:49 +0300
Subject: [PATCH 515/566] Updated Github Actions to python 3.10 and fixed
 following issues

---
 .github/workflows/build_wheels_linux.yml     | 12 ++++----
 .github/workflows/build_wheels_linux_arm.yml |  8 +++---
 .github/workflows/build_wheels_macos.yml     | 30 +++++++++++---------
 .github/workflows/build_wheels_macos_m1.yml  |  2 +-
 .github/workflows/build_wheels_windows.yml   |  2 +-
 docker/manylinux2014/Dockerfile_aarch64      | 10 +++----
 docker/manylinux2014/Dockerfile_i686         | 10 +++----
 docker/manylinux2014/Dockerfile_x86_64       | 10 +++----
 multibuild                                   |  2 +-
 pyproject.toml                               |  7 +++--
 scripts/build.sh                             |  1 -
 setup.py                                     |  8 ++++--
 travis_config.sh                             |  5 +++-
 travis_multibuild_customize.sh               |  2 +-
 14 files changed, 58 insertions(+), 51 deletions(-)

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index 526049ff..5c562d44 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -23,7 +23,7 @@ jobs:
       fail-fast: false
       matrix:
         os: [ubuntu-latest]
-        python-version: [3.6, 3.7, 3.8, 3.9]
+        python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
@@ -38,9 +38,10 @@ jobs:
       TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
       MB_ML_VER: 2014
       NP_TEST_DEP: numpy==1.19.4
+      NP_TEST_DEP_3_10: numpy==1.21.2
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
+      DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
       SDIST: ${{ matrix.build_sdist || 0 }}
@@ -63,8 +64,7 @@ jobs:
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "TRAVIS_EVENT_TYPE=cron" >> $GITHUB_ENV; else echo "TRAVIS_EVENT_TYPE=${{ github.event_name }}" >> $GITHUB_ENV; fi
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
         if [ "x64" == "${{ matrix.platform }}" ]; then echo "PLAT=x86_64" >> $GITHUB_ENV; fi
-        echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
-        echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
+        if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_3_10)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
 
     - name: build
       run: source scripts/build.sh
@@ -107,7 +107,7 @@ jobs:
       NP_TEST_DEP: numpy==1.19.4
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
+      DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
       SDIST: ${{ matrix.build_sdist || 0 }}
@@ -135,8 +135,6 @@ jobs:
       run: |
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "TRAVIS_EVENT_TYPE=cron" >> $GITHUB_ENV; else echo "TRAVIS_EVENT_TYPE=${{ github.event_name }}" >> $GITHUB_ENV; fi
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
-        echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
-        echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
 
     - name: before install
       run: |
diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index d71db231..310b3ee5 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -23,7 +23,7 @@ jobs:
       fail-fast: false
       matrix:
         os: [ARM64]
-        python-version: [3.6, 3.7, 3.8, 3.9]
+        python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
@@ -39,9 +39,10 @@ jobs:
       PLAT: aarch64
       MB_ML_VER: 2014
       NP_TEST_DEP: numpy==1.19.4
+      NP_TEST_DEP_3_10: numpy==1.21.2
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
+      DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
       DOCKER_TEST_IMAGE: multibuild/xenial_arm64v8
       USE_CCACHE: 0
       UNICODE_WIDTH: 32
@@ -63,8 +64,7 @@ jobs:
     - name: Setup Environment variables
       run: |
         if [ "ARM64" == "${{ matrix.os }}" ]; then echo "PLAT=aarch64" >> $GITHUB_ENV; fi
-        echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
-        echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
+        if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_3_10)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
 
     - name: build
       run: source scripts/build.sh
diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index 5b2b8066..aca84ae6 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -22,12 +22,23 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        os: [macos-latest]
-        python-version: [3.6, 3.7, 3.8, 3.9]
+        os: [macos-10.15, macos-11]
+        python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
         build_sdist: [0]
+        exclude:
+          - os: macos-10.15
+            python-version: '3.10'
+          - os: macos-11
+            python-version: '3.6'
+          - os: macos-11
+            python-version: '3.7'
+          - os: macos-11
+            python-version: '3.8'
+          - os: macos-11
+            python-version: '3.9'
 
     env:
       ACTIONS_ALLOW_UNSECURE_COMMANDS: true
@@ -38,9 +49,11 @@ jobs:
       TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
       MB_ML_VER: 2014
       NP_TEST_DEP: numpy==1.19.4
+      NP_TEST_DEP_3_10: numpy==1.21.2
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
+      TRAVIS_OS_NAME: osx
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/skvark/manylinux2014_${PLAT}
+      DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
       SDIST: ${{ matrix.build_sdist || 0 }}
@@ -58,22 +71,13 @@ jobs:
       if: github.event_name == 'pull_request'
       run: git submodule update --remote
 
-    - name: Set up Python ${{ matrix.python-version }}
-      uses: actions/setup-python@v2
-      if: ${{ 'macos-latest' == matrix.os }}
-      with:
-        python-version: ${{ matrix.python-version }}
-        architecture: ${{ matrix.platform }}
-
     - name: Setup Environment variables
       run: |
-        if [ "macos-latest" == "${{ matrix.os }}" ]; then echo "TRAVIS_OS_NAME=osx" >> $GITHUB_ENV; else echo "TRAVIS_OS_NAME=${{ matrix.os }}" >> $GITHUB_ENV; fi
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "TRAVIS_EVENT_TYPE=cron" >> $GITHUB_ENV; else echo "TRAVIS_EVENT_TYPE=${{ github.event_name }}" >> $GITHUB_ENV; fi
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
         if [ "x64" == "${{ matrix.platform }}" ]; then echo "PLAT=x86_64" >> $GITHUB_ENV; fi
         if [ "x86" == "${{ matrix.platform }}" ]; then echo "PLAT=i686" >> $GITHUB_ENV; fi
-        echo "BUILD_DEPENDS=$(echo $NP_BUILD_DEP)" >> $GITHUB_ENV;
-        echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV;
+        if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_3_10)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
 
     - name: before install
       run: |
diff --git a/.github/workflows/build_wheels_macos_m1.yml b/.github/workflows/build_wheels_macos_m1.yml
index 2c855874..79164dcf 100644
--- a/.github/workflows/build_wheels_macos_m1.yml
+++ b/.github/workflows/build_wheels_macos_m1.yml
@@ -20,7 +20,7 @@ jobs:
       fail-fast: false
       matrix:
         os: [macOS-M1]
-        python-version: [3.7, 3.8, 3.9]
+        python-version: ['3.7', '3.8', '3.9', '3.10']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index 554f684c..3eb13086 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -22,7 +22,7 @@ jobs:
       fail-fast: false
       matrix:
         os: [windows-latest]
-        python-version: [3.6, 3.7, 3.8, 3.9]
+        python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
         platform: [x86, x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
index e8920770..c76ccec4 100644
--- a/docker/manylinux2014/Dockerfile_aarch64
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -28,8 +28,8 @@ RUN mkdir ~/ffmpeg_sources && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.14.01/nasm-2.14.01.tar.bz2 && \
-    tar -xf nasm-2.14.01.tar.bz2 && cd nasm-2.14.01 && ./autogen.sh && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.15.04/nasm-2.15.04.tar.bz2 && \
+    tar -xf nasm-2.15.04.tar.bz2 && cd nasm-2.15.04 && ./autogen.sh && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
@@ -50,9 +50,9 @@ RUN cd ~/ffmpeg_sources && \
     make install
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
-    tar -xf ffmpeg-snapshot.tar.bz2 && \
-    cd ffmpeg && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-4.3.2.tar.bz2 && \
+    tar -xf ffmpeg-4.3.2.tar.bz2 && \
+    cd ffmpeg-4.3.2 && \
     PATH=~/bin:$PATH && \
     PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index 39fc1560..6a60a073 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -30,8 +30,8 @@ RUN mkdir ~/ffmpeg_sources && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.14.01/nasm-2.14.01.tar.bz2 && \
-    tar -xf nasm-2.14.01.tar.bz2 && cd nasm-2.14.01 && ./autogen.sh && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.15.04/nasm-2.15.04.tar.bz2 && \
+    tar -xf nasm-2.15.04.tar.bz2 && cd nasm-2.15.04 && ./autogen.sh && \
     linux32 ./configure && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
@@ -52,9 +52,9 @@ RUN cd ~/ffmpeg_sources && \
     make install
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
-    tar -xf ffmpeg-snapshot.tar.bz2 && \
-    cd ffmpeg && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-4.3.2.tar.bz2 && \
+    tar -xf ffmpeg-4.3.2.tar.bz2 && \
+    cd ffmpeg-4.3.2 && \
     PATH=~/bin:$PATH && \
     PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" linux32 ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index 010120ca..49622378 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -28,8 +28,8 @@ RUN mkdir ~/ffmpeg_sources && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.14.01/nasm-2.14.01.tar.bz2 && \
-    tar -xf nasm-2.14.01.tar.bz2 && cd nasm-2.14.01 && ./autogen.sh && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.15.04/nasm-2.15.04.tar.bz2 && \
+    tar -xf nasm-2.15.04.tar.bz2 && cd nasm-2.15.04 && ./autogen.sh && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
@@ -50,9 +50,9 @@ RUN cd ~/ffmpeg_sources && \
     make install
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
-    tar -xf ffmpeg-snapshot.tar.bz2 && \
-    cd ffmpeg && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-4.3.2.tar.bz2 && \
+    tar -xf ffmpeg-4.3.2.tar.bz2 && \
+    cd ffmpeg-4.3.2 && \
     PATH=~/bin:$PATH && \
     PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
diff --git a/multibuild b/multibuild
index 8882150d..b89bb903 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit 8882150df6529658700b66bec124dfb77eefca26
+Subproject commit b89bb903e94308be79abefa4f436bf123ebb1313
diff --git a/pyproject.toml b/pyproject.toml
index 5a2849f3..ec63b351 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -2,9 +2,10 @@
 requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
   "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
-  "numpy==1.19.3; python_version>='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
-  "numpy==1.21.0; python_version>='3.6' and sys_platform == 'darwin' and platform_machine == 'arm64'",
+  "numpy==1.21.2; python_version>='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
+  "numpy==1.21.2; python_version>='3.6' and sys_platform == 'darwin' and platform_machine == 'arm64'",
   "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
   "numpy==1.17.3; python_version=='3.8' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
-  "numpy==1.19.3; python_version>='3.9' and platform_machine != 'aarch64' and platform_machine != 'arm64'"
+  "numpy==1.21.2; python_version>='3.9' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
+  "numpy==1.21.2; python_version>='3.10' and platform_machine != 'aarch64' and platform_machine != 'arm64'"
 ]
diff --git a/scripts/build.sh b/scripts/build.sh
index aa9ff968..f48ca066 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -15,4 +15,3 @@ echo $ENABLE_CONTRIB > contrib.enabled
 echo $ENABLE_HEADLESS > headless.enabled
 set -x
 build_wheel $REPO_DIR $PLAT
-rm wheelhouse/numpy*
diff --git a/setup.py b/setup.py
index 22b6561d..f4e0a100 100644
--- a/setup.py
+++ b/setup.py
@@ -29,15 +29,17 @@ def main():
     if sys.version_info[:2] >= (3, 8):
         minimum_supported_numpy = "1.17.3"
     if sys.version_info[:2] >= (3, 9):
-        minimum_supported_numpy = "1.19.3"
+        minimum_supported_numpy = "1.21.2"
+    if sys.version_info[:2] >= (3, 10):
+        minimum_supported_numpy = "1.21.2"
 
     # linux arm64 is a special case
     if sys.platform.startswith("linux") and sys.version_info[:2] >= (3, 6) and platform.machine() == "aarch64":
-        minimum_supported_numpy = "1.19.3"
+        minimum_supported_numpy = "1.21.2"
 
     # macos arm64 is a special case
     if sys.platform == "darwin" and sys.version_info[:2] >= (3, 6) and platform.machine() == "arm64":
-        minimum_supported_numpy = "1.21.0"
+        minimum_supported_numpy = "1.21.2"
 
     numpy_version = "numpy>=%s" % minimum_supported_numpy
 
diff --git a/travis_config.sh b/travis_config.sh
index a387966c..937e5a2d 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -20,7 +20,10 @@ function bdist_wheel_cmd {
       TOOLS_PATH=/opt/_internal/tools
       /opt/python/cp37-cp37m/bin/python -m venv $TOOLS_PATH
       source $TOOLS_PATH/bin/activate
-      python patch_auditwheel_whitelist.py
+      python$PYTHON_VERSION -m pip install auditwheel==3.2.0
+      python$PYTHON_VERSION patch_auditwheel_whitelist.py
+      # to avoid issues with numpy wheels
+      rm /io/wheelhouse/numpy*
       deactivate
     fi
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
diff --git a/travis_multibuild_customize.sh b/travis_multibuild_customize.sh
index 5a9451be..178fd6ec 100644
--- a/travis_multibuild_customize.sh
+++ b/travis_multibuild_customize.sh
@@ -3,4 +3,4 @@
 export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
 set -x
 REPO_DIR=$(dirname "${BASH_SOURCE[0]}")
-DOCKER_IMAGE='quay.io/skvark/manylinux2014_$plat'
+DOCKER_IMAGE='quay.io/asenyaev/manylinux2014_$plat'

From 0114953aaeafb56ef3b9584555bb1119583468f0 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Fri, 8 Oct 2021 12:19:31 +0300
Subject: [PATCH 516/566] Fixed the version of numpy for linux aarch64 and
 python3.6

---
 pyproject.toml | 3 ++-
 setup.py       | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index ec63b351..7e887c41 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -2,8 +2,9 @@
 requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
   "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
-  "numpy==1.21.2; python_version>='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
+  "numpy==1.19.3; python_version=='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
   "numpy==1.21.2; python_version>='3.6' and sys_platform == 'darwin' and platform_machine == 'arm64'",
+  "numpy==1.21.2; python_version>='3.7' and sys_platform == 'linux' and platform_machine == 'aarch64'",
   "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
   "numpy==1.17.3; python_version=='3.8' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
   "numpy==1.21.2; python_version>='3.9' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
diff --git a/setup.py b/setup.py
index f4e0a100..7c3f610c 100644
--- a/setup.py
+++ b/setup.py
@@ -35,7 +35,7 @@ def main():
 
     # linux arm64 is a special case
     if sys.platform.startswith("linux") and sys.version_info[:2] >= (3, 6) and platform.machine() == "aarch64":
-        minimum_supported_numpy = "1.21.2"
+        minimum_supported_numpy = "1.19.3"
 
     # macos arm64 is a special case
     if sys.platform == "darwin" and sys.version_info[:2] >= (3, 6) and platform.machine() == "arm64":

From 9f43c0b2fd3c7ee745d11982ebabf65ad41f013a Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Fri, 8 Oct 2021 17:38:57 +0300
Subject: [PATCH 517/566] Changed the image for tests on linux arm

---
 .github/workflows/build_wheels_linux_arm.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index 310b3ee5..c2982e50 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -43,7 +43,7 @@ jobs:
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
       DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
-      DOCKER_TEST_IMAGE: multibuild/xenial_arm64v8
+      DOCKER_TEST_IMAGE: multibuild/focal_arm64v8
       USE_CCACHE: 0
       UNICODE_WIDTH: 32
       SDIST: ${{ matrix.build_sdist || 0 }}

From 4d0f6d2e17a8ded22cfe500be19617370f038a92 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Sat, 9 Oct 2021 12:31:06 +0300
Subject: [PATCH 518/566] Fixed if condition for numpy test version on linux
 arm and renamed numpy variable

---
 .github/workflows/build_wheels_linux.yml     | 4 ++--
 .github/workflows/build_wheels_linux_arm.yml | 4 ++--
 .github/workflows/build_wheels_macos.yml     | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index 5c562d44..7ff34a18 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -38,7 +38,7 @@ jobs:
       TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
       MB_ML_VER: 2014
       NP_TEST_DEP: numpy==1.19.4
-      NP_TEST_DEP_3_10: numpy==1.21.2
+      NP_TEST_DEP_LATEST: numpy==1.21.2
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
       DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
@@ -64,7 +64,7 @@ jobs:
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "TRAVIS_EVENT_TYPE=cron" >> $GITHUB_ENV; else echo "TRAVIS_EVENT_TYPE=${{ github.event_name }}" >> $GITHUB_ENV; fi
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
         if [ "x64" == "${{ matrix.platform }}" ]; then echo "PLAT=x86_64" >> $GITHUB_ENV; fi
-        if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_3_10)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
+        if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
 
     - name: build
       run: source scripts/build.sh
diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index c2982e50..8108c85f 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -39,7 +39,7 @@ jobs:
       PLAT: aarch64
       MB_ML_VER: 2014
       NP_TEST_DEP: numpy==1.19.4
-      NP_TEST_DEP_3_10: numpy==1.21.2
+      NP_TEST_DEP_LATEST: numpy==1.21.2
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
       DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
@@ -64,7 +64,7 @@ jobs:
     - name: Setup Environment variables
       run: |
         if [ "ARM64" == "${{ matrix.os }}" ]; then echo "PLAT=aarch64" >> $GITHUB_ENV; fi
-        if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_3_10)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
+        if [ "3.6" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; fi
 
     - name: build
       run: source scripts/build.sh
diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index aca84ae6..d4f10be0 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -49,7 +49,7 @@ jobs:
       TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
       MB_ML_VER: 2014
       NP_TEST_DEP: numpy==1.19.4
-      NP_TEST_DEP_3_10: numpy==1.21.2
+      NP_TEST_DEP_LATEST: numpy==1.21.2
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       TRAVIS_OS_NAME: osx
       CONFIG_PATH: travis_config.sh
@@ -77,7 +77,7 @@ jobs:
         if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
         if [ "x64" == "${{ matrix.platform }}" ]; then echo "PLAT=x86_64" >> $GITHUB_ENV; fi
         if [ "x86" == "${{ matrix.platform }}" ]; then echo "PLAT=i686" >> $GITHUB_ENV; fi
-        if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_3_10)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
+        if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
 
     - name: before install
       run: |

From fdcbcb11ade547f1dde9116ddb5af925616be32c Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Sun, 10 Oct 2021 01:36:19 +0300
Subject: [PATCH 519/566] Added lowest numpy version support instead of latest

---
 .github/workflows/build_wheels_linux_arm.yml | 2 +-
 pyproject.toml                               | 9 ++++-----
 setup.py                                     | 4 ++--
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index 8108c85f..89142a57 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -64,7 +64,7 @@ jobs:
     - name: Setup Environment variables
       run: |
         if [ "ARM64" == "${{ matrix.os }}" ]; then echo "PLAT=aarch64" >> $GITHUB_ENV; fi
-        if [ "3.6" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; fi
+        if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
 
     - name: build
       run: source scripts/build.sh
diff --git a/pyproject.toml b/pyproject.toml
index 7e887c41..6aaab1d3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -2,11 +2,10 @@
 requires = [
   "setuptools", "wheel", "scikit-build", "cmake", "pip",
   "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
-  "numpy==1.19.3; python_version=='3.6' and sys_platform == 'linux' and platform_machine == 'aarch64'",
-  "numpy==1.21.2; python_version>='3.6' and sys_platform == 'darwin' and platform_machine == 'arm64'",
-  "numpy==1.21.2; python_version>='3.7' and sys_platform == 'linux' and platform_machine == 'aarch64'",
   "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
   "numpy==1.17.3; python_version=='3.8' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
-  "numpy==1.21.2; python_version>='3.9' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
-  "numpy==1.21.2; python_version>='3.10' and platform_machine != 'aarch64' and platform_machine != 'arm64'"
+  "numpy==1.19.3; python_version<='3.9' and sys_platform == 'linux' and platform_machine == 'aarch64'",
+  "numpy==1.21.0; python_version<='3.9' and sys_platform == 'darwin' and platform_machine == 'arm64'",
+  "numpy==1.19.3; python_version=='3.9' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
+  "numpy==1.21.2; python_version>='3.10'"
 ]
diff --git a/setup.py b/setup.py
index 7c3f610c..b5ba5bf0 100644
--- a/setup.py
+++ b/setup.py
@@ -29,7 +29,7 @@ def main():
     if sys.version_info[:2] >= (3, 8):
         minimum_supported_numpy = "1.17.3"
     if sys.version_info[:2] >= (3, 9):
-        minimum_supported_numpy = "1.21.2"
+        minimum_supported_numpy = "1.19.3"
     if sys.version_info[:2] >= (3, 10):
         minimum_supported_numpy = "1.21.2"
 
@@ -39,7 +39,7 @@ def main():
 
     # macos arm64 is a special case
     if sys.platform == "darwin" and sys.version_info[:2] >= (3, 6) and platform.machine() == "arm64":
-        minimum_supported_numpy = "1.21.2"
+        minimum_supported_numpy = "1.21.0"
 
     numpy_version = "numpy>=%s" % minimum_supported_numpy
 

From 51226a7f2e32805f7728793b7ae2704d41b6ab9d Mon Sep 17 00:00:00 2001
From: Christian Clauss <cclauss@me.com>
Date: Mon, 11 Oct 2021 07:36:20 +0200
Subject: [PATCH 520/566] Travis CI seems to be on vacation

https://travis-ci.org/github/opencv
---
 .travis.yml | 410 ----------------------------------------------------
 1 file changed, 410 deletions(-)
 delete mode 100644 .travis.yml

diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 6ba06d4c..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,410 +0,0 @@
-env:
-    global:
-        - "PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'"
-        # pip dependencies to _test_ your project
-        - TEST_DEPENDS="numpy==1.11.1"
-        # params to bdist_wheel. used to set osx build target.
-        - CONFIG_PATH="travis_config.sh"
-        - USE_CCACHE=1
-        - UNICODE_WIDTH=32
-        - SDIST=0
-
-# Save some time, we and setup check them out on demand instead
-# https://docs.travis-ci.com/user/customizing-the-build/#Git-Clone-Depth
-git:
-    submodules: false
-
-# https://docs.travis-ci.com/user/caching
-cache:
-  directories:
-    # `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
-    - $HOME/.ccache
-
-# Add more cache stages (s2 etc) and corresponding OSX jobs like s1
-# if brew builds start to take longer than one Travis time limit
-stages:
-  - final
-
-jobs:
-  fast_finish: true
-  # Travis exclude is buggy, this seems to be the only way to disable default build
-  exclude:
-    - language: ruby
-  include:
-    # default builds for Linux
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-
-    # headless builds for Linux
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=0
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-
-    # contrib builds for Linux
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=0
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-
-
-    # headless contrib builds for Linux
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.6
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.7
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.8
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-    - os: linux
-      arch: arm64
-      language: generic
-      dist: xenial
-      services: docker
-      env:
-        - MB_PYTHON_VERSION=3.9
-        - PLAT=aarch64
-        - DOCKER_TEST_IMAGE=multibuild/xenial_arm64v8
-        - ENABLE_CONTRIB=1
-        - ENABLE_HEADLESS=1
-        - TEST_DEPENDS=numpy==1.19.0
-        - USE_CCACHE=0
-      cache:
-        directories: $HOME/.ccache
-
-# The first line is printed in the folding header in Travis output
-before_install: |
-    set -e
-
-    if [[ $SDIST == 0 ]]; then
-      # Check out and prepare the source
-      # Multibuild doesn't have releases, so --depth would break eventually (see
-      # https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
-      git submodule update --init multibuild
-
-      source multibuild/common_utils.sh
-
-      # https://github.com/matthew-brett/multibuild/issues/116
-      if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
-
-      source multibuild/travis_steps.sh
-      # This sets -x
-
-      source travis_multibuild_customize.sh
-      echo $ENABLE_CONTRIB > contrib.enabled
-      echo $ENABLE_HEADLESS > headless.enabled
-
-      echo "end"
-      # Not interested in travis internal scripts' output
-    fi
-
-    set +x
-
-install: |
-    # Build and package
-    set -x
-
-    if [[ $SDIST == 1 ]]; then
-      python -m pip install --upgrade pip
-      python -m pip install scikit-build
-      python setup.py sdist
-    else
-      build_wheel $REPO_DIR $PLAT
-    fi
-
-    set +x
-
-script: |
-    # Install and run tests
-    set -x
-    if [[ $SDIST == 1 ]]; then
-      echo "skipping tests because of sdist"
-    else
-      install_run $PLAT && rc=$? || rc=$?
-    fi
-
-    set +x
-
-    #otherwise, Travis logic terminates prematurely
-    #https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
-    trap ERR
-    test "$rc" -eq 0
-
-after_success: |
-    # Upload wheels to pypi if tag is set
-
-    set -x
-
-    if [ -n "$TRAVIS_TAG" ]; then
-
-      if [[ $ENABLE_CONTRIB == 0 ]]; then
-        if [[ $ENABLE_HEADLESS == 0 ]]; then
-          echo "This is default build. Deployment will be done to to PyPI entry opencv-python."
-        else
-          echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-python-headless."
-        fi
-      else
-        if [[ $ENABLE_HEADLESS == 0 ]]; then
-          echo "This is contrib build. Deployment will be done to to PyPI entry opencv-contrib-python."
-        else
-          echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-contrib-python-headless."
-        fi
-      fi
-
-      if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-        if [[ $SDIST == 1 ]]; then
-          pip install twine
-          twine upload -u ${PYPI_USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
-        else
-          pip install --user twine
-          pip install --user --upgrade six
-          twine upload -u ${PYPI_USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
-        fi
-
-      fi
-
-      if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
-        # macpython 3.5 doesn't support recent TLS protocols which causes twine
-        # upload to fail, so we use the system Python to run twine
-        /usr/bin/python -m ensurepip --user
-        /usr/bin/python -m pip install --user -U pip
-        /usr/bin/python -m pip install --user -U -I twine
-
-        if [[ $SDIST == 1 ]]; then
-          /usr/bin/python -m twine upload -u ${PYPI_USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist/opencv*
-        else
-          /usr/bin/python -m twine upload -u ${PYPI_USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
-        fi
-
-      fi
-
-    fi
-
-    # # Save to Azure storage always
-
-    # if [[ $TRAVIS_CPU_ARCH != "arm64" ]]; then
-    #   if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-    #     curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
-    #   else
-    #     brew install azure-cli
-    #   fi
-
-    #   az storage container create -n ${TRAVIS_COMMIT} --public-access blob
-
-    #   if [[ $SDIST == 1 ]]; then
-    #     az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/dist --pattern *.gz
-    #   else
-    #     az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern opencv*.whl
-    #   fi
-    # fi
-
-    set +x
-

From 5c81cdaff33ac21022650cebf0b12bb974d555ca Mon Sep 17 00:00:00 2001
From: "Andrei V. Konstantinov" <andrue.konst@gmail.com>
Date: Wed, 13 Oct 2021 16:45:45 +0300
Subject: [PATCH 521/566] Fix typo in Readme

Fixes a typo in Readme
---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index bb43bb99..d2831332 100644
--- a/README.md
+++ b/README.md
@@ -65,7 +65,7 @@ If you still encounter the error after you have checked all the previous solutio
 
 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 interpriter. What should I do?**
+**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](https://github.com/opencv/opencv/wiki) and [the official OpenCV forum](https://forum.opencv.org/) before file new bugs.
 

From 6a1f61b8d7e413059dbf0b9e897579c8305c327f Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Fri, 15 Oct 2021 19:35:51 +0300
Subject: [PATCH 522/566] Updated submodules to the release 4.5.4, added python
 loader support, updated Qt patch

---
 cv2/__init__.py        | 31 -------------------------------
 opencv                 |  2 +-
 opencv_contrib         |  2 +-
 opencv_extra           |  2 +-
 patches/patchQtPlugins | 19 +++++++++++++------
 scripts/__init__.py    | 23 +++++++++++++++++++++++
 setup.py               | 42 ++++++++++++++++++++++++++++++++++++++----
 7 files changed, 77 insertions(+), 44 deletions(-)
 create mode 100644 scripts/__init__.py

diff --git a/cv2/__init__.py b/cv2/__init__.py
index 0c080d52..e69de29b 100644
--- a/cv2/__init__.py
+++ b/cv2/__init__.py
@@ -1,31 +0,0 @@
-import importlib
-import os
-import sys
-
-from .cv2 import *
-from .data import *
-
-# wildcard import above does not import "private" variables like __version__
-# this makes them available
-globals().update(importlib.import_module("cv2.cv2").__dict__)
-
-ci_and_not_headless = False
-
-try:
-    from .version import ci_build, headless
-
-    ci_and_not_headless = ci_build and not headless
-except:
-    pass
-
-# the Qt plugin is included currently only in the pre-built wheels
-if sys.platform.startswith("linux") and ci_and_not_headless:
-    os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.path.join(
-        os.path.dirname(os.path.abspath(__file__)), "qt", "plugins"
-    )
-
-# Qt will throw warning on Linux if fonts are not found
-if sys.platform.startswith("linux") and ci_and_not_headless:
-    os.environ["QT_QPA_FONTDIR"] = os.path.join(
-        os.path.dirname(os.path.abspath(__file__)), "qt", "fonts"
-    )
diff --git a/opencv b/opencv
index ad6e8294..39c33341 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit ad6e82942b37be8ee2c71c1d9bc7fe79cd16f7ab
+Subproject commit 39c3334147ec02761b117f180c9c4518be18d1fa
diff --git a/opencv_contrib b/opencv_contrib
index d5317d62..2bc3e1a1 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit d5317d6297a8129b66dba1a1f7cc784e94639da9
+Subproject commit 2bc3e1a169afd2675ef68221176f32cc0ea5427a
diff --git a/opencv_extra b/opencv_extra
index d5c7212d..822ee112 160000
--- a/opencv_extra
+++ b/opencv_extra
@@ -1 +1 @@
-Subproject commit d5c7212d53f097c9fdf5e72c598ad051660599e8
+Subproject commit 822ee11240b969e98e20546663bc481a5e7089cc
diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index 03560f17..a05a5f83 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -3,9 +3,8 @@ index 4c0b3880fc..dffa0a4caa 100644
 --- a/opencv/CMakeLists.txt
 +++ b/opencv/CMakeLists.txt
 @@ -1187,6 +1187,13 @@ if(WITH_QT OR HAVE_QT)
-   if(HAVE_QT5)
-     status("    QT:" "YES (ver ${Qt5Core_VERSION_STRING})")
-     status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt5OpenGL_LIBRARIES} ${Qt5OpenGL_VERSION_STRING})" ELSE NO)
+   if(HAVE_QT)
+     status("    QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
 +    if(APPLE)
 +      install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
 +    endif()
@@ -13,6 +12,14 @@ index 4c0b3880fc..dffa0a4caa 100644
 +      install(DIRECTORY /opt/Qt5.15.0/plugins DESTINATION lib/qt)
 +      install(DIRECTORY /usr/share/fonts DESTINATION lib/qt)
 +    endif()
-   elseif(HAVE_QT)
-     status("    QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
-     status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)
+     if(HAVE_QT_OPENGL)
+       if(Qt${QT_VERSION_MAJOR}OpenGL_LIBRARIES)
+         status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt${QT_VERSION_MAJOR}OpenGL_LIBRARIES} ${Qt${QT_VERSION_MAJOR}OpenGL_VERSION_STRING})" ELSE NO)
+       else()
+         status("      QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)
+       endif()
+     else()
+       status("      QT OpenGL support:" "NO")
+     endif()
+   else()
+     status("    QT:" "NO")
diff --git a/scripts/__init__.py b/scripts/__init__.py
new file mode 100644
index 00000000..af17e205
--- /dev/null
+++ b/scripts/__init__.py
@@ -0,0 +1,23 @@
+from .cv2 import *
+from .data import *
+
+ci_and_not_headless = False
+
+try:
+    from .version import ci_build, headless
+
+    ci_and_not_headless = ci_build and not headless
+except:
+    pass
+
+# the Qt plugin is included currently only in the pre-built wheels
+if sys.platform.startswith("linux") and ci_and_not_headless:
+    os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.path.join(
+        os.path.dirname(os.path.abspath(__file__)), "qt", "plugins"
+    )
+
+# Qt will throw warning on Linux if fonts are not found
+if sys.platform.startswith("linux") and ci_and_not_headless:
+    os.environ["QT_QPA_FONTDIR"] = os.path.join(
+        os.path.dirname(os.path.abspath(__file__)), "qt", "fonts"
+    )
diff --git a/setup.py b/setup.py
index b5ba5bf0..dd1659d5 100644
--- a/setup.py
+++ b/setup.py
@@ -108,12 +108,32 @@ def main():
         # Naming conventions vary so widely between versions and OSes
         # had to give up on checking them.
         [
-            "python/cv2[^/]*%(ext)s"
-            % {"ext": re.escape(sysconfig.get_config_var("EXT_SUFFIX"))}
+            "python/cv2/python-%s.%s/cv2[^/]*%s"
+            % (sys.version_info[0], sys.version_info[1], re.escape(sysconfig.get_config_var("EXT_SUFFIX")))
+        ]
+        +
+        [
+            r"python/cv2/__init__.py"
+        ]
+        +
+        [
+            r"python/cv2/.*config.*.py"
         ],
         "cv2.data": [  # OPENCV_OTHER_INSTALL_PATH
             ("etc" if os.name == "nt" else "share/opencv4") + r"/haarcascades/.*\.xml"
         ],
+        "cv2.gapi": [
+            "python/cv2" + r"/gapi/.*\.py"
+        ],
+        "cv2.mat_wrapper": [
+            "python/cv2" + r"/mat_wrapper/.*\.py"
+        ],
+        "cv2.misc": [
+            "python/cv2" + r"/misc/.*\.py"
+        ],
+        "cv2.utils": [
+            "python/cv2" + r"/utils/.*\.py"
+        ],
     }
 
     # Files in sourcetree outside package dir that should be copied to package.
@@ -137,8 +157,6 @@ def main():
             "-DBUILD_opencv_python2=OFF",
             # Disable the Java build by default as it is not needed
             "-DBUILD_opencv_java=%s" % build_java,
-            # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
-            "-DOPENCV_SKIP_PYTHON_LOADER=ON",
             # Relative dir to install the built module to in the build tree.
             # The default is generated from sysconfig, we'd rather have a constant for simplicity
             "-DOPENCV_PYTHON3_INSTALL_PATH=python",
@@ -358,6 +376,22 @@ def _classify_installed_files_override(
 
         print("Copying files from CMake output")
 
+        with open('%spython/cv2/__init__.py'
+         % cmake_install_dir, 'r') as opencv_init:
+            opencv_init_data = ""
+            for line in opencv_init:
+                opencv_init_replacement = line.replace('importlib.import_module("cv2")', 'importlib.import_module("cv2.cv2")')
+                opencv_init_data = opencv_init_data + opencv_init_replacement
+        with open('%spython/cv2/__init__.py'
+        % cmake_install_dir, 'w') as opencv_python_init:
+            opencv_python_init.write(opencv_init_data)
+
+        with open('scripts/__init__.py', 'r') as custom_init:
+            custom_init_data = custom_init.read()
+        with open('%spython/cv2/config-%s.%s.py'
+        % (cmake_install_dir, sys.version_info[0], sys.version_info[1]), 'a') as opencv_init_config:
+            opencv_init_config.write(custom_init_data)
+
         for package_name, relpaths_re in cls.package_paths_re.items():
             package_dest_reldir = package_name.replace(".", os.path.sep)
             for relpath_re in relpaths_re:

From 545fe24728bfee7e0092d0e37dbdd0371bb1c2d8 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Fri, 15 Oct 2021 20:39:09 +0300
Subject: [PATCH 523/566] Added comments for new changes

---
 setup.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/setup.py b/setup.py
index dd1659d5..7766f96d 100644
--- a/setup.py
+++ b/setup.py
@@ -376,6 +376,7 @@ def _classify_installed_files_override(
 
         print("Copying files from CMake output")
 
+        # need for the proper import of a package
         with open('%spython/cv2/__init__.py'
          % cmake_install_dir, 'r') as opencv_init:
             opencv_init_data = ""
@@ -386,6 +387,7 @@ def _classify_installed_files_override(
         % cmake_install_dir, 'w') as opencv_python_init:
             opencv_python_init.write(opencv_init_data)
 
+        # add lines from the old __init__.py file to the config file
         with open('scripts/__init__.py', 'r') as custom_init:
             custom_init_data = custom_init.read()
         with open('%spython/cv2/config-%s.%s.py'

From 7e67ab5f10ae534d3902ff6883c4b1c9a4fccc02 Mon Sep 17 00:00:00 2001
From: Christian Clauss <cclauss@me.com>
Date: Sat, 16 Oct 2021 08:09:03 +0200
Subject: [PATCH 524/566] "Programming Language :: Python :: 3.10",

---
 setup.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index b5ba5bf0..e4f2ee76 100644
--- a/setup.py
+++ b/setup.py
@@ -260,6 +260,7 @@ def main():
             "Programming Language :: Python :: 3.7",
             "Programming Language :: Python :: 3.8",
             "Programming Language :: Python :: 3.9",
+            "Programming Language :: Python :: 3.10",
             "Programming Language :: C++",
             "Programming Language :: Python :: Implementation :: CPython",
             "Topic :: Scientific/Engineering",

From 851182fbb01f1655fe5ca4da9ca24b917765758a Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Mon, 18 Oct 2021 17:38:58 +0300
Subject: [PATCH 525/566] Removed useless lines and added replacing lines into
 init file

---
 scripts/__init__.py |  5 +++--
 setup.py            | 13 +------------
 2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/scripts/__init__.py b/scripts/__init__.py
index af17e205..587a42bf 100644
--- a/scripts/__init__.py
+++ b/scripts/__init__.py
@@ -1,5 +1,6 @@
-from .cv2 import *
-from .data import *
+PYTHON_EXTENSIONS_PATHS = [
+    LOADER_DIR
+] + PYTHON_EXTENSIONS_PATHS
 
 ci_and_not_headless = False
 
diff --git a/setup.py b/setup.py
index 7766f96d..6db572e3 100644
--- a/setup.py
+++ b/setup.py
@@ -376,22 +376,11 @@ def _classify_installed_files_override(
 
         print("Copying files from CMake output")
 
-        # need for the proper import of a package
-        with open('%spython/cv2/__init__.py'
-         % cmake_install_dir, 'r') as opencv_init:
-            opencv_init_data = ""
-            for line in opencv_init:
-                opencv_init_replacement = line.replace('importlib.import_module("cv2")', 'importlib.import_module("cv2.cv2")')
-                opencv_init_data = opencv_init_data + opencv_init_replacement
-        with open('%spython/cv2/__init__.py'
-        % cmake_install_dir, 'w') as opencv_python_init:
-            opencv_python_init.write(opencv_init_data)
-
         # add lines from the old __init__.py file to the config file
         with open('scripts/__init__.py', 'r') as custom_init:
             custom_init_data = custom_init.read()
         with open('%spython/cv2/config-%s.%s.py'
-        % (cmake_install_dir, sys.version_info[0], sys.version_info[1]), 'a') as opencv_init_config:
+        % (cmake_install_dir, sys.version_info[0], sys.version_info[1]), 'w') as opencv_init_config:
             opencv_init_config.write(custom_init_data)
 
         for package_name, relpaths_re in cls.package_paths_re.items():

From 810ca4ecd3e694ed5d5506daadaec3d49bf49d93 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Mon, 1 Nov 2021 17:56:25 +0300
Subject: [PATCH 526/566] Fixed a build from the source

---
 MANIFEST.in | 1 +
 setup.py    | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/MANIFEST.in b/MANIFEST.in
index 45cb6c40..b429eae0 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -9,3 +9,4 @@ recursive-include docker *
 recursive-include opencv *
 recursive-include opencv_contrib *
 recursive-include patches *
+recursive-include scripts *.py
diff --git a/setup.py b/setup.py
index 1b1f59c7..cf95aca1 100644
--- a/setup.py
+++ b/setup.py
@@ -378,7 +378,8 @@ def _classify_installed_files_override(
         print("Copying files from CMake output")
 
         # add lines from the old __init__.py file to the config file
-        with open('scripts/__init__.py', 'r') as custom_init:
+        with open('%s/scripts/__init__.py'
+        % os.path.split(os.path.abspath(__file__))[0], 'r') as custom_init:
             custom_init_data = custom_init.read()
         with open('%spython/cv2/config-%s.%s.py'
         % (cmake_install_dir, sys.version_info[0], sys.version_info[1]), 'w') as opencv_init_config:

From 28eb5bfd48c47f01d582d7a57382dc1095030046 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Mon, 1 Nov 2021 18:06:10 +0300
Subject: [PATCH 527/566] Updated attached commit for opencv repository

---
 opencv | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/opencv b/opencv
index 39c33341..4223495e 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 39c3334147ec02761b117f180c9c4518be18d1fa
+Subproject commit 4223495e6cd67011f86b8ecd9be1fa105018f3b1

From 012f556411f9d63df169966b8e37e1065f6d5bc9 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Mon, 1 Nov 2021 18:07:48 +0300
Subject: [PATCH 528/566] Added 3.10 python version in the description

---
 README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.md b/README.md
index d2831332..bade5faf 100644
--- a/README.md
+++ b/README.md
@@ -220,6 +220,7 @@ Python 3.x compatible pre-built wheels are provided for the officially supported
 - 3.7
 - 3.8
 - 3.9
+- 3.10
 
 ### Backward compatibility
 

From a25a2a8e5847335f269949797cc9aa9fb68ad256 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Wed, 3 Nov 2021 17:24:14 +0300
Subject: [PATCH 529/566] Added lines for a proper work using pylint and an
 autocomplete in IDE

---
 setup.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/setup.py b/setup.py
index 1b1f59c7..a53d9911 100644
--- a/setup.py
+++ b/setup.py
@@ -377,6 +377,22 @@ def _classify_installed_files_override(
 
         print("Copying files from CMake output")
 
+        # lines for a proper work using pylint and an autocomplete in IDE
+        with open("%spython/cv2/__init__.py"
+        % cmake_install_dir, 'r') as opencv_init:
+            opencv_init_lines = opencv_init.readlines()
+            extra_imports = 'from .cv2 import *\nglobals().update(importlib.import_module("cv2.cv2").__dict__)'
+            free_line_after_imports = 6
+            opencv_init_lines.insert(free_line_after_imports, extra_imports)
+            opencv_init_data = ""
+            for line in opencv_init_lines:
+                opencv_init_replacement = line.replace('importlib.import_module("cv2")', 'importlib.import_module("cv2.cv2")')
+                opencv_init_data = opencv_init_data + opencv_init_replacement
+
+        with open("%spython/cv2/__init__.py"
+        % cmake_install_dir, 'w') as opencv_final_init:
+            opencv_final_init.write(opencv_init_data)
+
         # add lines from the old __init__.py file to the config file
         with open('scripts/__init__.py', 'r') as custom_init:
             custom_init_data = custom_init.read()

From e7ce0519e3a2241719342bac65d9693e7b4c9e1d Mon Sep 17 00:00:00 2001
From: John Reese <jreese@fb.com>
Date: Wed, 3 Nov 2021 14:47:59 -0700
Subject: [PATCH 530/566] Use PEP-508 compliant dependency specifiers

This allows correctly resolving the numpy version requirement via PyPI metadata, using the same metadata regardless of what version of Python the package was built with or which wheel is uploaded to PyPI first.
---
 setup.py | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/setup.py b/setup.py
index 1b1f59c7..347cb5ba 100644
--- a/setup.py
+++ b/setup.py
@@ -22,26 +22,15 @@ def main():
     build_headless = get_build_env_var_by_name("headless")
     build_java = "ON" if get_build_env_var_by_name("java") else "OFF"
 
-    if sys.version_info[:2] >= (3, 6):
-        minimum_supported_numpy = "1.13.3"
-    if sys.version_info[:2] >= (3, 7):
-        minimum_supported_numpy = "1.14.5"
-    if sys.version_info[:2] >= (3, 8):
-        minimum_supported_numpy = "1.17.3"
-    if sys.version_info[:2] >= (3, 9):
-        minimum_supported_numpy = "1.19.3"
-    if sys.version_info[:2] >= (3, 10):
-        minimum_supported_numpy = "1.21.2"
-
-    # linux arm64 is a special case
-    if sys.platform.startswith("linux") and sys.version_info[:2] >= (3, 6) and platform.machine() == "aarch64":
-        minimum_supported_numpy = "1.19.3"
-
-    # macos arm64 is a special case
-    if sys.platform == "darwin" and sys.version_info[:2] >= (3, 6) and platform.machine() == "arm64":
-        minimum_supported_numpy = "1.21.0"
-
-    numpy_version = "numpy>=%s" % minimum_supported_numpy
+    install_requires = [
+        'numpy>=1.13.3; python_version<"3.7"',
+        'numpy>=1.14.5; python_version>="3.7"',
+        'numpy>=1.17.3; python_version>="3.8"',
+        'numpy>=1.19.3; python_version>="3.9"',
+        'numpy>=1.21.2; python_version>="3.10"',
+        'numpy>=1.19.3; python_version>="3.6" and platform_system=="Linux" and platform_machine=="aarch64"',
+        'numpy>=1.21.2; python_version>="3.6" and platform_system=="Darwin" and platform_machine=="arm64"',
+    ]
 
     python_version = cmaker.CMaker.get_python_version()
     python_lib_path = cmaker.CMaker.get_python_library(python_version).replace(
@@ -257,7 +246,7 @@ def main():
         package_data=package_data,
         maintainer="Olli-Pekka Heinisuo",
         ext_modules=EmptyListWithLength(),
-        install_requires=numpy_version,
+        install_requires=install_requires,
         python_requires=">=3.6",
         classifiers=[
             "Development Status :: 5 - Production/Stable",

From f46eabba1258834cabe2df669fbc56e7ceaa16fd Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Mon, 8 Nov 2021 02:36:06 +0300
Subject: [PATCH 531/566] Moving to auditwheel==5.0.0 (default in the latest
 manylinux image)

---
 patch_auditwheel_whitelist.py | 7 +++----
 travis_config.sh              | 8 ++++----
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/patch_auditwheel_whitelist.py b/patch_auditwheel_whitelist.py
index d0cbf5b2..b32da17a 100644
--- a/patch_auditwheel_whitelist.py
+++ b/patch_auditwheel_whitelist.py
@@ -5,12 +5,11 @@
 
 policies = None
 
-with open(join(dirname(abspath(policy.__file__)), "policy.json")) as f:
+with open(join(dirname(abspath(policy.__file__)), "manylinux-policy.json")) as f:
     policies = json.load(f)
 
 for p in policies:
-    if p["name"] == "manylinux2014":
-        p["lib_whitelist"].append("libxcb.so.1")
+    p["lib_whitelist"].append("libxcb.so.1")
 
-with open(join(dirname(abspath(policy.__file__)), "policy.json"), "w") as f:
+with open(join(dirname(abspath(policy.__file__)), "manylinux-policy.json"), "w") as f:
     f.write(json.dumps(policies))
diff --git a/travis_config.sh b/travis_config.sh
index 937e5a2d..2eb81faa 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -17,11 +17,11 @@ function bdist_wheel_cmd {
     CI_BUILD=1 pip wheel --verbose --wheel-dir="$PWD/dist" . $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
     if [ -z "$IS_OSX" ]; then
-      TOOLS_PATH=/opt/_internal/tools
-      /opt/python/cp37-cp37m/bin/python -m venv $TOOLS_PATH
+      # this path can be changed in the latest manylinux image
+      TOOLS_PATH=/opt/_internal/pipx/venvs/auditwheel
+      /opt/python/cp39-cp39/bin/python -m venv $TOOLS_PATH
       source $TOOLS_PATH/bin/activate
-      python$PYTHON_VERSION -m pip install auditwheel==3.2.0
-      python$PYTHON_VERSION patch_auditwheel_whitelist.py
+      python patch_auditwheel_whitelist.py
       # to avoid issues with numpy wheels
       rm /io/wheelhouse/numpy*
       deactivate

From 2188a44884bdc232bac9f87109158a0b94928389 Mon Sep 17 00:00:00 2001
From: "Kian-Meng, Ang" <kianmeng@cpan.org>
Date: Mon, 8 Nov 2021 09:57:24 +0800
Subject: [PATCH 532/566] Fix typos

---
 LICENSE-3RD-PARTY.txt    | 6 +++---
 README.md                | 2 +-
 travis_config.sh         | 2 +-
 travis_osx_brew_cache.sh | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt
index 20f4fb37..caeffe51 100644
--- a/LICENSE-3RD-PARTY.txt
+++ b/LICENSE-3RD-PARTY.txt
@@ -1000,7 +1000,7 @@ This license applies to above binaries in the directory cv2/.
  * The implementation was written so as to conform with Netscapes SSL.
  *
  * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
+ * the following conditions are adhered to.  The following conditions
  * apply to all code found in this distribution, be it the RC4, RSA,
  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
  * included with this distribution is covered by the same copyright terms
@@ -1025,7 +1025,7 @@ This license applies to above binaries in the directory cv2/.
  *    must display the following acknowledgement:
  *    "This product includes cryptographic software written by
  *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
+ *    The word 'cryptographic' can be left out if the routines from the library
  *    being used are not cryptographic related :-).
  * 4. If you include any Windows specific code (or a derivative thereof) from
  *    the apps directory (application code) you must include an acknowledgement:
@@ -1043,7 +1043,7 @@ This license applies to above binaries in the directory cv2/.
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * The licence and distribution terms for any publically available version or
+ * The licence and distribution terms for any publicly available version or
  * derivative of this code cannot be changed.  i.e. this code cannot simply be
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
diff --git a/README.md b/README.md
index d2831332..6844bd9f 100644
--- a/README.md
+++ b/README.md
@@ -79,7 +79,7 @@ A: It's easier for users to understand ``opencv-python`` than ``cv2`` and it mak
 
 ## Documentation for opencv-python
 
-[![Windows Buld Status](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_windows.yml/badge.svg)](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_windows.yml)
+[![Windows Build Status](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_windows.yml/badge.svg)](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_windows.yml)
 [![(Linux Build status)](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_linux.yml/badge.svg)](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_linux.yml)
 [![(Mac OS Build status)](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_macos.yml/badge.svg)](https://github.com/opencv/opencv-python/actions/workflows/build_wheels_macos.yml)
 
diff --git a/travis_config.sh b/travis_config.sh
index 937e5a2d..75a22d26 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -12,7 +12,7 @@ function build_wheel {
 
 function bdist_wheel_cmd {
     # copied from multibuild's common_utils.sh
-    # add osx deployment target so it doesnt default to 10.6
+    # add osx deployment target so it doesn't default to 10.6
     local abs_wheelhouse=$1
     CI_BUILD=1 pip wheel --verbose --wheel-dir="$PWD/dist" . $BDIST_PARAMS
     cp dist/*.whl $abs_wheelhouse
diff --git a/travis_osx_brew_cache.sh b/travis_osx_brew_cache.sh
index 401265f2..1a2a1c6c 100644
--- a/travis_osx_brew_cache.sh
+++ b/travis_osx_brew_cache.sh
@@ -249,7 +249,7 @@ function _brew_install_and_cache_within_time_limit {
     for dep in $DEPS; do
         #TIME_LIMIT only has to be met if we'll be actually building the main project this iteration, i.e. after the "root" module installation
         #While we don't know that yet, we can make better use of Travis-given time with a laxer limit
-        #We still can't overrun TIME_HARD_LIMIT as that would't leave time to save the cache
+        #We still can't overrun TIME_HARD_LIMIT as that wouldn't leave time to save the cache
         _brew_install_and_cache_within_time_limit "$dep" $(((TIME_LIMIT+TIME_HARD_LIMIT)/2)) "$TIME_HARD_LIMIT" "$TIME_START" || return $?
     done
 

From 9a7af2aa4090d40a981cf91ef2b3c4c363e356de Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Mon, 8 Nov 2021 15:38:20 +0300
Subject: [PATCH 533/566] Changed defining path to scripts/__init__.py file

---
 setup.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index cf95aca1..87632fe9 100644
--- a/setup.py
+++ b/setup.py
@@ -378,8 +378,7 @@ def _classify_installed_files_override(
         print("Copying files from CMake output")
 
         # add lines from the old __init__.py file to the config file
-        with open('%s/scripts/__init__.py'
-        % os.path.split(os.path.abspath(__file__))[0], 'r') as custom_init:
+        with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'scripts', '__init__.py'), 'r') as custom_init:
             custom_init_data = custom_init.read()
         with open('%spython/cv2/config-%s.%s.py'
         % (cmake_install_dir, sys.version_info[0], sys.version_info[1]), 'w') as opencv_init_config:

From b6e1ec80d8a362ea967b52ad5d64b635f63b43cf Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@xperience.ai>
Date: Tue, 9 Nov 2021 18:17:51 +0300
Subject: [PATCH 534/566] Fixed imports for a proper package work

---
 setup.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index a53d9911..27e61933 100644
--- a/setup.py
+++ b/setup.py
@@ -381,7 +381,8 @@ def _classify_installed_files_override(
         with open("%spython/cv2/__init__.py"
         % cmake_install_dir, 'r') as opencv_init:
             opencv_init_lines = opencv_init.readlines()
-            extra_imports = 'from .cv2 import *\nglobals().update(importlib.import_module("cv2.cv2").__dict__)'
+            extra_imports = ('\nfrom .cv2 import *\nfrom .cv2 import _registerMatType\nfrom . import mat_wrapper\nfrom . import gapi'
+                             '\nfrom . import misc\nfrom . import utils\nfrom . import data\n')
             free_line_after_imports = 6
             opencv_init_lines.insert(free_line_after_imports, extra_imports)
             opencv_init_data = ""

From 8cb031a47fe8a9a9072723140f0c3ab2858ac751 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Fri, 12 Nov 2021 17:37:03 +0300
Subject: [PATCH 535/566] Changed a string substitution to os.path.join

---
 setup.py | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/setup.py b/setup.py
index 27e61933..2fe7fc21 100644
--- a/setup.py
+++ b/setup.py
@@ -378,8 +378,7 @@ def _classify_installed_files_override(
         print("Copying files from CMake output")
 
         # lines for a proper work using pylint and an autocomplete in IDE
-        with open("%spython/cv2/__init__.py"
-        % cmake_install_dir, 'r') as opencv_init:
+        with open(os.path.join(cmake_install_dir, "python", "cv2", "__init__.py"), 'r') as opencv_init:
             opencv_init_lines = opencv_init.readlines()
             extra_imports = ('\nfrom .cv2 import *\nfrom .cv2 import _registerMatType\nfrom . import mat_wrapper\nfrom . import gapi'
                              '\nfrom . import misc\nfrom . import utils\nfrom . import data\n')
@@ -390,8 +389,7 @@ def _classify_installed_files_override(
                 opencv_init_replacement = line.replace('importlib.import_module("cv2")', 'importlib.import_module("cv2.cv2")')
                 opencv_init_data = opencv_init_data + opencv_init_replacement
 
-        with open("%spython/cv2/__init__.py"
-        % cmake_install_dir, 'w') as opencv_final_init:
+        with open(os.path.join(cmake_install_dir, "python", "cv2", "__init__.py"), 'w') as opencv_final_init:
             opencv_final_init.write(opencv_init_data)
 
         # add lines from the old __init__.py file to the config file

From 8f763b1ebcfa3f6dc62e226c61a5b8be7f141ec0 Mon Sep 17 00:00:00 2001
From: Christian Clauss <cclauss@me.com>
Date: Fri, 26 Nov 2021 11:45:37 +0100
Subject: [PATCH 536/566] Delete appveyor.yml

The last run was a year ago.  https://ci.appveyor.com/project/skvark/opencv-python/history
---
 appveyor.yml | 201 ---------------------------------------------------
 1 file changed, 201 deletions(-)
 delete mode 100644 appveyor.yml

diff --git a/appveyor.yml b/appveyor.yml
deleted file mode 100644
index c79e7de4..00000000
--- a/appveyor.yml
+++ /dev/null
@@ -1,201 +0,0 @@
-environment:
-  USER:
-    secure: fXgF9uyy6sT0JoVOR7BoqA==
-
-  PASS:
-    secure: 0bXSOVjf9x8L7nErTivu92TF1FwNosTjFJQPmxp8Dys=
-
-  matrix:
-    - PYTHON: "C:\\Python36"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python36-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python37"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python37-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python38"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python38-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python39"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python39-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python36"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python36-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python37"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python37-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python38"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python38-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python39"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python39-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 0
-
-    - PYTHON: "C:\\Python36"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python36-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python37"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python37-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python38"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python38-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python39"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python39-x64"
-      ENABLE_CONTRIB: 0
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python36"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python36-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python37"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python37-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python38"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python38-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python39"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-    - PYTHON: "C:\\Python39-x64"
-      ENABLE_CONTRIB: 1
-      ENABLE_HEADLESS: 1
-
-matrix:
-    fast_finish: true
-
-install:
-  - ps: |
-      if (-not (Test-Path $env:PYTHON)) {
-        curl -o install_python.ps1 https://raw.githubusercontent.com/matthew-brett/multibuild/devel/install_python.ps1
-        .\install_python.ps1
-      }
-  - ps: if (-not (Test-Path $env:PYTHON)) { throw "No $env:PYTHON" }
-  - "set PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
-  - python --version
-
-build_script:
-- cmd: |
-    "%PYTHON%\\python.exe" -m pip install --upgrade pip
-    "%PYTHON%\\python.exe" -m pip install --upgrade setuptools
-    set "CI_BUILD=1" && "%PYTHON%\\python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
-
-before_test:
-- ps: |
-
-    cd ${Env:APPVEYOR_BUILD_FOLDER}\tests
-    $env:PYTHONWARNINGS = "ignore:::pip._internal.cli.base_command"
-    &"${Env:PYTHON}\\python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
-    if ($LastExitCode -ne 0) {throw $LastExitCode}
-
-test_script:
-- cmd: |
-
-    cd %APPVEYOR_BUILD_FOLDER%\tests
-    "%PYTHON%\\python.exe" -m unittest test
-
-artifacts:
-- path: dist\opencv*.whl
-  name: wheels
-
-deploy_script:
-- ps: |
-
-    if (${Env:APPVEYOR_REPO_TAG} -eq "true") {
-      cd ${Env:APPVEYOR_BUILD_FOLDER}
-      if (${Env:ENABLE_CONTRIB} -eq 0) {
-        if (${Env:ENABLE_HEADLESS} -eq 0) {
-          echo "This is a default build. Deployment will be done to PyPI entry opencv-python."
-        }
-        else {
-          echo "This is a headless build. Deployment will be done to PyPI entry opencv-python-headless."
-        }
-      }
-      else {
-        if (${Env:ENABLE_HEADLESS} -eq 0) {
-          echo "This is a contrib build. Deployment will be done to PyPI entry opencv-contrib-python."
-        }
-        else {
-          echo "This is a headless contrib build. Deployment will be done to PyPI entry opencv-contrib-python-headless."
-        }
-      }
-
-      &"${Env:PYTHON}\\python.exe" -m pip install twine
-      &"${Env:PYTHON}\\python.exe" -m twine upload -u ${Env:USER} -p ${Env:PASS} --skip-existing dist/opencv*
-    }
-    else {
-      echo "Tag not set, deployment skipped."
-    }

From 040dc8d80fb3dffddc9bf235f0610f998d470a97 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Wed, 15 Dec 2021 15:58:12 +0300
Subject: [PATCH 537/566] Added python limited API support

---
 .github/workflows/build_wheels_linux.yml     | 123 ++++++++++---
 .github/workflows/build_wheels_linux_arm.yml | 121 +++++++++++--
 .github/workflows/build_wheels_macos.yml     | 144 +++++++++++++--
 .github/workflows/build_wheels_macos_m1.yml  | 109 ++++++++++--
 .github/workflows/build_wheels_windows.yml   | 174 +++++++++++++++++--
 setup.py                                     |   7 +-
 travis_config.sh                             |   6 +-
 7 files changed, 592 insertions(+), 92 deletions(-)

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index 7ff34a18..338673dc 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -23,7 +23,7 @@ jobs:
       fail-fast: false
       matrix:
         os: [ubuntu-latest]
-        python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
+        python-version: ['3.6']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
@@ -37,13 +37,12 @@ jobs:
       MB_PYTHON_VERSION: ${{ matrix.python-version }}
       TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
       MB_ML_VER: 2014
-      NP_TEST_DEP: numpy==1.19.4
-      NP_TEST_DEP_LATEST: numpy==1.21.2
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
       DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
+      PLAT: x86_64
       SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
@@ -59,25 +58,108 @@ jobs:
       if: github.event_name == 'pull_request'
       run: git submodule update --remote
 
-    - name: Setup Environment variables
-      run: |
-        if [ "schedule" == "${{ github.event_name }}" ]; then echo "TRAVIS_EVENT_TYPE=cron" >> $GITHUB_ENV; else echo "TRAVIS_EVENT_TYPE=${{ github.event_name }}" >> $GITHUB_ENV; fi
-        if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
-        if [ "x64" == "${{ matrix.platform }}" ]; then echo "PLAT=x86_64" >> $GITHUB_ENV; fi
-        if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
-
-    - name: build
+    - name: Build a package
       run: source scripts/build.sh
 
-    - name: install and test
-      run: source scripts/install.sh
-
-    - name: saving artifacts
+    - name: Saving all wheels
       uses: actions/upload-artifact@v2
       with:
         name: wheels
         path: wheelhouse/opencv*.whl
 
+    - name: Saving opencv-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-python-wheels
+        path: wheelhouse/opencv_python-*.whl
+
+    - name: Saving opencv-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-python-headless-wheels
+        path: wheelhouse/opencv_python_headless-*.whl
+
+    - name: Saving opencv-contrib-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-contrib-python-wheels
+        path: wheelhouse/opencv_contrib_python-*.whl
+
+    - name: Saving opencv-contrib-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-contrib-python-headless-wheels
+        path: wheelhouse/opencv_contrib_python_headless-*.whl
+
+  test:
+    needs: [build]
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        shell: bash
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ubuntu-latest]
+        python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
+        platform: [x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [0]
+
+    env:
+      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+      MB_PYTHON_VERSION: ${{ matrix.python-version }}
+      NP_TEST_DEP: numpy==1.19.4
+      NP_TEST_DEP_LATEST: numpy==1.21.2
+      CONFIG_PATH: travis_config.sh
+      PLAT: x86_64
+
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: false
+        fetch-depth: 0
+
+    - name: Setup Environment variables
+      run: if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
+
+    - name: Download opencv-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-python-wheels
+        path: wheelhouse/
+
+    - name: Download opencv-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-python-headless-wheels
+        path: wheelhouse/
+
+    - name: Download opencv-contrib-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-contrib-python-wheels
+        path: wheelhouse/
+
+    - name: Download opencv-contrib-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-contrib-python-headless-wheels
+        path: wheelhouse/
+
+    - name: Package installation and run tests
+      run: source scripts/install.sh
 
   build_sdist:
     runs-on: ${{ matrix.os }}
@@ -131,12 +213,7 @@ jobs:
         python-version: ${{ matrix.python-version }}
         architecture: ${{ matrix.platform }}
 
-    - name: Setup Environment variables
-      run: |
-        if [ "schedule" == "${{ github.event_name }}" ]; then echo "TRAVIS_EVENT_TYPE=cron" >> $GITHUB_ENV; else echo "TRAVIS_EVENT_TYPE=${{ github.event_name }}" >> $GITHUB_ENV; fi
-        if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
-
-    - name: before install
+    - name: Build a package
       run: |
         set -e
         # Build and package
@@ -157,7 +234,7 @@ jobs:
 
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
-    needs: [build, build_sdist]
+    needs: [build, build_sdist, test]
     runs-on: ubuntu-latest
     environment: test-opencv-python-release
     defaults:
@@ -176,7 +253,7 @@ jobs:
 
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
-    needs: [build, build_sdist]
+    needs: [build, build_sdist, test]
     runs-on: ubuntu-latest
     environment: opencv-python-release
     defaults:
diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index 89142a57..08badc5b 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -23,7 +23,7 @@ jobs:
       fail-fast: false
       matrix:
         os: [ARM64]
-        python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
+        python-version: ['3.6']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
@@ -38,12 +38,9 @@ jobs:
       TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
       PLAT: aarch64
       MB_ML_VER: 2014
-      NP_TEST_DEP: numpy==1.19.4
-      NP_TEST_DEP_LATEST: numpy==1.21.2
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
       DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
-      DOCKER_TEST_IMAGE: multibuild/focal_arm64v8
       USE_CCACHE: 0
       UNICODE_WIDTH: 32
       SDIST: ${{ matrix.build_sdist || 0 }}
@@ -61,26 +58,118 @@ jobs:
         submodules: false
         fetch-depth: 0
 
-    - name: Setup Environment variables
-      run: |
-        if [ "ARM64" == "${{ matrix.os }}" ]; then echo "PLAT=aarch64" >> $GITHUB_ENV; fi
-        if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
-
-    - name: build
+    - name: Build a package
       run: source scripts/build.sh
 
-    - name: install and test
-      run: source scripts/install.sh
-
-    - name: saving artifacts
+    - name: Saving all wheels
       uses: actions/upload-artifact@v2
       with:
         name: wheels
         path: wheelhouse/opencv*.whl
 
+    - name: Saving opencv-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-python-wheels
+        path: wheelhouse/opencv_python-*.whl
+
+    - name: Saving opencv-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-python-headless-wheels
+        path: wheelhouse/opencv_python_headless-*.whl
+
+    - name: Saving opencv-contrib-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-contrib-python-wheels
+        path: wheelhouse/opencv_contrib_python-*.whl
+
+    - name: Saving opencv-contrib-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-contrib-python-headless-wheels
+        path: wheelhouse/opencv_contrib_python_headless-*.whl
+
+  test:
+    needs: [build_arm]
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        shell: bash
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ARM64]
+        python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
+        platform: [x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [0]
+
+    env:
+      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+      MB_PYTHON_VERSION: ${{ matrix.python-version }}
+      PLAT: aarch64
+      NP_TEST_DEP: numpy==1.19.4
+      NP_TEST_DEP_LATEST: numpy==1.21.4
+      CONFIG_PATH: travis_config.sh
+      DOCKER_TEST_IMAGE: multibuild/focal_arm64v8
+      UNICODE_WIDTH: 32
+
+    steps:
+    - name: Cleanup
+      if: always()
+      uses: AutoModality/action-clean@v1
+
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: true
+        fetch-depth: 0
+
+    - name: Setup Environment variables
+      run: if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
+
+    - name: Download opencv-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-python-wheels
+        path: wheelhouse/
+
+    - name: Download opencv-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-python-headless-wheels
+        path: wheelhouse/
+
+    - name: Download opencv-contrib-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-contrib-python-wheels
+        path: wheelhouse/
+
+    - name: Download opencv-contrib-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-contrib-python-headless-wheels
+        path: wheelhouse/
+
+    - name: Package installation and run tests
+      run: source scripts/install.sh
+
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
-    needs: [build_arm]
+    needs: [build_arm, test]
     runs-on: ubuntu-latest
     environment: test-opencv-python-release
     defaults:
@@ -99,7 +188,7 @@ jobs:
 
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
-    needs: [build_arm]
+    needs: [build_arm, test]
     runs-on: ubuntu-latest
     environment: opencv-python-release
     defaults:
diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index d4f10be0..0ff69ede 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -23,7 +23,7 @@ jobs:
       fail-fast: false
       matrix:
         os: [macos-10.15, macos-11]
-        python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
+        python-version: ['3.6']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
@@ -48,14 +48,13 @@ jobs:
       MB_PYTHON_VERSION: ${{ matrix.python-version }}
       TRAVIS_PYTHON_VERSION: ${{ matrix.python-version }}
       MB_ML_VER: 2014
-      NP_TEST_DEP: numpy==1.19.4
-      NP_TEST_DEP_LATEST: numpy==1.21.2
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       TRAVIS_OS_NAME: osx
       CONFIG_PATH: travis_config.sh
       DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
+      PLAT: x86_64
       SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
@@ -71,15 +70,7 @@ jobs:
       if: github.event_name == 'pull_request'
       run: git submodule update --remote
 
-    - name: Setup Environment variables
-      run: |
-        if [ "schedule" == "${{ github.event_name }}" ]; then echo "TRAVIS_EVENT_TYPE=cron" >> $GITHUB_ENV; else echo "TRAVIS_EVENT_TYPE=${{ github.event_name }}" >> $GITHUB_ENV; fi
-        if [ "schedule" == "${{ github.event_name }}" ]; then echo "BUILD_COMMIT=master" >> $GITHUB_ENV; else echo "BUILD_COMMIT=$BUILD_COMMIT" >> $GITHUB_ENV; fi
-        if [ "x64" == "${{ matrix.platform }}" ]; then echo "PLAT=x86_64" >> $GITHUB_ENV; fi
-        if [ "x86" == "${{ matrix.platform }}" ]; then echo "PLAT=i686" >> $GITHUB_ENV; fi
-        if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
-
-    - name: before install
+    - name: Build a package
       run: |
         set -e
         # Check out and prepare the source
@@ -96,19 +87,136 @@ jobs:
         echo $ENABLE_HEADLESS > headless.enabled
         set -x
         build_wheel $REPO_DIR $PLAT
-        git submodule update --init --recursive
-        install_run $PLAT
-        set +x
 
-    - name: saving artifacts
+    - name: Saving all wheels
       uses: actions/upload-artifact@v2
       with:
         name: wheels
         path: wheelhouse/opencv*.whl
 
+    - name: Saving opencv-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-python-wheels
+        path: wheelhouse/opencv_python-*.whl
+
+    - name: Saving opencv-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-python-headless-wheels
+        path: wheelhouse/opencv_python_headless-*.whl
+
+    - name: Saving opencv-contrib-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-contrib-python-wheels
+        path: wheelhouse/opencv_contrib_python-*.whl
+
+    - name: Saving opencv-contrib-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-contrib-python-headless-wheels
+        path: wheelhouse/opencv_contrib_python_headless-*.whl
+
+  test:
+    needs: [build]
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        shell: bash
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [macos-10.15, macos-11]
+        python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
+        platform: [x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [0]
+        exclude:
+          - os: macos-10.15
+            python-version: '3.10'
+          - os: macos-11
+            python-version: '3.6'
+          - os: macos-11
+            python-version: '3.7'
+          - os: macos-11
+            python-version: '3.8'
+          - os: macos-11
+            python-version: '3.9'
+
+    env:
+      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+      MB_PYTHON_VERSION: ${{ matrix.python-version }}
+      NP_TEST_DEP: numpy==1.19.4
+      NP_TEST_DEP_LATEST: numpy==1.21.4
+      CONFIG_PATH: travis_config.sh
+      PLAT: x86_64
+      OPENCV_TEST_DATA_PATH: ${{ github.workspace }}/opencv_extra/testdata
+
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: true
+        fetch-depth: 0
+
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v2
+      with:
+        python-version: ${{ matrix.python-version }}
+        architecture: ${{ matrix.platform }}
+
+    - name: Setup Environment variables
+      run: if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
+
+    - name: Download opencv-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-python-wheels
+        path: wheelhouse/
+
+    - name: Download opencv-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-python-headless-wheels
+        path: wheelhouse/
+
+    - name: Download opencv-contrib-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-contrib-python-wheels
+        path: wheelhouse/
+
+    - name: Download opencv-contrib-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-contrib-python-headless-wheels
+        path: wheelhouse/
+
+    - name: Package installation
+      run: |
+        python -m pip install wheelhouse/opencv*.whl
+        cd ${{ github.workspace }}/tests
+        python get_build_info.py
+
+    - name: Run tests
+      run: |
+        cd ${{ github.workspace }}/opencv
+        python modules/python/test/test.py -v --repo .
+
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
-    needs: [build]
+    needs: [build, test]
     runs-on: ubuntu-latest
     environment: test-opencv-python-release
     defaults:
@@ -127,7 +235,7 @@ jobs:
 
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
-    needs: [build]
+    needs: [build, test]
     runs-on: ubuntu-latest
     environment: opencv-python-release
     defaults:
diff --git a/.github/workflows/build_wheels_macos_m1.yml b/.github/workflows/build_wheels_macos_m1.yml
index 79164dcf..cd183389 100644
--- a/.github/workflows/build_wheels_macos_m1.yml
+++ b/.github/workflows/build_wheels_macos_m1.yml
@@ -20,7 +20,7 @@ jobs:
       fail-fast: false
       matrix:
         os: [macOS-M1]
-        python-version: ['3.7', '3.8', '3.9', '3.10']
+        python-version: ['3.7']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
@@ -31,7 +31,6 @@ jobs:
       SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
-      OPENCV_TEST_DATA_PATH: ${{ github.workspace }}/opencv_extra/testdata
 
     steps:
     - name: Checkout
@@ -44,36 +43,116 @@ jobs:
       if: github.event_name == 'pull_request'
       run: git submodule update --remote
 
-    - name: build script
+    - name: Build a package
       run: |
         git submodule update --init multibuild
         echo $ENABLE_CONTRIB > contrib.enabled
         echo $ENABLE_HEADLESS > headless.enabled
         export MACOSX_DEPLOYMENT_TARGET=11.0
-        arch -arm64 python${{ matrix.python-version }} -m pip wheel --wheel-dir=wheelhouse . --verbose
+        arch -arm64 python${{ matrix.python-version }} -m pip install toml && python${{ matrix.python-version }} -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["build-system"]["requires"]))' | python${{ matrix.python-version }} -m pip install -r /dev/stdin
+        arch -arm64 python${{ matrix.python-version }} setup.py bdist_wheel --py-limited-api=cp37 --dist-dir=wheelhouse -v
         delocate-wheel ${{ github.workspace }}/wheelhouse/opencv*
 
-    - name: before test
+    - name: Saving all wheels
+      uses: actions/upload-artifact@v2
+      with:
+        name: wheels
+        path: wheelhouse/opencv*.whl
+
+    - name: Saving opencv-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-python-wheels
+        path: wheelhouse/opencv_python-*.whl
+
+    - name: Saving opencv-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-python-headless-wheels
+        path: wheelhouse/opencv_python_headless-*.whl
+
+    - name: Saving opencv-contrib-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-contrib-python-wheels
+        path: wheelhouse/opencv_contrib_python-*.whl
+
+    - name: Saving opencv-contrib-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-contrib-python-headless-wheels
+        path: wheelhouse/opencv_contrib_python_headless-*.whl
+
+  test:
+    needs: [build]
+    runs-on: ${{ matrix.os }}
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [macOS-M1]
+        python-version: ['3.7', '3.8', '3.9', '3.10']
+        platform: [x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [0]
+
+    env:
+      OPENCV_TEST_DATA_PATH: ${{ github.workspace }}/opencv_extra/testdata
+
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: true
+        fetch-depth: 0
+
+    - name: Download opencv-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-python-wheels
+        path: wheelhouse/
+
+    - name: Download opencv-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-python-headless-wheels
+        path: wheelhouse/
+
+    - name: Download opencv-contrib-python wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-contrib-python-wheels
+        path: wheelhouse/
+
+    - name: Download opencv-contrib-python-headless wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-contrib-python-headless-wheels
+        path: wheelhouse/
+
+    - name: Package installation
       run: |
-        git submodule update --init --recursive
         arch -arm64 python${{ matrix.python-version }} -m pip install --user --no-cache --force-reinstall wheelhouse/opencv*.whl
         cd ${{ github.workspace }}/tests
         arch -arm64 python${{ matrix.python-version }} get_build_info.py
 
-    - name: run test
+    - name: Run tests
       run: |
         cd ${{ github.workspace }}/opencv
         arch -arm64 python${{ matrix.python-version }} modules/python/test/test.py -v --repo .
 
-    - name: saving artifacts
-      uses: actions/upload-artifact@v2
-      with:
-        name: wheels
-        path: wheelhouse/opencv*.whl
-
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
-    needs: [build]
+    needs: [build, test]
     runs-on: ubuntu-latest
     environment: test-opencv-python-release
     defaults:
@@ -92,7 +171,7 @@ jobs:
 
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
-    needs: [build]
+    needs: [build, test]
     runs-on: ubuntu-latest
     environment: opencv-python-release
     defaults:
diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index 3eb13086..ade90ead 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -22,7 +22,7 @@ jobs:
       fail-fast: false
       matrix:
         os: [windows-latest]
-        python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
+        python-version: ['3.6']
         platform: [x86, x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
@@ -55,38 +55,184 @@ jobs:
     - name: Setup MSBuild.exe
       uses: warrenbuckley/Setup-MSBuild@v1
 
-    - name: build script
+    - name: Build a package
       run: |
         python --version
         python -m pip install --upgrade pip
         python -m pip install --upgrade setuptools
-        set "CI_BUILD=1" && python -m pip wheel --wheel-dir=%cd%\wheelhouse . --verbose
+        python -m pip install toml && python -c "import toml; c = toml.load('pyproject.toml'); print('\n'.join(c['build-system']['requires']))" >> requirements.txt | python -m pip install -r requirements.txt
+        set "CI_BUILD=1" && python setup.py bdist_wheel --py-limited-api=cp36 --dist-dir=%cd%\wheelhouse -v
       shell: cmd
 
-    - name: before test
+    - name: Saving all wheels
+      uses: actions/upload-artifact@v2
+      with:
+        name: wheels
+        path: wheelhouse/opencv*.whl
+
+    - name: Saving opencv-python x86 wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 && matrix.platform == 'x86' }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-python-wheels-x86
+        path: wheelhouse/opencv_python-*.whl
+
+    - name: Saving opencv-python x64 wheels  
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 && matrix.platform == 'x64' }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-python-wheels-x64
+        path: wheelhouse/opencv_python-*.whl
+
+    - name: Saving opencv-python-headless x86 wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 && matrix.platform == 'x86' }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-python-headless-wheels-x86
+        path: wheelhouse/opencv_python_headless-*.whl
+
+    - name: Saving opencv-python-headless x64 wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 && matrix.platform == 'x64' }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-python-headless-wheels-x64
+        path: wheelhouse/opencv_python_headless-*.whl
+
+    - name: Saving opencv-contrib-python x86 wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 && matrix.platform == 'x86' }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-contrib-python-wheels-x86
+        path: wheelhouse/opencv_contrib_python-*.whl
+
+    - name: Saving opencv-contrib-python x64 wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 && matrix.platform == 'x64' }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-contrib-python-wheels-x64
+        path: wheelhouse/opencv_contrib_python-*.whl
+
+    - name: Saving opencv-contrib-python-headless x86 wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 && matrix.platform == 'x86' }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-contrib-python-headless-wheels-x86
+        path: wheelhouse/opencv_contrib_python_headless-*.whl
+
+    - name: Saving opencv-contrib-python-headless x64 wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 && matrix.platform == 'x64' }}
+      uses: actions/upload-artifact@v2
+      with:
+        name: opencv-contrib-python-headless-wheels-x64
+        path: wheelhouse/opencv_contrib_python_headless-*.whl
+
+  test:
+    needs: [build-windows-x86_64]
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        shell: powershell
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [windows-latest]
+        python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
+        platform: [x86, x64]
+        with_contrib: [0, 1]
+        without_gui: [0, 1]
+        build_sdist: [0]
+
+    env:
+      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+      OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata
+
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        submodules: true
+        fetch-depth: 0
+
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v2
+      with:
+        python-version: ${{ matrix.python-version }}
+        architecture: ${{ matrix.platform }}
+
+    - name: Download opencv-python x86 wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 && matrix.platform == 'x86' }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-python-wheels-x86
+        path: wheelhouse/
+
+    - name: Download opencv-python x64 wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 && matrix.platform == 'x64' }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-python-wheels-x64
+        path: wheelhouse/
+
+    - name: Download opencv-python-headless x86 wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 && matrix.platform == 'x86' }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-python-headless-wheels-x86
+        path: wheelhouse/
+
+    - name: Download opencv-python-headless x64 wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 && matrix.platform == 'x64' }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-python-headless-wheels-x64
+        path: wheelhouse/
+
+    - name: Download opencv-contrib-python x86 wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 && matrix.platform == 'x86' }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-contrib-python-wheels-x86
+        path: wheelhouse/
+
+    - name: Download opencv-contrib-python x64 wheels
+      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 && matrix.platform == 'x64' }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-contrib-python-wheels-x64
+        path: wheelhouse/
+
+    - name: Download opencv-contrib-python-headless x86 wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 && matrix.platform == 'x86' }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-contrib-python-headless-wheels-x86
+        path: wheelhouse/
+
+    - name: Download opencv-contrib-python-headless x64 wheels
+      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 && matrix.platform == 'x64' }}
+      uses: actions/download-artifact@v2
+      with:
+        name: opencv-contrib-python-headless-wheels-x64
+        path: wheelhouse/
+
+    - name: Package installation
       run: |
-        git submodule update --init --recursive
         cd ${{ github.workspace }}/tests
         &python -m pip install --user --no-warn-script-location (ls "../wheelhouse/opencv*.whl")
         if ($LastExitCode -ne 0) {throw $LastExitCode}
         python get_build_info.py
       shell: powershell
 
-    - name: run test
+    - name: Run tests
       run: |
         cd ${{ github.workspace }}/opencv
         python modules\python\test\test.py -v --repo .
       shell: cmd
 
-    - name: saving artifacts
-      uses: actions/upload-artifact@v2
-      with:
-        name: wheels
-        path: wheelhouse/opencv*.whl
-
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
-    needs: [build-windows-x86_64]
+    needs: [build-windows-x86_64, test]
     runs-on: ubuntu-latest
     environment: test-opencv-python-release
     defaults:
@@ -105,7 +251,7 @@ jobs:
 
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
-    needs: [build-windows-x86_64]
+    needs: [build-windows-x86_64, test]
     runs-on: ubuntu-latest
     environment: opencv-python-release
     defaults:
diff --git a/setup.py b/setup.py
index a49fcc37..331631ea 100644
--- a/setup.py
+++ b/setup.py
@@ -97,8 +97,8 @@ def main():
         # Naming conventions vary so widely between versions and OSes
         # had to give up on checking them.
         [
-            "python/cv2/python-%s.%s/cv2[^/]*%s"
-            % (sys.version_info[0], sys.version_info[1], re.escape(sysconfig.get_config_var("EXT_SUFFIX")))
+            r"python/cv2/python-%s/cv2.*"
+            % (sys.version_info[0])
         ]
         +
         [
@@ -159,6 +159,7 @@ def main():
             "-DBUILD_TESTS=OFF",
             "-DBUILD_PERF_TESTS=OFF",
             "-DBUILD_DOCS=OFF",
+            "-DPYTHON3_LIMITED_API=ON",
         ]
         + (
             # If it is not defined 'linker flags: /machine:X86' on Windows x64
@@ -370,7 +371,7 @@ def _classify_installed_files_override(
         with open(os.path.join(cmake_install_dir, "python", "cv2", "__init__.py"), 'r') as opencv_init:
             opencv_init_lines = opencv_init.readlines()
             extra_imports = ('\nfrom .cv2 import *\nfrom .cv2 import _registerMatType\nfrom . import mat_wrapper\nfrom . import gapi'
-                             '\nfrom . import misc\nfrom . import utils\nfrom . import data\n')
+                             '\nfrom . import misc\nfrom . import utils\nfrom . import data\nfrom . import version\n')
             free_line_after_imports = 6
             opencv_init_lines.insert(free_line_after_imports, extra_imports)
             opencv_init_data = ""
diff --git a/travis_config.sh b/travis_config.sh
index 6d6cc06b..7bbfec68 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -14,7 +14,9 @@ function bdist_wheel_cmd {
     # copied from multibuild's common_utils.sh
     # add osx deployment target so it doesn't default to 10.6
     local abs_wheelhouse=$1
-    CI_BUILD=1 pip wheel --verbose --wheel-dir="$PWD/dist" . $BDIST_PARAMS
+    # install all required packages in pyproject.toml, because bdist_wheel does not do it
+    python${PYTHON_VERSION} -m pip install toml && python${PYTHON_VERSION} -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["build-system"]["requires"]))' | python${PYTHON_VERSION} -m pip install -r /dev/stdin
+    CI_BUILD=1 python${PYTHON_VERSION} setup.py bdist_wheel --py-limited-api=cp36 -v
     cp dist/*.whl $abs_wheelhouse
     if [ -z "$IS_OSX" ]; then
       # this path can be changed in the latest manylinux image
@@ -22,8 +24,6 @@ function bdist_wheel_cmd {
       /opt/python/cp39-cp39/bin/python -m venv $TOOLS_PATH
       source $TOOLS_PATH/bin/activate
       python patch_auditwheel_whitelist.py
-      # to avoid issues with numpy wheels
-      rm /io/wheelhouse/numpy*
       deactivate
     fi
     if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi

From edd6b14d97c51f077f2fae37271db4f77841df2c Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Wed, 15 Dec 2021 21:04:34 +0300
Subject: [PATCH 538/566] Changed a path to config-X.py file after python
 limited API support, optimized uploading and downloading artifacts

---
 .github/workflows/build_wheels_linux.yml     |  54 +--------
 .github/workflows/build_wheels_linux_arm.yml |  54 +--------
 .github/workflows/build_wheels_macos.yml     |  54 +--------
 .github/workflows/build_wheels_macos_m1.yml  |  54 +--------
 .github/workflows/build_wheels_windows.yml   | 110 +------------------
 setup.py                                     |   4 +-
 6 files changed, 27 insertions(+), 303 deletions(-)

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index 338673dc..bd42944c 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -67,33 +67,11 @@ jobs:
         name: wheels
         path: wheelhouse/opencv*.whl
 
-    - name: Saving opencv-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
+    - name: Saving a wheel accordingly to matrix
       uses: actions/upload-artifact@v2
       with:
-        name: opencv-python-wheels
-        path: wheelhouse/opencv_python-*.whl
-
-    - name: Saving opencv-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-python-headless-wheels
-        path: wheelhouse/opencv_python_headless-*.whl
-
-    - name: Saving opencv-contrib-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-contrib-python-wheels
-        path: wheelhouse/opencv_contrib_python-*.whl
-
-    - name: Saving opencv-contrib-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-contrib-python-headless-wheels
-        path: wheelhouse/opencv_contrib_python_headless-*.whl
+        name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}
+        path: wheelhouse/opencv*.whl
 
   test:
     needs: [build]
@@ -130,32 +108,10 @@ jobs:
     - name: Setup Environment variables
       run: if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
 
-    - name: Download opencv-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-python-wheels
-        path: wheelhouse/
-
-    - name: Download opencv-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-python-headless-wheels
-        path: wheelhouse/
-
-    - name: Download opencv-contrib-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-contrib-python-wheels
-        path: wheelhouse/
-
-    - name: Download opencv-contrib-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
+    - name: Download a wheel accordingly to matrix
       uses: actions/download-artifact@v2
       with:
-        name: opencv-contrib-python-headless-wheels
+        name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}
         path: wheelhouse/
 
     - name: Package installation and run tests
diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index 08badc5b..a97bbc29 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -67,33 +67,11 @@ jobs:
         name: wheels
         path: wheelhouse/opencv*.whl
 
-    - name: Saving opencv-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
+    - name: Saving a wheel accordingly to matrix
       uses: actions/upload-artifact@v2
       with:
-        name: opencv-python-wheels
-        path: wheelhouse/opencv_python-*.whl
-
-    - name: Saving opencv-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-python-headless-wheels
-        path: wheelhouse/opencv_python_headless-*.whl
-
-    - name: Saving opencv-contrib-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-contrib-python-wheels
-        path: wheelhouse/opencv_contrib_python-*.whl
-
-    - name: Saving opencv-contrib-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-contrib-python-headless-wheels
-        path: wheelhouse/opencv_contrib_python_headless-*.whl
+        name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}
+        path: wheelhouse/opencv*.whl
 
   test:
     needs: [build_arm]
@@ -136,32 +114,10 @@ jobs:
     - name: Setup Environment variables
       run: if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
 
-    - name: Download opencv-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-python-wheels
-        path: wheelhouse/
-
-    - name: Download opencv-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-python-headless-wheels
-        path: wheelhouse/
-
-    - name: Download opencv-contrib-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-contrib-python-wheels
-        path: wheelhouse/
-
-    - name: Download opencv-contrib-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
+    - name: Download a wheel accordingly to matrix
       uses: actions/download-artifact@v2
       with:
-        name: opencv-contrib-python-headless-wheels
+        name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}
         path: wheelhouse/
 
     - name: Package installation and run tests
diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index 0ff69ede..87fe6f99 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -94,33 +94,11 @@ jobs:
         name: wheels
         path: wheelhouse/opencv*.whl
 
-    - name: Saving opencv-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
+    - name: Saving a wheel accordingly to matrix
       uses: actions/upload-artifact@v2
       with:
-        name: opencv-python-wheels
-        path: wheelhouse/opencv_python-*.whl
-
-    - name: Saving opencv-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-python-headless-wheels
-        path: wheelhouse/opencv_python_headless-*.whl
-
-    - name: Saving opencv-contrib-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-contrib-python-wheels
-        path: wheelhouse/opencv_contrib_python-*.whl
-
-    - name: Saving opencv-contrib-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-contrib-python-headless-wheels
-        path: wheelhouse/opencv_contrib_python_headless-*.whl
+        name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}
+        path: wheelhouse/opencv*.whl
 
   test:
     needs: [build]
@@ -175,32 +153,10 @@ jobs:
     - name: Setup Environment variables
       run: if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
 
-    - name: Download opencv-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-python-wheels
-        path: wheelhouse/
-
-    - name: Download opencv-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-python-headless-wheels
-        path: wheelhouse/
-
-    - name: Download opencv-contrib-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-contrib-python-wheels
-        path: wheelhouse/
-
-    - name: Download opencv-contrib-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
+    - name: Download a wheel accordingly to matrix
       uses: actions/download-artifact@v2
       with:
-        name: opencv-contrib-python-headless-wheels
+        name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}
         path: wheelhouse/
 
     - name: Package installation
diff --git a/.github/workflows/build_wheels_macos_m1.yml b/.github/workflows/build_wheels_macos_m1.yml
index cd183389..3711e1b3 100644
--- a/.github/workflows/build_wheels_macos_m1.yml
+++ b/.github/workflows/build_wheels_macos_m1.yml
@@ -59,33 +59,11 @@ jobs:
         name: wheels
         path: wheelhouse/opencv*.whl
 
-    - name: Saving opencv-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
+    - name: Saving a wheel accordingly to matrix
       uses: actions/upload-artifact@v2
       with:
-        name: opencv-python-wheels
-        path: wheelhouse/opencv_python-*.whl
-
-    - name: Saving opencv-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-python-headless-wheels
-        path: wheelhouse/opencv_python_headless-*.whl
-
-    - name: Saving opencv-contrib-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-contrib-python-wheels
-        path: wheelhouse/opencv_contrib_python-*.whl
-
-    - name: Saving opencv-contrib-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-contrib-python-headless-wheels
-        path: wheelhouse/opencv_contrib_python_headless-*.whl
+        name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}
+        path: wheelhouse/opencv*.whl
 
   test:
     needs: [build]
@@ -111,32 +89,10 @@ jobs:
         submodules: true
         fetch-depth: 0
 
-    - name: Download opencv-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-python-wheels
-        path: wheelhouse/
-
-    - name: Download opencv-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-python-headless-wheels
-        path: wheelhouse/
-
-    - name: Download opencv-contrib-python wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-contrib-python-wheels
-        path: wheelhouse/
-
-    - name: Download opencv-contrib-python-headless wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 }}
+    - name: Download a wheel accordingly to matrix
       uses: actions/download-artifact@v2
       with:
-        name: opencv-contrib-python-headless-wheels
+        name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}
         path: wheelhouse/
 
     - name: Package installation
diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index ade90ead..0f697291 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -70,61 +70,11 @@ jobs:
         name: wheels
         path: wheelhouse/opencv*.whl
 
-    - name: Saving opencv-python x86 wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 && matrix.platform == 'x86' }}
+    - name: Saving a wheel accordingly to matrix
       uses: actions/upload-artifact@v2
       with:
-        name: opencv-python-wheels-x86
-        path: wheelhouse/opencv_python-*.whl
-
-    - name: Saving opencv-python x64 wheels  
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 && matrix.platform == 'x64' }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-python-wheels-x64
-        path: wheelhouse/opencv_python-*.whl
-
-    - name: Saving opencv-python-headless x86 wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 && matrix.platform == 'x86' }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-python-headless-wheels-x86
-        path: wheelhouse/opencv_python_headless-*.whl
-
-    - name: Saving opencv-python-headless x64 wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 && matrix.platform == 'x64' }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-python-headless-wheels-x64
-        path: wheelhouse/opencv_python_headless-*.whl
-
-    - name: Saving opencv-contrib-python x86 wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 && matrix.platform == 'x86' }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-contrib-python-wheels-x86
-        path: wheelhouse/opencv_contrib_python-*.whl
-
-    - name: Saving opencv-contrib-python x64 wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 && matrix.platform == 'x64' }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-contrib-python-wheels-x64
-        path: wheelhouse/opencv_contrib_python-*.whl
-
-    - name: Saving opencv-contrib-python-headless x86 wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 && matrix.platform == 'x86' }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-contrib-python-headless-wheels-x86
-        path: wheelhouse/opencv_contrib_python_headless-*.whl
-
-    - name: Saving opencv-contrib-python-headless x64 wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 && matrix.platform == 'x64' }}
-      uses: actions/upload-artifact@v2
-      with:
-        name: opencv-contrib-python-headless-wheels-x64
-        path: wheelhouse/opencv_contrib_python_headless-*.whl
+        name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}-${{ matrix.platform }}
+        path: wheelhouse/opencv*
 
   test:
     needs: [build-windows-x86_64]
@@ -160,60 +110,10 @@ jobs:
         python-version: ${{ matrix.python-version }}
         architecture: ${{ matrix.platform }}
 
-    - name: Download opencv-python x86 wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 && matrix.platform == 'x86' }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-python-wheels-x86
-        path: wheelhouse/
-
-    - name: Download opencv-python x64 wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 0 && matrix.platform == 'x64' }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-python-wheels-x64
-        path: wheelhouse/
-
-    - name: Download opencv-python-headless x86 wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 && matrix.platform == 'x86' }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-python-headless-wheels-x86
-        path: wheelhouse/
-
-    - name: Download opencv-python-headless x64 wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 0 && matrix.platform == 'x64' }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-python-headless-wheels-x64
-        path: wheelhouse/
-
-    - name: Download opencv-contrib-python x86 wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 && matrix.platform == 'x86' }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-contrib-python-wheels-x86
-        path: wheelhouse/
-
-    - name: Download opencv-contrib-python x64 wheels
-      if: ${{ matrix.without_gui == 0 && matrix.with_contrib == 1 && matrix.platform == 'x64' }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-contrib-python-wheels-x64
-        path: wheelhouse/
-
-    - name: Download opencv-contrib-python-headless x86 wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 && matrix.platform == 'x86' }}
-      uses: actions/download-artifact@v2
-      with:
-        name: opencv-contrib-python-headless-wheels-x86
-        path: wheelhouse/
-
-    - name: Download opencv-contrib-python-headless x64 wheels
-      if: ${{ matrix.without_gui == 1 && matrix.with_contrib == 1 && matrix.platform == 'x64' }}
+    - name: Download a wheel accordingly to matrix
       uses: actions/download-artifact@v2
       with:
-        name: opencv-contrib-python-headless-wheels-x64
+        name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}-${{ matrix.platform }}
         path: wheelhouse/
 
     - name: Package installation
diff --git a/setup.py b/setup.py
index 331631ea..cef4c93f 100644
--- a/setup.py
+++ b/setup.py
@@ -385,8 +385,8 @@ def _classify_installed_files_override(
         # add lines from the old __init__.py file to the config file
         with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'scripts', '__init__.py'), 'r') as custom_init:
             custom_init_data = custom_init.read()
-        with open('%spython/cv2/config-%s.%s.py'
-        % (cmake_install_dir, sys.version_info[0], sys.version_info[1]), 'w') as opencv_init_config:
+        with open('%spython/cv2/config-%s.py'
+        % (cmake_install_dir, sys.version_info[0]), 'w') as opencv_init_config:
             opencv_init_config.write(custom_init_data)
 
         for package_name, relpaths_re in cls.package_paths_re.items():

From cc12af622b06c2900bc134cf4c3ff7b9a3ee84e1 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Sat, 25 Dec 2021 15:42:39 +0300
Subject: [PATCH 539/566] Updated commits to 4.5.5 release

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 opencv_extra   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/opencv b/opencv
index 4223495e..dad26339 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit 4223495e6cd67011f86b8ecd9be1fa105018f3b1
+Subproject commit dad26339a975b49cfb6c7dbe4bd5276c9dcb36e2
diff --git a/opencv_contrib b/opencv_contrib
index 2bc3e1a1..49e8f123 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 2bc3e1a169afd2675ef68221176f32cc0ea5427a
+Subproject commit 49e8f123ca08e76891856a1ecce491b62d08ba20
diff --git a/opencv_extra b/opencv_extra
index 822ee112..37294e3c 160000
--- a/opencv_extra
+++ b/opencv_extra
@@ -1 +1 @@
-Subproject commit 822ee11240b969e98e20546663bc481a5e7089cc
+Subproject commit 37294e3c876a72c992d4718b9bbfc8346b9e779a

From ec7b7e48ba145484e10f71bad0a804093dacc973 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Sun, 26 Dec 2021 22:02:16 +0300
Subject: [PATCH 540/566] Added openexr build flag

---
 setup.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index cef4c93f..63c66320 100644
--- a/setup.py
+++ b/setup.py
@@ -160,6 +160,7 @@ def main():
             "-DBUILD_PERF_TESTS=OFF",
             "-DBUILD_DOCS=OFF",
             "-DPYTHON3_LIMITED_API=ON",
+            "-DBUILD_OPENEXR=ON",
         ]
         + (
             # If it is not defined 'linker flags: /machine:X86' on Windows x64

From 0a17e6c91b36baf133fbf2546483805d806bd5f2 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Mon, 24 Jan 2022 23:18:32 +0300
Subject: [PATCH 541/566] Updated dependencies to the latest releases (openssl
 and ffmpeg) in a dockerfile, turned on building libpng

---
 docker/manylinux2014/Dockerfile_aarch64 | 12 ++++++------
 docker/manylinux2014/Dockerfile_i686    | 12 ++++++------
 docker/manylinux2014/Dockerfile_x86_64  | 12 ++++++------
 setup.py                                |  1 +
 4 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
index c76ccec4..9a5b0a48 100644
--- a/docker/manylinux2014/Dockerfile_aarch64
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -18,9 +18,9 @@ ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
-    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1g.tar.gz && \
-    tar -xf OpenSSL_1_1_1g.tar.gz && \
-    cd openssl-OpenSSL_1_1_1g && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1m.tar.gz && \
+    tar -xf OpenSSL_1_1_1m.tar.gz && \
+    cd openssl-OpenSSL_1_1_1m && \
     ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" no-pinshared shared zlib && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     # skip installing documentation
@@ -50,9 +50,9 @@ RUN cd ~/ffmpeg_sources && \
     make install
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L https://ffmpeg.org/releases/ffmpeg-4.3.2.tar.bz2 && \
-    tar -xf ffmpeg-4.3.2.tar.bz2 && \
-    cd ffmpeg-4.3.2 && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-4.4.1.tar.bz2 && \
+    tar -xf ffmpeg-4.4.1.tar.bz2 && \
+    cd ffmpeg-4.4.1 && \
     PATH=~/bin:$PATH && \
     PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index 6a60a073..b434f5c0 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -18,9 +18,9 @@ ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
-    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1g.tar.gz && \
-    tar -xf OpenSSL_1_1_1g.tar.gz && \
-    cd openssl-OpenSSL_1_1_1g && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1m.tar.gz && \
+    tar -xf OpenSSL_1_1_1m.tar.gz && \
+    cd openssl-OpenSSL_1_1_1m && \
     # in i686, ./config detects x64 in i686 container without linux32
     # when run from "docker build"
     linux32 ./config --prefix="$HOME/ffmpeg_build" no-pinshared shared zlib && \
@@ -52,9 +52,9 @@ RUN cd ~/ffmpeg_sources && \
     make install
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L https://ffmpeg.org/releases/ffmpeg-4.3.2.tar.bz2 && \
-    tar -xf ffmpeg-4.3.2.tar.bz2 && \
-    cd ffmpeg-4.3.2 && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-4.4.1.tar.bz2 && \
+    tar -xf ffmpeg-4.4.1.tar.bz2 && \
+    cd ffmpeg-4.4.1 && \
     PATH=~/bin:$PATH && \
     PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" linux32 ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index 49622378..f07baf74 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -18,9 +18,9 @@ ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
-    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1g.tar.gz && \
-    tar -xf OpenSSL_1_1_1g.tar.gz && \
-    cd openssl-OpenSSL_1_1_1g && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1m.tar.gz && \
+    tar -xf OpenSSL_1_1_1m.tar.gz && \
+    cd openssl-OpenSSL_1_1_1m && \
     ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" no-pinshared shared zlib && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     # skip installing documentation
@@ -50,9 +50,9 @@ RUN cd ~/ffmpeg_sources && \
     make install
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L https://ffmpeg.org/releases/ffmpeg-4.3.2.tar.bz2 && \
-    tar -xf ffmpeg-4.3.2.tar.bz2 && \
-    cd ffmpeg-4.3.2 && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-4.4.1.tar.bz2 && \
+    tar -xf ffmpeg-4.4.1.tar.bz2 && \
+    cd ffmpeg-4.4.1 && \
     PATH=~/bin:$PATH && \
     PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
diff --git a/setup.py b/setup.py
index 63c66320..5b79e389 100644
--- a/setup.py
+++ b/setup.py
@@ -161,6 +161,7 @@ def main():
             "-DBUILD_DOCS=OFF",
             "-DPYTHON3_LIMITED_API=ON",
             "-DBUILD_OPENEXR=ON",
+            "-DBUILD_PNG=ON",
         ]
         + (
             # If it is not defined 'linker flags: /machine:X86' on Windows x64

From 0066feb17909a5fa2295bb9c376054febc902340 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Tue, 25 Jan 2022 11:32:45 +0300
Subject: [PATCH 542/566] Added versions of dependecies as arguments in
 dockerfiles

---
 docker/manylinux2014/Dockerfile_aarch64 | 47 ++++++++++++---------
 docker/manylinux2014/Dockerfile_i686    | 56 ++++++++++++++-----------
 docker/manylinux2014/Dockerfile_x86_64  | 40 ++++++++++--------
 3 files changed, 82 insertions(+), 61 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
index 9a5b0a48..b380d3ba 100644
--- a/docker/manylinux2014/Dockerfile_aarch64
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -1,26 +1,33 @@
 FROM quay.io/pypa/manylinux2014_aarch64:latest
 
+ARG CCACHE_VERSION=3.7.9
+ARG FFMPEG_VERSION=4.4.1
+ARG NASM_VERSION=2.15.04
+ARG OPENSSL_VERSION=1_1_1m
+ARG QT_VERSION=5.15.0
+ARG YASM_VERSION=1.3.0
+
 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
 
-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 && \
-    tar -xf qt-everywhere-src-5.15.0.tar.xz && \
+RUN curl -O -L https://download.qt.io/official_releases/qt/5.15/${QT_VERSION}/single/qt-everywhere-src-${QT_VERSION}.tar.xz && \
+    tar -xf qt-everywhere-src-${QT_VERSION}.tar.xz && \
     cd qt-everywhere* && \
     export MAKEFLAGS=-j$(nproc) && \
-    ./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 && \
+    ./configure -prefix /opt/Qt${QT_VERSION} -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 && \
     make && \
     make install && \
     cd .. && \
-    rm -rf qt-everywhere-src-5.15.0 && \
-    rm qt-everywhere-src-5.15.0.tar.xz
+    rm -rf qt-everywhere-src-${QT_VERSION} && \
+    rm qt-everywhere-src-${QT_VERSION}.tar.xz
 
-ENV QTDIR /opt/Qt5.15.0
+ENV QTDIR /opt/Qt${QT_VERSION}
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
-    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1m.tar.gz && \
-    tar -xf OpenSSL_1_1_1m.tar.gz && \
-    cd openssl-OpenSSL_1_1_1m && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_${OPENSSL_VERSION}.tar.gz && \
+    tar -xf OpenSSL_${OPENSSL_VERSION}.tar.gz && \
+    cd openssl-OpenSSL_${OPENSSL_VERSION} && \
     ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" no-pinshared shared zlib && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     # skip installing documentation
@@ -28,16 +35,16 @@ RUN mkdir ~/ffmpeg_sources && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.15.04/nasm-2.15.04.tar.bz2 && \
-    tar -xf nasm-2.15.04.tar.bz2 && cd nasm-2.15.04 && ./autogen.sh && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.bz2 && \
+    tar -xf nasm-${NASM_VERSION}.tar.bz2 && cd nasm-${NASM_VERSION} && ./autogen.sh && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
-    tar -xf yasm-1.3.0.tar.gz && \
-    cd yasm-1.3.0 && \
+    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-${YASM_VERSION}.tar.gz && \
+    tar -xf yasm-${YASM_VERSION}.tar.gz && \
+    cd yasm-${YASM_VERSION} && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
@@ -50,9 +57,9 @@ RUN cd ~/ffmpeg_sources && \
     make install
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L https://ffmpeg.org/releases/ffmpeg-4.4.1.tar.bz2 && \
-    tar -xf ffmpeg-4.4.1.tar.bz2 && \
-    cd ffmpeg-4.4.1 && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
+    tar -xf ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
+    cd ffmpeg-${FFMPEG_VERSION} && \
     PATH=~/bin:$PATH && \
     PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
@@ -61,9 +68,9 @@ RUN cd ~/ffmpeg_sources && \
     ldconfig && \
     rm -rf ~/ffmpeg_sources
 
-RUN curl -O -L https://github.com/ccache/ccache/releases/download/v3.7.9/ccache-3.7.9.tar.gz && \
-    tar -xf ccache-3.7.9.tar.gz && \
-    cd ccache-3.7.9 && \
+RUN curl -O -L https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz && \
+    tar -xf ccache-${CCACHE_VERSION}.tar.gz && \
+    cd ccache-${CCACHE_VERSION} && \
     linux32 ./configure && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
diff --git a/docker/manylinux2014/Dockerfile_i686 b/docker/manylinux2014/Dockerfile_i686
index b434f5c0..3b866874 100644
--- a/docker/manylinux2014/Dockerfile_i686
+++ b/docker/manylinux2014/Dockerfile_i686
@@ -1,26 +1,34 @@
 FROM quay.io/pypa/manylinux2014_i686:latest
 
+ARG CCACHE_VERSION=3.7.9
+ARG CMAKE_VERSION=3.17.0
+ARG FFMPEG_VERSION=4.4.1
+ARG NASM_VERSION=2.15.04
+ARG OPENSSL_VERSION=1_1_1m
+ARG QT_VERSION=5.15.0
+ARG YASM_VERSION=1.3.0
+
 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
 
-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 && \
-    tar -xf qt-everywhere-src-5.15.0.tar.xz && \
+RUN curl -O -L https://download.qt.io/official_releases/qt/5.15/${QT_VERSION}/single/qt-everywhere-src-${QT_VERSION}.tar.xz && \
+    tar -xf qt-everywhere-src-${QT_VERSION}.tar.xz && \
     cd qt-everywhere* && \
     export MAKEFLAGS=-j$(nproc) && \
-    ./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 && \
+    ./configure -prefix /opt/Qt${QT_VERSION} -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 && \
     make && \
     make install && \
     cd .. && \
-    rm -rf qt-everywhere-src-5.15.0 && \
-    rm qt-everywhere-src-5.15.0.tar.xz
+    rm -rf qt-everywhere-src-${QT_VERSION} && \
+    rm qt-everywhere-src-${QT_VERSION}.tar.xz
 
-ENV QTDIR /opt/Qt5.15.0
+ENV QTDIR /opt/Qt${QT_VERSION}
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
-    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1m.tar.gz && \
-    tar -xf OpenSSL_1_1_1m.tar.gz && \
-    cd openssl-OpenSSL_1_1_1m && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_${OPENSSL_VERSION}.tar.gz && \
+    tar -xf OpenSSL_${OPENSSL_VERSION}.tar.gz && \
+    cd openssl-OpenSSL_${OPENSSL_VERSION} && \
     # in i686, ./config detects x64 in i686 container without linux32
     # when run from "docker build"
     linux32 ./config --prefix="$HOME/ffmpeg_build" no-pinshared shared zlib && \
@@ -30,16 +38,16 @@ RUN mkdir ~/ffmpeg_sources && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.15.04/nasm-2.15.04.tar.bz2 && \
-    tar -xf nasm-2.15.04.tar.bz2 && cd nasm-2.15.04 && ./autogen.sh && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.bz2 && \
+    tar -xf nasm-${NASM_VERSION}.tar.bz2 && cd nasm-${NASM_VERSION} && ./autogen.sh && \
     linux32 ./configure && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
-    tar -xf yasm-1.3.0.tar.gz && \
-    cd yasm-1.3.0 && \
+    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-${YASM_VERSION}.tar.gz && \
+    tar -xf yasm-${YASM_VERSION}.tar.gz && \
+    cd yasm-${YASM_VERSION} && \
     linux32 ./configure && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
@@ -52,9 +60,9 @@ RUN cd ~/ffmpeg_sources && \
     make install
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L https://ffmpeg.org/releases/ffmpeg-4.4.1.tar.bz2 && \
-    tar -xf ffmpeg-4.4.1.tar.bz2 && \
-    cd ffmpeg-4.4.1 && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
+    tar -xf ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
+    cd ffmpeg-${FFMPEG_VERSION} && \
     PATH=~/bin:$PATH && \
     PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" linux32 ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
@@ -63,22 +71,22 @@ RUN cd ~/ffmpeg_sources && \
     ldconfig && \
     rm -rf ~/ffmpeg_sources
 
-RUN curl -O -L https://github.com/ccache/ccache/releases/download/v3.7.9/ccache-3.7.9.tar.gz && \
-    tar -xf ccache-3.7.9.tar.gz && \
-    cd ccache-3.7.9 && \
+RUN curl -O -L https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz && \
+    tar -xf ccache-${CCACHE_VERSION}.tar.gz && \
+    cd ccache-${CCACHE_VERSION} && \
     linux32 ./configure && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
 
-RUN curl -O -L https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-3.17.0.tar.gz && \
-    tar -xf cmake-3.17.0.tar.gz && \
-    cd cmake-3.17.0 && \
+RUN curl -O -L https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}.tar.gz && \
+    tar -xf cmake-${CMAKE_VERSION}.tar.gz && \
+    cd cmake-${CMAKE_VERSION} && \
     export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \
     ./configure --system-curl && \
     make && \
     make install && \
     cd .. && \
-    rm -rf cmake-3.17.0*
+    rm -rf cmake-${CMAKE_VERSION}*
 
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index f07baf74..fb367c0a 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -1,26 +1,32 @@
 FROM quay.io/pypa/manylinux2014_x86_64:latest
 
+ARG FFMPEG_VERSION=4.4.1
+ARG NASM_VERSION=2.15.04
+ARG OPENSSL_VERSION=1_1_1m
+ARG QT_VERSION=5.15.0
+ARG YASM_VERSION=1.3.0
+
 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
 
-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 && \
-    tar -xf qt-everywhere-src-5.15.0.tar.xz && \
+RUN curl -O -L https://download.qt.io/official_releases/qt/5.15/${QT_VERSION}/single/qt-everywhere-src-${QT_VERSION}.tar.xz && \
+    tar -xf qt-everywhere-src-${QT_VERSION}.tar.xz && \
     cd qt-everywhere* && \
     export MAKEFLAGS=-j$(nproc) && \
-    ./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 && \
+    ./configure -prefix /opt/Qt${QT_VERSION} -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 && \
     make && \
     make install && \
     cd .. && \
-    rm -rf qt-everywhere-src-5.15.0 && \
-    rm qt-everywhere-src-5.15.0.tar.xz
+    rm -rf qt-everywhere-src-${QT_VERSION} && \
+    rm qt-everywhere-src-${QT_VERSION}.tar.xz
 
-ENV QTDIR /opt/Qt5.15.0
+ENV QTDIR /opt/Qt${QT_VERSION}
 ENV PATH "$QTDIR/bin:$PATH"
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
-    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1m.tar.gz && \
-    tar -xf OpenSSL_1_1_1m.tar.gz && \
-    cd openssl-OpenSSL_1_1_1m && \
+    curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_${OPENSSL_VERSION}.tar.gz && \
+    tar -xf OpenSSL_${OPENSSL_VERSION}.tar.gz && \
+    cd openssl-OpenSSL_${OPENSSL_VERSION} && \
     ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" no-pinshared shared zlib && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     # skip installing documentation
@@ -28,16 +34,16 @@ RUN mkdir ~/ffmpeg_sources && \
     rm -rf ~/openssl_build
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.15.04/nasm-2.15.04.tar.bz2 && \
-    tar -xf nasm-2.15.04.tar.bz2 && cd nasm-2.15.04 && ./autogen.sh && \
+    curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.bz2 && \
+    tar -xf nasm-${NASM_VERSION}.tar.bz2 && cd nasm-${NASM_VERSION} && ./autogen.sh && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
-    tar -xf yasm-1.3.0.tar.gz && \
-    cd yasm-1.3.0 && \
+    curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-${YASM_VERSION}.tar.gz && \
+    tar -xf yasm-${YASM_VERSION}.tar.gz && \
+    cd yasm-${YASM_VERSION} && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
@@ -50,9 +56,9 @@ RUN cd ~/ffmpeg_sources && \
     make install
 
 RUN cd ~/ffmpeg_sources && \
-    curl -O -L https://ffmpeg.org/releases/ffmpeg-4.4.1.tar.bz2 && \
-    tar -xf ffmpeg-4.4.1.tar.bz2 && \
-    cd ffmpeg-4.4.1 && \
+    curl -O -L https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
+    tar -xf ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
+    cd ffmpeg-${FFMPEG_VERSION} && \
     PATH=~/bin:$PATH && \
     PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \

From 700cb0095233e104d6c9e96bb45d3d3312015cd1 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Thu, 3 Mar 2022 11:12:51 +0300
Subject: [PATCH 543/566] Defined static version of windows server

---
 .github/workflows/build_wheels_windows.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index 0f697291..cb2beb12 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -21,7 +21,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        os: [windows-latest]
+        os: [windows-2019]
         python-version: ['3.6']
         platform: [x86, x64]
         with_contrib: [0, 1]
@@ -86,7 +86,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        os: [windows-latest]
+        os: [windows-2019]
         python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
         platform: [x86, x64]
         with_contrib: [0, 1]

From 141a763d0e2675476b92e4a15359b19684c68eb2 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Thu, 3 Mar 2022 11:30:02 +0300
Subject: [PATCH 544/566] Updated MSBuild action

---
 .github/workflows/build_wheels_windows.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index cb2beb12..0262c7b8 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -53,7 +53,7 @@ jobs:
         architecture: ${{ matrix.platform }}
 
     - name: Setup MSBuild.exe
-      uses: warrenbuckley/Setup-MSBuild@v1
+      uses: microsoft/setup-msbuild@v1.1
 
     - name: Build a package
       run: |

From 602a8be9e21df225a32827a621f15d7be0e5eebd Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Thu, 3 Mar 2022 14:00:43 +0300
Subject: [PATCH 545/566] Defined ffmpeg version for macos (4.4.1) and fixed
 MacOS build

---
 .github/workflows/build_wheels_macos.yml |  1 +
 travis_config.sh                         | 37 ++++++------------------
 2 files changed, 10 insertions(+), 28 deletions(-)

diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index 87fe6f99..c70f2b2d 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -55,6 +55,7 @@ jobs:
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
       PLAT: x86_64
+      FFMPEG_FORMULA_VERSION: '@4'
       SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
diff --git a/travis_config.sh b/travis_config.sh
index 7bbfec68..dfb656e8 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -50,7 +50,7 @@ if [ -n "$IS_OSX" ]; then
     function generate_ffmpeg_formula {
         local FF="ffmpeg"
         local LFF="ffmpeg_opencv"
-        local FF_FORMULA; FF_FORMULA=$(brew formula "$FF")
+        local FF_FORMULA; FF_FORMULA=$(brew formula "${FF}${FFMPEG_FORMULA_VERSION}")
         local LFF_FORMULA; LFF_FORMULA="$(dirname "$FF_FORMULA")/${LFF}.rb"
 
         local REGENERATE
@@ -70,8 +70,9 @@ if [ -n "$IS_OSX" ]; then
         if [ -n "$REGENERATE" ]; then
             echo "Regenerating custom ffmpeg formula"
             # Bottle block syntax: https://docs.brew.sh/Bottles#bottle-dsl-domain-specific-language
+            # FfmpegAT4 is a class in ffmpeg@4 formula
             perl -wpe 'BEGIN {our ($found_blank, $bottle_block);}
-                if (/(^class )(Ffmpeg)(\s.*)/) {$_=$1.$2."Opencv".$3."\n"; next;}
+                if (/(^class )(FfmpegAT4)(\s.*)/) {$_=$1."FfmpegOpencv".$3."\n"; next;}
                 if (!$found_blank && /^$/) {$_.="conflicts_with \"ffmpeg\"\n\n"; $found_blank=1; next;}
                 if (!$bottle_block && /^\s*bottle do$/) { $bottle_block=1; next; }
                 if ($bottle_block) { if (/^\s*end\s*$/) { $bottle_block=0} elsif (/^\s*sha256\s/) {$_=""} next; }
@@ -111,34 +112,14 @@ function pre_build {
     CACHE_STAGE=
     export HOMEBREW_NO_AUTO_UPDATE=1
 
-    #after the cache stage, all bottles and Homebrew metadata should be already cached locally
-    # if [ -n "$CACHE_STAGE" ]; then
-    #     brew update
-    #     generate_ffmpeg_formula
-    #     brew_add_local_bottles
-    # fi
-
     echo 'Installing FFmpeg'
 
-    # if [ -n "$CACHE_STAGE" ]; then
-    #     brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
-    # else
-        brew update
-        generate_ffmpeg_formula
-        brew_add_local_bottles
-        # brew unlink python@2
-        brew install --build-bottle ffmpeg_opencv
-    # fi
-
-    # echo 'Installing qt5'
-
-    # if [ -n "$CACHE_STAGE" ]; then
-    #    echo "Qt5 has bottle, no caching needed"
-    # else
-    #    brew switch qt 5.13.2
-    #    brew pin qt
-    #    export PATH="/usr/local/opt/qt/bin:$PATH"
-    # fi
+    brew update
+    generate_ffmpeg_formula
+    brew_add_local_bottles
+    brew install --build-bottle ffmpeg_opencv
+    # It needs when we use not the latest ffmpeg formula
+    brew link ffmpeg_opencv
 
     if [ -n "$CACHE_STAGE" ]; then
         brew_go_bootstrap_mode 0

From 9de011e3885dc2a7d4f39f4a5d289857395b3eb8 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Tue, 22 Mar 2022 17:57:51 +0300
Subject: [PATCH 546/566] Added pylint test

---
 .github/workflows/build_wheels_macos.yml    |  5 +++
 .github/workflows/build_wheels_macos_m1.yml |  5 +++
 .github/workflows/build_wheels_windows.yml  |  6 ++++
 tests/pylint.py                             |  3 ++
 travis_config.sh                            | 37 ++++++++++-----------
 5 files changed, 37 insertions(+), 19 deletions(-)
 create mode 100644 tests/pylint.py

diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index c70f2b2d..2e434a5f 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -171,6 +171,11 @@ jobs:
         cd ${{ github.workspace }}/opencv
         python modules/python/test/test.py -v --repo .
 
+    - name: Pylint test
+      run: |
+        python -m pip install pylint
+        python -m pylint ${{ github.workspace }}/tests/pylint.py --extension-pkg-whitelist=cv2 --disable=missing-docstring
+
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
     needs: [build, test]
diff --git a/.github/workflows/build_wheels_macos_m1.yml b/.github/workflows/build_wheels_macos_m1.yml
index 3711e1b3..46ecb631 100644
--- a/.github/workflows/build_wheels_macos_m1.yml
+++ b/.github/workflows/build_wheels_macos_m1.yml
@@ -106,6 +106,11 @@ jobs:
         cd ${{ github.workspace }}/opencv
         arch -arm64 python${{ matrix.python-version }} modules/python/test/test.py -v --repo .
 
+    - name: Pylint test
+      run: |
+        arch -arm64 python${{ matrix.python-version }} -m pip install pylint
+        arch -arm64 python${{ matrix.python-version }} -m pylint ${{ github.workspace }}/tests/pylint.py --extension-pkg-whitelist=cv2 --disable=missing-docstring
+
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
     needs: [build, test]
diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index 0262c7b8..cee1d848 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -130,6 +130,12 @@ jobs:
         python modules\python\test\test.py -v --repo .
       shell: cmd
 
+    - name: Pylint test
+      run: |
+        python -m pip install pylint
+        python -m pylint ${{ github.workspace }}\tests\pylint.py --extension-pkg-whitelist=cv2 --disable=missing-docstring
+      shell: cmd
+
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
     needs: [build-windows-x86_64, test]
diff --git a/tests/pylint.py b/tests/pylint.py
new file mode 100644
index 00000000..d10ad684
--- /dev/null
+++ b/tests/pylint.py
@@ -0,0 +1,3 @@
+from cv2 import getStructuringElement, MORPH_ELLIPSE
+
+a = getStructuringElement(MORPH_ELLIPSE, (3, 3))
diff --git a/travis_config.sh b/travis_config.sh
index dfb656e8..751a1772 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -141,37 +141,36 @@ function run_tests {
 
     PYTHON=python$PYTHON_VERSION
 
-    if [ -n "$IS_OSX" ]; then
-      echo "Running for OS X"
-
-      cd ../tests
-      $PYTHON get_build_info.py
-
-      cd ../opencv/
-      export OPENCV_TEST_DATA_PATH=../opencv_extra/testdata
-    else
-      echo "Running for linux"
-
-      if [ $PYTHON == "python3.6" ]; then
-        $PYTHON -m pip install -U numpy==1.19.4
-      fi
-      cd /io/tests
-      $PYTHON get_build_info.py
+    echo "Running for linux"
 
-      cd /io/opencv
-      export OPENCV_TEST_DATA_PATH=/io/opencv_extra/testdata
+    if [ $PYTHON == "python3.6" ]; then
+      $PYTHON -m pip install -U numpy==1.19.4
     fi
+    cd /io/tests
+    $PYTHON get_build_info.py
+
+    cd /io/opencv
+    export OPENCV_TEST_DATA_PATH=/io/opencv_extra/testdata
 
     test_wheels
+    pylint_test
 }
 
 function test_wheels {
 
-    echo "Starting tests..."
+    echo "Starting OpenCV tests..."
 
     #Test package
     $PYTHON modules/python/test/test.py -v --repo .
 }
 
+function pylint_test {
+
+    echo "Starting Pylint tests..."
+
+    $PYTHON -m pip install pylint
+    $PYTHON -m pylint /io/tests/pylint.py --extension-pkg-whitelist=cv2 --disable=missing-docstring
+}
+
 export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
 set -x

From 1e26c5d08c182fdbb09d73bc97594bab793e79f6 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Wed, 23 Mar 2022 10:38:47 +0300
Subject: [PATCH 547/566] Pinned pylint version

---
 .github/workflows/build_wheels_macos.yml    | 2 +-
 .github/workflows/build_wheels_macos_m1.yml | 2 +-
 .github/workflows/build_wheels_windows.yml  | 2 +-
 travis_config.sh                            | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index 2e434a5f..f22d56e1 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -173,7 +173,7 @@ jobs:
 
     - name: Pylint test
       run: |
-        python -m pip install pylint
+        python -m pip install pylint==2.12.2
         python -m pylint ${{ github.workspace }}/tests/pylint.py --extension-pkg-whitelist=cv2 --disable=missing-docstring
 
   test_release_opencv_python:
diff --git a/.github/workflows/build_wheels_macos_m1.yml b/.github/workflows/build_wheels_macos_m1.yml
index 46ecb631..1f51a342 100644
--- a/.github/workflows/build_wheels_macos_m1.yml
+++ b/.github/workflows/build_wheels_macos_m1.yml
@@ -108,7 +108,7 @@ jobs:
 
     - name: Pylint test
       run: |
-        arch -arm64 python${{ matrix.python-version }} -m pip install pylint
+        arch -arm64 python${{ matrix.python-version }} -m pip install pylint==2.12.2
         arch -arm64 python${{ matrix.python-version }} -m pylint ${{ github.workspace }}/tests/pylint.py --extension-pkg-whitelist=cv2 --disable=missing-docstring
 
   test_release_opencv_python:
diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index cee1d848..bf9f9906 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -132,7 +132,7 @@ jobs:
 
     - name: Pylint test
       run: |
-        python -m pip install pylint
+        python -m pip install pylint==2.12.2
         python -m pylint ${{ github.workspace }}\tests\pylint.py --extension-pkg-whitelist=cv2 --disable=missing-docstring
       shell: cmd
 
diff --git a/travis_config.sh b/travis_config.sh
index 751a1772..db3bf773 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -168,7 +168,7 @@ function pylint_test {
 
     echo "Starting Pylint tests..."
 
-    $PYTHON -m pip install pylint
+    $PYTHON -m pip install pylint==2.12.2
     $PYTHON -m pylint /io/tests/pylint.py --extension-pkg-whitelist=cv2 --disable=missing-docstring
 }
 

From ed16e8ef97a35647aa129f167ade956e4630714f Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Wed, 23 Mar 2022 16:20:07 +0300
Subject: [PATCH 548/566] Changed using custom test for pylint to opencv sample

---
 .github/workflows/build_wheels_linux.yml    |  2 +-
 .github/workflows/build_wheels_macos.yml    |  4 +++-
 .github/workflows/build_wheels_macos_m1.yml |  4 +++-
 .github/workflows/build_wheels_windows.yml  |  4 +++-
 tests/pylint.py                             |  3 ---
 tests/pylintrc                              | 12 ++++++++++++
 travis_config.sh                            |  3 ++-
 7 files changed, 24 insertions(+), 8 deletions(-)
 delete mode 100644 tests/pylint.py
 create mode 100644 tests/pylintrc

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index bd42944c..5ed44e21 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -102,7 +102,7 @@ jobs:
     - name: Checkout
       uses: actions/checkout@v2
       with:
-        submodules: false
+        submodules: true
         fetch-depth: 0
 
     - name: Setup Environment variables
diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index f22d56e1..bccec01f 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -137,6 +137,7 @@ jobs:
       CONFIG_PATH: travis_config.sh
       PLAT: x86_64
       OPENCV_TEST_DATA_PATH: ${{ github.workspace }}/opencv_extra/testdata
+      PYLINT_TEST_FILE: ${{ github.workspace }}/opencv/samples/python/squares.py
 
     steps:
     - name: Checkout
@@ -174,7 +175,8 @@ jobs:
     - name: Pylint test
       run: |
         python -m pip install pylint==2.12.2
-        python -m pylint ${{ github.workspace }}/tests/pylint.py --extension-pkg-whitelist=cv2 --disable=missing-docstring
+        cd ${{ github.workspace }}/tests
+        python -m pylint $PYLINT_TEST_FILE
 
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
diff --git a/.github/workflows/build_wheels_macos_m1.yml b/.github/workflows/build_wheels_macos_m1.yml
index 1f51a342..9f7b0f37 100644
--- a/.github/workflows/build_wheels_macos_m1.yml
+++ b/.github/workflows/build_wheels_macos_m1.yml
@@ -81,6 +81,7 @@ jobs:
 
     env:
       OPENCV_TEST_DATA_PATH: ${{ github.workspace }}/opencv_extra/testdata
+      PYLINT_TEST_FILE: ${{ github.workspace }}/opencv/samples/python/squares.py
 
     steps:
     - name: Checkout
@@ -109,7 +110,8 @@ jobs:
     - name: Pylint test
       run: |
         arch -arm64 python${{ matrix.python-version }} -m pip install pylint==2.12.2
-        arch -arm64 python${{ matrix.python-version }} -m pylint ${{ github.workspace }}/tests/pylint.py --extension-pkg-whitelist=cv2 --disable=missing-docstring
+        cd ${{ github.workspace }}/tests
+        arch -arm64 python${{ matrix.python-version }} -m pylint $PYLINT_TEST_FILE
 
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index bf9f9906..337c77b2 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -96,6 +96,7 @@ jobs:
     env:
       ACTIONS_ALLOW_UNSECURE_COMMANDS: true
       OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata
+      PYLINT_TEST_FILE: ${{ github.workspace }}\opencv\samples\python\squares.py
 
     steps:
     - name: Checkout
@@ -133,7 +134,8 @@ jobs:
     - name: Pylint test
       run: |
         python -m pip install pylint==2.12.2
-        python -m pylint ${{ github.workspace }}\tests\pylint.py --extension-pkg-whitelist=cv2 --disable=missing-docstring
+        cd ${{ github.workspace }}\tests
+        python -m pylint $PYLINT_TEST_FILE
       shell: cmd
 
   test_release_opencv_python:
diff --git a/tests/pylint.py b/tests/pylint.py
deleted file mode 100644
index d10ad684..00000000
--- a/tests/pylint.py
+++ /dev/null
@@ -1,3 +0,0 @@
-from cv2 import getStructuringElement, MORPH_ELLIPSE
-
-a = getStructuringElement(MORPH_ELLIPSE, (3, 3))
diff --git a/tests/pylintrc b/tests/pylintrc
new file mode 100644
index 00000000..a3892018
--- /dev/null
+++ b/tests/pylintrc
@@ -0,0 +1,12 @@
+# Source: opencv/platforms/scripts/pylintrc
+
+[MESSAGES CONTROL]
+
+# Disable all to choose the Tests one by one
+disable=all
+
+# Tests
+enable=bad-indentation,       # Used when an unexpected number of indentation’s tabulations or spaces has been found.
+       mixed-indentation,     # Used when there are some mixed tabs and spaces in a module.
+       unnecessary-semicolon, # Used when a statement is ended by a semi-colon (”;”), which isn’t necessary.
+       unused-variable        # Used when a variable is defined but not used. (Use _var to ignore var).
diff --git a/travis_config.sh b/travis_config.sh
index db3bf773..4560f726 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -169,7 +169,8 @@ function pylint_test {
     echo "Starting Pylint tests..."
 
     $PYTHON -m pip install pylint==2.12.2
-    $PYTHON -m pylint /io/tests/pylint.py --extension-pkg-whitelist=cv2 --disable=missing-docstring
+    cd /io/tests
+    $PYTHON -m pylint /io/opencv/samples/python/squares.py
 }
 
 export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'

From 3a4c30e50438a3f50c28deb80d16b96235dc7bb7 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Thu, 24 Mar 2022 18:17:16 +0300
Subject: [PATCH 549/566] Added pre-downloaded 3rdparty files to source
 packages

---
 .github/workflows/build_wheels_linux.yml |  6 ++++--
 scripts/source-packages-preparation.sh   | 20 ++++++++++++++++++++
 setup.py                                 |  2 ++
 3 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100755 scripts/source-packages-preparation.sh

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index 5ed44e21..3e3e010b 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -171,12 +171,14 @@ jobs:
 
     - name: Build a package
       run: |
+        # Download all 3rdparty files
+        source scripts/source-packages-preparation.sh ${{ github.workspace }}
         set -e
         # Build and package
         set -x
           python -m pip install --upgrade pip
           python -m pip install scikit-build
-          python setup.py sdist
+          python setup.py sdist --formats=xztar
         set +x
         # Install and run tests
         set -x
@@ -186,7 +188,7 @@ jobs:
       uses: actions/upload-artifact@v2
       with:
         name: wheels
-        path: dist/opencv*.tar.gz
+        path: dist/opencv*.tar.xz
 
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
diff --git a/scripts/source-packages-preparation.sh b/scripts/source-packages-preparation.sh
new file mode 100755
index 00000000..be49b5b8
--- /dev/null
+++ b/scripts/source-packages-preparation.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# ${1} variable is a path to repository opencv-python
+
+# Define flags
+if [ "0" == $ENABLE_CONTRIB ]; then
+  git submodule update --init opencv
+  EXTRA_CMAKE_OPTIONS="-DOPENCV_DOWNLOAD_PATH=${1}/opencv/3rdparty"
+else
+  git submodule update --init opencv opencv_contrib
+  EXTRA_CMAKE_OPTIONS="-DOPENCV_DOWNLOAD_PATH=${1}/opencv/3rdparty -DOPENCV_EXTRA_MODULES_PATH=${1}/opencv_contrib/modules"
+fi
+
+# Download 3rdparty files
+cd opencv && \
+mkdir generate && \
+cd generate && \
+cmake $EXTRA_CMAKE_OPTIONS ${1}/opencv && \
+cd ${1} && \
+rm -rf opencv/generate
diff --git a/setup.py b/setup.py
index 5b79e389..c9f09212 100644
--- a/setup.py
+++ b/setup.py
@@ -162,6 +162,8 @@ def main():
             "-DPYTHON3_LIMITED_API=ON",
             "-DBUILD_OPENEXR=ON",
             "-DBUILD_PNG=ON",
+            # To have all 3rdparty files in one place for source packages
+            "-DOPENCV_DOWNLOAD_PATH=%s" % (os.path.join(os.path.dirname(os.path.abspath(__file__)), "opencv", "3rdparty")),
         ]
         + (
             # If it is not defined 'linker flags: /machine:X86' on Windows x64

From 7ba53fc4f48894593bda7493709d542e38e2c36d Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Fri, 25 Mar 2022 11:52:15 +0300
Subject: [PATCH 550/566] Revert changes for pre-downloaded files

---
 .github/workflows/build_wheels_linux.yml |  2 --
 scripts/source-packages-preparation.sh   | 20 --------------------
 setup.py                                 |  2 --
 3 files changed, 24 deletions(-)
 delete mode 100755 scripts/source-packages-preparation.sh

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index 3e3e010b..a368661d 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -171,8 +171,6 @@ jobs:
 
     - name: Build a package
       run: |
-        # Download all 3rdparty files
-        source scripts/source-packages-preparation.sh ${{ github.workspace }}
         set -e
         # Build and package
         set -x
diff --git a/scripts/source-packages-preparation.sh b/scripts/source-packages-preparation.sh
deleted file mode 100755
index be49b5b8..00000000
--- a/scripts/source-packages-preparation.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/bash
-
-# ${1} variable is a path to repository opencv-python
-
-# Define flags
-if [ "0" == $ENABLE_CONTRIB ]; then
-  git submodule update --init opencv
-  EXTRA_CMAKE_OPTIONS="-DOPENCV_DOWNLOAD_PATH=${1}/opencv/3rdparty"
-else
-  git submodule update --init opencv opencv_contrib
-  EXTRA_CMAKE_OPTIONS="-DOPENCV_DOWNLOAD_PATH=${1}/opencv/3rdparty -DOPENCV_EXTRA_MODULES_PATH=${1}/opencv_contrib/modules"
-fi
-
-# Download 3rdparty files
-cd opencv && \
-mkdir generate && \
-cd generate && \
-cmake $EXTRA_CMAKE_OPTIONS ${1}/opencv && \
-cd ${1} && \
-rm -rf opencv/generate
diff --git a/setup.py b/setup.py
index c9f09212..5b79e389 100644
--- a/setup.py
+++ b/setup.py
@@ -162,8 +162,6 @@ def main():
             "-DPYTHON3_LIMITED_API=ON",
             "-DBUILD_OPENEXR=ON",
             "-DBUILD_PNG=ON",
-            # To have all 3rdparty files in one place for source packages
-            "-DOPENCV_DOWNLOAD_PATH=%s" % (os.path.join(os.path.dirname(os.path.abspath(__file__)), "opencv", "3rdparty")),
         ]
         + (
             # If it is not defined 'linker flags: /machine:X86' on Windows x64

From ad010427c7197033532b3f2238b273bb9a5513fb Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Fri, 25 Mar 2022 17:10:44 +0300
Subject: [PATCH 551/566] Skip only gapi if it was not found

---
 setup.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index c9f09212..2fbdc816 100644
--- a/setup.py
+++ b/setup.py
@@ -414,7 +414,8 @@ def _classify_installed_files_override(
                     final_install_relpaths.append(new_install_relpath)
                     del m, fslash_relpath, new_install_relpath
                 else:
-                    if not found:
+                    # gapi can be missed if ADE was not downloaded (network issue)
+                    if not found and "gapi" not in relpath_re:
                         raise Exception("Not found: '%s'" % relpath_re)
                 del r, found
 

From f68be384bb0310f1fdf95351fdffda7bf288b8d1 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Fri, 25 Mar 2022 17:10:44 +0300
Subject: [PATCH 552/566] Skip only gapi if it was not found

---
 setup.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 5b79e389..5784d5a4 100644
--- a/setup.py
+++ b/setup.py
@@ -412,7 +412,8 @@ def _classify_installed_files_override(
                     final_install_relpaths.append(new_install_relpath)
                     del m, fslash_relpath, new_install_relpath
                 else:
-                    if not found:
+                    # gapi can be missed if ADE was not downloaded (network issue)
+                    if not found and "gapi" not in relpath_re:
                         raise Exception("Not found: '%s'" % relpath_re)
                 del r, found
 

From 96cffde198e5bc3411a9577b97021ce59477f97a Mon Sep 17 00:00:00 2001
From: Yclept Nemo <pscjtwjdjtAhnbjm/dpn>
Date: Mon, 21 Mar 2022 15:06:30 -0400
Subject: [PATCH 553/566] Synchronize with scikit-build

scikit-build commit 94089992b353ea3e4b4c2f118ea1987ca54ecbb8:
skbuild/setuptools_wrap.py:_classify_installed_files
    cmake_install_dir -> _cmake_install_dir

This allows tracking scikit-build versions >= 0.13.2. The dependencies
file has been updated.
---
 pyproject.toml | 3 ++-
 setup.py       | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index 6aaab1d3..a47525d5 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,7 @@
 [build-system]
 requires = [
-  "setuptools", "wheel", "scikit-build", "cmake", "pip",
+  "setuptools", "wheel", "cmake", "pip",
+  "scikit-build>=0.13.2",
   "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
   "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
   "numpy==1.17.3; python_version=='3.8' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
diff --git a/setup.py b/setup.py
index 5b79e389..3714e9e3 100644
--- a/setup.py
+++ b/setup.py
@@ -451,7 +451,7 @@ def _classify_installed_files_override(
             data_files,
             # To get around a check that prepends source dir to paths and breaks package detection code.
             cmake_source_dir="",
-            cmake_install_dir=cmake_install_reldir,
+            _cmake_install_dir=cmake_install_reldir,
         )
 
 

From 7419f5820ea9c4d2d816f484f1930f2eca23e9cb Mon Sep 17 00:00:00 2001
From: Niyas Sait <niyas.sait@linaro.org>
Date: Mon, 28 Mar 2022 10:13:56 +0100
Subject: [PATCH 554/566] add support for building windows/arm64 package

---
 setup.py | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/setup.py b/setup.py
index 5784d5a4..b5c5580a 100644
--- a/setup.py
+++ b/setup.py
@@ -60,7 +60,7 @@ def main():
     )
 
     # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
-    x64 = sys.maxsize > 2 ** 32
+    is64 = sys.maxsize > 2 ** 32
 
     package_name = "opencv-python"
 
@@ -88,7 +88,7 @@ def main():
     # Path regexes with forward slashes relative to CMake install dir.
     rearrange_cmake_output_data = {
         "cv2": (
-            [r"bin/opencv_videoio_ffmpeg\d{3}%s\.dll" % ("_64" if x64 else "")]
+            [r"bin/opencv_videoio_ffmpeg\d{3}%s\.dll" % ("_64" if is64 else "")]
             if os.name == "nt"
             else []
         )
@@ -130,7 +130,7 @@ def main():
     files_outside_package_dir = {"cv2": ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"]}
 
     ci_cmake_generator = (
-        ["-G", "Visual Studio 14" + (" Win64" if x64 else "")]
+        ["-G", "Visual Studio 14" + (" Win64" if is64 else "")]
         if os.name == "nt"
         else ["-G", "Unix Makefiles"]
     )
@@ -164,9 +164,15 @@ def main():
             "-DBUILD_PNG=ON",
         ]
         + (
+            # CMake flags for windows/arm64 build
+            ["-DCMAKE_GENERATOR_PLATFORM=ARM64",
+             # Emulated cmake requires following flags to correctly detect
+             # target architecture for windows/arm64 build
+             "-DOPENCV_WORKAROUND_CMAKE_20989=ON",
+             "-DCMAKE_SYSTEM_PROCESSOR=ARM64"]
+            if platform.machine() == "ARM64" and sys.platform == "win32"
             # If it is not defined 'linker flags: /machine:X86' on Windows x64
-            ["-DCMAKE_GENERATOR_PLATFORM=x64"]
-            if x64 and sys.platform == "win32"
+            else ["-DCMAKE_GENERATOR_PLATFORM=x64"] if is64 and sys.platform == "win32"
             else []
           )
         + (
@@ -186,7 +192,7 @@ def main():
                 "-DWITH_MSMF=OFF"
             )  # see: https://github.com/skvark/opencv-python/issues/263
 
-    if sys.platform.startswith("linux") and not x64 and "bdist_wheel" in sys.argv:
+    if sys.platform.startswith("linux") and not is64 and "bdist_wheel" in sys.argv:
         subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
 
     # OS-specific components during CI builds

From 4b068fcba76c2d61a041ed87f7e36b8248b53397 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Thu, 7 Apr 2022 13:34:12 +0300
Subject: [PATCH 555/566] Pinned versions for dependencies

---
 pyproject.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index a47525d5..f237ddbc 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [build-system]
 requires = [
-  "setuptools", "wheel", "cmake", "pip",
+  "setuptools==59.2.0", "wheel==0.37.0", "cmake==3.22.3", "pip",
   "scikit-build>=0.13.2",
   "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
   "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64' and platform_machine != 'arm64'",

From f89dca7a27c9ba9659b0b3091e4f64ac1c9bc13d Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Fri, 8 Apr 2022 10:01:04 +0300
Subject: [PATCH 556/566] Downgraded cmake version

---
 pyproject.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index f237ddbc..ade9bc2d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [build-system]
 requires = [
-  "setuptools==59.2.0", "wheel==0.37.0", "cmake==3.22.3", "pip",
+  "setuptools==59.2.0", "wheel==0.37.0", "cmake>=3.6.3", "pip",
   "scikit-build>=0.13.2",
   "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
   "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64' and platform_machine != 'arm64'",

From 443b747a4ee7ff8d23af221e0361d7f199d5c8ae Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Fri, 8 Apr 2022 10:30:35 +0300
Subject: [PATCH 557/566] Downgraded cmake version to 3.1

---
 pyproject.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index ade9bc2d..ff535e86 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [build-system]
 requires = [
-  "setuptools==59.2.0", "wheel==0.37.0", "cmake>=3.6.3", "pip",
+  "setuptools==59.2.0", "wheel==0.37.0", "cmake>=3.1", "pip",
   "scikit-build>=0.13.2",
   "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
   "numpy==1.14.5; python_version=='3.7' and platform_machine != 'aarch64' and platform_machine != 'arm64'",

From 3ac27ad2f3648e4c750a4c3230171713cd2d1edf Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Tue, 31 May 2022 01:23:49 +0300
Subject: [PATCH 558/566] Updated dependecies for the next release

---
 .github/workflows/build_wheels_linux.yml     |  4 +-
 .github/workflows/build_wheels_linux_arm.yml |  2 +-
 docker/manylinux2014/Dockerfile_aarch64      | 77 +++++++++++++++----
 docker/manylinux2014/Dockerfile_x86_64       | 79 ++++++++++++++++----
 setup.py                                     |  1 -
 travis_config.sh                             |  5 --
 6 files changed, 127 insertions(+), 41 deletions(-)

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index a368661d..fac5ebad 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -39,7 +39,7 @@ jobs:
       MB_ML_VER: 2014
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
+      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014:${PLAT}
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
       PLAT: x86_64
@@ -145,7 +145,7 @@ jobs:
       NP_TEST_DEP: numpy==1.19.4
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
+      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014:${PLAT}
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
       SDIST: ${{ matrix.build_sdist || 0 }}
diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index a97bbc29..c58e0631 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -40,7 +40,7 @@ jobs:
       MB_ML_VER: 2014
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/asenyaev/manylinux2014_${PLAT}
+      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014:${PLAT}
       USE_CCACHE: 0
       UNICODE_WIDTH: 32
       SDIST: ${{ matrix.build_sdist || 0 }}
diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
index b380d3ba..fedf1e98 100644
--- a/docker/manylinux2014/Dockerfile_aarch64
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -2,29 +2,60 @@ FROM quay.io/pypa/manylinux2014_aarch64:latest
 
 ARG CCACHE_VERSION=3.7.9
 ARG FFMPEG_VERSION=4.4.1
+ARG FREETYPE_VERSION=2.12.1
+ARG LIBPNG_VERSION=1.6.37
 ARG NASM_VERSION=2.15.04
-ARG OPENSSL_VERSION=1_1_1m
+ARG OPENSSL_VERSION=1_1_1o
 ARG QT_VERSION=5.15.0
 ARG YASM_VERSION=1.3.0
 
-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
+ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
+
+# epel-release need for aarch64 to get openblas packages
+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 lapack-devel epel-release -y && \
+    yum install openblas-devel -y && \
+    cp /usr/include/lapacke/lapacke*.h /usr/include/ && \
+    curl https://raw.githubusercontent.com/xianyi/OpenBLAS/v0.3.3/cblas.h -o /usr/include/cblas.h && \
+    # libpng will be built from source
+    yum remove libpng -y
+
+RUN mkdir ~/libpng_sources && \
+    cd ~/libpng_sources && \
+    curl -O -L https://download.sourceforge.net/libpng/libpng-${LIBPNG_VERSION}.tar.gz && \
+    tar -xf libpng-${LIBPNG_VERSION}.tar.gz && \
+    cd libpng-${LIBPNG_VERSION} && \
+    ./configure --prefix=/usr/local && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf ~/libpng_sources
+
+RUN mkdir ~/freetype_sources && \
+    cd ~/freetype_sources && \
+    curl -O -L https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VERSION}.tar.gz && \
+    tar -xf freetype-${FREETYPE_VERSION}.tar.gz && \
+    cd freetype-${FREETYPE_VERSION} && \
+    ./configure --prefix="$HOME/ffmpeg_build" --enable-freetype-config && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf ~/freetype_sources
 
 RUN curl -O -L https://download.qt.io/official_releases/qt/5.15/${QT_VERSION}/single/qt-everywhere-src-${QT_VERSION}.tar.xz && \
     tar -xf qt-everywhere-src-${QT_VERSION}.tar.xz && \
-    cd qt-everywhere* && \
+    cd qt-everywhere-src-${QT_VERSION} && \
     export MAKEFLAGS=-j$(nproc) && \
     ./configure -prefix /opt/Qt${QT_VERSION} -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 && \
     make && \
     make install && \
     cd .. && \
-    rm -rf qt-everywhere-src-${QT_VERSION} && \
-    rm qt-everywhere-src-${QT_VERSION}.tar.xz
+    rm -rf qt-everywhere*
 
 ENV QTDIR /opt/Qt${QT_VERSION}
 ENV PATH "$QTDIR/bin:$PATH"
 
-RUN mkdir ~/ffmpeg_sources && \
-    cd ~/ffmpeg_sources && \
+RUN mkdir ~/openssl_sources && \
+    cd ~/openssl_sources && \
     curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_${OPENSSL_VERSION}.tar.gz && \
     tar -xf OpenSSL_${OPENSSL_VERSION}.tar.gz && \
     cd openssl-OpenSSL_${OPENSSL_VERSION} && \
@@ -32,31 +63,40 @@ RUN mkdir ~/ffmpeg_sources && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     # skip installing documentation
     make install_sw && \
-    rm -rf ~/openssl_build
+    cd .. && \
+    rm -rf ~/openssl_build ~/openssl_sources
 
-RUN cd ~/ffmpeg_sources && \
+RUN mkdir ~/nasm_sources && \
+    cd ~/nasm_sources && \
     curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.bz2 && \
     tar -xf nasm-${NASM_VERSION}.tar.bz2 && cd nasm-${NASM_VERSION} && ./autogen.sh && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
-    make install
+    make install && \
+    cd .. && \
+    rm -rf ~/nasm_sources
 
-RUN cd ~/ffmpeg_sources && \
+RUN mkdir ~/yasm_sources && \
+    cd ~/yasm_sources && \
     curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-${YASM_VERSION}.tar.gz && \
     tar -xf yasm-${YASM_VERSION}.tar.gz && \
     cd yasm-${YASM_VERSION} && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
-    make install
+    make install && \
+    cd .. && \
+    rm -rf ~/yasm_sources
 
-RUN cd ~/ffmpeg_sources && \
-    git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
+RUN mkdir ~/libvpx_sources && \
+    cd ~/libvpx_sources && \
+    git clone --depth 1 https://github.com/webmproject/libvpx.git && \
     cd libvpx && \
     ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
 
-RUN cd ~/ffmpeg_sources && \
+RUN mkdir ~/ffmpeg_sources && \
+    cd ~/ffmpeg_sources && \
     curl -O -L https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
     tar -xf ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
     cd ffmpeg-${FFMPEG_VERSION} && \
@@ -66,7 +106,8 @@ RUN cd ~/ffmpeg_sources && \
     make install && \
     echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
     ldconfig && \
-    rm -rf ~/ffmpeg_sources
+    rm -rf ~/ffmpeg_sources && \
+    yum remove bzip2-devel -y
 
 RUN curl -O -L https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz && \
     tar -xf ccache-${CCACHE_VERSION}.tar.gz && \
@@ -75,6 +116,10 @@ RUN curl -O -L https://github.com/ccache/ccache/releases/download/v${CCACHE_VERS
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install
 
+# Git security vulnerability: https://github.blog/2022-04-12-git-security-vulnerability-announced
+RUN mkdir /io && \
+    git config --global --add safe.directory /io
+
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
 ENV PATH "$HOME/bin:$PATH"
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index fb367c0a..13325756 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -1,29 +1,60 @@
 FROM quay.io/pypa/manylinux2014_x86_64:latest
 
 ARG FFMPEG_VERSION=4.4.1
+ARG FREETYPE_VERSION=2.12.1
+ARG LIBPNG_VERSION=1.6.37
 ARG NASM_VERSION=2.15.04
-ARG OPENSSL_VERSION=1_1_1m
+ARG OPENSSL_VERSION=1_1_1o
 ARG QT_VERSION=5.15.0
 ARG YASM_VERSION=1.3.0
 
-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
+ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
+
+# epel-release need for aarch64 to get openblas packages
+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 lapack-devel epel-release -y && \
+    yum install openblas-devel -y && \
+    cp /usr/include/lapacke/lapacke*.h /usr/include/ && \
+    curl https://raw.githubusercontent.com/xianyi/OpenBLAS/v0.3.3/cblas.h -o /usr/include/cblas.h && \
+    # libpng will be built from source
+    yum remove libpng -y
+
+RUN mkdir ~/libpng_sources && \
+    cd ~/libpng_sources && \
+    curl -O -L https://download.sourceforge.net/libpng/libpng-${LIBPNG_VERSION}.tar.gz && \
+    tar -xf libpng-${LIBPNG_VERSION}.tar.gz && \
+    cd libpng-${LIBPNG_VERSION} && \
+    ./configure --prefix=/usr/local && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf ~/libpng_sources
+
+RUN mkdir ~/freetype_sources && \
+    cd ~/freetype_sources && \
+    curl -O -L https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VERSION}.tar.gz && \
+    tar -xf freetype-${FREETYPE_VERSION}.tar.gz && \
+    cd freetype-${FREETYPE_VERSION} && \
+    ./configure --prefix="$HOME/ffmpeg_build" --enable-freetype-config && \
+    make && \
+    make install && \
+    cd .. && \
+    rm -rf ~/freetype_sources
 
 RUN curl -O -L https://download.qt.io/official_releases/qt/5.15/${QT_VERSION}/single/qt-everywhere-src-${QT_VERSION}.tar.xz && \
     tar -xf qt-everywhere-src-${QT_VERSION}.tar.xz && \
-    cd qt-everywhere* && \
+    cd qt-everywhere-src-${QT_VERSION} && \
     export MAKEFLAGS=-j$(nproc) && \
     ./configure -prefix /opt/Qt${QT_VERSION} -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 && \
     make && \
     make install && \
     cd .. && \
-    rm -rf qt-everywhere-src-${QT_VERSION} && \
-    rm qt-everywhere-src-${QT_VERSION}.tar.xz
+    rm -rf qt-everywhere*
 
 ENV QTDIR /opt/Qt${QT_VERSION}
 ENV PATH "$QTDIR/bin:$PATH"
 
-RUN mkdir ~/ffmpeg_sources && \
-    cd ~/ffmpeg_sources && \
+RUN mkdir ~/openssl_sources && \
+    cd ~/openssl_sources && \
     curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_${OPENSSL_VERSION}.tar.gz && \
     tar -xf OpenSSL_${OPENSSL_VERSION}.tar.gz && \
     cd openssl-OpenSSL_${OPENSSL_VERSION} && \
@@ -31,31 +62,42 @@ RUN mkdir ~/ffmpeg_sources && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     # skip installing documentation
     make install_sw && \
-    rm -rf ~/openssl_build
+    cd .. && \
+    rm -rf ~/openssl_build ~/openssl_sources
 
-RUN cd ~/ffmpeg_sources && \
+RUN mkdir ~/nasm_sources && \
+    cd ~/nasm_sources && \
     curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.bz2 && \
     tar -xf nasm-${NASM_VERSION}.tar.bz2 && cd nasm-${NASM_VERSION} && ./autogen.sh && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
-    make install
+    make install && \
+    cd .. && \
+    rm -rf ~/nasm_sources
 
-RUN cd ~/ffmpeg_sources && \
+RUN mkdir ~/yasm_sources && \
+    cd ~/yasm_sources && \
     curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-${YASM_VERSION}.tar.gz && \
     tar -xf yasm-${YASM_VERSION}.tar.gz && \
     cd yasm-${YASM_VERSION} && \
     ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
-    make install
+    make install && \
+    cd .. && \
+    rm -rf ~/yasm_sources
 
-RUN cd ~/ffmpeg_sources && \
+RUN mkdir ~/libvpx_sources && \
+    cd ~/libvpx_sources && \
     git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
     cd libvpx && \
     ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
-    make install
+    make install && \
+    cd .. && \
+    rm -rf ~/libvpx_sources
 
-RUN cd ~/ffmpeg_sources && \
+RUN mkdir ~/ffmpeg_sources && \
+    cd ~/ffmpeg_sources && \
     curl -O -L https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
     tar -xf ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
     cd ffmpeg-${FFMPEG_VERSION} && \
@@ -65,7 +107,12 @@ RUN cd ~/ffmpeg_sources && \
     make install && \
     echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
     ldconfig && \
-    rm -rf ~/ffmpeg_sources
+    rm -rf ~/ffmpeg_sources && \
+    yum remove bzip2-devel -y
+
+# Git security vulnerability: https://github.blog/2022-04-12-git-security-vulnerability-announced
+RUN mkdir /io && \
+    git config --global --add safe.directory /io
 
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/root/ffmpeg_build/lib
diff --git a/setup.py b/setup.py
index 02d991b9..e9255907 100644
--- a/setup.py
+++ b/setup.py
@@ -161,7 +161,6 @@ def main():
             "-DBUILD_DOCS=OFF",
             "-DPYTHON3_LIMITED_API=ON",
             "-DBUILD_OPENEXR=ON",
-            "-DBUILD_PNG=ON",
         ]
         + (
             # If it is not defined 'linker flags: /machine:X86' on Windows x64
diff --git a/travis_config.sh b/travis_config.sh
index 4560f726..366d35ad 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -98,11 +98,6 @@ function pre_build {
 
   if [ -n "$IS_OSX" ]; then
     brew install lapack
-  else
-    # epel-release need for aarch64 to get openblas packages
-    yum install -y lapack-devel epel-release && yum install -y openblas-devel
-    cp /usr/include/lapacke/lapacke*.h /usr/include/
-    curl https://raw.githubusercontent.com/xianyi/OpenBLAS/v0.3.3/cblas.h -o /usr/include/cblas.h
   fi
 
   if [ -n "$IS_OSX" ]; then

From 4f8289d4627a42621303d9fce6f46b630950186e Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Tue, 31 May 2022 10:48:58 +0300
Subject: [PATCH 559/566] Updated dependecies for the next release

---
 docker/manylinux2014/Dockerfile_aarch64 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
index fedf1e98..03889a51 100644
--- a/docker/manylinux2014/Dockerfile_aarch64
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -93,7 +93,9 @@ RUN mkdir ~/libvpx_sources && \
     cd libvpx && \
     ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
-    make install
+    make install && \
+    cd .. && \
+    rm -rf ~/libvpx_sources
 
 RUN mkdir ~/ffmpeg_sources && \
     cd ~/ffmpeg_sources && \
@@ -114,7 +116,9 @@ RUN curl -O -L https://github.com/ccache/ccache/releases/download/v${CCACHE_VERS
     cd ccache-${CCACHE_VERSION} && \
     linux32 ./configure && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
-    make install
+    make install && \
+    cd .. && \
+    rm -rf ccache-${CCACHE_VERSION}.tar.gz
 
 # Git security vulnerability: https://github.blog/2022-04-12-git-security-vulnerability-announced
 RUN mkdir /io && \

From 9ec924e1818c9ee755458cb8ac71fd2475d0153d Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Tue, 31 May 2022 13:31:34 +0300
Subject: [PATCH 560/566] Updated submodules to the latest commits

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 opencv_extra   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/opencv b/opencv
index dad26339..d6151eae 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit dad26339a975b49cfb6c7dbe4bd5276c9dcb36e2
+Subproject commit d6151eae23aebdb3fce524a86026c2753daed685
diff --git a/opencv_contrib b/opencv_contrib
index 49e8f123..84f8ea8e 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 49e8f123ca08e76891856a1ecce491b62d08ba20
+Subproject commit 84f8ea8e99f98d8ab7868dbd29cccb6bdd26fb94
diff --git a/opencv_extra b/opencv_extra
index 37294e3c..c2cf721e 160000
--- a/opencv_extra
+++ b/opencv_extra
@@ -1 +1 @@
-Subproject commit 37294e3c876a72c992d4718b9bbfc8346b9e779a
+Subproject commit c2cf721e3b8ce535900bc0f97a5cd17efb35361e

From df365e5d8ca5cc0b4b29e26fdcc1837a38e8318e Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Tue, 31 May 2022 13:33:43 +0300
Subject: [PATCH 561/566] Check changes on 3.4 branch in PRs

---
 .github/workflows/build_wheels_linux.yml     | 1 +
 .github/workflows/build_wheels_linux_arm.yml | 1 +
 .github/workflows/build_wheels_macos.yml     | 1 +
 .github/workflows/build_wheels_macos_m1.yml  | 1 +
 .github/workflows/build_wheels_windows.yml   | 1 +
 5 files changed, 5 insertions(+)

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index fac5ebad..362001fb 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -4,6 +4,7 @@ on:
   pull_request:
     branches:
       - master
+      - 3.4
     paths-ignore:
       - '.github/workflows/build_wheels_linux_arm.yml'
       - '.github/workflows/build_wheels_windows*'
diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index c58e0631..a892040b 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -4,6 +4,7 @@ on:
   pull_request:
     branches:
       - master
+      - 3.4
     paths-ignore:
       - '.github/workflows/build_wheels_linux.yml'
       - '.github/workflows/build_wheels_windows*'
diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index bccec01f..c453ab85 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -4,6 +4,7 @@ on:
   pull_request:
     branches:
       - master
+      - 3.4
     paths-ignore:
       - '.github/workflows/build_wheels_linux*'
       - '.github/workflows/build_wheels_windows*'
diff --git a/.github/workflows/build_wheels_macos_m1.yml b/.github/workflows/build_wheels_macos_m1.yml
index 9f7b0f37..1ac065f1 100644
--- a/.github/workflows/build_wheels_macos_m1.yml
+++ b/.github/workflows/build_wheels_macos_m1.yml
@@ -4,6 +4,7 @@ on:
   pull_request:
     branches:
       - master
+      - 3.4
     paths-ignore:
       - '.github/workflows/build_wheels_linux*'
       - '.github/workflows/build_wheels_windows*'
diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index 337c77b2..0dad17b5 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -4,6 +4,7 @@ on:
   pull_request:
     branches:
       - master
+      - 3.4
     paths-ignore:
       - '.github/workflows/build_wheels_linux*'
       - '.github/workflows/build_wheels_macos*'

From 5633cf319efadb628e8369b48834d74491c10b1a Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Tue, 31 May 2022 14:09:35 +0300
Subject: [PATCH 562/566] Removed unused lines

---
 setup.py | 15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/setup.py b/setup.py
index 37366d9a..11014d6b 100644
--- a/setup.py
+++ b/setup.py
@@ -374,21 +374,6 @@ def _classify_installed_files_override(
 
         print("Copying files from CMake output")
 
-        # lines for a proper work using pylint and an autocomplete in IDE
-        with open(os.path.join(cmake_install_dir, "python", "cv2", "__init__.py"), 'r') as opencv_init:
-            opencv_init_lines = opencv_init.readlines()
-            extra_imports = ('\nfrom .cv2 import *\nfrom .cv2 import _registerMatType\nfrom . import mat_wrapper\nfrom . import gapi'
-                             '\nfrom . import misc\nfrom . import utils\nfrom . import data\nfrom . import version\n')
-            free_line_after_imports = 6
-            opencv_init_lines.insert(free_line_after_imports, extra_imports)
-            opencv_init_data = ""
-            for line in opencv_init_lines:
-                opencv_init_replacement = line.replace('importlib.import_module("cv2")', 'importlib.import_module("cv2.cv2")')
-                opencv_init_data = opencv_init_data + opencv_init_replacement
-
-        with open(os.path.join(cmake_install_dir, "python", "cv2", "__init__.py"), 'w') as opencv_final_init:
-            opencv_final_init.write(opencv_init_data)
-
         # add lines from the old __init__.py file to the config file
         with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'scripts', '__init__.py'), 'r') as custom_init:
             custom_init_data = custom_init.read()

From 04b1a52ac69811a33db2fb2110a03b2971c110e5 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Mon, 6 Jun 2022 00:48:04 +0300
Subject: [PATCH 563/566] Updated submodules to 4.6.0 release

---
 opencv         | 2 +-
 opencv_contrib | 2 +-
 opencv_extra   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/opencv b/opencv
index d6151eae..b0dc4741 160000
--- a/opencv
+++ b/opencv
@@ -1 +1 @@
-Subproject commit d6151eae23aebdb3fce524a86026c2753daed685
+Subproject commit b0dc474160e389b9c9045da5db49d03ae17c6a6b
diff --git a/opencv_contrib b/opencv_contrib
index 84f8ea8e..db16caf6 160000
--- a/opencv_contrib
+++ b/opencv_contrib
@@ -1 +1 @@
-Subproject commit 84f8ea8e99f98d8ab7868dbd29cccb6bdd26fb94
+Subproject commit db16caf6ceee76b43b94c846be276e92a43e9700
diff --git a/opencv_extra b/opencv_extra
index c2cf721e..936854e2 160000
--- a/opencv_extra
+++ b/opencv_extra
@@ -1 +1 @@
-Subproject commit c2cf721e3b8ce535900bc0f97a5cd17efb35361e
+Subproject commit 936854e2b666853d6d0732a8eabc2d699f4fa3d8

From 8d045058df0245039a8a8754d140a820548dedb8 Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <andrey.senyaev@gmail.com>
Date: Wed, 8 Jun 2022 13:36:57 +0300
Subject: [PATCH 564/566] Changed format of an archive for source packages

---
 .github/workflows/build_wheels_linux.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index 362001fb..5315e161 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -177,7 +177,7 @@ jobs:
         set -x
           python -m pip install --upgrade pip
           python -m pip install scikit-build
-          python setup.py sdist --formats=xztar
+          python setup.py sdist --formats=gztar
         set +x
         # Install and run tests
         set -x
@@ -187,7 +187,7 @@ jobs:
       uses: actions/upload-artifact@v2
       with:
         name: wheels
-        path: dist/opencv*.tar.xz
+        path: dist/opencv*.tar.gz
 
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease

From 54473f17f7c138d4632b003a5e6f736e80481572 Mon Sep 17 00:00:00 2001
From: Andrew Murray <radarhere@users.noreply.github.com>
Date: Fri, 24 Jun 2022 22:09:56 +1000
Subject: [PATCH 565/566] Updated multibuild to upgrade default 64-bit test
 image to focal

---
 .gitmodules | 2 +-
 multibuild  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/.gitmodules b/.gitmodules
index 655467e8..7193d3b9 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -6,7 +6,7 @@
 	url = https://github.com/opencv/opencv_contrib.git
 [submodule "multibuild"]
 	path = multibuild
-	url = https://github.com/matthew-brett/multibuild.git
+	url = https://github.com/multi-build/multibuild.git
 [submodule "opencv_extra"]
 	path = opencv_extra
 	url = https://github.com/opencv/opencv_extra.git
diff --git a/multibuild b/multibuild
index b89bb903..bce1637e 160000
--- a/multibuild
+++ b/multibuild
@@ -1 +1 @@
-Subproject commit b89bb903e94308be79abefa4f436bf123ebb1313
+Subproject commit bce1637e202cb52b0e7ea42baa1cccc894b82806

From 4638ce51fa4ce1b8a8752acdb2320a8b328d275f Mon Sep 17 00:00:00 2001
From: Andrey Senyaev <76472231+asenyaev@users.noreply.github.com>
Date: Mon, 4 Jul 2022 16:08:39 +0300
Subject: [PATCH 566/566] Changed labeles for macOS ARM64 and Linux ARM64
 builds (#681)

* Changed labeles for macOS ARM64 and Linux ARM64 builds

* Changed labeles for macOS ARM64 and Linux ARM64 builds

* Added proper cleanup step for all workflows, removed unused lines, changed ubuntu-latest to ubuntu-20.04

* Updated docker images to work under non-root user, unified cleanup step
---
 .github/workflows/build_wheels_linux.yml     | 53 +++++++-------------
 .github/workflows/build_wheels_linux_arm.yml | 41 ++++-----------
 .github/workflows/build_wheels_macos.yml     | 31 +++---------
 .github/workflows/build_wheels_macos_m1.yml  | 31 ++++--------
 .github/workflows/build_wheels_windows.yml   | 51 +++++++------------
 docker/manylinux2014/Dockerfile_aarch64      | 35 +++++++++----
 docker/manylinux2014/Dockerfile_x86_64       | 45 +++++++++++++----
 7 files changed, 121 insertions(+), 166 deletions(-)

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index 5315e161..98ad3dc8 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -15,21 +15,18 @@ on:
 
 jobs:
   build:
-    runs-on: ${{ matrix.os }}
+    runs-on: ubuntu-20.04
     defaults:
       run:
         shell: bash
-
     strategy:
       fail-fast: false
       matrix:
-        os: [ubuntu-latest]
         python-version: ['3.6']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
         build_sdist: [0]
-
     env:
       ACTIONS_ALLOW_UNSECURE_COMMANDS: true
       REPO_DIR: .
@@ -40,34 +37,32 @@ jobs:
       MB_ML_VER: 2014
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014:${PLAT}
-      USE_CCACHE: 1
+      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014-x86-64:20220628
+      USE_CCACHE: 0
       UNICODE_WIDTH: 32
       PLAT: x86_64
       SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
-
     steps:
+    - name: Cleanup
+      run: find . -mindepth 1 -delete
+      working-directory: ${{ github.workspace }}
     - name: Checkout
       uses: actions/checkout@v2
       with:
         submodules: false
         fetch-depth: 0
-
     - name: Update submodules
       if: github.event_name == 'pull_request'
       run: git submodule update --remote
-
     - name: Build a package
       run: source scripts/build.sh
-
     - name: Saving all wheels
       uses: actions/upload-artifact@v2
       with:
         name: wheels
         path: wheelhouse/opencv*.whl
-
     - name: Saving a wheel accordingly to matrix
       uses: actions/upload-artifact@v2
       with:
@@ -76,21 +71,18 @@ jobs:
 
   test:
     needs: [build]
-    runs-on: ${{ matrix.os }}
+    runs-on: ubuntu-20.04
     defaults:
       run:
         shell: bash
-
     strategy:
       fail-fast: false
       matrix:
-        os: [ubuntu-latest]
         python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
         build_sdist: [0]
-
     env:
       ACTIONS_ALLOW_UNSECURE_COMMANDS: true
       MB_PYTHON_VERSION: ${{ matrix.python-version }}
@@ -98,42 +90,38 @@ jobs:
       NP_TEST_DEP_LATEST: numpy==1.21.2
       CONFIG_PATH: travis_config.sh
       PLAT: x86_64
-
     steps:
+    - name: Cleanup
+      run: find . -mindepth 1 -delete
+      working-directory: ${{ github.workspace }}
     - name: Checkout
       uses: actions/checkout@v2
       with:
         submodules: true
         fetch-depth: 0
-
     - name: Setup Environment variables
       run: if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
-
     - name: Download a wheel accordingly to matrix
       uses: actions/download-artifact@v2
       with:
         name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}
         path: wheelhouse/
-
     - name: Package installation and run tests
       run: source scripts/install.sh
 
   build_sdist:
-    runs-on: ${{ matrix.os }}
+    runs-on: ubuntu-20.04
     defaults:
       run:
         shell: bash
-
     strategy:
       fail-fast: false
       matrix:
-        os: [ubuntu-latest]
         python-version: [3.8]
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
         build_sdist: [1]
-
     env:
       ACTIONS_ALLOW_UNSECURE_COMMANDS: true
       REPO_DIR: .
@@ -146,30 +134,29 @@ jobs:
       NP_TEST_DEP: numpy==1.19.4
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014:${PLAT}
+      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014-x86-64:20220628
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
       SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui || 0 }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib || 0 }}
-
     steps:
+    - name: Cleanup
+      run: find . -mindepth 1 -delete
+      working-directory: ${{ github.workspace }}
     - name: Checkout
       uses: actions/checkout@v2
       with:
         submodules: false
         fetch-depth: 0
-
     - name: Update submodules
       if: github.event_name == 'pull_request'
       run: git submodule update --remote
-
     - name: Set up Python ${{ matrix.python-version }}
       uses: actions/setup-python@v2
       with:
         python-version: ${{ matrix.python-version }}
         architecture: ${{ matrix.platform }}
-
     - name: Build a package
       run: |
         set -e
@@ -182,7 +169,6 @@ jobs:
         # Install and run tests
         set -x
         echo "skipping tests because of sdist"
-
     - name: saving artifacts
       uses: actions/upload-artifact@v2
       with:
@@ -192,7 +178,7 @@ jobs:
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
     needs: [build, build_sdist, test]
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     environment: test-opencv-python-release
     defaults:
       run:
@@ -202,7 +188,6 @@ jobs:
         with:
           name: wheels
           path: wheelhouse/
-
       - name: Upload all wheels
         run: |
           python -m pip install twine
@@ -211,7 +196,7 @@ jobs:
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
     needs: [build, build_sdist, test]
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     environment: opencv-python-release
     defaults:
       run:
@@ -221,22 +206,18 @@ jobs:
         with:
           name: wheels
           path: wheelhouse/
-
       - name: Upload wheels for opencv_python
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-* wheelhouse/opencv-python-[^h]*
-
       - name: Upload wheels for opencv_contrib_python
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-* wheelhouse/opencv-contrib-python-[^h]*
-
       - name: Upload wheels for opencv_python_headless
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-* wheelhouse/opencv-python-headless-*
-
       - name: Upload wheels for opencv_contrib_python_headless
         run: |
           python -m pip install twine
diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index a892040b..4d0c3daf 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -15,21 +15,18 @@ on:
 
 jobs:
   build_arm:
-    runs-on: ${{ matrix.os }}
+    runs-on: opencv-cn-lin-arm64
     defaults:
       run:
         shell: bash
-
     strategy:
       fail-fast: false
       matrix:
-        os: [ARM64]
         python-version: ['3.6']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
         build_sdist: [0]
-
     env:
       ACTIONS_ALLOW_UNSECURE_COMMANDS: true
       REPO_DIR: .
@@ -41,33 +38,30 @@ jobs:
       MB_ML_VER: 2014
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014:${PLAT}
+      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014-aarch64:20220628
       USE_CCACHE: 0
       UNICODE_WIDTH: 32
       SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
-
     steps:
+    - name: UID
+      run: id -u
     - name: Cleanup
-      if: always()
-      uses: AutoModality/action-clean@v1
-
+      run: find . -mindepth 1 -delete
+      working-directory: ${{ github.workspace }}
     - name: Checkout
       uses: actions/checkout@v2
       with:
         submodules: false
         fetch-depth: 0
-
     - name: Build a package
       run: source scripts/build.sh
-
     - name: Saving all wheels
       uses: actions/upload-artifact@v2
       with:
         name: wheels
         path: wheelhouse/opencv*.whl
-
     - name: Saving a wheel accordingly to matrix
       uses: actions/upload-artifact@v2
       with:
@@ -76,21 +70,18 @@ jobs:
 
   test:
     needs: [build_arm]
-    runs-on: ${{ matrix.os }}
+    runs-on: opencv-cn-lin-arm64
     defaults:
       run:
         shell: bash
-
     strategy:
       fail-fast: false
       matrix:
-        os: [ARM64]
         python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
         build_sdist: [0]
-
     env:
       ACTIONS_ALLOW_UNSECURE_COMMANDS: true
       MB_PYTHON_VERSION: ${{ matrix.python-version }}
@@ -100,34 +91,29 @@ jobs:
       CONFIG_PATH: travis_config.sh
       DOCKER_TEST_IMAGE: multibuild/focal_arm64v8
       UNICODE_WIDTH: 32
-
     steps:
     - name: Cleanup
-      if: always()
-      uses: AutoModality/action-clean@v1
-
+      run: find . -mindepth 1 -delete
+      working-directory: ${{ github.workspace }}
     - name: Checkout
       uses: actions/checkout@v2
       with:
         submodules: true
         fetch-depth: 0
-
     - name: Setup Environment variables
       run: if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
-
     - name: Download a wheel accordingly to matrix
       uses: actions/download-artifact@v2
       with:
         name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}
         path: wheelhouse/
-
     - name: Package installation and run tests
       run: source scripts/install.sh
 
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
     needs: [build_arm, test]
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     environment: test-opencv-python-release
     defaults:
       run:
@@ -137,7 +123,6 @@ jobs:
         with:
           name: wheels
           path: wheelhouse/
-
       - name: Upload all wheels
         run: |
           python -m pip install twine
@@ -146,7 +131,7 @@ jobs:
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
     needs: [build_arm, test]
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     environment: opencv-python-release
     defaults:
       run:
@@ -156,22 +141,18 @@ jobs:
         with:
           name: wheels
           path: wheelhouse/
-
       - name: Upload wheels for opencv_python
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-*
-
       - name: Upload wheels for opencv_contrib_python
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-*
-
       - name: Upload wheels for opencv_python_headless
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-*
-
       - name: Upload wheels for opencv_contrib_python_headless
         run: |
           python -m pip install twine
diff --git a/.github/workflows/build_wheels_macos.yml b/.github/workflows/build_wheels_macos.yml
index c453ab85..af892101 100644
--- a/.github/workflows/build_wheels_macos.yml
+++ b/.github/workflows/build_wheels_macos.yml
@@ -19,7 +19,6 @@ jobs:
     defaults:
       run:
         shell: bash
-
     strategy:
       fail-fast: false
       matrix:
@@ -40,7 +39,6 @@ jobs:
             python-version: '3.8'
           - os: macos-11
             python-version: '3.9'
-
     env:
       ACTIONS_ALLOW_UNSECURE_COMMANDS: true
       REPO_DIR: .
@@ -60,18 +58,18 @@ jobs:
       SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
-
     steps:
+    - name: Cleanup
+      run: find . -mindepth 1 -delete
+      working-directory: ${{ github.workspace }}
     - name: Checkout
       uses: actions/checkout@v2
       with:
         submodules: false
         fetch-depth: 0
-
     - name: Update submodules
       if: github.event_name == 'pull_request'
       run: git submodule update --remote
-
     - name: Build a package
       run: |
         set -e
@@ -89,13 +87,11 @@ jobs:
         echo $ENABLE_HEADLESS > headless.enabled
         set -x
         build_wheel $REPO_DIR $PLAT
-
     - name: Saving all wheels
       uses: actions/upload-artifact@v2
       with:
         name: wheels
         path: wheelhouse/opencv*.whl
-
     - name: Saving a wheel accordingly to matrix
       uses: actions/upload-artifact@v2
       with:
@@ -108,7 +104,6 @@ jobs:
     defaults:
       run:
         shell: bash
-
     strategy:
       fail-fast: false
       matrix:
@@ -129,7 +124,6 @@ jobs:
             python-version: '3.8'
           - os: macos-11
             python-version: '3.9'
-
     env:
       ACTIONS_ALLOW_UNSECURE_COMMANDS: true
       MB_PYTHON_VERSION: ${{ matrix.python-version }}
@@ -139,40 +133,36 @@ jobs:
       PLAT: x86_64
       OPENCV_TEST_DATA_PATH: ${{ github.workspace }}/opencv_extra/testdata
       PYLINT_TEST_FILE: ${{ github.workspace }}/opencv/samples/python/squares.py
-
     steps:
+    - name: Cleanup
+      run: find . -mindepth 1 -delete
+      working-directory: ${{ github.workspace }}
     - name: Checkout
       uses: actions/checkout@v2
       with:
         submodules: true
         fetch-depth: 0
-
     - name: Set up Python ${{ matrix.python-version }}
       uses: actions/setup-python@v2
       with:
         python-version: ${{ matrix.python-version }}
         architecture: ${{ matrix.platform }}
-
     - name: Setup Environment variables
       run: if [ "3.10" == "${{ matrix.python-version }}" ]; then echo "TEST_DEPENDS=$(echo $NP_TEST_DEP_LATEST)" >> $GITHUB_ENV; else echo "TEST_DEPENDS=$(echo $NP_TEST_DEP)" >> $GITHUB_ENV; fi
-
     - name: Download a wheel accordingly to matrix
       uses: actions/download-artifact@v2
       with:
         name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}
         path: wheelhouse/
-
     - name: Package installation
       run: |
         python -m pip install wheelhouse/opencv*.whl
         cd ${{ github.workspace }}/tests
         python get_build_info.py
-
     - name: Run tests
       run: |
         cd ${{ github.workspace }}/opencv
         python modules/python/test/test.py -v --repo .
-
     - name: Pylint test
       run: |
         python -m pip install pylint==2.12.2
@@ -182,7 +172,7 @@ jobs:
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
     needs: [build, test]
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     environment: test-opencv-python-release
     defaults:
       run:
@@ -192,7 +182,6 @@ jobs:
         with:
           name: wheels
           path: wheelhouse/
-
       - name: Upload all wheels
         run: |
           python -m pip install twine
@@ -201,7 +190,7 @@ jobs:
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
     needs: [build, test]
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     environment: opencv-python-release
     defaults:
       run:
@@ -211,22 +200,18 @@ jobs:
         with:
           name: wheels
           path: wheelhouse/
-
       - name: Upload wheels for opencv_python
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-*
-
       - name: Upload wheels for opencv_contrib_python
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-*
-
       - name: Upload wheels for opencv_python_headless
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-*
-
       - name: Upload wheels for opencv_contrib_python_headless
         run: |
           python -m pip install twine
diff --git a/.github/workflows/build_wheels_macos_m1.yml b/.github/workflows/build_wheels_macos_m1.yml
index 1ac065f1..a1d7c924 100644
--- a/.github/workflows/build_wheels_macos_m1.yml
+++ b/.github/workflows/build_wheels_macos_m1.yml
@@ -15,35 +15,32 @@ on:
 
 jobs:
   build:
-    runs-on: ${{ matrix.os }}
-
+    runs-on: opencv-cn-mac-arm64
     strategy:
       fail-fast: false
       matrix:
-        os: [macOS-M1]
         python-version: ['3.7']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
         build_sdist: [0]
-
     env:
       CI_BUILD: 1
       SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
-
     steps:
+    - name: Cleanup
+      run: find . -mindepth 1 -delete
+      working-directory: ${{ github.workspace }}
     - name: Checkout
       uses: actions/checkout@v2
       with:
         submodules: false
         fetch-depth: 0
-
     - name: Update submodules
       if: github.event_name == 'pull_request'
       run: git submodule update --remote
-
     - name: Build a package
       run: |
         git submodule update --init multibuild
@@ -53,13 +50,11 @@ jobs:
         arch -arm64 python${{ matrix.python-version }} -m pip install toml && python${{ matrix.python-version }} -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["build-system"]["requires"]))' | python${{ matrix.python-version }} -m pip install -r /dev/stdin
         arch -arm64 python${{ matrix.python-version }} setup.py bdist_wheel --py-limited-api=cp37 --dist-dir=wheelhouse -v
         delocate-wheel ${{ github.workspace }}/wheelhouse/opencv*
-
     - name: Saving all wheels
       uses: actions/upload-artifact@v2
       with:
         name: wheels
         path: wheelhouse/opencv*.whl
-
     - name: Saving a wheel accordingly to matrix
       uses: actions/upload-artifact@v2
       with:
@@ -68,46 +63,41 @@ jobs:
 
   test:
     needs: [build]
-    runs-on: ${{ matrix.os }}
-
+    runs-on: opencv-cn-mac-arm64-tests
     strategy:
       fail-fast: false
       matrix:
-        os: [macOS-M1]
         python-version: ['3.7', '3.8', '3.9', '3.10']
         platform: [x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
         build_sdist: [0]
-
     env:
       OPENCV_TEST_DATA_PATH: ${{ github.workspace }}/opencv_extra/testdata
       PYLINT_TEST_FILE: ${{ github.workspace }}/opencv/samples/python/squares.py
-
     steps:
+    - name: Cleanup
+      run: find . -mindepth 1 -delete
+      working-directory: ${{ github.workspace }}
     - name: Checkout
       uses: actions/checkout@v2
       with:
         submodules: true
         fetch-depth: 0
-
     - name: Download a wheel accordingly to matrix
       uses: actions/download-artifact@v2
       with:
         name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}
         path: wheelhouse/
-
     - name: Package installation
       run: |
         arch -arm64 python${{ matrix.python-version }} -m pip install --user --no-cache --force-reinstall wheelhouse/opencv*.whl
         cd ${{ github.workspace }}/tests
         arch -arm64 python${{ matrix.python-version }} get_build_info.py
-
     - name: Run tests
       run: |
         cd ${{ github.workspace }}/opencv
         arch -arm64 python${{ matrix.python-version }} modules/python/test/test.py -v --repo .
-
     - name: Pylint test
       run: |
         arch -arm64 python${{ matrix.python-version }} -m pip install pylint==2.12.2
@@ -117,7 +107,7 @@ jobs:
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
     needs: [build, test]
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     environment: test-opencv-python-release
     defaults:
       run:
@@ -136,7 +126,7 @@ jobs:
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
     needs: [build, test]
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     environment: opencv-python-release
     defaults:
       run:
@@ -146,7 +136,6 @@ jobs:
         with:
           name: wheels
           path: wheelhouse/
-
       - name: Upload wheels for opencv_python
         run: |
           python -m pip install twine
diff --git a/.github/workflows/build_wheels_windows.yml b/.github/workflows/build_wheels_windows.yml
index 0dad17b5..087efc04 100644
--- a/.github/workflows/build_wheels_windows.yml
+++ b/.github/workflows/build_wheels_windows.yml
@@ -14,48 +14,43 @@ on:
 
 jobs:
   build-windows-x86_64:
-    runs-on: ${{ matrix.os }}
-    defaults:
-      run:
-        shell: powershell
-
+    runs-on: windows-2019
     strategy:
       fail-fast: false
       matrix:
-        os: [windows-2019]
         python-version: ['3.6']
         platform: [x86, x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
         build_sdist: [0]
-
     env:
       ACTIONS_ALLOW_UNSECURE_COMMANDS: true
       SDIST: ${{ matrix.build_sdist || 0 }}
       ENABLE_HEADLESS: ${{ matrix.without_gui }}
       ENABLE_CONTRIB: ${{ matrix.with_contrib }}
       OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata
-
     steps:
+    - name: Cleanup
+      shell: bash
+      run: |
+        rm -rf ./* || true
+        rm -rf ./.??* || true
+      working-directory: ${{ github.workspace }}
     - name: Checkout
       uses: actions/checkout@v2
       with:
         submodules: false
         fetch-depth: 0
-
     - name: Update submodules
       if: github.event_name == 'pull_request'
       run: git submodule update --remote
-
     - name: Set up Python ${{ matrix.python-version }}
       uses: actions/setup-python@v2
       with:
         python-version: ${{ matrix.python-version }}
         architecture: ${{ matrix.platform }}
-
     - name: Setup MSBuild.exe
       uses: microsoft/setup-msbuild@v1.1
-
     - name: Build a package
       run: |
         python --version
@@ -64,13 +59,11 @@ jobs:
         python -m pip install toml && python -c "import toml; c = toml.load('pyproject.toml'); print('\n'.join(c['build-system']['requires']))" >> requirements.txt | python -m pip install -r requirements.txt
         set "CI_BUILD=1" && python setup.py bdist_wheel --py-limited-api=cp36 --dist-dir=%cd%\wheelhouse -v
       shell: cmd
-
     - name: Saving all wheels
       uses: actions/upload-artifact@v2
       with:
         name: wheels
         path: wheelhouse/opencv*.whl
-
     - name: Saving a wheel accordingly to matrix
       uses: actions/upload-artifact@v2
       with:
@@ -79,45 +72,44 @@ jobs:
 
   test:
     needs: [build-windows-x86_64]
-    runs-on: ${{ matrix.os }}
+    runs-on: windows-2019
     defaults:
       run:
-        shell: powershell
-
+        shell: cmd
     strategy:
       fail-fast: false
       matrix:
-        os: [windows-2019]
         python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
         platform: [x86, x64]
         with_contrib: [0, 1]
         without_gui: [0, 1]
         build_sdist: [0]
-
     env:
       ACTIONS_ALLOW_UNSECURE_COMMANDS: true
       OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata
       PYLINT_TEST_FILE: ${{ github.workspace }}\opencv\samples\python\squares.py
-
     steps:
+    - name: Cleanup
+      shell: bash
+      run: |
+        rm -rf ./* || true
+        rm -rf ./.??* || true
+      working-directory: ${{ github.workspace }}
     - name: Checkout
       uses: actions/checkout@v2
       with:
         submodules: true
         fetch-depth: 0
-
     - name: Set up Python ${{ matrix.python-version }}
       uses: actions/setup-python@v2
       with:
         python-version: ${{ matrix.python-version }}
         architecture: ${{ matrix.platform }}
-
     - name: Download a wheel accordingly to matrix
       uses: actions/download-artifact@v2
       with:
         name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}-${{ matrix.platform }}
         path: wheelhouse/
-
     - name: Package installation
       run: |
         cd ${{ github.workspace }}/tests
@@ -125,24 +117,20 @@ jobs:
         if ($LastExitCode -ne 0) {throw $LastExitCode}
         python get_build_info.py
       shell: powershell
-
     - name: Run tests
       run: |
         cd ${{ github.workspace }}/opencv
         python modules\python\test\test.py -v --repo .
-      shell: cmd
-
     - name: Pylint test
       run: |
         python -m pip install pylint==2.12.2
         cd ${{ github.workspace }}\tests
         python -m pylint $PYLINT_TEST_FILE
-      shell: cmd
 
   test_release_opencv_python:
     if: github.event_name == 'release' && github.event.release.prerelease
     needs: [build-windows-x86_64, test]
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     environment: test-opencv-python-release
     defaults:
       run:
@@ -152,7 +140,6 @@ jobs:
         with:
           name: wheels
           path: wheelhouse/
-
       - name: Upload all wheels
         run: |
           python -m pip install twine
@@ -161,7 +148,7 @@ jobs:
   release_opencv_python:
     if: github.event_name == 'release' && !github.event.release.prerelease
     needs: [build-windows-x86_64, test]
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     environment: opencv-python-release
     defaults:
       run:
@@ -171,22 +158,18 @@ jobs:
         with:
           name: wheels
           path: wheelhouse/
-
       - name: Upload wheels for opencv_python
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-*
-
       - name: Upload wheels for opencv_contrib_python
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-*
-
       - name: Upload wheels for opencv_python_headless
         run: |
           python -m pip install twine
           python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-*
-
       - name: Upload wheels for opencv_contrib_python_headless
         run: |
           python -m pip install twine
diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
index 03889a51..2679cbbf 100644
--- a/docker/manylinux2014/Dockerfile_aarch64
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -1,3 +1,6 @@
+# Version: 20220628
+# Image name: quay.io/opencv-ci/opencv-python-manylinux2014-aarch64
+
 FROM quay.io/pypa/manylinux2014_aarch64:latest
 
 ARG CCACHE_VERSION=3.7.9
@@ -35,7 +38,7 @@ RUN mkdir ~/freetype_sources && \
     curl -O -L https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VERSION}.tar.gz && \
     tar -xf freetype-${FREETYPE_VERSION}.tar.gz && \
     cd freetype-${FREETYPE_VERSION} && \
-    ./configure --prefix="$HOME/ffmpeg_build" --enable-freetype-config && \
+    ./configure --prefix="/ffmpeg_build" --enable-freetype-config && \
     make && \
     make install && \
     cd .. && \
@@ -59,7 +62,7 @@ RUN mkdir ~/openssl_sources && \
     curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_${OPENSSL_VERSION}.tar.gz && \
     tar -xf OpenSSL_${OPENSSL_VERSION}.tar.gz && \
     cd openssl-OpenSSL_${OPENSSL_VERSION} && \
-    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" no-pinshared shared zlib && \
+    ./config --prefix="/ffmpeg_build" --openssldir="/ffmpeg_build" no-pinshared shared zlib && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     # skip installing documentation
     make install_sw && \
@@ -70,7 +73,7 @@ RUN mkdir ~/nasm_sources && \
     cd ~/nasm_sources && \
     curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.bz2 && \
     tar -xf nasm-${NASM_VERSION}.tar.bz2 && cd nasm-${NASM_VERSION} && ./autogen.sh && \
-    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    ./configure --prefix="/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install && \
     cd .. && \
@@ -81,7 +84,7 @@ RUN mkdir ~/yasm_sources && \
     curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-${YASM_VERSION}.tar.gz && \
     tar -xf yasm-${YASM_VERSION}.tar.gz && \
     cd yasm-${YASM_VERSION} && \
-    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    ./configure --prefix="/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install && \
     cd .. && \
@@ -91,7 +94,7 @@ RUN mkdir ~/libvpx_sources && \
     cd ~/libvpx_sources && \
     git clone --depth 1 https://github.com/webmproject/libvpx.git && \
     cd libvpx && \
-    ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
+    ./configure --prefix="/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install && \
     cd .. && \
@@ -103,10 +106,10 @@ RUN mkdir ~/ffmpeg_sources && \
     tar -xf ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
     cd ffmpeg-${FFMPEG_VERSION} && \
     PATH=~/bin:$PATH && \
-    PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+    PKG_CONFIG_PATH="/ffmpeg_build/lib/pkgconfig" ./configure --prefix="/ffmpeg_build" --extra-cflags="-I/ffmpeg_build/include" --extra-ldflags="-L/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install && \
-    echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
+    echo "/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
     ldconfig && \
     rm -rf ~/ffmpeg_sources && \
     yum remove bzip2-devel -y
@@ -120,10 +123,20 @@ RUN curl -O -L https://github.com/ccache/ccache/releases/download/v${CCACHE_VERS
     cd .. && \
     rm -rf ccache-${CCACHE_VERSION}.tar.gz
 
+# Self-hosted runner UID is 1004
+RUN useradd ci -m -s /bin/bash -G users --uid=1004 && \
+    mkdir /io && \
+    chown -R ci:ci /io && \
+    # This needs to find ffmpeg packages from ci user
+    chown -R ci:ci /ffmpeg_build && \
+    # This calls in mutlibuild scripts and cannot be run without permissions
+    chown -R ci:ci /opt/_internal/pipx/venvs/auditwheel
+
+USER ci
+
 # Git security vulnerability: https://github.blog/2022-04-12-git-security-vulnerability-announced
-RUN mkdir /io && \
-    git config --global --add safe.directory /io
+RUN git config --global --add safe.directory /io
 
-ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
-ENV LDFLAGS -L/root/ffmpeg_build/lib
+ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/ffmpeg_build/lib/pkgconfig
+ENV LDFLAGS -L/ffmpeg_build/lib
 ENV PATH "$HOME/bin:$PATH"
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index 13325756..8bb77341 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -1,5 +1,9 @@
+# Version: 20220628
+# Image name: quay.io/opencv-ci/opencv-python-manylinux2014-x86-64
+
 FROM quay.io/pypa/manylinux2014_x86_64:latest
 
+ARG CCACHE_VERSION=3.7.9
 ARG FFMPEG_VERSION=4.4.1
 ARG FREETYPE_VERSION=2.12.1
 ARG LIBPNG_VERSION=1.6.37
@@ -34,7 +38,7 @@ RUN mkdir ~/freetype_sources && \
     curl -O -L https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VERSION}.tar.gz && \
     tar -xf freetype-${FREETYPE_VERSION}.tar.gz && \
     cd freetype-${FREETYPE_VERSION} && \
-    ./configure --prefix="$HOME/ffmpeg_build" --enable-freetype-config && \
+    ./configure --prefix="/ffmpeg_build" --enable-freetype-config && \
     make && \
     make install && \
     cd .. && \
@@ -58,7 +62,7 @@ RUN mkdir ~/openssl_sources && \
     curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_${OPENSSL_VERSION}.tar.gz && \
     tar -xf OpenSSL_${OPENSSL_VERSION}.tar.gz && \
     cd openssl-OpenSSL_${OPENSSL_VERSION} && \
-    ./config --prefix="$HOME/ffmpeg_build" --openssldir="$HOME/ffmpeg_build" no-pinshared shared zlib && \
+    ./config --prefix="/ffmpeg_build" --openssldir="/ffmpeg_build" no-pinshared shared zlib && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     # skip installing documentation
     make install_sw && \
@@ -69,7 +73,7 @@ RUN mkdir ~/nasm_sources && \
     cd ~/nasm_sources && \
     curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.bz2 && \
     tar -xf nasm-${NASM_VERSION}.tar.bz2 && cd nasm-${NASM_VERSION} && ./autogen.sh && \
-    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    ./configure --prefix="/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install && \
     cd .. && \
@@ -80,7 +84,7 @@ RUN mkdir ~/yasm_sources && \
     curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-${YASM_VERSION}.tar.gz && \
     tar -xf yasm-${YASM_VERSION}.tar.gz && \
     cd yasm-${YASM_VERSION} && \
-    ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
+    ./configure --prefix="/ffmpeg_build" --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install && \
     cd .. && \
@@ -90,7 +94,7 @@ RUN mkdir ~/libvpx_sources && \
     cd ~/libvpx_sources && \
     git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
     cd libvpx && \
-    ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
+    ./configure --prefix="/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install && \
     cd .. && \
@@ -102,18 +106,37 @@ RUN mkdir ~/ffmpeg_sources && \
     tar -xf ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
     cd ffmpeg-${FFMPEG_VERSION} && \
     PATH=~/bin:$PATH && \
-    PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
+    PKG_CONFIG_PATH="/ffmpeg_build/lib/pkgconfig" ./configure --prefix="/ffmpeg_build" --extra-cflags="-I/ffmpeg_build/include" --extra-ldflags="-L/ffmpeg_build/lib" --enable-openssl --enable-libvpx --enable-shared --enable-pic --bindir="$HOME/bin" && \
     make -j$(getconf _NPROCESSORS_ONLN) && \
     make install && \
-    echo "/root/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
+    echo "/ffmpeg_build/lib/" >> /etc/ld.so.conf && \
     ldconfig && \
     rm -rf ~/ffmpeg_sources && \
     yum remove bzip2-devel -y
 
+RUN curl -O -L https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz && \
+    tar -xf ccache-${CCACHE_VERSION}.tar.gz && \
+    cd ccache-${CCACHE_VERSION} && \
+    ./configure && \
+    make -j$(getconf _NPROCESSORS_ONLN) && \
+    make install && \
+    cd .. && \
+    rm -rf ccache-${CCACHE_VERSION}.tar.gz
+
+# GitHub Actions user`s UID is 1001
+RUN useradd ci -m -s /bin/bash -G users --uid=1001 && \
+    mkdir /io && \
+    chown -R ci:ci /io && \
+    # This needs to find ffmpeg packages from ci user
+    chown -R ci:ci /ffmpeg_build && \
+    # This calls in mutlibuild scripts and cannot be run without permissions
+    chown -R ci:ci /opt/_internal/pipx/venvs/auditwheel
+
+USER ci
+
 # Git security vulnerability: https://github.blog/2022-04-12-git-security-vulnerability-announced
-RUN mkdir /io && \
-    git config --global --add safe.directory /io
+RUN git config --global --add safe.directory /io
 
-ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/root/ffmpeg_build/lib/pkgconfig
-ENV LDFLAGS -L/root/ffmpeg_build/lib
+ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/ffmpeg_build/lib/pkgconfig
+ENV LDFLAGS -L/ffmpeg_build/lib
 ENV PATH "$HOME/bin:$PATH"