I read usb camera as cv2.VideoCapture() function and showing frames. I need to some c++ application read frames from python application.
How can i make this?
Steps:
You can use embedding python in C++ and call python function in a C++ program. Put the python module and define a dict in this module that contain data of frame in file for example test.py.
#include <Python.h>
int main(int argc, char *argv[])
{
Py_Initialize();
pName = PyString_FromString("test.py");
pModule = PyImport_Import(pName);
pDict = PyModule_GetDict(pModule);
pFunc = PyDict_GetItemString(pDict, "frame");
if (PyCallable_Check(pFunc))
{
PyObject_CallObject(pFunc, NULL);
}
else
{
PyErr_Print();
}
// Clean up
Py_DECREF(pModule);
Py_DECREF(pName);
// Finish the Python Interpreter
Py_Finalize();
return 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.