forked from kitovyj/ratrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_serialization.py
61 lines (46 loc) · 2.36 KB
/
config_serialization.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
import os.path
import json
from tracking import *
animal_model_to_str = { tracking.Animal.Configuration.model_normal : "normal",
tracking.Animal.Configuration.model_with_drive : "with_drive" }
str_to_animal_model = dict([[v,k] for k,v in animal_model_to_str.items()])
def load_tracking_config(file_name):
config = tracking.Tracking.Configuration()
if not os.path.isfile(file_name):
save_tracking_config(config, file_name)
else:
data_file = open(file_name)
data = json.load(data_file)
config.skeletonization_res_width = data["skeletonization_res_width"]
config.skeletonization_res_height = data["skeletonization_res_height"]
config.vertebra_length = data["vertebra_length"]
config.scale = data["scale"]
return config
def save_tracking_config(config, file_name):
file = open(file_name, 'w')
json.dump({ 'skeletonization_res_width': config.skeletonization_res_width,
'skeletonization_res_height': config.skeletonization_res_height,
'vertebra_length': config.vertebra_length,
'scale': config.scale }, file, indent = 4)
def load_animal_config(file_name):
config = tracking.Animal.Configuration()
if not os.path.isfile(file_name):
save_animal_config(config, file_name)
else:
data_file = open(file_name)
data = json.load(data_file)
config.back_min_value_coeff = data["back_min_value_coeff"]
config.front_min_value_coeff = data["front_min_value_coeff"]
config.max_body_length = data["max_body_length"]
config.max_body_width = data["max_body_width"]
config.min_body_width = data["min_body_width"]
config.model = str_to_animal_model[data["model"]]
return config
def save_animal_config(config, file_name):
file = open(file_name, 'w')
json.dump({ 'back_min_value_coeff': config.back_min_value_coeff,
'front_min_value_coeff': config.front_min_value_coeff,
'max_body_length': config.max_body_length,
'model': animal_model_to_str[config.model],
'max_body_width': config.max_body_width,
'min_body_width': config.min_body_width }, file, indent = 4)