edmBernard / pybind11_opencv_numpy

Implementation of cv::Mat conversion to numpy.array for pybind11
Apache License 2.0
198 stars 41 forks source link

Use cv::AutoBuffer::operator _Tp*() on older versions #23

Closed sloretz closed 3 years ago

sloretz commented 3 years ago

cv::AutoBuffer::data() was added in OpenCV 3.4.3. This PR causes the older casting operator to be used instead on older versions.

edmBernard commented 3 years ago

currently your PR disable the cv::AutoBuffer::data() also for 3.4.3+, do you think it will be an issue ?

edmBernard commented 3 years ago

the content of this file is not writen by me but it's more a patchwork. I would prefer a fix like

 #if CV_MAJOR_VERSION >= 4 || (CV_MAJOR_VERSION == 3 && CV_VERSION_MINOR == 4 && CV_VERSION_REVISION >= 3)
      // For Version >= 4 and >= 3.4.3
      PyObject* o = PyArray_SimpleNew(dims, _sizes.data(), typenum);
  #else
      // cv::AutoBuffer::data() was added in OpenCV 3.4.3
      PyObject* o = PyArray_SimpleNew(dims, _sizes, typenum);
  #endif

3.4.2 : https://github.com/opencv/opencv/blob/3.4.2/modules/python/src2/cv2.cpp#L192 3.4.3 : https://github.com/opencv/opencv/blob/3.4.3/modules/python/src2/cv2.cpp#L193

sloretz commented 3 years ago

I updated the preprocessor conditional to use data() in OpenCV 3.4.3 and above. I see that 3.4.2 uses just _sizes, but I'm a bit surprised that works. Is it invoking operator _Tp*()? I left it as &(_sizes[0]) for now.