forked from ZainUlMustafa/Basler-PyPylon-Control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaware_webcam_control.py
98 lines (83 loc) · 2.21 KB
/
aware_webcam_control.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
'''
AWARE WEBCAM CONTROL [AWCON]
This is a specially designed camera booter that runs and auto tries to run camera
and fetch the required info. It is crash-safe which enables it to revive again and
again.
AWCON uses accon.json as strategy definer within which camera control properties can
be defined.
'''
print("ACCON INIT")
import json
from operator import itemgetter
import os
import signal
import cv2
import numpy as np
showLogs = False
awcon = './awcon.json'
pid = None
cap = None
def main():
global pid; pid = os.getpid()
if not os.path.exists(awcon):
print('AWCON config not found!')
return
#endif
while(cap.isOpened):
try:
f = open(awcon)
data = json.load(f)
f.close()
cameraIndex, camLogs, camPid, camShowImage, camKill = itemgetter('cameraIndex', 'showLogs', 'showPid', 'showImage', 'kill')(data)
if camPid:
print(pid)
#endif
if camKill:
cap.release()
os.kill(pid, signal.SIGTERM)
#endif
global showLogs; showLogs = camLogs
buglog(data)
except Exception as e:
print(e)
buglog("Defaulted. Maybe incorrect AWCON data?")
#endtry
_, img = cap.read()
if camShowImage:
cv2.imshow('right', cv2.resize(img, (640*1,480*1)))
if cv2.waitKey(1) & 0xff == ord('q'):
break
#endif
else:
cap.release()
cv2.destroyAllWindows()
#endif
#endwhile
cap.release()
cv2.destroyAllWindows()
#enddef
def buglog(data):
if showLogs:
print(f'[CAM LOGS]: {data}')
#endif
#enddef
if __name__ == '__main__':
# main()
count = 0
while True:
try:
cv2.destroyAllWindows()
print(f"CAP: {count}")
cap = cv2.VideoCapture(count)
main()
except:
if count < 10:
count = count + 1
cap.release()
print(f"Reviving {count}...")
else:
count = 0
#endif
#endtry
#endwhile
#endif