Go语言实现Onvif客户端:7、获取摄像头快照

Go语言实现Onvif客户端:7、获取摄像头快照


1、代码

摄像头对该时刻可以进行快照抓拍,抓拍结果可以以url地址的形式提供,在浏览器上可以直接查看抓拍的结果,Onvif协议也支持该服务。

/**
 * @Description: 获取快照的url信息,可以直接在浏览器打开
 * @time: 2021-04-02 09:56:52
 * @receiver client
 * @return returnInfo
 */
func (client *GoOnvifClient) GetSnapUri() returnInfo {
	if client.localSelectProfileToken == "" {
		return returnInfo{GetSnapShotUriErr, "profile token is nil."}
	}

	return client.getSnapshotUri()
}

/**
 * @Description: 获取抓拍Uri地址
 * @time: 2021-03-25 14:51:53
 * @receiver client
 * @return returnInfo
 */
func (client *GoOnvifClient) getSnapshotUri() returnInfo {
	ptzSnapReq := media.GetSnapshotUri{
		ProfileToken: onvif.ReferenceToken(client.localSelectProfileToken),
	}

	return client.sendReqGetResp(GetSnapShotUriErr, ptzSnapReq)
}

调用:

res = client.GetSnapUri()
if res.Code != onvifClient.OK {
    fmt.Println("get snap url failed.")
    fmt.Println(res.Info)
} else {
    fmt.Println("snap url xml info:")
    fmt.Println(res.Info)
}

2、结果

得到的xml信息如下:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:tst="http://www.onvif.org/ver10/storage/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:dn="http://www.onvif.org/ver10/network/wsdl" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl" xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12" xmlns:http="http://schemas.xmlsoap.org/wsdl/http" xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsadis="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wsntw="http://docs.oasis-open.org/wsn/bw-2" xmlns:wsrf-rw="http://docs.oasis-open.org/wsrf/rw-2" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsrf-r="http://docs.oasis-open.org/wsrf/r-2" xmlns:trc="http://www.onvif.org/ver10/recording/wsdl" xmlns:tse="http://www.onvif.org/ver10/search/wsdl" xmlns:trp="http://www.onvif.org/ver10/replay/wsdl" xmlns:tnshik="http://www.hikvision.com/2011/event/topics" xmlns:hikwsd="http://www.onvifext.com/onvif/ext/ver10/wsdl" xmlns:hikxsd="http://www.onvifext.com/onvif/ext/ver10/schema" xmlns:tas="http://www.onvif.org/ver10/advancedsecurity/wsdl" xmlns:tr2="http://www.onvif.org/ver20/media/wsdl" xmlns:axt="http://www.onvif.org/ver20/analytics">
	<env:Body>
		<trt:GetSnapshotUriResponse>
			<trt:MediaUri>
				<tt:Uri>http://40.40.40.101/onvif-http/snapshot?Profile_1</tt:Uri>
				<tt:InvalidAfterConnect>false</tt:InvalidAfterConnect>
				<tt:InvalidAfterReboot>false</tt:InvalidAfterReboot>
				<tt:Timeout>PT0S</tt:Timeout>
			</trt:MediaUri>
		</trt:GetSnapshotUriResponse>
	</env:Body>
</env:Envelope>

3、查看

通过上面的Uri在浏览器查看(需要用户名密码登录):

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
实现一个 C# 的 Onvif 客户,你需要遵循以下步骤: 1. 引用 Onvif 标准的 WSDL 文件 Onvif 标准定义了一组 Web Services Description Language (WSDL) 文件,你需要将这些文件添加到你的 C# 项目中。这些文件包含了 Onvif 标准所定义的服务接口和数据类型。 2. 生成客户代理类 使用 Visual Studio 或者命令行工具,基于 WSDL 文件生成客户代理类,这样你就可以使用 C# 代码调用 Onvif 标准定义的服务接口。 3. 创建客户对象 使用生成的客户代理类创建客户对象,你需要提供 Onvif 设备的 IP 地址、口号、用户名和密码等信息。 4. 调用服务接口 使用客户对象调用 Onvif 标准定义的服务接口,例如获取设备信息、控制云台、获取视频流等操作。 下面是一个简单的示例代码,演示了如何使用 C# 实现 Onvif 客户: ```csharp using System; using System.ServiceModel; using onvif.services; namespace onvif_client { class Program { static void Main(string[] args) { // Onvif 设备的 IP 地址、口号、用户名和密码 string address = "http://192.168.1.100/onvif/device_service"; string username = "admin"; string password = "admin"; // 创建服务绑定和客户对象 var binding = new BasicHttpBinding(); var endpoint = new EndpointAddress(address); var client = new DeviceClient(binding, endpoint); // 设置验证凭据 client.ClientCredentials.UserName.UserName = username; client.ClientCredentials.UserName.Password = password; try { // 调用服务接口 var response = client.GetDeviceInformation(new GetDeviceInformationRequest()); // 打印设备信息 Console.WriteLine("Manufacturer: {0}", response.Manufacturer); Console.WriteLine("Model: {0}", response.Model); Console.WriteLine("Serial Number: {0}", response.SerialNumber); } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.Message); } finally { // 关闭客户 client.Close(); } } } } ``` 以上示例代码演示了如何使用 Onvif 标准定义的 GetDeviceInformation 接口获取设备信息。你可以根据需要调用其他的服务接口,实现更加复杂的操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昵称系统有问题

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值