forked from shariq/track-bright-point
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformers.py
47 lines (41 loc) · 1.3 KB
/
transformers.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
from tps import from_control_points
import os
import shutil
import pdb
import time
# install from https://github.com/olt/thinplatespline
class transformer:
def __init__(self, initial_points = []):
self.points = initial_points
if initial_points:
self.control_points = from_control_points(self.points)
else:
self.control_points = None
def update(self, new_point):
self.points.append(new_point)
self.control_points = from_control_points(self.points)
def reset(self):
self.points = []
self.control_points = None
def evaluate(self, pair):
return self.control_points.transform(pair[0], pair[1])
def to_string(self):
return str(self.points)
def transformer_from_string(string):
return transformer(eval(string))
if 'transformer_cache' in os.listdir('.'):
Transformer = transformer_from_string(open('transformer_cache').read())
else:
Transformer = transformer()
open('transformer_cache','w').close()
import shutil
def forever_dump():
while False:
time.sleep(5.0)
s = Transformer.to_string()
shutil.copy('transformer_cache','cache_bkp')
open('transformer_cache','w').write(s)
import threading
T = threading.Thread(target = forever_dump)
T.daemon = True
T.start()