-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
57 lines (46 loc) · 2.16 KB
/
main.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
import argparse
from cvdarts.capturingdevice import MockCapturingDevice, WebCamCapturingDevice
from persistence.configuration_repository import create_config, put_config_for_device, find_config_for_device
from cvdarts.gameloop import GameLoop
def parse_args():
global args
parser = argparse.ArgumentParser(description="""
Detect darts on a dart board using web cam. Run this command with the ids of the web cam as arguments. The ids \n
are starting with 0 and increment with the numbers of web cams that are connected to your computer.
Use the --config option to configure the web cams before detecting darts.
""")
parser.add_argument('device_ids', metavar='N', type=int, nargs='+',
help='Device ids for the devices that should be used')
parser.add_argument('--config', '-c', help='sum the integers (default: find the max)', action="store_true")
parser.add_argument('--testdata', '-t', help='Use testdata instead of webcams', action="store_true")
args = parser.parse_args()
def initialize_real_devices():
for device_id in args.device_ids:
config_of_device = find_config_for_device(device_id)
dartboard_level_from_config = 0
if config_of_device is not None:
dartboard_level_from_config = config_of_device[1]
devices.append(WebCamCapturingDevice(device_id, dartboard_level_from_config))
def configure_devices():
for device in devices:
config_of_device = find_config_for_device(device.device_number)
level_loaded_from_config = 0
if config_of_device is not None:
level_loaded_from_config = config_of_device[1]
dartboard_level = device.configure(level_loaded_from_config)
put_config_for_device(device.device_number, dartboard_level)
if __name__ == '__main__':
parse_args()
devices = []
create_config()
if args.testdata:
devices = [MockCapturingDevice(0)]
game_loop = GameLoop(devices)
game_loop.run()
else:
initialize_real_devices()
if args.config:
configure_devices()
else:
game_loop = GameLoop(devices)
game_loop.run()