-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcamcontroller.py
73 lines (61 loc) · 2.27 KB
/
camcontroller.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 config
import queue
import time
import logging
from modules import *
logging.basicConfig(level=logging.DEBUG,
format='(%(threadName)-9s) %(message)s',)
config.run = True
logging.debug("Config.run is True")
buffers = {}
threads = {}
i = 0
if config.DSLR:
setup_DSLRs = GPhotoUtils()
for gcamera in setup_DSLRs.camera_list:
name = gcamera[0]
addr = gcamera[1]
buffers["gcamera"+str(i)] = queue.Queue(maxsize=0)
threads["gcamera"+str(i)] = GPhotoCamera(args =(buffers["gcamera"+str(i)]), index=i, name=gcamera[0], addr=gcamera[1])
i += 1
if config.opencv:
opencv_cameras = CV2Utils.returnCameraIndexes()
opencv_best_res = CV2Utils.returnCameraResolutions( opencv_cameras )
for cvcamera in opencv_cameras:
buffers["ocamera"+str(cvcamera)] = queue.Queue(maxsize=0)
threads["ocamera"+str(cvcamera)] = WebcamVideoStream( q = buffers["ocamera"+str(cvcamera)], src = int(cvcamera), width = opencv_best_res[0], height = opencv_best_res[1])
if config.serial:
serial_buffer = queue.Queue(maxsize=0)
arduino = DAQReader(args = (serial_buffer), baudrate = config.serial_baudrate ,port = config.serial_port)
buffers["arduino"] = serial_buffer
threads["arduino"] = arduino
clips = Clipboard(args =(buffers))
threads["clips"] = clips
inputQueue = queue.Queue()
keyboard = KeyMonitor( args=(inputQueue) )
for key, thread in threads.items():
logging.debug("Starting thread: " + key)
thread.start()
if config.continuous_serial == True:
continuous_logger = DAQLogger(args = (serial_buffer))
continuous_logger.start()
keyboard.start()
logging.debug("Press 'Q' to exit.")
while (True):
if (inputQueue.qsize() > 0):
input_str = inputQueue.get()
logging.debug("input_str = {}".format(input_str))
if (input_str == "q"):
config.run = False
logging.debug("Exiting serial terminal.")
logging.debug("Wait for the connection closed signal before Ctrl+C...")
break
elif (input_str == "s"):
config.trigger = True
logging.debug("Triggered caliration shot.")
config.run = False
logging.debug("Config.run is False")
time.sleep(3)
for key, thread in threads.items():
thread.stop()
thread.join()