简体   繁体   中英

Passing frames to c++ from python VideoCapture()

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:

  • Read camera with python from usb camera.
  • Show frames cv2.imshow("usb_cam_frame", frame).
  • Run c++ application.
  • Transfer frames to c++ application. ???
  • Show same frames with c++ application.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM