Algomorph/pyboostcvconverter

Fatal Python error: PyEval_SaveThread: NULL tstate

Closed this issue · 2 comments

aj96 commented

I want to be able to convert cv::Mat to ndarrays so I can pass them to python maplotlib functions, things like plt.subplot, etc. I only modified the CMakeLists.txt for building an executable and wrote a simple main.cpp for reading in an image, which I've verified I can read in, and then converting it to an ndarray. But I always get this Fatal Python error: PyEval_SaveThread: NULL tstate error the moment I call pbcvt::fromMatToNDArray().

I am running on Ubuntu 16.04, OpenCV version 3.4.4, cmake version 3.5.1

Please help.

Thank you.

@aj96 , I'm not sure what you're trying to do by changing the target from a dynamic library to an executable. If you want to do some processing of images with C++ using OpenCV and then visualize these using matplotlib, the typical workflow is to keep target as a library, to be used as a module within your python code after it is compiled and installed (see instructions in README).

Then, from within your python code, you can read in the images as numpy arrays, for instance by using the official cv2 python module, i.e. image = cv2.imread(...), process them with output = yourlibrary.process(image), and then visualize, i.e. plt.subplot(x=output, ...).

The error you're getting seems to be indicative of the fact that there is no python interpreter running to interpret your code, which is what I would expect if you were trying to run your own, separate C++ executable and using a Boost Python module somehow within it.

Closing inactive thread.