Commit 9712728e authored by Richard Torenvliet's avatar Richard Torenvliet

Merge

parents 1895f423 5a5697bd
...@@ -25,6 +25,11 @@ DATASET = os.environ.get('DATASET', 'ibug') # see src/datasets for options ...@@ -25,6 +25,11 @@ DATASET = os.environ.get('DATASET', 'ibug') # see src/datasets for options
# load correct module to support the dataset # load correct module to support the dataset
dataset_module = import_dataset_module(DATASET) dataset_module = import_dataset_module(DATASET)
images = glob('{}/*.jpg'.format(FACE_DB))
images.sort()
asf = glob('{}/*.asf'.format(FACE_DB))
asf.sort()
class ImageWebSocketHandler(websocket.WebSocketHandler): class ImageWebSocketHandler(websocket.WebSocketHandler):
handlers = { handlers = {
...@@ -33,12 +38,6 @@ class ImageWebSocketHandler(websocket.WebSocketHandler): ...@@ -33,12 +38,6 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
} }
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.images = glob('{}/*.jpg'.format(FACE_DB))
self.asf = glob('{}/*.asf'.format(FACE_DB))
self.images.sort()
self.asf.sort()
# todo get from settings # todo get from settings
model_texture_file = '{}/pca_{}_texture_model.npy'.format( model_texture_file = '{}/pca_{}_texture_model.npy'.format(
FILES_DIR, DATASET) FILES_DIR, DATASET)
...@@ -81,9 +80,9 @@ class ImageWebSocketHandler(websocket.WebSocketHandler): ...@@ -81,9 +80,9 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
t1 = time() t1 = time()
if DATASET == 'imm': if DATASET == 'imm':
image_filename = self.asf[image_index] image_filename = asf[image_index]
else: else:
image_filename = self.images[image_index] image_filename = images[image_index]
dst_image = reconstruction.reconstruct_shape_texture( dst_image = reconstruction.reconstruct_shape_texture(
dataset_module, dataset_module,
...@@ -114,15 +113,15 @@ class ImageWebSocketHandler(websocket.WebSocketHandler): ...@@ -114,15 +113,15 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
for m in message.keys(): for m in message.keys():
try: try:
handler = getattr(self, self.handlers[m]) handler = getattr(self, self.handlers[m])
print handler logger.debug('calling handler %s', handler)
handler(message[m]) handler(message[m])
except (AttributeError, KeyError) as e: except (AttributeError, KeyError) as e:
msg = 'no handler for {}'.format(m) msg = 'no handler for {}: {}'.format(m, e)
print(msg, e) logger.info('%s', msg)
self.__return_error(msg) self.__return_error(msg)
except Exception as e: except Exception as e:
msg = 'no handler for {}'.format(m) msg = 'no handler for {}: {}'.format(m, e)
print(msg, e) logger.info('%s', msg)
self.__return_error(msg) self.__return_error(msg)
traceback.print_exc() traceback.print_exc()
...@@ -132,11 +131,6 @@ class ImageWebSocketHandler(websocket.WebSocketHandler): ...@@ -132,11 +131,6 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
class ApiHandler(web.RequestHandler): class ApiHandler(web.RequestHandler):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.images = glob('{}/*.jpg'.format(FACE_DB))
self.asf_files = glob('{}/*.asf'.format(FACE_DB))
self.images.sort()
self.asf_files.sort()
web.RequestHandler.__init__(self, *args, **kwargs) web.RequestHandler.__init__(self, *args, **kwargs)
def set_default_headers(self): def set_default_headers(self):
...@@ -145,6 +139,7 @@ class ApiHandler(web.RequestHandler): ...@@ -145,6 +139,7 @@ class ApiHandler(web.RequestHandler):
self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
self.set_header("Content-Type", 'application/vnd.api+json') self.set_header("Content-Type", 'application/vnd.api+json')
class FaceHandler(ApiHandler): class FaceHandler(ApiHandler):
@web.asynchronous @web.asynchronous
def get(self, *args): def get(self, *args):
...@@ -154,13 +149,13 @@ class FaceHandler(ApiHandler): ...@@ -154,13 +149,13 @@ class FaceHandler(ApiHandler):
""" """
data = [] data = []
for id, filename in enumerate(self.asf_files): for id, filename in enumerate(asf):
data.append({ data.append({
'type': 'faces', 'type': 'faces',
'id': id, 'id': id,
'attributes': { 'attributes': {
'filename': '{}/{}'.format( 'filename': '{}/{}'.format(
FACE_DB_NAME, os.path.basename(self.images[id]) FACE_DB_NAME, os.path.basename(images[id])
), ),
} }
}) })
......
...@@ -48,7 +48,6 @@ logging.config.dictConfig({ ...@@ -48,7 +48,6 @@ logging.config.dictConfig({
}) })
logger = logging.getLogger('root') logger = logging.getLogger('root')
#logger.setLevel(logging.DEBUG)
if os.environ.get('DEBUG', False): if os.environ.get('DEBUG', False):
logger = logging.getLogger('debug') logger = logging.getLogger('debug')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment