From 6a1f61b8d7e413059dbf0b9e897579c8305c327f Mon Sep 17 00:00:00 2001 From: Andrey Senyaev Date: Fri, 15 Oct 2021 19:35:51 +0300 Subject: [PATCH 1/3] 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 Date: Fri, 15 Oct 2021 20:39:09 +0300 Subject: [PATCH 2/3] 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 851182fbb01f1655fe5ca4da9ca24b917765758a Mon Sep 17 00:00:00 2001 From: Andrey Senyaev Date: Mon, 18 Oct 2021 17:38:58 +0300 Subject: [PATCH 3/3] 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():