fromMatToNDArray and fromNDArrayToMat crashing without any error message.
Closed this issue · 13 comments
Hi there,
I was trying to use this library and I found the following problem,
when I am trying to create the PyObject from a Mat calling fromMatToNDArray as in the example:
cv::Mat image = cv::Mat::zeros(240,320, CV_16UC3);
PyObject* py_image = pbcvt::fromMatToNDArray(image);
my program just stop running without any exception or error message.
After tracing the code a little I have found that the problem occures when the allocate function from the NumpyAllocator is called specifically in the following line:
PyObject* o = PyArray_SimpleNew(dims, _sizes, typenum);
Do you have any clue, o notion of what should I try to solve this problem?
I also tried the reverse way and it is also not working... It happened the same
@Algomorph Thanks for answering so soon
std::cout << CV_VERSION << std::endl;
prints 2.4.8
edit: Python 2.7
And python?
Python 2.7
@Algomorph Okey, thank you very much :)
@ChemaF I was unable to replicate your issue. I made a function:
PyObject* makeCV_16UC3Matrix(){
cv::Mat image = cv::Mat::zeros(240,320, CV_16UC3);
PyObject* py_image = pbcvt::fromMatToNDArray(image);
return py_image;
}
, and added it to the module:
def("makeCV_16UC3Matrix", makeCV_16UC3Matrix);
I was able to successfully run the code and I'm getting an empty 16-bit uint numpy array. The only difference with my setup is, I'm using the stock opencv from Ubuntu repo, and that is 2.4.9. Perhaps, try upgrading?
It didn't solve the problem...
@ChemaF , since I cannot replicate your issue, chances are there's something wrong with your local setup. I'll have to mark this issue as invalid and close it for now. Feel free to reopen if you actually discover there's an issue with my code or CMake that caused your problem.
No... sorry I could not find the reason of the error :(.
I ended up using https://github.com/yati-sagade/opencv-ndarray-conversion
I solved this problem. The code is no problem. The bug is due to the opencv version in python and c++ is different. So the error is come up. You can catch the bug by
try {
// your code
} catch (bp::error_already_set) {
PyErr_Print();
}
And the info is "Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)"
One way that solves the bug is replacing cv2.so in python install dir by the cv2.so in opencv which you use for c++.