-
Notifications
You must be signed in to change notification settings - Fork 12
/
V380_complete.py
90 lines (69 loc) · 2.54 KB
/
V380_complete.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
#!/usr/bin/env python
import requests
import getch
from time import sleep
import cv2
cam = cv2.VideoCapture("rtsp://admin:admin7@192.168.0.131/live/ch00_1")
cv2.namedWindow("test")
img_counter = 0
# Set the name of the XML file.
xml_up = "postup.xml"
xml_down = "postdown.xml"
xml_left = "postleft.xml"
xml_right = "postright.xml"
xml_stop = "poststop.xml"
headers = {'Content-Type':'text/xml'}
while True:
ret, frame = cam.read()
cv2.imshow("test", frame)
if not ret:
break
k = cv2.waitKey(1)
if k%256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
elif k%256 == 32:
# SPACE pressed
img_name = "opencv_frame_{}.png".format(img_counter)
cv2.imwrite(img_name, frame)
print("{} written!".format(img_name))
img_counter += 1
elif k%256 == 105:
with open(xml_up) as xml:
# Give the object representing the XML file to requests.post.
r = requests.post('http://192.168.0.131:8899/onvif/ptz', data=xml)
sleep(0.5)
with open(xml_stop) as xml:
# Give the object representing the XML file to requests.post.
r = requests.post('http://192.168.0.131:8899/onvif/ptz', data=xml)
elif k%256 == 44:
with open(xml_down) as xml:
# Give the object representing the XML file to requests.post.
r = requests.post('http://192.168.0.131:8899/onvif/ptz', data=xml)
sleep(0.5)
with open(xml_stop) as xml:
# Give the object representing the XML file to requests.post.
r = requests.post('http://192.168.0.131:8899/onvif/ptz', data=xml)
elif (k%256 == 106):
with open(xml_left) as xml:
# Give the object representing the XML file to requests.post.
r = requests.post('http://192.168.0.131:8899/onvif/ptz', data=xml)
sleep(0.5)
with open(xml_stop) as xml:
# Give the object representing the XML file to requests.post.
r = requests.post('http://192.168.0.131:8899/onvif/ptz', data=xml)
elif (k%256 == 108):
with open(xml_right) as xml:
# Give the object representing the XML file to requests.post.
r = requests.post('http://192.168.0.131:8899/onvif/ptz', data=xml)
sleep(0.5)
with open(xml_stop) as xml:
# Give the object representing the XML file to requests.post.
r = requests.post('http://192.168.0.131:8899/onvif/ptz', data=xml)
elif (k%256 == 107):
with open(xml_stop) as xml:
# Give the object representing the XML file to requests.post.
r = requests.post('http://192.168.0.131:8899/onvif/ptz', data=xml)
cam.release()
cv2.destroyAllWindows()