Unable to execute Cython wrapped Python code

前端 未结 1 1625
庸人自扰
庸人自扰 2020-12-11 20:27

I am exporting C++ API for python code using Cython. The application will be executed on Ubuntu. The project files are present here

The function I am wrapping, reads

1条回答
  •  半阙折子戏
    2020-12-11 21:01

    To follow up on my comment, You have to call an init function for the module:

    // ...
    Py_Initialize();
    initShow_Img(); // for Python3
       // (especially with the more modern 2 phase module initialization)
       //  the process is a little more complicated - see the documentation
    Print_image(name);
    Py_Finalize();
    // ...
    

    The reason being is that this sets up the module, include executing the line import cv2. Without it things like accessing the module globals (to get to cv2) won't reliably work. This a likely cause of the segmentation fault.

    This is in the documentation example.

    0 讨论(0)
提交回复
热议问题