2015-09-25 171 views

回答

1

所以,很多搜索后我设法从摄像机捕获的图像。

第一个问题是我已经使用“添加服务引用 - >高级 - >添加Web引用”,而不是直接在“添加服务引用”框中输入服务地址。

在这里,我添加了地址:http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl

然后,我可以用MediaClient类,正确的评论所指出的pepOS,最终代码如下所示:

var messageElement = new TextMessageEncodingBindingElement(); 
messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); 
HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); 
httpBinding.AuthenticationScheme = AuthenticationSchemes.Basic; 
CustomBinding bind = new CustomBinding(messageElement, httpBinding); 
EndpointAddress mediaAddress = new EndpointAddress("http://192.168.1.168:10001/onvif/Media"); 
MediaClient mediaClient = new MediaClient(bind, mediaAddress); 
mediaClient.ClientCredentials.UserName.UserName = "admin"; 
mediaClient.ClientCredentials.UserName.Password = "admin"; 
Profile[] profiles = mediaClient.GetProfiles(); 
string profileToken = profiles[1].token; 
MediaUri mediaUri = mediaClient.GetSnapshotUri(profileToken); 

的URI该图像然后可能来自于MediaUri.Uri地址

+1

这与我做的一样,它运作良好。在我的项目中,我坚持在需要将该流保存到文件的同时在屏幕上显示超过2个相机的同时。我使用了VLC .NET ActiveX插件,该插件工作非常不稳定,我没有发现任何其他严重(和免费)的插件来做到这一点。在我看来,使用原始API比购买非常昂贵的Ozeki SDK好得多 - 但是您需要解决将玩家嵌入到应用中的问题。 –

1

GetSnapshotUri返回一个URI用于使用HTTP get下载图像。 所以理论上你只需要调用这个函数,并在此文章#1所示的功能使用返回的URI: https://stackoverflow.com/a/3615831/4815603

+0

我该怎么称呼GetSnapshotUri?这是我的主要问题 –

+0

对不起,我没有使用它的经验,但也许这个开源项目将有助于:http://sourceforge.net/projects/onvifdm/ –

+1

您是否使用media.wsdl中的MediaClient类服务规格。 – pepOS

0

我在这里使用onvif设备管理器DLL。要实现这种方法,必须知道相机的IP,用户名和密码。

// Onvif ODM 
using onvif.services; 
using odm.core; 
using onvif.utils; 
using utils; 
public string GetSnapshotUrl() 
{ 
    try 
     { 
      string camera_ip = "http://" + camIp + "/onvif/device_service"; 
      Uri Camuri = new Uri(camera_ip); 
      NvtSessionFactory sessionFactory = new NvtSessionFactory(account); 
      INvtSession session = sessionFactory.CreateSession(Camuri); 
      Profile[] Profiles = session.GetProfiles().RunSynchronously(); 
      var snapshotlink = session.GetSnapshotUri(Profiles[0].token).RunSynchronously(); // taking snapshot on the first profile of the camera 
      return snapshotlink.uri; 
     } 
     catch (Exception ex) 
     { 
      return null; 
     } 
    }