【发布时间】:2019-12-01 11:51:02
【问题描述】:
我正在尝试使用 C# Windows 窗体应用程序从 IP 摄像机的 RTSP 流中获取图像。我正在使用 EMGU CV 连续捕获流,但 RTSP Steam 在几秒钟后停止,然后 imageGrabbedEvent 永远不会触发。
我的目的很简单:从相机中获取每一帧并进行分析。
我正在使用 IP 地址为 192.168.1.64 的 HIKVision IP 摄像机 (DS-2CD2683G1-IZ) 在端口 554 上流式传输 RTSP(这是许多 Hikvision IP 摄像机的默认 IP 地址和端口号)
DateTime LastTimeImageGrabReinitialised = new DateTime();
public void InitializeCameraEMGUStream()
{
//added a datetime to the URL as recommended by another answer but it didnt help.
VideoCapture myVideoCapture = new VideoCapture("rtsp://admin:mysecretpassword@192.168.1.64:554/ch1/main/av_stream?"+DateTime.Now.ToString());
myVideoCapture.ImageGrabbed += imageGrabbedEvent;
myVideoCapture.Start();
LastTimeImageGrabReinitialised = DateTime.Now;
}
private void imageGrabbedEvent(object sender, EventArgs e)
{
lastTimeImageGrabbed = DateTime.Now;
try
{
Mat m = new Mat();
myVideoCapture.Retrieve(m);
LatestAcquiredImage = m.ToImage<Bgr, byte>().Bitmap;
pictureBox.Image = m.ToImage<Bgr, byte>().Bitmap;
imgEntrada = m.ToImage<Bgr, byte>();
}
catch (Exception Ex)
{
}
//I tried adding some logic to reinitialize the stream after a few hundred milliseconds,
//but it seems the reinitialization takes a while to obtain a clear image and many frames cannot be read.
if((DateTime.Now- LastTimeImageGrabReinitialised).TotalMilliseconds>200)
{
myVideoCapture.Start();
LastTimeImageGrabReinitialised = DateTime.Now;
}
}
我已经浏览了几个在线可用的答案,但找不到确定的方法来保持直播。在这方面我非常感谢任何帮助。
仅供参考:我已经尝试过:
我尝试每隔一段时间重新初始化 VideoCapture,但速度很慢,而且许多初始帧都是嘈杂/不清晰的图像。
我已经尝试使用 VLC.Dotnet 来运行 RTSP 流,流工作得非常好,但是抓取图像并将其转换为图像非常慢,主要是因为 VLCControl.TakeSnapshot() 保存文件在磁盘上。充其量,这会消耗超过 500 毫秒,并且在此期间丢失了许多帧。
我还尝试使用 RTSPClientSharp,在使用它时,imageGrabbed 事件会定期触发,但我无法显示解码的图像。
我尝试使用 HTTP 从摄像头获取图像,但是,每张图像的到达时间超过 600 毫秒,同时摄像头不会接受任何其他连接请求,因此再次丢失了许多帧。
【问题讨论】: