-
Notifications
You must be signed in to change notification settings - Fork 11
/
move.py
135 lines (99 loc) · 3.81 KB
/
move.py
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# -*- coding: utf-8 -*-
# @Time : 2021/4/20 10:53
# @Author : RichardoMu
# @File : move.py
# @Software: PyCharm
from time import sleep
from onvif import ONVIFCamera
import zeep
XMAX = 1
XMIN = -1
YMAX = 1
YMIN = -1
def zeep_pythonvalue(self, xmlvalue):
return xmlvalue
def perform_move(ptz, request, timeout):
# Start continuous move
ptz.ContinuousMove(request)
# Wait a certain time
sleep(timeout)
# Stop continuous move
ptz.Stop({'ProfileToken': request.ProfileToken})
def move_up(ptz, request, timeout=1):
print('move up...')
request.Velocity.PanTilt.x = 0
request.Velocity.PanTilt.y = YMAX
perform_move(ptz, request, timeout)
def move_down(ptz, request, timeout=1):
print('move down...')
request.Velocity.PanTilt.x = 0
request.Velocity.PanTilt.y = YMIN
perform_move(ptz, request, timeout)
def move_right(ptz, request, timeout=1):
print('move right...')
request.Velocity.PanTilt.x = XMAX
request.Velocity.PanTilt.y = 0
perform_move(ptz, request, timeout)
def move_left(ptz, request, timeout=1):
print('move left...')
request.Velocity.PanTilt.x = XMIN
request.Velocity.PanTilt.y = 0
perform_move(ptz, request, timeout)
def zoom_up(ptz,request,timeout=1):
print('zoom up')
request.Velocity.Zoom.x = 1
request.Velocity.PanTilt.x = 0
request.Velocity.PanTilt.y = 0
perform_move(ptz,request,timeout)
def zoom_dowm(ptz,request,timeout=1):
print('zoom down')
request.Velocity.Zoom.x = -1
request.Velocity.PanTilt.x = 0
request.Velocity.PanTilt.y = 0
perform_move(ptz, request, timeout)
def continuous_move():
mycam = ONVIFCamera('192.168.66.64', 80, 'admin', 'wst123456')
# Create media service object
media = mycam.create_media_service()
# Create ptz service object
ptz = mycam.create_ptz_service()
# Get target profile
zeep.xsd.simple.AnySimpleType.pythonvalue = zeep_pythonvalue
media_profile = media.GetProfiles()[0]
# Get PTZ configuration options for getting continuous move range
request = ptz.create_type('GetConfigurationOptions')
request.ConfigurationToken = media_profile.PTZConfiguration.token
ptz_configuration_options = ptz.GetConfigurationOptions(request)
request = ptz.create_type('ContinuousMove')
request.ProfileToken = media_profile.token
ptz.Stop({'ProfileToken': media_profile.token})
if request.Velocity is None:
request.Velocity = ptz.GetStatus({'ProfileToken': media_profile.token}).Position
request.Velocity = ptz.GetStatus({'ProfileToken': media_profile.token}).Position
request.Velocity.PanTilt.space = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].URI
request.Velocity.Zoom.space = ptz_configuration_options.Spaces.ContinuousZoomVelocitySpace[0].URI
# Get range of pan and tilt
# NOTE: X and Y are velocity vector
global XMAX, XMIN, YMAX, YMIN
XMAX = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].XRange.Max
XMIN = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].XRange.Min
YMAX = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].YRange.Max
YMIN = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].YRange.Min
for i in range(10):
zoom_up(ptz,request)
for i in range(10):
zoom_dowm(ptz,request)
# move right
for i in range(10):
move_right(ptz, request)
# move left
for i in range(10):
move_left(ptz, request)
# Move up
for i in range(10):
move_up(ptz, request)
# move down
for i in range(10):
move_down(ptz, request)
if __name__ == '__main__':
continuous_move()