繁体   English   中英

如何在C#中使用emgucv使用IP摄像机通过http捕获视频流

[英]How to capture video stream via http with an IP camera using emgucv in c#

我很难找到我认为非常简单的解决方案。 Emgu.CV中的Capture构造函数(字符串)应“从文件或视频流创建捕获”。

但是,尽管我的IP摄像机(安讯士)允许以下视频流,但我无法用C#代码捕获任何内容:请求Motion JPEG视频流-> http://myserver/axis-cgi/mjpg/video.cgi (由按照制造商的说法,“成功的请求将返回连续的JPEG图像流。内容类型是multipart / x-mixed-replace,每个图像都以边界字符串结尾。”)

仅供参考,相机服务器确实需要用户名和密码登录,我还无法弄清楚如何将其包含在Capture中,或者……我应该先发出HTTPWebRequest然后执行Capture,还是我?应该做些更复杂的事情? 不确定登录是否可能是一个问题,因为我没有得到特定的错误,但怀疑可能需要webrequest,我不知道该如何添加...

在我的form.cs中精简代码:

Capture _capture = null; //Camera
string sourceURL = "http://192.168.0.90/axis-cgi/mjpg/video.cgi";
_capture = new Capture(sourceURL);
Image<Bgr, Byte> imgOriginal = new Image<Bgr, byte>(_capture.RetrieveBgrFrame().ToBitmap());

然后,我尝试在ImageBox中显示imgOriginal。 但是,在上面的最后一步,它已经生成了一个错误,指出“无法创建捕获...”或类似的错误。

使用emguCV这不是很简单,还是我弄错了? 如果有人可以帮助我弄清楚如何捕获图像,则可以从那里进行图像处理。 先感谢您!

对于这篇文章来说可能为时已晚,但希望它将对以后的其他人有所帮助。

对于MJPEG视频编解码器,请使用==> http:// root:pass@172.16.10.38/axis-cgi/mjpg/video.cgi?x.mjpeg

对于H.264编解码器,请使用==> rtsp:// root:pass@172.16.10.38/axis-media/media.amp?videocodec = h264&resolution = 640x480

请注意,这些URI仅适用于AXIS品牌的IP摄像机。 对于其他IP摄像机品牌,建议您访问以下网站,因为每个制造商都有不同的HTTP或RTSP URI

http://www.soleratec.com/support/rtsp/rtsp_listing

至于实现代码,这是一个起点:

private static Capture _cameraCapture;

//Windows form button to start the video stream                
private void btn_play_Click(object sender, EventArgs e)
{            
 Run();                            
} 

private void Run()
{
 if (rdbWebcam.Checked == true) //radio button
 {
  _cameraCapture = new Capture(0); //use local webcam
 }
else
  {
  _cameraCapture = new Capture(txtrtsp.Text); //use rtsp or http uri you typed into a textbox
  }
 Application.Idle += ProcessFrame;
}   

private void  ProcessFrame(object sender, EventArgs e)
 {         
   try
       {
        Mat frame = _cameraCapture.QueryFrame();
        imageBox1.Image = frame; //imagebox to  show live video
        }
       catch (Exception ex)
        {
        MessageBox.Show(ex.Message);
         Application.Exit();
         }
}

//Windows Form FormClosing event
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{     
 if (_cameraCapture != null)
    {
     _cameraCapture.Stop();
     _cameraCapture.Dispose();
    }

}

您可能需要尝试一些操作。

  1. 首先,您可以使用诸如fiddler之类的东西(它是监视网络流量的代理)来检查应用程序向服务器发出请求时返回的响应是什么。
  2. 其次,如果服务器需要身份验证,则很有可能使用HTTP Basic身份验证,您可能想尝试调用url之类的东西

    string sourceURL = "http://username:password@192.168.0.90/axis-cgi/mjpg/video.cgi"; _capture = new Capture(sourceURL);

否则,您将必须在授权标头中发送参数

  1. 您可以使用本机cvInvoke函数检查是否有帮助。代码将是这样的。

    Capture _Capture = new Emgu.CV.CvInvoke.cvCreateFileCapture("http://username:password@192.168.0.90/axis-cgi/mjpg/video.cgi");

请参考此答案更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM