Send cv::Mat from c++ to python
Hi I have created a c++ code that reads GIGE camera image using its sdk and converted it into cv::Mat. Now I have wrapped this code to use it in python but i dont know how to return Mat object to python.
PyObject* some_function(PyObject* self, PyObject* args)
{ //GIGE SDK gets image to hcamera3 object //***OPENCV PART******** // do image processing std::cout << "Acquired image...\n";
CvSize size;
size.width = ImageWidth(hCamera3);
size.height = ImageHeight(hCamera3);
retval = cvCreateImageHeader(size, ocv_depth(ImageDatatype(hCamera3, 0)), ImageDimension(hCamera3));
ppixels = nullptr;
GetLinearAccess(hCamera3, 0, &ppixels, &xInc, &yInc);
cvSetData(retval, ppixels, yInc);
//matToReturn = cv::cvarrToMat(retval, true);
matToReturn = cv::cvarrToMat(retval, true);
std::cout << matToReturn.size << "SIZE" << std::endl;;
cv::imwrite("E:/PythonGenie.bmp", matToReturn);
//******************************************************
// stop the grab (kill = true: wait for ongoing frame acquisition to stop)
result = G2Freeze(hCamera3, true);
// free camera
ReleaseObject(hCamera3);
}
return ?????????????????????
}
I am not sure what to put into return ?? and then how assign it in python. In java it was just passin a Mat object to c++ but here I am lost.
Any help appriciated!
you actually have to pass a numpy array back to python, neither a cv::Mat, nor (HELL, NO !) a c-api IplImage*
Thanks I will try it and let you know how it went.
do i need to convert cv::Mat to numpy and than return numpy from Cpp code.?? are you able to solve this issue..??
@vineetkr137, please ask a new question, with your specific situation.
@berak , I have the same problem mentioned above. created a C++ for pointgrey camera suing sdk. and converted into cv::Mat, wrapped cpp code to use in python. but how do I converted into numpy array so that i can use this image in python code such as cv::imshow...??