【问题标题】:Passing frames to c++ from python VideoCapture()从 python VideoCapture() 将帧传递给 c++
【发布时间】:2020-06-30 07:50:17
【问题描述】:

我将 USB 摄像头读取为 cv2.VideoCapture() 函数并显示帧。我需要一些 c++ 应用程序从 python 应用程序读取帧。

我该怎么做?

步骤:

  • 使用 python 从 USB 摄像头读取摄像头。
  • 显示帧 cv2.imshow("usb_cam_frame", frame)。
  • 运行 c++ 应用程序。
  • 将帧传输到 c++ 应用程序。 ???
  • 使用 c++ 应用程序显示相同的帧。

【问题讨论】:

  • 您想运行 2 个单独的二进制文件并使用某种 IPC(进程间通信)传输数据吗?

标签: python c++ video-capture imshow


【解决方案1】:

您可以在 C++ 中使用嵌入 python 并在 C++ 程序中调用 python 函数。放入python模块并在该模块中定义一个dict,其中包含文件中帧的数据,例如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;
 }
   

【讨论】:

    猜你喜欢
    • 2018-10-07
    • 1970-01-01
    • 2016-03-03
    • 2020-10-09
    • 2020-05-29
    • 2018-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多