繁体   English   中英

将帧从 python VideoCapture() 传递到 c++

[英]Passing frames to c++ from python VideoCapture()

我将 usb 相机读取为 cv2.VideoCapture() function 并显示帧。 我需要一些 c++ 应用程序从 python 应用程序读取帧。

我怎么能做这个?

脚步:

  • 从 usb 相机中读取带有 python 的相机。
  • 显示帧 cv2.imshow("usb_cam_frame", frame)。
  • 运行 c++ 应用程序。
  • 将帧传输到 c++ 应用程序。 ???
  • 显示与 c++ 应用程序相同的帧。

You can use embedding python in C++ and call python function in a C++ program. 放入 python 模块并在此模块中定义一个字典,其中包含文件中的帧数据,例如 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;
 }
   

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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