Skip to content

Commit a0f47e9

Browse files
authored
Merge pull request #563 from asenyaev/asen/python_loader_support
Updated submodules to the release 4.5.4 and added python loader support
2 parents 85b9bc5 + 851182f commit a0f47e9

File tree

7 files changed

+69
-44
lines changed

7 files changed

+69
-44
lines changed

cv2/__init__.py

-31
Original file line numberDiff line numberDiff line change
@@ -1,31 +0,0 @@
1-
import importlib
2-
import os
3-
import sys
4-
5-
from .cv2 import *
6-
from .data import *
7-
8-
# wildcard import above does not import "private" variables like __version__
9-
# this makes them available
10-
globals().update(importlib.import_module("cv2.cv2").__dict__)
11-
12-
ci_and_not_headless = False
13-
14-
try:
15-
from .version import ci_build, headless
16-
17-
ci_and_not_headless = ci_build and not headless
18-
except:
19-
pass
20-
21-
# the Qt plugin is included currently only in the pre-built wheels
22-
if sys.platform.startswith("linux") and ci_and_not_headless:
23-
os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.path.join(
24-
os.path.dirname(os.path.abspath(__file__)), "qt", "plugins"
25-
)
26-
27-
# Qt will throw warning on Linux if fonts are not found
28-
if sys.platform.startswith("linux") and ci_and_not_headless:
29-
os.environ["QT_QPA_FONTDIR"] = os.path.join(
30-
os.path.dirname(os.path.abspath(__file__)), "qt", "fonts"
31-
)

opencv

Submodule opencv updated 449 files

opencv_contrib

Submodule opencv_contrib updated 123 files

opencv_extra

Submodule opencv_extra updated 232 files

patches/patchQtPlugins

+13-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@ index 4c0b3880fc..dffa0a4caa 100644
33
--- a/opencv/CMakeLists.txt
44
+++ b/opencv/CMakeLists.txt
55
@@ -1187,6 +1187,13 @@ if(WITH_QT OR HAVE_QT)
6-
if(HAVE_QT5)
7-
status(" QT:" "YES (ver ${Qt5Core_VERSION_STRING})")
8-
status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt5OpenGL_LIBRARIES} ${Qt5OpenGL_VERSION_STRING})" ELSE NO)
6+
if(HAVE_QT)
7+
status(" QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
98
+ if(APPLE)
109
+ install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
1110
+ endif()
1211
+ if(UNIX AND NOT APPLE)
1312
+ install(DIRECTORY /opt/Qt5.15.0/plugins DESTINATION lib/qt)
1413
+ install(DIRECTORY /usr/share/fonts DESTINATION lib/qt)
1514
+ endif()
16-
elseif(HAVE_QT)
17-
status(" QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
18-
status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)
15+
if(HAVE_QT_OPENGL)
16+
if(Qt${QT_VERSION_MAJOR}OpenGL_LIBRARIES)
17+
status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt${QT_VERSION_MAJOR}OpenGL_LIBRARIES} ${Qt${QT_VERSION_MAJOR}OpenGL_VERSION_STRING})" ELSE NO)
18+
else()
19+
status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)
20+
endif()
21+
else()
22+
status(" QT OpenGL support:" "NO")
23+
endif()
24+
else()
25+
status(" QT:" "NO")

scripts/__init__.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
PYTHON_EXTENSIONS_PATHS = [
2+
LOADER_DIR
3+
] + PYTHON_EXTENSIONS_PATHS
4+
5+
ci_and_not_headless = False
6+
7+
try:
8+
from .version import ci_build, headless
9+
10+
ci_and_not_headless = ci_build and not headless
11+
except:
12+
pass
13+
14+
# the Qt plugin is included currently only in the pre-built wheels
15+
if sys.platform.startswith("linux") and ci_and_not_headless:
16+
os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.path.join(
17+
os.path.dirname(os.path.abspath(__file__)), "qt", "plugins"
18+
)
19+
20+
# Qt will throw warning on Linux if fonts are not found
21+
if sys.platform.startswith("linux") and ci_and_not_headless:
22+
os.environ["QT_QPA_FONTDIR"] = os.path.join(
23+
os.path.dirname(os.path.abspath(__file__)), "qt", "fonts"
24+
)

setup.py

+29-4
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,32 @@ def main():
108108
# Naming conventions vary so widely between versions and OSes
109109
# had to give up on checking them.
110110
[
111-
"python/cv2[^/]*%(ext)s"
112-
% {"ext": re.escape(sysconfig.get_config_var("EXT_SUFFIX"))}
111+
"python/cv2/python-%s.%s/cv2[^/]*%s"
112+
% (sys.version_info[0], sys.version_info[1], re.escape(sysconfig.get_config_var("EXT_SUFFIX")))
113+
]
114+
+
115+
[
116+
r"python/cv2/__init__.py"
117+
]
118+
+
119+
[
120+
r"python/cv2/.*config.*.py"
113121
],
114122
"cv2.data": [ # OPENCV_OTHER_INSTALL_PATH
115123
("etc" if os.name == "nt" else "share/opencv4") + r"/haarcascades/.*\.xml"
116124
],
125+
"cv2.gapi": [
126+
"python/cv2" + r"/gapi/.*\.py"
127+
],
128+
"cv2.mat_wrapper": [
129+
"python/cv2" + r"/mat_wrapper/.*\.py"
130+
],
131+
"cv2.misc": [
132+
"python/cv2" + r"/misc/.*\.py"
133+
],
134+
"cv2.utils": [
135+
"python/cv2" + r"/utils/.*\.py"
136+
],
117137
}
118138

119139
# Files in sourcetree outside package dir that should be copied to package.
@@ -137,8 +157,6 @@ def main():
137157
"-DBUILD_opencv_python2=OFF",
138158
# Disable the Java build by default as it is not needed
139159
"-DBUILD_opencv_java=%s" % build_java,
140-
# When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
141-
"-DOPENCV_SKIP_PYTHON_LOADER=ON",
142160
# Relative dir to install the built module to in the build tree.
143161
# The default is generated from sysconfig, we'd rather have a constant for simplicity
144162
"-DOPENCV_PYTHON3_INSTALL_PATH=python",
@@ -358,6 +376,13 @@ def _classify_installed_files_override(
358376

359377
print("Copying files from CMake output")
360378

379+
# add lines from the old __init__.py file to the config file
380+
with open('scripts/__init__.py', 'r') as custom_init:
381+
custom_init_data = custom_init.read()
382+
with open('%spython/cv2/config-%s.%s.py'
383+
% (cmake_install_dir, sys.version_info[0], sys.version_info[1]), 'w') as opencv_init_config:
384+
opencv_init_config.write(custom_init_data)
385+
361386
for package_name, relpaths_re in cls.package_paths_re.items():
362387
package_dest_reldir = package_name.replace(".", os.path.sep)
363388
for relpath_re in relpaths_re:

0 commit comments

Comments
 (0)