-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.py
63 lines (48 loc) · 1.46 KB
/
configure.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
# -*- coding: utf-8 -*-
__author__ = 'Mr.Bemani'
import os
import logging
from typing import Optional
from addict import Dict
import yaml
logging.basicConfig(level=logging.WARN)
############################################################
# define default config settings
config = Dict()
config.debug = False
config.frame_dist_cm = 1.0
config.max_detection = 240
config.video_src = 0
config.rock_boundaries = []
config.tracking.min_rock_pix = 8
config.tracking.max_rock_pix = 300
config.tracking.max_rock_ratio = 2.0
config.tracking.dist_thresh = 80
config.tracking.max_skip_frame = 3
config.tracking.max_trace_length = 2
config.tracking.max_object_count = 20
############################################################
default_cfgfile = os.path.join(os.path.curdir, "settings.yml")
def loadConfig(cfgfile=None):
global config
if cfgfile is None:
cfgfile = default_cfgfile
if not os.path.isfile(cfgfile):
return False
try:
config.update(yaml.load(open(cfgfile, 'r', encoding="utf-8"), Loader=yaml.FullLoader))
return True
except Exception as e:
logging.error(e)
return False
def saveConfig(config_obj: Dict, cfgfile: Optional[str]=None):
if cfgfile is None:
cfgfile = default_cfgfile
if not os.path.isfile(cfgfile):
return False
try:
yaml.dump(config_obj.to_dict(), open(cfgfile, 'w+'))
return True
except Exception as e:
logging.error(e)
return False