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