How can convert PyObject variable to Mat in c++ opencv code

后端 未结 3 664
不思量自难忘°
不思量自难忘° 2021-01-27 08:59

I have a c++ facerecognition code and a python code in opencv. In python code i read frames from a robot and i want to send this fram to my c++ code. I use this link tho call p

3条回答
  •  一生所求
    2021-01-27 09:39

    For Python 3.x C-API:

    In Python side return the frame in bytearray format:

    return bytearray(frame)
    

    and in cpp side get it by PyByteArray_AsString function:

    pData = PyObject_CallObject(pFunc, pArgs);
    uchar *data = (uchar *)PyByteArray_AsString(pData );
    cv::Mat img(rows, cols, CV_8UC3, data)
    

提交回复
热议问题