-
Notifications
You must be signed in to change notification settings - Fork 0
/
cont_mov_num.py
155 lines (136 loc) · 4.79 KB
/
cont_mov_num.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Key Bindings
# 8 - 56
# 6 - 54
# 4 - 52
# 2 - 50
# + - 43
# - - 45
# * - 42
# / - 47
from onvif import ONVIFCamera
from getch.getch import getch
class Continious_Ptz():
def __init__(self,ip,port,user,passw): #Init'ing class
self.ip = ip
self.port = port
self.user = user
self.passw = passw
self.cam = ONVIFCamera(self.ip, self.port, self.user, self.passw)
global ptz
print 'Connected to ONVIF Camera ' + ip
token = self.cam.create_media_service().GetProfiles()[0]._token #Getting profile's token
ptz = self.cam.create_ptz_service() #Creating ptz service
self.Define_Requests(token)
def Define_Requests(self, token): #Defining global requests
global req_move, req_stop, req_goto_home
req_move = ptz.create_type('ContinuousMove')
req_move.ProfileToken = token
req_stop = ptz.create_type('Stop')
req_stop.ProfileToken = token
req_goto_home = ptz.create_type('GotoHomePosition')
req_goto_home.ProfileToken = token
def stop(self):
ptz.Stop(req_stop)
def move_left(self, speed=0.5): #Setting functions to
req_move.Velocity.Zoom._x = 0.0 #handle all entries from keyboard
req_move.Velocity.PanTilt._x = -speed
req_move.Velocity.PanTilt._y = 0.0
ptz.ContinuousMove(req_move)
self.stop()
def move_right(self, speed=0.5):
req_move.Velocity.Zoom._x = 0.0
req_move.Velocity.PanTilt._x = speed
req_move.Velocity.PanTilt._y = 0.0
ptz.ContinuousMove(req_move)
self.stop()
def move_down(self, speed=0.5):
req_move.Velocity.Zoom._x = 0.0
req_move.Velocity.PanTilt._x = 0.0
req_move.Velocity.PanTilt._y = -speed
ptz.ContinuousMove(req_move)
self.stop()
def move_up(self, speed=0.5):
req_move.Velocity.Zoom._x = 0.0
req_move.Velocity.PanTilt._x = 0.0
req_move.Velocity.PanTilt._y = speed
ptz.ContinuousMove(req_move)
self.stop()
def move_right_up(self, speed=0.5):
req_move.Velocity.Zoom._x = 0.0
req_move.Velocity.PanTilt._x = speed
req_move.Velocity.PanTilt._y = speed
ptz.ContinuousMove(req_move)
self.stop()
def move_left_up(self, speed=0.5):
req_move.Velocity.Zoom._x = 0.0
req_move.Velocity.PanTilt._x = -speed
req_move.Velocity.PanTilt._y = speed
ptz.ContinuousMove(req_move)
self.stop()
def move_right_down(self, speed=0.5):
req_move.Velocity.Zoom._x = 0.0
req_move.Velocity.PanTilt._x = speed
req_move.Velocity.PanTilt._y = -speed
ptz.ContinuousMove(req_move)
self.stop()
def move_left_down(self, speed=0.5):
req_move.Velocity.Zoom._x = 0.0
req_move.Velocity.PanTilt._x = -speed
req_move.Velocity.PanTilt._y = -speed
ptz.ContinuousMove(req_move)
self.stop()
def move_home(self):
ptz.GotoHomePosition(req_goto_home)
def zoom_in(self, speed=0.5):
self.stop()
req_move.Velocity.PanTilt._x = 0.0
req_move.Velocity.PanTilt._y = 0.0
req_move.Velocity.Zoom._x = speed
ptz.ContinuousMove(req_move)
def zoom_out(self, speed=0.5):
self.stop()
req_move.Velocity.PanTilt._x = 0.0
req_move.Velocity.PanTilt._y = 0.0
req_move.Velocity.Zoom._x = -speed
ptz.ContinuousMove(req_move)
cam = Continious_Ptz('192.168.11.12', 80, 'admin', 'Supervisor')
print 'Press ESC to exit'
speed = 0.5
while True:
key = ord(getch())
if key == 27: #ESC
break
elif key == 56: #Up
cam.move_up(speed)
elif key == 50: #Down
cam.move_down(speed)
elif key == 54: #Right
cam.move_right(speed)
elif key == 52: #Left
cam.move_left(speed)
elif key == 53: #Home
cam.move_home()
elif key == 57: #Right Up
cam.move_right_up(speed)
elif key == 55: #Left Up
cam.move_left_up(speed)
elif key == 49: #Left Down
cam.move_left_down(speed)
elif key == 51: #Right Down
cam.move_right_down(speed)
elif key == 43: #Plus(+)
cam.zoom_in(speed)
elif key == 45: #Minus(-)
cam.zoom_out(speed)
elif key == 47: #Divide(/)
if (speed >= 0.2):
speed = speed - 0.1
print 'Current speed:', speed
else:
print 'Min speed already'
elif key == 42: #Myltiply(*)
if (speed <= 0.9):
speed = speed + 0.1
print 'Current speed:', speed
else:
print 'Max speed already'