Commit 20492cc6 authored by Richard Torenvliet's avatar Richard Torenvliet

Update server to use the ibug reconstruction method

parent 67f1b14e
......@@ -248,7 +248,7 @@ def build_texture_feature_vectors(
x, y, w_slice, h_slice = mean_points.get_bounding_box()
for i, f in enumerate(files[:10]):
for i, f in enumerate(files):
image, points = get_image_with_points(f)
Points = AAMPoints(
......
......@@ -18,7 +18,7 @@ class IBUGPoints(aam.AAMPoints):
SHAPE = (68, 2)
"""IBUG datapoints abstraction"""
def __init__(self, filename=None, points_list=None):
def __init__(self, filename=None, image=None, points_list=None):
"""
Args:
filename: optional image file
......@@ -30,7 +30,11 @@ class IBUGPoints(aam.AAMPoints):
self.filename = filename
if self.filename:
self.__get_image()
if image is None:
self.__get_image()
else:
self.image = image
self.detector = landmarks.Detector()
points_list = self.detector.detect_shape(self.image)[0]
points_list = np.asarray(points_list, dtype=np.float32)
......@@ -114,7 +118,7 @@ def get_points(files):
points = []
total_files = len(files)
for i, filename in enumerate(files[:10]):
for i, filename in enumerate(files):
t1 = time()
ibug = IBUGPoints(filename=filename)
points.append(ibug.get_points())
......
import json
import traceback
import os.path
import base64
from glob import glob
......@@ -7,6 +8,7 @@ import cv2
import numpy as np
from tornado import websocket, web, ioloop, autoreload
import pca
from datasets import imm
from reconstruction import reconstruction
......@@ -30,8 +32,8 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
self.asf = glob('{}/*.asf'.format(FACE_DB))
# todo get from settings
model_texture_file = '{}/pca_texture_model.npy'.format(FILES_DIR)
model_shape_file = '{}/pca_shape_model.npy'.format(FILES_DIR)
model_texture_file = '{}/pca_ibug_texture_model.npy'.format(FILES_DIR)
model_shape_file = '{}/pca_ibug_shape_model.npy'.format(FILES_DIR)
self.shape_model = pca.PCAModel(model_shape_file)
self.texture_model = pca.PCAModel(model_texture_file)
......@@ -63,6 +65,8 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
image_as_background = message.get('background_image', True)
shape_components = message.get('shape_components', 58)
shape_eigenvalues_multiplier = message.get('shape_eigenvalues')
#image = message.get('image')
#input_image = base64.b64decode(image)
shape_eigenvalues_multiplier = np.asarray(
shape_eigenvalues_multiplier, dtype=np.float32
......@@ -70,13 +74,13 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
logger.info('using %s shape_components', shape_components)
asf_filename = self.asf[image_index]
image_filename = self.images[image_index]
dataset_module = import_dataset_module(args.shape_type)
input_points = imm.IMMPoints(filename=asf_filename)
dataset_module = import_dataset_module('ibug')
input_points = dataset_module.factory(filename=image_filename)
input_image = input_points.get_image()
mean_points = dataset_module.factory(points_list=shape_model.mean_values)
mean_points = dataset_module.factory(points_list=self.shape_model.mean_values)
mean_points.get_scaled_points(input_image.shape)
# set dst image to an empty image if value is None
......@@ -86,7 +90,7 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
else:
dst_image = input_image
output_points = imm.IMMPoints(
output_points = dataset_module.factory(
points_list=input_points.get_points()
)
......@@ -99,8 +103,7 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
reconstruction.reconstruct_shape(
output_points,
self.shape_model,
shape_Vt=shape_Vt, # overwrite by scaled Vt
n_components=shape_components
shape_Vt=shape_Vt # overwrite by scaled Vt
)
reconstruction.reconstruct_texture(
......@@ -131,6 +134,7 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
for m in message.keys():
try:
handler = getattr(self, self.handlers[m])
print handler
handler(message[m])
except (AttributeError, KeyError) as e:
msg = 'no handler for {}'.format(m)
......@@ -140,6 +144,7 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
msg = 'no handler for {}'.format(m)
print(msg, e)
self.__return_error(msg)
traceback.print_exc()
def on_close(self):
print("WebSocket closed")
......
......@@ -9,7 +9,8 @@ import logging.config
import os
LANDMARK_DETECTOR_PATH = 'data/shape_predictor_68_face_landmarks.dat'
dir_path = os.path.dirname(os.path.realpath(__file__))
LANDMARK_DETECTOR_PATH = dir_path + '/../data/shape_predictor_68_face_landmarks.dat'
#logging.basicConfig(level=logging.INFO,
# format='%(asctime)s %(levelname)s %(name)s: %(message)s')
......
......@@ -20,15 +20,43 @@ const ImageLoaderComponent = Ember.Component.extend({
return this.get('params')[1];
}),
convertFilenameToBase64: function(fileUrl, resolve) {
var image = new Image();
image.crossOrigin = 'Anonymous';
image.onload = function() {
var canvas = document.createElement('CANVAS');
var ctx = canvas.getContext('2d');
var dataURL;
canvas.height = this.height;
canvas.width = this.width;
ctx.drawImage(this, 0, 0);
dataURL = canvas.toDataURL('image/jpeg');
console.log(dataUrl);
resolve(dataURL);
canvas = null;
};
image.src = fileUrl;
},
actions: {
/**
* Update the current face given the current index
*/
updateCurrentFace() {
var face = this.get('faces').objectAt(this.get('image_index'));
var filename = face.get('filename');
//var that = this;
//var requestConversion = new Ember.RSVP.Promise(function(resolve, reject) {
// that.convertFilenameToBase64(filename, resolve);
//});
//requestConversion.then((base64Image) => {
this.set('current_face', face);
this.set('current_face_filename', ENV.APP.staticURL + face.get('filename'));
//this.set('current_face_base64', base64Image);
this.set('current_face_filename', ENV.APP.staticURL + filename);
}
}
});
......
......@@ -8,7 +8,9 @@ const ThreeComponent = Ember.Component.extend({
scene: null,
willRender() {
if (this.scene) { return; }
if (this.scene) {
return;
}
var scene = new THREE.Scene();
var gui = new dat.GUI();
......
......@@ -79,7 +79,6 @@ export default Ember.Controller.extend({
getReconstruction: Ember.observer(
'image_index', 'background_image',
'shape_components', 'shape_eigenvalues', function() {
console.log('updating');
this.send('getReconstruction');
}),
......@@ -91,6 +90,7 @@ export default Ember.Controller.extend({
getImage(faceModel) {
this.set('loading', true);
var filename = faceModel.get('filename');
const socket = this.get('socketRef');
socket.send(
......@@ -101,6 +101,7 @@ export default Ember.Controller.extend({
getReconstruction() {
this.set('loading', true);
const socket = this.get('socketRef');
console.log(this.get('current_face_base64'));
socket.send(
JSON.stringify({
......@@ -138,7 +139,7 @@ export default Ember.Controller.extend({
this.send('getReconstruction');
},
resetShapeEigenValues(gui) {
resetShapeEigenValues(/*gui*/) {
this.initShapeEigenValues(15);
}
}
......
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