forked from smartsenselab/sensecam-control
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_control_onvif.py
73 lines (48 loc) · 1.62 KB
/
example_control_onvif.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
import cv2
import sys
import threading
from sensecam_control import onvif_control
ip = '000.000.000.000'
login = 'login'
password = 'password'
exit_program = 0
def event_keyboard(k):
global exit_program
if k == 27: # esc
exit_program = 1
elif k == ord('w') or k == ord('W'):
X.relative_move(0, 0.1, 0)
elif k == ord('a') or k == ord('A'):
X.relative_move(-0.1, 0, 0)
elif k == ord('s') or k == ord('S'):
X.relative_move(0, -0.1, 0)
elif k == ord('d') or k == ord('D'):
X.relative_move(0.1, 0, 0)
elif k == ord('h') or k == ord('H'):
X.go_home_position()
elif k == ord('z') or k == ord('Z'):
X.relative_move(0, 0, 0.05)
elif k == ord('x') or k == ord('X'):
X.relative_move(0, 0, -0.05)
def capture(ip_camera):
global exit_program
#url http login axis camera
ip2 = 'http://' + login + ':' + password + '@' + ip_camera + '/mjpg/1/video.mjpg?'
#url rtsp axis camera
#ip2 = 'rtsp://' + login + ':' + password + '@' + ip_camera + '/axis-media/media.amp'
cap = cv2.VideoCapture(ip2)
while True:
ret, frame = cap.read()
if ret is not False:
break
while True:
ret, frame = cap.read()
if exit_program == 1:
sys.exit()
#cv2.namedWindow('Camera', cv2.WINDOW_NORMAL)
cv2.imshow('Camera', frame)
event_keyboard(cv2.waitKey(1) & 0xff)
X = onvif_control.CameraControl(ip, login, password)
X.camera_start()
t = threading.Thread(target=capture, args=(ip,))
t.start()