将视频从 Raspberry pi 流式传输到远程计算机上的 Opencv 应用程序 [英] Stream video from Raspberry pi to Opencv application on remote computer
问题描述
我想要实现的是,我有一个带有 pi 摄像头 v2 的 raspberry 3 连接到我的本地 wifi.我想将实时视频从 raspberry pi 传输到运行 Ubuntu 的计算机.在我的电脑上,我正在尝试使用 opencv 实时处理该视频.下面的代码只是一个示例代码,用于在我的 Ubuntu 计算机上测试来自 raspberry pi 的视频.我正在使用 netcat 来流式传输视频,并且在代码下方列出了 shell 脚本.
What I am trying to achieve is, I have a raspberry 3 with pi camera v2 connected to my local wifi. I want to transmit a live video from the raspberry pi to a computer running Ubuntu. On my computer I am trying to process that video with opencv in real time. The code below is just a sample code to test the video coming from the raspberry pi on my Ubuntu computer. I am using netcat to stream the video and I have listed the shell script below the code.
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap;
cap.open("/dev/stdin");
if (!cap.isOpened())
return -1;
Mat edges;
namedWindow("edges",1);
for(;;){
Mat frame;
cap>>frame;
imshow("edges",frame);
if(waitKey(30)>=0)break;
}
return 0;
}
这是在opencv中播放流的代码.
This is the code to play the stream in opencv.
- 首先,我将流重定向到我的 opencv 应用程序.nc -l -p 5001 |./app
- 然后运行我的 raspberry 相机并使用 netcat 流式传输它raspivid -t 999999 -o |nc x.x.x.x 5001 x 是客户端电脑的 IP 地址.
这对我不起作用,但我已经用 mplayer 试过了通过运行 nc -l -p 5001 |mplayer -fps 31 -cache 1024 - 它运行完美.
This doesn't work for me but I have tried it with mplayer by running nc -l -p 5001 | mplayer -fps 31 -cache 1024 - and it works perfectly.
我认为我的问题是我没有在我的 opencv 应用程序上正确捕获流.我需要帮助.
I think my problem is I am not capturing the stream properly on my opencv application. I need help please.
推荐答案
我花了大约 4 个小时试图使这项工作成功,并最终使其成功.我不确定哪个是关键步骤,也不确定为什么,但我发现如果在我的 Ubuntu 16 LTS VirtualBox 上安装以下软件包,一切都可以正常工作:
I spent around 4 hours trying to make this work and got it working in the end. I am not certain which was the key step, nor why, but I found it all works if I install the following packages on my Ubuntu 16 LTS VirtualBox:
libtbb2
ffmpeg
libavcodec
libavcodec-dev
libavformat-dev
libtbb-dev
libswscale-dev
libgtk2.0-dev
libtbb-dev
libjpeg-dev
libpng-dev
libtiff-dev
libjasper-dev
libdc1394-22-dev
libv4l-dev
libx264-dev
并使用以下命令在我的 Raspberry Pi 上运行相机:
and run the camera on my Raspberry Pi with:
raspivid -ih -w 1024 -h 768 -o - | nc 192.168.0.98 5001
关键字: Raspberry Pi、RASPI、raspivid、相机、OpenCV、流、流、netcat、nc、网络、视频
Keywords: Raspberry Pi, RASPI, raspivid, camera, OpenCV, stream, streaming, netcat, nc, network, video
这篇关于将视频从 Raspberry pi 流式传输到远程计算机上的 Opencv 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!