/
frame_match.py
51 lines (43 loc) · 1.65 KB
/
frame_match.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
import wearscript
import base64
import os
import random
import msgpack
import argparse
import time
import copy
import picarus_takeout
import numpy as np
from match import ImagePoints, ImageMatch
def main():
image_points = ImagePoints()
image_match = ImageMatch()
match_points = {}
ar_model = picarus_takeout.ModelChain(msgpack.dumps([{'kw':{}, 'name': 'picarus.ARMarkerDetector'}]))
print()
def callback(ws, **kw):
def image_handler(*data):
groupDevice = '' # data[0].split(':', 1)[1]
print('Image[%s]' % data[0])
if groupDevice in match_points:
st = time.time()
pts = image_points(data[2])
print('Points[%f]' % (time.time() - st))
st = time.time()
h = image_match(match_points[groupDevice], pts)
print('Match[%f]' % (time.time() - st))
print('Sending')
ws.publish('warph:' + groupDevice, h.ravel().tolist())
tags, tag_size = msgpack.loads(ar_model.process_binary(data[2]))
ws.publish('warptags:image', np.array(tags).reshape(tag_size).tolist())
def warp_sample_handler(*data):
print('Warp Sample')
match_points[data[1]] = image_points(data[2])
tags, tag_size = msgpack.loads(ar_model.process_binary(data[2]))
ws.publish('warptags:sample', np.array(tags).reshape(tag_size).tolist())
ws.subscribe('image', image_handler)
ws.subscribe('warpsample', warp_sample_handler)
ws.handler_loop()
wearscript.parse(callback, argparse.ArgumentParser())
if __name__ == '__main__':
main()