Add Python 3 support to the Python test.py script.
The print function is used in place of the print statement.
The urlopen function has been moved to urllib.request in Python 3, so
attempt to import it from either location.
TestCase.assert_() has been deprecated in place of
TestCase.assertTrue().
The tests all pass in both Python 2 and 3.
Build the Python 3 cv2 module in lib/python3/, to avoid potential naming
conflicts with the Python 2 bindings.
The Python 2 bindings are placed directly in lib/, where they are
required for the Buildbot to successfully execute the Python tests.
Place the built Python module library in a dedicated folder inside of
lib/. This ensures that even if the Python 2 and Python 3 module names
conflict, they will not overwrite one another.
If both Python 2 and Python 3 are found, then build bindings for both of
them during the build process. Currently, one version of Python is
detected automatically, and building for the other requires changes the
CMake config.
The largest chunk of this change generalizes OpenCVDetectPython.cmake to
find both a Python 2 and Python 3 version of Python. Secondly, the
opencv_python module is split into two modules, opencv_python2 and
opencv_python3. Both are built from the same source. but for different
versions of Python.
some of the stuff will be moved to opencv_contrib module.
in order to make this PR pass buildbot, please, comment off opencv_legacy, opencv_contrib and opencv_softcascade test runs.
The keys() and values() functions on dictionaries in Python 3 no longer
return lists. pyopencv_to() for flann::IndexParams now iterates over
the dictionary in a way that is version-agnostic.
- all parsed headers are included into "cv2.cpp" with "pyopencv_generated_include.h"
- types starting with "Ptr_" converted to "Ptr<...>" form (avoids many typedefs in "cv2.cpp")
In Python 3, version 3.3+, PyUnicode_AsUTF8() provides similar
functionality to Python 2's PyString_AsString().
In older versions of Python 3, there is no public function to provide
the same functionality. However, the "internal" _PyUnicode_AsString()
does provide that functionality, so use it to replace
PyString_AsString().
With this patch, cv2 should compile for Python 3.[0-2].