diff --git a/CMakeLists.txt b/CMakeLists.txt index 64f850583b6eadbbfdffcbabeac1ad5eb4c4df08..8b897d882ce2d414afa65d792b6d985ada7fd95e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,12 @@ elseif() endif() message(STATUS "BGSLIBRARY WITH PYTHON SUPPORT: ${BGS_PYTHON_SUPPORT}") +# cmake -D BGS_PYTHON_SUPPORT=ON -D BGS_PYTHON_VERSION=2 .. +if(NOT DEFINED BGS_PYTHON_VERSION) + set(BGS_PYTHON_VERSION 2) +endif() +message(STATUS "PYTHON VERSION: ${BGS_PYTHON_VERSION}") + if(UNIX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x") set(CMAKE_MACOSX_RPATH 1) @@ -82,7 +88,12 @@ if(BGS_PYTHON_SUPPORT) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) - find_package(Boost REQUIRED COMPONENTS python) + message(STATUS "SEARCHING FOR BOOST COMPONENT FOR PYTHON ${BGS_PYTHON_VERSION}") + if(BGS_PYTHON_VERSION EQUAL 2) + find_package(Boost REQUIRED COMPONENTS python) + else() + find_package(Boost REQUIRED COMPONENTS python3) + endif() find_package(PythonInterp REQUIRED) find_package(PythonLibs REQUIRED) diff --git a/wrapper_python/np_opencv_converter.cpp b/wrapper_python/np_opencv_converter.cpp index 6050f6b40e5815670d2f2f8383381642ee2fd413..6799b4c0853fec9d59849cd1c37ef2bc8b44cb0d 100644 --- a/wrapper_python/np_opencv_converter.cpp +++ b/wrapper_python/np_opencv_converter.cpp @@ -19,10 +19,18 @@ along with BGSLibrary. If not, see <http://www.gnu.org/licenses/>. namespace fs { namespace python { // Static PyInit -static void py_init() { - Py_Initialize(); - import_array(); -} +#if PY_VERSION_HEX >= 0x03000000 + static int py_init() { + Py_Initialize(); + import_array(); + return NULL; + } +#else + static void py_init() { + Py_Initialize(); + import_array(); + } +#endif // Singleton init and export converters static bool export_type_conversions_once = false; diff --git a/wrapper_python/utils/conversion.cpp b/wrapper_python/utils/conversion.cpp index f979d354fa0368ce02e6f89b52aa83f2a1cfde7c..00a8a1e570eed54645b7f973ab3c87afdeaa1e19 100644 --- a/wrapper_python/utils/conversion.cpp +++ b/wrapper_python/utils/conversion.cpp @@ -23,10 +23,18 @@ along with BGSLibrary. If not, see <http://www.gnu.org/licenses/>. * inside modules/python/src2 folder. */ +#if PY_VERSION_HEX >= 0x03000000 +static int init() +{ + import_array(); + return NULL; +} +#else static void init() { - import_array(); + import_array(); } +#endif static int failmsg(const char *fmt, ...) { @@ -204,10 +212,18 @@ NumpyAllocator g_numpyAllocator; NDArrayConverter::NDArrayConverter() { init(); } +#if PY_VERSION_HEX >= 0x03000000 +int NDArrayConverter::init() +{ + import_array(); + return NULL; +} +#else void NDArrayConverter::init() { - import_array(); + import_array(); } +#endif cv::Mat NDArrayConverter::toMat(const PyObject *o) { diff --git a/wrapper_python/utils/conversion.h b/wrapper_python/utils/conversion.h index 17288f91360f7d4c56ce7dbf047fb18cde3c7f72..4f7aa968a84b850b8668370bfa43bfd6ccf90d6b 100644 --- a/wrapper_python/utils/conversion.h +++ b/wrapper_python/utils/conversion.h @@ -66,7 +66,12 @@ enum { ARG_NONE = 0, ARG_MAT = 1, ARG_SCALAR = 2 }; class NDArrayConverter { private: - void init(); +#if PY_VERSION_HEX >= 0x03000000 + int init(); +#else + void init(); +#endif + public: NDArrayConverter(); cv::Mat toMat(const PyObject* o);