From cabe01198521edc45682d75627542681896df20b Mon Sep 17 00:00:00 2001 From: Sam Pfeiffer Date: Fri, 18 May 2018 02:57:12 +1000 Subject: [PATCH] Adapt to support boost 1.65 From the Boost 1.65 release notes: http://www.boost.org/users/history/version_1_65_1.html > The boost::python::numeric API has been removed, as it is being obsoleted by boost::python::numpy. I found how to fix it from: https://github.com/mcs07/rdkit/blob/a5358f7744dae13731b28963b5c4c45983331dba/Code/RDBoost/boost_numpy.h Building stuff for Gentoo pulls the latest Boost and so, this popped. --- cells/cv_bp/opencv/cv_mat.cpp | 37 +++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/cells/cv_bp/opencv/cv_mat.cpp b/cells/cv_bp/opencv/cv_mat.cpp index 2945f7f..8ffa084 100644 --- a/cells/cv_bp/opencv/cv_mat.cpp +++ b/cells/cv_bp/opencv/cv_mat.cpp @@ -4,6 +4,15 @@ #include #include #include +// Boost python numpy available in Boost 1.63+ +// Boost python numeric removed in Boost 1.65+ +#if BOOST_VERSION < 106500 +#include +typedef typename boost::python::numeric::array NumpyArrayType; +#else +#include +typedef typename boost::python::numpy::ndarray NumpyArrayType; +#endif #include @@ -81,16 +90,16 @@ namespace } //Create a Numeric array with dimensions dimens and Numeric type t - bp::numeric::array + NumpyArrayType makeNum(std::vector dimens, PyArray_TYPES t = PyArray_DOUBLE) { using namespace bp; object obj(handle<>(PyArray_FromDims(dimens.size(), &dimens[0], t))); - return extract(obj); + return extract(obj); } void* - data(bp::numeric::array arr) + data(NumpyArrayType arr) { if (!PyArray_Check(arr.ptr())) { @@ -102,7 +111,7 @@ namespace //Copy data into the array void - copy_data(boost::python::numeric::array arr, const uchar* new_data) + copy_data(NumpyArrayType arr, const uchar* new_data) { uchar* arr_data = (uchar*) data(arr); size_t nbytes = PyArray_NBYTES(arr.ptr()); @@ -114,7 +123,7 @@ namespace //Copy data into the array void - copy_data(uchar* new_data, boost::python::numeric::array arr) + copy_data(uchar* new_data, NumpyArrayType arr) { uchar* arr_data = (uchar*) data(arr); size_t nbytes = PyArray_NBYTES(arr.ptr()); @@ -124,14 +133,14 @@ namespace } } PyArray_TYPES - type(bp::numeric::array arr) + type(NumpyArrayType arr) { return PyArray_TYPES(PyArray_TYPE(arr.ptr())); } //Return the number of dimensions int - rank(bp::numeric::array arr) + rank(NumpyArrayType arr) { using namespace bp; //std::cout << "inside rank" << std::endl; @@ -144,7 +153,7 @@ namespace } std::vector - shape(bp::numeric::array arr) + shape(NumpyArrayType arr) { using namespace bp; std::vector out_dims; @@ -164,7 +173,7 @@ namespace } void - mat_from_array(cv::Mat& m, bp::numeric::array array) + mat_from_array(cv::Mat& m, NumpyArrayType array) { std::vector shape = numpy_helpers::shape(array); int cv_depth = numpy_helpers::fromPyArray_TYPES(numpy_helpers::type(array)); @@ -179,13 +188,13 @@ namespace bp::object mat_to_array(cv::Mat& m) { - typedef bp::numeric::array array_t; + typedef NumpyArrayType array_t; std::vector dim(2); dim[0] = m.rows; dim[1] = m.cols; if(m.channels() != 1) dim.push_back(m.channels()); - bp::numeric::array array(numpy_helpers::makeNum(dim, numpy_helpers::fromCVDepth(m.depth()))); + NumpyArrayType array(numpy_helpers::makeNum(dim, numpy_helpers::fromCVDepth(m.depth()))); numpy_helpers::copy_data(array, m.ptr(0)); return array; } @@ -321,7 +330,7 @@ namespace return m.t(); } - boost::shared_ptr from_numpy( bp::numeric::array array) + boost::shared_ptr from_numpy( NumpyArrayType array) { cv::Mat m; mat_from_array(m,array); @@ -336,7 +345,9 @@ namespace opencv_wrappers wrap_mat() { import_array(); - bp::numeric::array::set_module_and_type("numpy", "ndarray"); + #if BOOST_VERSION < 106500 + NumpyArrayType::set_module_and_type("numpy", "ndarray"); + #endif typedef std::vector buffer_t; bp::class_ >("buffer").def(bp::vector_indexing_suite, false>());