云台控制
云台控制包括基本控制、预置点、设置巡航线、轨迹操作、自动扫描、获取PTZ相关信息等。
接口概览
流程说明
---
title: 云台控制
---
flowchart TD
A(设备SDK初始化<br><strong>NET_SDK_Init</strong>)
B(用户注册设备<br><strong>NET_SDK_Login</strong>或<br><strong>NET_SDK_LoginEx</strong>)
C("开启预览<br><strong>NET_SDK_LivePlay</strong>")
D("云台控制<br><strong>NET_SDK_PTZControl</strong>")
E("云台预置点操作<br><strong>NET_SDK_PTZPreset</strong>")
F("... ...")
G("停止预览<br><strong>NET_SDK_StopLivePlay</strong>")
H("云台巡航操作<br><strong>NET_SDK_PTZTrack_Other</strong>")
I("云台自动扫描操作<br><strong>NET_SDK_PTZAutoScan_Other</strong>")
J("... ...")
Y(注销设备<br><strong>NET_SDK_Logout</strong>)
Z(释放SDK资源<br><strong>NET_SDK_Cleanup</strong>)
C --> D --> G
C --> E --> G
C --> F --> G
A --> B ---> C
G --> Y --> Z
B --> H ---> Y
B --> I ---> Y
B --> J ---> Y
示例代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 | #include "PTZ.h"
#include <afx.h>
#include <string>
#include <stdio>
#include <iostream>
#include "DVR_NET_SDK.h"
void PTZControl()
{
// Device information.
const std::string device_ip = "10.80.1.177";
const DWORD decice_port = 6036;
const std::string username = "admin";
const std::string password = "123456";
// Initialize SDK.
NET_SDK_Init();
NET_SDK_DEVICEINFO device_info{0};
DWORD errCode = 0;
// Device login.
int userid = NET_SDK_Login(const_cast<char *>(device_ip.c_str()), decice_port, const_cast<char *>(username.c_str()), const_cast<char *>(password.c_str()), &device_info);
if (userid > 0)
{
std::cout << "Login successful!" << std::endl;
}
else
{
errCode = NET_SDK_GetLastError();
std::cout << "Login failed!" << "Error code:" << errCode << std::endl;
NET_SDK_Cleanup();
return;
}
// Live Play.
NET_SDK_CLIENTINFO clientInfo{0};
clientInfo.hPlayWnd = GetConsoleWindow();
// Channel number, starting from 0.
clientInfo.lChannel = 0;
/*
Video stream type, including:
NET_SDK_MAIN_STREAM、
NET_SDK_SUB_STREAM、
NET_SDK_THIRD_STREAM、
NET_SDK_FOURTH_STREAM,
Depends on the device's support.
*/
clientInfo.streamType = NET_SDK_MAIN_STREAM;
// Whether to decode.
// 0: Decoding;
// 1: Non-decoding, only for the Windows platform, default 0.
clientInfo.bNoDecode = 0;
// Start Live Play.
LONG playHandle = NET_SDK_LivePlay(userid, &clientInfo, NULL, NULL);
if (playHandle != -1)
{
std::cout << "Live Play successful!" << std::endl;
// PTZ control operation.
// Control the PTZ to tilt up.
BOOL ptzStatus = NET_SDK_PTZControl(playHandle, PTZ_CMD_UP, PTZ_SPEED_1);
if (ptzStatus)
{
std::cout << "PTZ control successful!" << std::endl;
}
else
{
errCode = NET_SDK_GetLastError();
std::cout << "PTZ control failed!" << "Error code:" << errCode << std::endl;
}
// The PTZ stops after continuously rotating for 5 seconds.
Sleep(5000);
BOOL stopStatus = NET_SDK_PTZControl(playHandle, PTZ_CMD_STOP, PTZ_SPEED_1);
if (!stopStatus)
{
errCode = NET_SDK_GetLastError();
std::cout << "PTZ stop failed!" << "Error code:" << errCode << std::endl;
}
// Stop Live Play.
NET_SDK_StopLivePlay(playHandle);
}
else
{
errCode = NET_SDK_GetLastError();
std::cout << "Live Play failed!" << "Error code:" << errCode << std::endl;
}
// Logout.
NET_SDK_Logout(userid);
// Release SDK resources.
NET_SDK_Cleanup();
return;
}
|