Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pbctv in embedded Python #45

Open
linux-fan-dave opened this issue Jul 12, 2021 · 5 comments
Open

Use pbctv in embedded Python #45

linux-fan-dave opened this issue Jul 12, 2021 · 5 comments

Comments

@linux-fan-dave
Copy link

linux-fan-dave commented Jul 12, 2021

I try to use this code in a embedded python interpreter. Embedded means that I start a programm which embeds python via boost python. The pbctv as well as the Testcode use a c++ dll inside of python instead. I use the static library and added the initialisation code to my code.

My problem is that I get an segfault whenever I use pbctv. It segfaults in the call to pyboost_cv4_converter.cpp:105 in the call to PyArray_SimpleNew.
The problem seems to be that I did not initialize/import numpy correctly. I use the following code to init the libraries (init_ar is copied from the example. This init code is executed before I use the converter for the first time.

PythonAdapter::PythonAdapter()
{
    // Register the module with the interpreter
    if (PyImport_AppendInittab("embedded_extension", PyInit_embedded_extension) == -1)
	throw std::runtime_error("Failed to add embedded_extension to the interpreter's "
	         "builtin modules");
    Py_Initialize();
    boost::python::numpy::initialize();
    //using namespace XM;
    init_ar();

    //initialize converters
    boost::python::to_python_converter<cv::Mat,pbcvt::matToNDArrayBoostConverter>();
    pbcvt::matFromNDArrayBoostConverter();

}

The following code shows how I use pbctv in my code:

    pbcvt::matToNDArrayBoostConverter conv;
    m_extManager.handleImage(boost::python::object(boost::python::handle<>(conv.convert(frame))));

Is there something I'm missing? I tried as well without the call to boost::python::numpy::initialize().

I forgot to mention that I can succesfully compile and use pbctv correctly as a python plugin dll.

@linux-fan-dave
Copy link
Author

I changed my code to pass cv::Mat to python and not explicitely call the converter. This works just fine without any segfault.
I therefore close this issue.

@linux-fan-dave
Copy link
Author

The converter was not used because the function with cv::Mat was never called. When I call this function the segfault can be observed again.

@Algomorph
Copy link
Owner

Hi, @linux-fan-dave. Sorry you are having trouble with pbcvt. I am not currently supporting embedded python development (I'm very far away from either embedded things or OpenCV at this point in time), but you're welcome to contribute anything that helps to get this issue resolved. The only thing I can think of is: try to understand / debug why pbcvt works in a regular python setting, but segfaults in the embedded setting.

@KingfaLuis
Copy link

where is the configure?

@Algomorph
Copy link
Owner

@KingfaLuis I'm not sure what you mean by "configure". The configure script of autotools? This project uses CMake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants