Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 2088

Send cv::Mat from c++ to python

$
0
0
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!

Viewing all articles
Browse latest Browse all 2088