问题描述
我有一个ONVIF网络摄像机.
I have an ONVIF ip camera.
我想从相机捕获图像,以便可以处理该图像并将其保存到文件系统中.
I want to to capture an image from the camera so that I can process that image and save it to the file system.
我发现有一个onvif api提供了方法GetSnapshotUri
,该方法应该为我提供图像快照:
I found out that there is an onvif api which provides a method GetSnapshotUri
which should provide me with an image snapshot:
http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl
我设法通过在Visual Studio中添加服务引用来导入该api:
I managed to import this api in visual studio by adding a service reference to it:
我该如何构建一个客户端来从此服务调用GetSnapshotUri
?
How do I construct a client to call GetSnapshotUri
from this service?
推荐答案
因此,经过大量搜索,我设法从相机捕获了图像.
So, after lots of searching I managed to capture an image from the camera.
第一个问题是我使用了添加服务引用->高级->添加Web引用",而不是直接在添加服务引用"框中键入服务地址.
The first Problem was that I have used "Add Service Reference->Advanced->Add Web reference" instead of typing the service address directly in the "Add Service Reference" box.
在这里,我添加了地址: http://www.onvif .org/onvif/ver10/media/wsdl/media.wsdl
Here, I added the address: http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl
然后我可以使用pepOS在注释中正确指出的MediaClient
类,最终代码如下:
Then I could use the MediaClient
class, correctly pointed out by pepOS in a comment, and the final code looks like:
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);
然后可以在MediaUri.Uri
地址上找到图片的uri
The uri of the image could then be fount at the MediaUri.Uri
address
这篇关于C#中的ONVIF API捕获图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!