python - 从 python VideoCapture() 将帧传递给 c++
问题描述
我将 USB 摄像头读取为 cv2.VideoCapture() 函数并显示帧。我需要一些 c++ 应用程序从 python 应用程序读取帧。
我怎样才能做到这一点?
脚步:
- 从 USB 摄像头用 python 读取摄像头。
- 显示帧 cv2.imshow("usb_cam_frame", frame)。
- 运行 c++ 应用程序。
- 将帧传输到 C++ 应用程序。???
- 使用 c++ 应用程序显示相同的帧。
解决方案
您可以在 C++ 中使用嵌入 python 并在 C++ 程序中调用 python 函数。放入 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;
}
推荐阅读
- matlab - MATLAB:使用块向量高效生成块矩阵
- javascript - 从javascript使用window.location调用控制器方法时Tomcat状态404 spring boot
- php - PHP 可以将包含特定内容的页面加载到 iframe 中吗?
- javascript - 如何获取带有 id 的空 div 的总和?
- python - 减少 Docker 镜像大小
- matlab - 瀑布函数的限制......与否?
- javascript - 如何使用 javascript 和 html 中的范围滑块更改图像大小?
- matlab - mat 文件中没有信号分析器会话
- java - java android Eclipse retrofit 2.0 转换为 Dalvik 格式失败:无法执行 dex:多个 dex 文件定义 Lretrofit2/Converter
- qt - 有没有办法让 QToolButton 的箭头变大