Opencv python bindings crashing with opencv_ARRAY_API is nullptr

I am trying to set up a python API for my own application and I have a previously working state with version 3.5.* and version 4.5.3, however the same code seems broken in 4.5.5.

I pass a numpy array through a shiboken wrapper to the pyopencv_to_safe function. Internally that is supposed to convert to a cv::Mat, but I get the exception

Exception thrown: read access violation.
opencv_ARRAY_API was nullptr.

in line 75 of cv2_convert.hpp
if( !PyArray_Check(o) )

I assume this is somehow using an uninitialized numpy API, because I can see that the former maintainer of the code base called PyInit_cv2(); directly. However that does not work anymore (or was a hack to begin with).

How do I properly configure the access to the array API?
I also put a message on stackoverflow, but it seems people only want to know the answer, but cannot help themselves… :smiley:

Any pointers on how to find the solution myself would already be appreciated, but a solution would be even preferable!

Thanks in advance!

Bumping this because I still haven’t found a solution to this problem. I cannot find documentation on how to properly initialize the Array API. Any pointers are welcome.

Found a solution which feels more like a hack. if someone in the future finds this, I would appreciate any pointers if the way I solved it was not correct, or if there is a better way.

In the end I just made a header file that declares the function again, making it known in the context of my translation unit.