MATLAB - 捕获视频流(MJPEG、rtsp、mpeg)
有人在 MATLAB 中使用过从 IP 摄像机捕获视频流吗?例如,在 MATLAB 中从 rtsp://10.10.10.10:554/live.sdp(rtsp 流)或 http://xxxx/axis-cgi/mjpg/video.cgi(mjpeg 流)。 MATLAB 的图像采集工具箱当前不支持此功能。我找到了2个选择: 1)使用mmread。但是 64 位 MATLAB 不支持 http 流读取或 2)编写我自己的C++函数来抓取帧(我使用OpenCV库),然后将其编译成MATLAB MEX函数。 任何建议表示赞赏。
Has anyone worked with capturing video streams from IP cameras in MATLAB? For example to grab frames in MATLAB from rtsp://10.10.10.10:554/live.sdp (rtsp stream) or from http://x.x.x.x/axis-cgi/mjpg/video.cgi (mjpeg stream). MATLAB's Image Acquisition Toolbox does not currently support this. I found 2 options:
1) using mmread. However http stream reading is not supported under 64-bit MATLAB or
2) to write my own C++ function that grabs frames (I use OpenCV library) and then compile it into MATLAB MEX function.
Any suggestions are appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我从 MATLAB 支持处得到的答案:
我建议实现您自己的 Matlab mex 函数来抓取视频帧。以下是执行此操作的一些指示:
http://10.10.10.10/axis-cgi/mjpg/video.cgi?resolution=800x600&.mjpg
。以下是 OpenCV 库的 matlab mex 函数集合和开发套件的链接(感谢 Kota Yamaguchi): https://github.com/kyamagu/mexopencv。该库可以轻松地在 OpenCV 数据类型和 mxArray 之间进行转换。这是一个例子:
<前><代码>#include“mexopencv.hpp”
无效 mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
// 检查参数
if (nlhs!=1 || nrhs!=1)
mexErrMsgIdAndTxt("myfunc:invalidArgs", "参数数量错误");
// 将 MxArray 转换为 cv::Mat
cv::Mat mat = MxArray(prhs[0]).toMat();
// 做你想做的事
// 将 cv::Mat 转换回 mxArray*
plhs[0] = MxArray(mat);
}
可以使用线程使应用程序异步,其中生产者线程从相机抓取帧并将其放入循环缓冲区中。另一方面,消费者线程从缓冲区检索帧并将其转换为 mxArray(矩阵)输出。请参阅如何实现 cv::Mat 对象 (OpenCV) 的循环缓冲区?。循环缓冲区需要线程安全,请参阅循环缓冲区的线程安全实现。
This is the answer I got from MATLAB support:
I suggest implementing your own Matlab mex function to grab video frames. Here are some pointers to do so:
http://10.10.10.10/axis-cgi/mjpg/video.cgi?resolution=800x600&.mjpg
.Below is a link to collection and development kit of matlab mex functions for OpenCV library (thanks to Kota Yamaguchi): https://github.com/kyamagu/mexopencv. This library makes it easy to convert between OpenCV data types and mxArray. Here's an example:
The application can be made asynchronous by using threads, where producer thread grabs frames from the camera and puts it into a circular buffer. Consumer thread, on the other hand, retrieves frames from the buffer and converts them into mxArray (matrix) output. See How to implement a circular buffer of cv::Mat objects (OpenCV)?. Circular buffer will need to be made thread safe, see Thread safe implementation of circular buffer.
自 MATLAB R2015a 起,使用函数 ipcam 变得非常简单:
第一次调用该函数时,MATLAB 可能会提示您下载它。
好消息是,该解决方案甚至不需要相机采集工具箱的许可证。
Since MATLAB R2015a it's become very easy with the function ipcam:
The first time you call that function MATLAB may prompt you to download it.
The good news is that solution doesn't even require a license to the camera acquisition toolbox.