From 1a3523d2d85233e1e57bf5aa27b1d35882fb6c90 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 13 Jul 2023 16:07:10 +0300 Subject: [PATCH] Drop Python2 support. --- .github/workflows/arm64-build-checks.yml | 6 +--- CMakeLists.txt | 13 -------- cmake/OpenCVDetectPython.cmake | 23 +------------- cmake/OpenCVMinDepVersions.cmake | 1 - cmake/OpenCVModule.cmake | 1 - .../vars/OPENCV_DISABLE_THREAD_SUPPORT.cmake | 1 - doc/pattern_tools/test_charuco_board.py | 2 -- .../py_2d_histogram/py_2d_histogram.markdown | 2 +- .../py_histogram_begins.markdown | 2 +- .../py_setup_in_fedora.markdown | 3 ++ .../py_setup_in_ubuntu.markdown | 12 -------- .../py_setup_in_windows.markdown | 3 ++ .../config_reference.markdown | 1 - .../macos_install/macos_install.markdown | 2 -- modules/python/CMakeLists.txt | 10 ------- modules/python/python2/CMakeLists.txt | 15 ---------- modules/ts/misc/chart.py | 1 - modules/ts/misc/perf_tests_timing.py | 1 - modules/ts/misc/report.py | 1 - modules/ts/misc/run_long.py | 1 - modules/ts/misc/run_suite.py | 6 ++-- modules/ts/misc/run_utils.py | 8 +---- modules/ts/misc/summary.py | 1 - modules/ts/misc/table_formatter.py | 10 +------ modules/ts/misc/testlog_parser.py | 13 ++++---- modules/ts/misc/trace_profiler.py | 12 -------- modules/ts/misc/xls-report.py | 2 -- platforms/apple/cv_build_utils.py | 2 +- platforms/js/build_js.py | 1 - platforms/wince/readme.md | 1 - platforms/winpack_dldt/build_package.py | 1 - samples/_winpack_run_python_sample.cmd | 8 ++--- samples/dnn/download_models.py | 7 ++--- samples/dnn/object_detection.py | 5 +--- samples/python/browse.py | 10 +------ samples/python/camshift.py | 10 +------ samples/python/coherence.py | 10 +------ samples/python/common.py | 19 ++---------- samples/python/contours.py | 12 ++------ samples/python/demo.py | 30 +++++-------------- samples/python/digits_adjust.py | 14 ++------- samples/python/fitline.py | 15 ++-------- samples/python/gaussian_mix.py | 10 +------ samples/python/kalman.py | 8 +---- samples/python/lappyr.py | 14 ++------- samples/python/morphology.py | 23 +++----------- samples/python/mosse.py | 10 +------ samples/python/plane_tracker.py | 10 +------ samples/python/qrcode.py | 10 ------- samples/python/squares.py | 12 ++------ samples/python/turing.py | 14 ++------- 51 files changed, 65 insertions(+), 344 deletions(-) delete mode 100644 modules/python/python2/CMakeLists.txt diff --git a/.github/workflows/arm64-build-checks.yml b/.github/workflows/arm64-build-checks.yml index e0d374ea77..b7420e6ae5 100644 --- a/.github/workflows/arm64-build-checks.yml +++ b/.github/workflows/arm64-build-checks.yml @@ -21,7 +21,6 @@ jobs: crossbuild-essential-arm64 \ git \ cmake \ - libpython-dev:arm64 \ libpython3-dev:arm64 \ python-numpy \ python3-numpy @@ -34,10 +33,7 @@ jobs: run: | mkdir build cd build - cmake -DPYTHON2_INCLUDE_PATH=/usr/include/python2.7/ \ - -DPYTHON2_LIBRARIES=/usr/lib/aarch64-linux-gnu/libpython2.7.so \ - -DPYTHON2_NUMPY_INCLUDE_DIRS=/usr/lib/python2.7/dist-packages/numpy/core/include \ - -DPYTHON3_INCLUDE_PATH=/usr/include/python3.6m/ \ + cmake -DPYTHON3_INCLUDE_PATH=/usr/include/python3.6m/ \ -DPYTHON3_LIBRARIES=/usr/lib/aarch64-linux-gnu/libpython3.6m.so \ -DPYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include \ -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 76eb4c493a..24e8fee7c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1778,19 +1778,6 @@ if(WITH_CANN) endif() # ========================== python ========================== -if(BUILD_opencv_python2) - status("") - status(" Python 2:") - status(" Interpreter:" PYTHON2INTERP_FOUND THEN "${PYTHON2_EXECUTABLE} (ver ${PYTHON2_VERSION_STRING})" ELSE NO) - if(PYTHON2LIBS_VERSION_STRING) - status(" Libraries:" HAVE_opencv_python2 THEN "${PYTHON2_LIBRARIES} (ver ${PYTHON2LIBS_VERSION_STRING})" ELSE NO) - else() - status(" Libraries:" HAVE_opencv_python2 THEN "${PYTHON2_LIBRARIES}" ELSE NO) - endif() - status(" numpy:" PYTHON2_NUMPY_INCLUDE_DIRS THEN "${PYTHON2_NUMPY_INCLUDE_DIRS} (ver ${PYTHON2_NUMPY_VERSION})" ELSE "NO (Python wrappers can not be generated)") - status(" install path:" HAVE_opencv_python2 THEN "${__INSTALL_PATH_PYTHON2}" ELSE "-") -endif() - if(BUILD_opencv_python3) status("") status(" Python 3:") diff --git a/cmake/OpenCVDetectPython.cmake b/cmake/OpenCVDetectPython.cmake index c93eb9f9a7..6e95fbf3a0 100644 --- a/cmake/OpenCVDetectPython.cmake +++ b/cmake/OpenCVDetectPython.cmake @@ -85,11 +85,7 @@ if(NOT ${found}) endif() ocv_clear_vars(PYTHONINTERP_FOUND PYTHON_EXECUTABLE PYTHON_VERSION_STRING PYTHON_VERSION_MAJOR PYTHON_VERSION_MINOR PYTHON_VERSION_PATCH) if(NOT CMAKE_VERSION VERSION_LESS "3.12") - if(_python_version_major STREQUAL "2") - set(__PYTHON_PREFIX Python2) - else() - set(__PYTHON_PREFIX Python3) - endif() + set(__PYTHON_PREFIX Python3) find_host_package(${__PYTHON_PREFIX} "${preferred_version}" COMPONENTS Interpreter) if(${__PYTHON_PREFIX}_EXECUTABLE) set(PYTHON_EXECUTABLE "${${__PYTHON_PREFIX}_EXECUTABLE}") @@ -208,9 +204,6 @@ if(NOT ${found}) if(CMAKE_CROSSCOMPILING) message(STATUS "Cannot probe for Python/Numpy support (because we are cross-compiling OpenCV)") message(STATUS "If you want to enable Python/Numpy support, set the following variables:") - message(STATUS " PYTHON2_INCLUDE_PATH") - message(STATUS " PYTHON2_LIBRARIES (optional on Unix-like systems)") - message(STATUS " PYTHON2_NUMPY_INCLUDE_DIRS") message(STATUS " PYTHON3_INCLUDE_PATH") message(STATUS " PYTHON3_LIBRARIES (optional on Unix-like systems)") message(STATUS " PYTHON3_NUMPY_INCLUDE_DIRS") @@ -268,14 +261,6 @@ if(OPENCV_PYTHON_SKIP_DETECTION) return() endif() -find_python("" "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR - PYTHON2INTERP_FOUND PYTHON2_EXECUTABLE PYTHON2_VERSION_STRING - PYTHON2_VERSION_MAJOR PYTHON2_VERSION_MINOR PYTHON2LIBS_FOUND - PYTHON2LIBS_VERSION_STRING PYTHON2_LIBRARIES PYTHON2_LIBRARY - PYTHON2_DEBUG_LIBRARIES PYTHON2_LIBRARY_DEBUG PYTHON2_INCLUDE_PATH - PYTHON2_INCLUDE_DIR PYTHON2_INCLUDE_DIR2 PYTHON2_PACKAGES_PATH - PYTHON2_NUMPY_INCLUDE_DIRS PYTHON2_NUMPY_VERSION) - option(OPENCV_PYTHON3_VERSION "Python3 version" "") find_python("${OPENCV_PYTHON3_VERSION}" "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR PYTHON3INTERP_FOUND PYTHON3_EXECUTABLE PYTHON3_VERSION_STRING @@ -285,15 +270,9 @@ find_python("${OPENCV_PYTHON3_VERSION}" "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYT PYTHON3_INCLUDE_DIR PYTHON3_INCLUDE_DIR2 PYTHON3_PACKAGES_PATH PYTHON3_NUMPY_INCLUDE_DIRS PYTHON3_NUMPY_VERSION) - if(PYTHON_DEFAULT_EXECUTABLE) set(PYTHON_DEFAULT_AVAILABLE "TRUE") -elseif(PYTHON2_EXECUTABLE AND PYTHON2INTERP_FOUND) - # Use Python 2 as default Python interpreter - set(PYTHON_DEFAULT_AVAILABLE "TRUE") - set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}") elseif(PYTHON3_EXECUTABLE AND PYTHON3INTERP_FOUND) - # Use Python 3 as fallback Python interpreter (if there is no Python 2) set(PYTHON_DEFAULT_AVAILABLE "TRUE") set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON3_EXECUTABLE}") endif() diff --git a/cmake/OpenCVMinDepVersions.cmake b/cmake/OpenCVMinDepVersions.cmake index db225e2ab5..e13bc154d3 100644 --- a/cmake/OpenCVMinDepVersions.cmake +++ b/cmake/OpenCVMinDepVersions.cmake @@ -3,6 +3,5 @@ if(NOT DEFINED MIN_VER_CMAKE) endif() set(MIN_VER_CUDA 6.5) set(MIN_VER_CUDNN 7.5) -set(MIN_VER_PYTHON2 2.7) set(MIN_VER_PYTHON3 3.2) set(MIN_VER_ZLIB 1.2.3) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 1bf64bab51..2085877cbc 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -544,7 +544,6 @@ function(__ocv_resolve_dependencies) foreach(the_module ${OPENCV_MODULES_BUILD}) foreach (wrapper ${OPENCV_MODULE_${the_module}_WRAPPERS}) if(wrapper STREQUAL "python") # hack for python (BINDINDS) - ocv_add_dependencies(opencv_python2 OPTIONAL ${the_module}) ocv_add_dependencies(opencv_python3 OPTIONAL ${the_module}) else() ocv_add_dependencies(opencv_${wrapper} OPTIONAL ${the_module}) diff --git a/cmake/vars/OPENCV_DISABLE_THREAD_SUPPORT.cmake b/cmake/vars/OPENCV_DISABLE_THREAD_SUPPORT.cmake index 5f5fc0204d..8f3a4c0048 100644 --- a/cmake/vars/OPENCV_DISABLE_THREAD_SUPPORT.cmake +++ b/cmake/vars/OPENCV_DISABLE_THREAD_SUPPORT.cmake @@ -13,7 +13,6 @@ ocv_update(WITH_VA OFF) ocv_update(WITH_VA_INTEL OFF) # Disable bindings -ocv_update(BUILD_opencv_python2 OFF) ocv_update(BUILD_opencv_python3 OFF) ocv_update(BUILD_JAVA OFF) ocv_update(BUILD_opencv_java OFF) diff --git a/doc/pattern_tools/test_charuco_board.py b/doc/pattern_tools/test_charuco_board.py index 83d355b7a6..93a3e68d3c 100644 --- a/doc/pattern_tools/test_charuco_board.py +++ b/doc/pattern_tools/test_charuco_board.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import os, tempfile, numpy as np import sys diff --git a/doc/py_tutorials/py_imgproc/py_histograms/py_2d_histogram/py_2d_histogram.markdown b/doc/py_tutorials/py_imgproc/py_histograms/py_2d_histogram/py_2d_histogram.markdown index 8e05a64080..301b90cb38 100644 --- a/doc/py_tutorials/py_imgproc/py_histograms/py_2d_histogram/py_2d_histogram.markdown +++ b/doc/py_tutorials/py_imgproc/py_histograms/py_2d_histogram/py_2d_histogram.markdown @@ -108,7 +108,7 @@ You can verify it with any image editing tools like GIMP. ### Method 3 : OpenCV sample style !! -There is a sample code for color-histogram in OpenCV-Python2 samples +There is a sample code for color-histogram in OpenCV-Python samples (samples/python/color_histogram.py). If you run the code, you can see the histogram shows the corresponding color also. Or simply it outputs a color coded histogram. diff --git a/doc/py_tutorials/py_imgproc/py_histograms/py_histogram_begins/py_histogram_begins.markdown b/doc/py_tutorials/py_imgproc/py_histograms/py_histogram_begins/py_histogram_begins.markdown index 5667cee36c..4f56da777a 100644 --- a/doc/py_tutorials/py_imgproc/py_histograms/py_histogram_begins/py_histogram_begins.markdown +++ b/doc/py_tutorials/py_imgproc/py_histograms/py_histogram_begins/py_histogram_begins.markdown @@ -157,7 +157,7 @@ should be due to the sky) Well, here you adjust the values of histograms along with its bin values to look like x,y coordinates so that you can draw it using cv.line() or cv.polyline() function to generate same -image as above. This is already available with OpenCV-Python2 official samples. Check the +image as above. This is already available with OpenCV-Python official samples. Check the code at samples/python/hist.py. Application of Mask diff --git a/doc/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.markdown b/doc/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.markdown index 9ef961de3f..4c0433f4ff 100644 --- a/doc/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.markdown +++ b/doc/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.markdown @@ -1,6 +1,9 @@ Install OpenCV-Python in Fedora {#tutorial_py_setup_in_fedora} =============================== +@warning +The instruction is deprecated. Please use OpenCV-Python package instead. See https://github.com/opencv/opencv-python for more details + Goals ----- diff --git a/doc/py_tutorials/py_setup/py_setup_in_ubuntu/py_setup_in_ubuntu.markdown b/doc/py_tutorials/py_setup/py_setup_in_ubuntu/py_setup_in_ubuntu.markdown index 8b99c5df92..b68e7e4797 100644 --- a/doc/py_tutorials/py_setup/py_setup_in_ubuntu/py_setup_in_ubuntu.markdown +++ b/doc/py_tutorials/py_setup/py_setup_in_ubuntu/py_setup_in_ubuntu.markdown @@ -64,12 +64,6 @@ We need **CMake** to configure the installation, **GCC** for compilation, **Pyth sudo apt-get install cmake sudo apt-get install gcc g++ ``` -to support python2: - -``` -sudo apt-get install python-dev python-numpy -``` - to support python3: ``` @@ -154,12 +148,6 @@ For additional information about CMake options refer to OpenCV @ref tutorial_lin You should see these lines in your CMake output (they mean that Python is properly found): ``` --- Python 2: --- Interpreter: /usr/bin/python2.7 (ver 2.7.6) --- Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.6) --- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2) --- packages path: lib/python2.7/dist-packages --- -- Python 3: -- Interpreter: /usr/bin/python3.4 (ver 3.4.3) -- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3) diff --git a/doc/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.markdown b/doc/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.markdown index 1cefb01d5c..d111dcfdf3 100644 --- a/doc/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.markdown +++ b/doc/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.markdown @@ -1,6 +1,9 @@ Install OpenCV-Python in Windows {#tutorial_py_setup_in_windows} ================================ +@warning +The instruction is deprecated. Please use OpenCV-Python package instead. See https://github.com/opencv/opencv-python for more details + Goals ----- diff --git a/doc/tutorials/introduction/config_reference/config_reference.markdown b/doc/tutorials/introduction/config_reference/config_reference.markdown index 6b8d71341a..684355106f 100644 --- a/doc/tutorials/introduction/config_reference/config_reference.markdown +++ b/doc/tutorials/introduction/config_reference/config_reference.markdown @@ -573,7 +573,6 @@ Following options can be used to change installation layout for common scenarios | `ENABLE_FLAKE8` | _ON_ (when docs or examples are enabled) | Enable python scripts check with [Flake8](https://flake8.pycqa.org/) (_check_flake8_ target). Flake8 must be installed. | | `BUILD_JAVA` | _ON_ | Enable Java wrappers build. Java SDK and Ant must be installed. | | `BUILD_FAT_JAVA_LIB` | _ON_ (for static Android builds) | Build single _opencv_java_ dynamic library containing all library functionality bundled with Java bindings. | -| `BUILD_opencv_python2` | _ON_ | Build python2 bindings (deprecated). Python with development files and numpy must be installed. | | `BUILD_opencv_python3` | _ON_ | Build python3 bindings. Python with development files and numpy must be installed. | TODO: need separate tutorials covering bindings builds diff --git a/doc/tutorials/introduction/macos_install/macos_install.markdown b/doc/tutorials/introduction/macos_install/macos_install.markdown index dadce9304c..f170b47fec 100644 --- a/doc/tutorials/introduction/macos_install/macos_install.markdown +++ b/doc/tutorials/introduction/macos_install/macos_install.markdown @@ -109,8 +109,6 @@ Building OpenCV from Source Using CMake - `PYTHON3_INCLUDE_DIR = /usr/include/python` - `PYTHON3_NUMPY_INCLUDE_DIRS = /usr/lib/python/dist-packages/numpy/core/include/` - @note - To specify Python2 versions, you can replace `PYTHON3_` with `PYTHON2_` in the above parameters. -# Build. From build directory execute *make*, it is recommended to do this in several threads diff --git a/modules/python/CMakeLists.txt b/modules/python/CMakeLists.txt index 93eab8c94d..a13501e03f 100644 --- a/modules/python/CMakeLists.txt +++ b/modules/python/CMakeLists.txt @@ -4,13 +4,9 @@ if(DEFINED OPENCV_INITIAL_PASS) # OpenCV build if(ANDROID OR APPLE_FRAMEWORK OR WINRT) - ocv_module_disable_(python2) ocv_module_disable_(python3) return() elseif(BUILD_opencv_world OR (WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")) - if(NOT DEFINED BUILD_opencv_python2) - set(__disable_python2 ON) - endif() if(NOT DEFINED BUILD_opencv_python3) set(__disable_python3 ON) endif() @@ -20,17 +16,11 @@ add_subdirectory(bindings) add_subdirectory(test) -if(__disable_python2) - ocv_module_disable_(python2) -endif() if(__disable_python3) ocv_module_disable_(python3) -endif() -if(__disable_python2 AND __disable_python3) return() endif() -add_subdirectory(python2) add_subdirectory(python3) else() # standalone build diff --git a/modules/python/python2/CMakeLists.txt b/modules/python/python2/CMakeLists.txt deleted file mode 100644 index 37e20fe330..0000000000 --- a/modules/python/python2/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -if(NOT PYTHON2_INCLUDE_PATH OR NOT PYTHON2_NUMPY_INCLUDE_DIRS) - ocv_module_disable(python2) -endif() - -set(the_description "The python2 bindings") -set(MODULE_NAME python2) -# Buildbot requires Python 2 to be in root lib dir -set(MODULE_INSTALL_SUBDIR "") - -set(PYTHON PYTHON2) - -include(../common.cmake) - -unset(MODULE_NAME) -unset(MODULE_INSTALL_SUBDIR) diff --git a/modules/ts/misc/chart.py b/modules/ts/misc/chart.py index e2b79ed78e..6543ab630e 100755 --- a/modules/ts/misc/chart.py +++ b/modules/ts/misc/chart.py @@ -42,7 +42,6 @@ sum::Size_MatType::(Y, X) 32FC1 0.05 ms 1.77 ms 5.23 ms 11.72 ms """ -from __future__ import print_function import testlog_parser, sys, os, xml, re from table_formatter import * from optparse import OptionParser diff --git a/modules/ts/misc/perf_tests_timing.py b/modules/ts/misc/perf_tests_timing.py index af26572969..d7a409bc49 100755 --- a/modules/ts/misc/perf_tests_timing.py +++ b/modules/ts/misc/perf_tests_timing.py @@ -22,7 +22,6 @@ opencv Normalize::OCL_NormalizeFixture 5.412 96 ... ... ... ... """ -from __future__ import print_function import testlog_parser, sys, os, xml, glob, re from table_formatter import * from optparse import OptionParser diff --git a/modules/ts/misc/report.py b/modules/ts/misc/report.py index 0300d4426d..7a010b77fd 100755 --- a/modules/ts/misc/report.py +++ b/modules/ts/misc/report.py @@ -34,7 +34,6 @@ RadiusMatch::OCL_BruteForceMatcherFixture::(640x480, 32FC1) 1372.68 ms 1375.52 m --show-all - also include empty and "notrun" lines """ -from __future__ import print_function import testlog_parser, sys, os, xml, re, glob from table_formatter import * from optparse import OptionParser diff --git a/modules/ts/misc/run_long.py b/modules/ts/misc/run_long.py index d7cfa96bf5..7f09305200 100755 --- a/modules/ts/misc/run_long.py +++ b/modules/ts/misc/run_long.py @@ -2,7 +2,6 @@ """ Utility package for run.py """ -from __future__ import print_function import xml.etree.ElementTree as ET from glob import glob from pprint import PrettyPrinter as PP diff --git a/modules/ts/misc/run_suite.py b/modules/ts/misc/run_suite.py index f1812cdf2a..fa3ed99da0 100644 --- a/modules/ts/misc/run_suite.py +++ b/modules/ts/misc/run_suite.py @@ -73,7 +73,7 @@ class TestSuite(object): return set(res) def isTest(self, fullpath): - if fullpath in ['java', 'python2', 'python3']: + if fullpath in ['java', 'python3']: return self.options.mode == 'test' if not os.path.isfile(fullpath): return False @@ -123,7 +123,7 @@ class TestSuite(object): cmd += ["buildAndTest"] ret = execute(cmd, cwd=self.cache.java_test_dir) return None, ret - elif module in ['python2', 'python3']: + elif module == 'python3': executable = os.getenv('OPENCV_PYTHON_BINARY', None) if executable is None or module == 'python{}'.format(sys.version_info[0]): executable = sys.executable @@ -181,7 +181,7 @@ class TestSuite(object): more_args = [] exe = self.getTest(test) - if exe in ["java", "python2", "python3"]: + if exe in ["java", "python3"]: logname = None else: userlog = [a for a in args if a.startswith("--gtest_output=")] diff --git a/modules/ts/misc/run_utils.py b/modules/ts/misc/run_utils.py index aadc2b4eae..25557c5e88 100644 --- a/modules/ts/misc/run_utils.py +++ b/modules/ts/misc/run_utils.py @@ -92,7 +92,6 @@ parse_patterns = ( {'name': "java_test_dir", 'default': None, 'pattern': re.compile(r"^OPENCV_JAVA_TEST_DIR:\w+=(.*)$")}, {'name': "is_x64", 'default': "OFF", 'pattern': re.compile(r"^CUDA_64_BIT_DEVICE_CODE:\w+=(ON)$")}, {'name': "cmake_generator", 'default': None, 'pattern': re.compile(r"^CMAKE_GENERATOR:\w+=(.+)$")}, - {'name': "python2", 'default': None, 'pattern': re.compile(r"^BUILD_opencv_python2:\w+=(.*)$")}, {'name': "python3", 'default': None, 'pattern': re.compile(r"^BUILD_opencv_python3:\w+=(.*)$")}, ) @@ -153,22 +152,17 @@ class CMakeCache: files = glob.glob(os.path.join(d, mask)) if not self.getOS() == "android" and self.withJava(): files.append("java") - if self.withPython2(): - files.append("python2") if self.withPython3(): files.append("python3") return [f for f in files if isGood(f)] return [] def isMainModule(self, name): - return name in self.main_modules + ['python2', 'python3'] + return name in self.main_modules + ['python3'] def withJava(self): return self.ant_executable and self.java_test_dir and os.path.exists(self.java_test_dir) - def withPython2(self): - return self.python2 == 'ON' - def withPython3(self): return self.python3 == 'ON' diff --git a/modules/ts/misc/summary.py b/modules/ts/misc/summary.py index 5874d37e72..693a161b10 100755 --- a/modules/ts/misc/summary.py +++ b/modules/ts/misc/summary.py @@ -32,7 +32,6 @@ LUT::OCL_LUTFixture::(640x480, 32FC4) 21.254 4.296 4.95 LUT::SizePrm::640x480 2.268 0.687 3.30 """ -from __future__ import print_function import testlog_parser, sys, os, xml, glob, re from table_formatter import * from optparse import OptionParser diff --git a/modules/ts/misc/table_formatter.py b/modules/ts/misc/table_formatter.py index f88681b200..b849450159 100644 --- a/modules/ts/misc/table_formatter.py +++ b/modules/ts/misc/table_formatter.py @@ -4,12 +4,8 @@ This module serves as utility for other scripts. """ -from __future__ import print_function import sys, re, os.path, stat, math -try: - from html import escape -except ImportError: - from cgi import escape # Python 2.7 +from html import escape from optparse import OptionParser from color import getColorizer, dummyColorizer @@ -215,12 +211,8 @@ class table(object): cell.width = len(max(cell.text, key = lambda line: len(line))) def reformatTextValue(self, value): - if sys.version_info >= (2,7): - unicode = str if isinstance(value, str): vstr = value - elif isinstance(value, unicode): - vstr = str(value) else: try: vstr = '\n'.join([str(v) for v in value]) diff --git a/modules/ts/misc/testlog_parser.py b/modules/ts/misc/testlog_parser.py index a148b31116..6b5a4fac52 100644 --- a/modules/ts/misc/testlog_parser.py +++ b/modules/ts/misc/testlog_parser.py @@ -3,16 +3,13 @@ This module serves as utility for other scripts. """ -from __future__ import print_function import collections import re import os.path import sys from xml.dom.minidom import parse -if sys.version_info > (3,): - long = int - def cmp(a, b): return (a>b)-(ab)-(a ABC DEF Gxx''' args = [iter(iterable)] * n - if PY3: - output = it.zip_longest(fillvalue=fillvalue, *args) - else: - output = it.izip_longest(fillvalue=fillvalue, *args) + output = it.zip_longest(fillvalue=fillvalue, *args) return output def mosaic(w, imgs): @@ -215,10 +205,7 @@ def mosaic(w, imgs): imgs -- images (must have same size and format) ''' imgs = iter(imgs) - if PY3: - img0 = next(imgs) - else: - img0 = imgs.next() + img0 = next(imgs) pad = np.zeros_like(img0) imgs = it.chain([img0], imgs) rows = grouper(w, imgs, pad) diff --git a/samples/python/contours.py b/samples/python/contours.py index 285e376a33..3d3fe55455 100755 --- a/samples/python/contours.py +++ b/samples/python/contours.py @@ -9,26 +9,18 @@ Usage: A trackbar is put up which controls the contour level from -3 to 3 ''' -# Python 2/3 compatibility -from __future__ import print_function -import sys -PY3 = sys.version_info[0] == 3 - -if PY3: - xrange = range - import numpy as np import cv2 as cv def make_image(): img = np.zeros((500, 500), np.uint8) black, white = 0, 255 - for i in xrange(6): + for i in range(6): dx = int((i%2)*250 - 30) dy = int((i/2.)*150) if i == 0: - for j in xrange(11): + for j in range(11): angle = (j+5)*np.pi/21 c, s = np.cos(angle), np.sin(angle) x1, y1 = np.int32([dx+100+j*10-80*c, dy+100-90*s]) diff --git a/samples/python/demo.py b/samples/python/demo.py index a56614ce4d..e90fb6495a 100755 --- a/samples/python/demo.py +++ b/samples/python/demo.py @@ -4,8 +4,6 @@ Sample-launcher application. ''' -# Python 2/3 compatibility -from __future__ import print_function import sys # local modules @@ -16,13 +14,8 @@ import webbrowser from glob import glob from subprocess import Popen -try: - import tkinter as tk # Python 3 - from tkinter.scrolledtext import ScrolledText -except ImportError: - import Tkinter as tk # Python 2 - from ScrolledText import ScrolledText - +import tkinter as tk +from tkinter.scrolledtext import ScrolledText #from IPython.Shell import IPShellEmbed #ipshell = IPShellEmbed() @@ -117,19 +110,12 @@ class App: descr = "" try: - if sys.version_info[0] > 2: - # Python 3.x - module_globals = {} - module_locals = {} - with open(fn, 'r') as f: - module_code = f.read() - exec(compile(module_code, fn, 'exec'), module_globals, module_locals) - descr = module_locals.get('__doc__', 'no-description') - else: - # Python 2 - module_globals = {} - execfile(fn, module_globals) # noqa: F821 - descr = module_globals.get('__doc__', 'no-description') + module_globals = {} + module_locals = {} + with open(fn, 'r') as f: + module_code = f.read() + exec(compile(module_code, fn, 'exec'), module_globals, module_locals) + descr = module_locals.get('__doc__', 'no-description') except Exception as e: descr = str(e) diff --git a/samples/python/digits_adjust.py b/samples/python/digits_adjust.py index 1c041c1d31..94771e63b1 100755 --- a/samples/python/digits_adjust.py +++ b/samples/python/digits_adjust.py @@ -13,14 +13,6 @@ Usage: ''' -# Python 2/3 compatibility -from __future__ import print_function -import sys -PY3 = sys.version_info[0] == 3 - -if PY3: - xrange = range - import numpy as np import cv2 as cv @@ -45,9 +37,9 @@ def cross_validate(model_class, params, samples, labels, kfold = 3, pool = None) print(".", end='') return score if pool is None: - scores = list(map(f, xrange(kfold))) + scores = list(map(f, range(kfold))) else: - scores = pool.map(f, xrange(kfold)) + scores = pool.map(f, range(kfold)) return np.mean(scores) @@ -108,7 +100,7 @@ class App(object): err = cross_validate(KNearest, dict(k=k), samples, labels) return k, err best_err, best_k = np.inf, -1 - for k, err in self.run_jobs(f, xrange(1, 9)): + for k, err in self.run_jobs(f, range(1, 9)): if err < best_err: best_err, best_k = err, k print('k = %d, error: %.2f %%' % (k, err*100)) diff --git a/samples/python/fitline.py b/samples/python/fitline.py index db695cbb2b..afcae5251d 100755 --- a/samples/python/fitline.py +++ b/samples/python/fitline.py @@ -22,11 +22,6 @@ f - change distance function ESC - exit ''' -# Python 2/3 compatibility -from __future__ import print_function -import sys -PY3 = sys.version_info[0] == 3 - import numpy as np import cv2 as cv @@ -49,10 +44,7 @@ def sample_line(p1, p2, n, noise=0.0): dist_func_names = it.cycle('DIST_L2 DIST_L1 DIST_L12 DIST_FAIR DIST_WELSCH DIST_HUBER'.split()) -if PY3: - cur_func_name = next(dist_func_names) -else: - cur_func_name = dist_func_names.next() +cur_func_name = next(dist_func_names) def update(_=None): noise = cv.getTrackbarPos('noise', 'fit line') @@ -89,10 +81,7 @@ def main(): ch = cv.waitKey(0) if ch == ord('f'): global cur_func_name - if PY3: - cur_func_name = next(dist_func_names) - else: - cur_func_name = dist_func_names.next() + cur_func_name = next(dist_func_names) if ch == 27: break diff --git a/samples/python/gaussian_mix.py b/samples/python/gaussian_mix.py index 4c1f86794c..dd49535ab8 100755 --- a/samples/python/gaussian_mix.py +++ b/samples/python/gaussian_mix.py @@ -1,13 +1,5 @@ #!/usr/bin/env python -# Python 2/3 compatibility -from __future__ import print_function -import sys -PY3 = sys.version_info[0] == 3 - -if PY3: - xrange = range - import numpy as np import cv2 as cv @@ -16,7 +8,7 @@ from numpy import random def make_gaussians(cluster_n, img_size): points = [] ref_distrs = [] - for _i in xrange(cluster_n): + for _i in range(cluster_n): mean = (0.1 + 0.8*random.rand(2)) * img_size a = (random.rand(2, 2)-0.5)*img_size*0.1 cov = np.dot(a.T, a) + img_size*0.05*np.eye(2) diff --git a/samples/python/kalman.py b/samples/python/kalman.py index cf152a8700..c54a1c65b1 100755 --- a/samples/python/kalman.py +++ b/samples/python/kalman.py @@ -15,12 +15,6 @@ Pressing any key (except ESC) will reset the tracking. Pressing ESC will stop the program. """ -# Python 2/3 compatibility -import sys -PY3 = sys.version_info[0] == 3 - -if PY3: - long = int import numpy as np import cv2 as cv @@ -32,7 +26,7 @@ def main(): img_width = 500 kalman = cv.KalmanFilter(2, 1, 0) - code = long(-1) + code = -1 num_circle_steps = 12 while True: img = np.zeros((img_height, img_width, 3), np.uint8) diff --git a/samples/python/lappyr.py b/samples/python/lappyr.py index 2835b98d13..18d74fcd09 100755 --- a/samples/python/lappyr.py +++ b/samples/python/lappyr.py @@ -12,14 +12,6 @@ References: Alexander Mordvintsev 6/10/12 ''' -# Python 2/3 compatibility -from __future__ import print_function -import sys -PY3 = sys.version_info[0] == 3 - -if PY3: - xrange = range - import numpy as np import cv2 as cv @@ -29,7 +21,7 @@ from common import nothing, getsize def build_lappyr(img, leveln=6, dtype=np.int16): img = dtype(img) levels = [] - for _i in xrange(leveln-1): + for _i in range(leveln-1): next_img = cv.pyrDown(img) img1 = cv.pyrUp(next_img, dstsize=getsize(img)) levels.append(img-img1) @@ -56,14 +48,14 @@ def main(): leveln = 6 cv.namedWindow('level control') - for i in xrange(leveln): + for i in range(leveln): cv.createTrackbar('%d'%i, 'level control', 5, 50, nothing) while True: _ret, frame = cap.read() pyr = build_lappyr(frame, leveln) - for i in xrange(leveln): + for i in range(leveln): v = int(cv.getTrackbarPos('%d'%i, 'level control') / 5) pyr[i] *= v res = merge_lappyr(pyr) diff --git a/samples/python/morphology.py b/samples/python/morphology.py index 183f5e8288..fb17b5e74c 100755 --- a/samples/python/morphology.py +++ b/samples/python/morphology.py @@ -12,11 +12,6 @@ Keys: ESC - exit ''' -# Python 2/3 compatibility -from __future__ import print_function -import sys -PY3 = sys.version_info[0] == 3 - import numpy as np import cv2 as cv @@ -42,12 +37,8 @@ def main(): modes = cycle(['erode/dilate', 'open/close', 'blackhat/tophat', 'gradient']) str_modes = cycle(['ellipse', 'rect', 'cross']) - if PY3: - cur_mode = next(modes) - cur_str_mode = next(str_modes) - else: - cur_mode = modes.next() - cur_str_mode = str_modes.next() + cur_mode = next(modes) + cur_str_mode = next(str_modes) def update(dummy=None): try: # do not get trackbar position while trackbar is not created @@ -84,15 +75,9 @@ def main(): if ch == 27: break if ch == ord('1'): - if PY3: - cur_mode = next(modes) - else: - cur_mode = modes.next() + cur_mode = next(modes) if ch == ord('2'): - if PY3: - cur_str_mode = next(str_modes) - else: - cur_str_mode = str_modes.next() + cur_str_mode = next(str_modes) update() print('Done') diff --git a/samples/python/mosse.py b/samples/python/mosse.py index e11e9215c6..e6027b2745 100755 --- a/samples/python/mosse.py +++ b/samples/python/mosse.py @@ -21,14 +21,6 @@ Keys: http://www.cs.colostate.edu/~draper/papers/bolme_cvpr10.pdf ''' -# Python 2/3 compatibility -from __future__ import print_function -import sys -PY3 = sys.version_info[0] == 3 - -if PY3: - xrange = range - import numpy as np import cv2 as cv from common import draw_str, RectSelector @@ -73,7 +65,7 @@ class MOSSE: self.G = cv.dft(g, flags=cv.DFT_COMPLEX_OUTPUT) self.H1 = np.zeros_like(self.G) self.H2 = np.zeros_like(self.G) - for _i in xrange(128): + for _i in range(128): a = self.preprocess(rnd_warp(img)) A = cv.dft(a, flags=cv.DFT_COMPLEX_OUTPUT) self.H1 += cv.mulSpectrums(self.G, A, 0, conjB=True) diff --git a/samples/python/plane_tracker.py b/samples/python/plane_tracker.py index ed84fb0d3d..8134bfa41e 100755 --- a/samples/python/plane_tracker.py +++ b/samples/python/plane_tracker.py @@ -21,14 +21,6 @@ Keys: Select a textured planar object to track by drawing a box with a mouse. ''' -# Python 2/3 compatibility -from __future__ import print_function -import sys -PY3 = sys.version_info[0] == 3 - -if PY3: - xrange = range - import numpy as np import cv2 as cv @@ -104,7 +96,7 @@ class PlaneTracker: matches = [m[0] for m in matches if len(m) == 2 and m[0].distance < m[1].distance * 0.75] if len(matches) < MIN_MATCH_COUNT: return [] - matches_by_id = [[] for _ in xrange(len(self.targets))] + matches_by_id = [[] for _ in range(len(self.targets))] for m in matches: matches_by_id[m.imgIdx].append(m) tracked = [] diff --git a/samples/python/qrcode.py b/samples/python/qrcode.py index 73c6cd3bd2..e6521eec5e 100644 --- a/samples/python/qrcode.py +++ b/samples/python/qrcode.py @@ -7,20 +7,10 @@ Usage: qrcode.py ''' - -# Python 2/3 compatibility -from __future__ import print_function - import numpy as np import cv2 as cv import argparse -import sys - -PY3 = sys.version_info[0] == 3 -if PY3: - xrange = range - class QrSample: def __init__(self, args): diff --git a/samples/python/squares.py b/samples/python/squares.py index 99a69e9de3..973f440f00 100755 --- a/samples/python/squares.py +++ b/samples/python/squares.py @@ -6,14 +6,6 @@ Simple "Square Detector" program. Loads several images sequentially and tries to find squares in each image. ''' -# Python 2/3 compatibility -from __future__ import print_function -import sys -PY3 = sys.version_info[0] == 3 - -if PY3: - xrange = range - import numpy as np import cv2 as cv @@ -26,7 +18,7 @@ def find_squares(img): img = cv.GaussianBlur(img, (5, 5), 0) squares = [] for gray in cv.split(img): - for thrs in xrange(0, 255, 26): + for thrs in range(0, 255, 26): if thrs == 0: bin = cv.Canny(gray, 0, 50, apertureSize=5) bin = cv.dilate(bin, None) @@ -38,7 +30,7 @@ def find_squares(img): cnt = cv.approxPolyDP(cnt, 0.02*cnt_len, True) if len(cnt) == 4 and cv.contourArea(cnt) > 1000 and cv.isContourConvex(cnt): cnt = cnt.reshape(-1, 2) - max_cos = np.max([angle_cos( cnt[i], cnt[(i+1) % 4], cnt[(i+2) % 4] ) for i in xrange(4)]) + max_cos = np.max([angle_cos( cnt[i], cnt[(i+1) % 4], cnt[(i+2) % 4] ) for i in range(4)]) if max_cos < 0.1: squares.append(cnt) return squares diff --git a/samples/python/turing.py b/samples/python/turing.py index dc920d1295..5eb56cb157 100755 --- a/samples/python/turing.py +++ b/samples/python/turing.py @@ -7,14 +7,6 @@ Multiscale Turing Patterns generator Inspired by http://www.jonathanmccabe.com/Cyclic_Symmetric_Multi-Scale_Turing_Patterns.pdf ''' -# Python 2/3 compatibility -from __future__ import print_function -import sys -PY3 = sys.version_info[0] == 3 - -if PY3: - xrange = range - import numpy as np import cv2 as cv from common import draw_str @@ -45,7 +37,7 @@ def main(): def process_scale(a_lods, lod): d = a_lods[lod] - cv.pyrUp(a_lods[lod+1]) - for _i in xrange(lod): + for _i in range(lod): d = cv.pyrUp(d) v = cv.GaussianBlur(d*d, (3, 3), 0) return np.sign(d), v @@ -53,10 +45,10 @@ def main(): scale_num = 6 for frame_i in count(): a_lods = [a] - for i in xrange(scale_num): + for i in range(scale_num): a_lods.append(cv.pyrDown(a_lods[-1])) ms, vs = [], [] - for i in xrange(1, scale_num): + for i in range(1, scale_num): m, v = process_scale(a_lods, i) ms.append(m) vs.append(v)