Commit 1895f423 authored by Richard Torenvliet's avatar Richard Torenvliet

face alignment .dat file was loading every time for a request, made changes to...

face alignment .dat file was loading every time for a request, made changes to the import times to make it faster
parent 1d8566ce
FROM smvanveen/computer-vision:20160120173546
RUN pip install dlib
FROM smvanveen/computer-vision:20161109143812
RUN git clone https://github.com/davisking/dlib.git
RUN (cd dlib; python setup.py install --yes USE_AVX_INSTRUCTIONS)
WORKDIR /src
#COPY requirements.txt /tmp
......
......@@ -13,6 +13,9 @@ import aam
import landmarks
from settings import logger
# load detector (this loads the datafile from disk, so needs to be done once).
detector = landmarks.Detector()
class IBUGPoints(aam.AAMPoints):
SHAPE = (68, 2)
......@@ -35,8 +38,7 @@ class IBUGPoints(aam.AAMPoints):
else:
self.image = image
self.detector = landmarks.Detector()
points_list = self.detector.detect_shape(self.image)[0]
points_list = detector.detect_shape(self.image)[0]
points_list = np.asarray(points_list, dtype=np.float32)
# normalizing data by dividing it by the image
......
......@@ -137,12 +137,11 @@ def reconstruct_texture(src_image, dst_image, texture_model,
)
def reconstruct_shape_texture(dataset_name, shape_model, texture_model,
def reconstruct_shape_texture(dataset_module, shape_model, texture_model,
image_filename, shape_components,
shape_eigenvalues_multiplier=[],
image_as_background=False):
"""Reconstructs shape and texture"""
dataset_module = import_dataset_module(dataset_name)
input_points = dataset_module.factory(filename=image_filename)
input_image = input_points.get_image()
......@@ -190,6 +189,6 @@ def reconstruct_shape_texture(dataset_name, shape_model, texture_model,
output_points
)
# output_points.draw_triangles(image=dst_image, show_points=False)
output_points.draw_triangles(image=dst_image, show_points=False)
return dst_image
......@@ -14,6 +14,7 @@ from datasets import imm
from reconstruction import reconstruction
from settings import logger
from utility import import_dataset_module
from time import time
FILES_DIR = '/data/'
......@@ -21,6 +22,9 @@ FACE_DB_NAME = 'imm_face_db'
FACE_DB = '{}{}'.format(FILES_DIR, FACE_DB_NAME)
DATASET = os.environ.get('DATASET', 'ibug') # see src/datasets for options
# load correct module to support the dataset
dataset_module = import_dataset_module(DATASET)
class ImageWebSocketHandler(websocket.WebSocketHandler):
handlers = {
......@@ -74,13 +78,15 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
logger.info('using %s shape_components', shape_components)
t1 = time()
if DATASET == 'imm':
image_filename = self.asf[image_index]
else:
image_filename = self.images[image_index]
dst_image = reconstruction.reconstruct_shape_texture(
DATASET,
dataset_module,
self.shape_model,
self.texture_model,
image_filename,
......@@ -89,6 +95,8 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
image_as_background=image_as_background
)
logger.info('Time elapsed : %s sec', time() - t1)
_, reconstructed = cv2.imencode('.jpg', dst_image)
reconstructed = base64.b64encode(reconstructed)
......
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