Skip to content
Snippets Groups Projects
Commit ace34375 authored by Andrews Sobral's avatar Andrews Sobral
Browse files

Some bug fixes for building python 3 wrapper.

parent ba00d6a6
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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;
......
......@@ -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)
{
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment