ONVIF api在C#中捕获图像

问题描述 投票:1回答:3

我有一台ONVIF ip camera。

我想从相机捕获图像,以便我可以处理该图像并将其保存到文件系统。

我发现有一个onvif api提供了一个方法GetSnapshotUri,它应该为我提供一个图像快照:

http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl

我设法通过添加服务引用来在visual studio中导入这个api:

enter image description here

如何构建客户端以从此服务调用GetSnapshotUri

c# visual-studio wsdl ip-camera onvif
3个回答
2
投票

因此,经过大量搜索后,我设法从相机中捕获图像。

第一个问题是我使用了“添加服务引用 - >高级 - >添加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);

然后可以在qazxsw poi地址找到图像的uri


1
投票

GetSnapshotUri返回一个uri,用于使用HTTP get下载图像。所以理论上你只需要调用这个函数,并在Stackoverflow文章中显示的函数中使用返回的uri:MediaUri.Uri


0
投票

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

https://stackoverflow.com/a/3615831/4815603
© www.soinside.com 2019 - 2024. All rights reserved.