edmBernard / pybind11_opencv_numpy

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

AttributeError: type object 'numpy.flatiter' has no attribute 'converter' #13

Closed kotbegemot closed 4 years ago

kotbegemot commented 4 years ago
Traceback (most recent call last):
  File "/home/kotbegemot/CLionProjects/testdrive/cmake-build-debug/main.py", line 1, in <module>
    import numpy as np
  File "/home/kotbegemot/CLionProjects/testdrive/venv/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
    from . import core
  File "/home/kotbegemot/CLionProjects/testdrive/venv/lib/python3.6/site-packages/numpy/core/__init__.py", line 104, in <module>
    from . import _add_newdocs
  File "/home/kotbegemot/CLionProjects/testdrive/venv/lib/python3.6/site-packages/numpy/core/_add_newdocs.py", line 83, in <module>
    """))
  File "/home/kotbegemot/CLionProjects/testdrive/venv/lib/python3.6/site-packages/numpy/core/function_base.py", line 511, in add_newdoc
    _add_docstring(getattr(new, attr), docstring.strip(), warn_on_python)
AttributeError: type object 'numpy.flatiter' has no attribute 'converter'

Process finished with exit code 1
#include <pybind11/pybind11.h>

#include "ndarray_converter.hpp" /// https://github.com/edmBernard/pybind11_opencv_numpy

#include "test.hpp"

PYBIND11_MODULE(module, m) {

    NDArrayConverter::init_numpy();

    py::class_<test>(m, "test", py::buffer_protocol())
            .def(py::init<const std::string &, float, float, int>())
            .def("forward", &test::forward);

} 
import numpy as np
import cv2

from module import test
image = cv2.imread("frame.bmp")
d = test("test.db", 0,-1, 0)
out = d.forward(image)

print(out)
set(${PROJECT_NAME}_headers
        ndarray_converter.hpp
       test.hpp
)

set(${PROJECT_NAME}_sources
    ndarray_converter.cpp
     test.cpp
)

pybind11_add_module(module main.cpp ${${PROJECT_NAME}_sources} ${${PROJECT_NAME}_headers})
target_include_directories(
        module
        PRIVATE
        /usr/local/lib/python3.6/dist-packages/numpy/core/include/
)
target_link_directories(
        module
        PRIVATE
        /usr/local/lib/python3.6/dist-packages/numpy/core/lib/
)
target_link_libraries(module PRIVATE
        npymath
        ${CONAN_LIBS}
)
edmBernard commented 4 years ago

Thanks for the example. I will check for the issue Can you give me the signature of test::forward ? or maybe you test.cpp file

edmBernard commented 4 years ago

It seem to be an issue during the import of numpy and not in the library generated by pybind11. Did you get this erro if you comment

from module import test
image = cv2.imread("frame.bmp")
d = Nm("test.db", 0,-1, 0)
out = d.forward(image)

print(out)
kotbegemot commented 4 years ago

What is required of me ?

kotbegemot commented 4 years ago

method signature :

auto test::forward(cv::Mat input_data) -> py::array_t<float> { }
edmBernard commented 4 years ago

Could you give me the content of test.cpp ? I was not able to reproduce your issue

edmBernard commented 4 years ago

@kotbegemot any news ? have been able to fix the issue ?

edmBernard commented 4 years ago

If you have any update on this issue, feel free to reopen it. thanks