Commit 347a71c3 authored by Richard Torenvliet's avatar Richard Torenvliet

Moved imm_points to imm, in preperation of including a dataset implementation capability

parent f495975f
...@@ -51,7 +51,7 @@ class AAMPoints(): ...@@ -51,7 +51,7 @@ class AAMPoints():
return self.bounding_box return self.bounding_box
def get_scaled_points(self, shape, rescale=False): def get_scaled_points(self, width_height_dimensions, rescale=False):
""" """
Scale the normalized flattened points list to a scale given by 'shape'. Scale the normalized flattened points list to a scale given by 'shape'.
The x and y values should be scaled to the width and height of the image. The x and y values should be scaled to the width and height of the image.
...@@ -66,11 +66,14 @@ class AAMPoints(): ...@@ -66,11 +66,14 @@ class AAMPoints():
if self.points_list is None or rescale: if self.points_list is None or rescale:
self.points_list = self.normalized_flattened_points_list self.points_list = self.normalized_flattened_points_list
# shape into [[x, y(, z)], [x, y, (,z)]]
# we use the 'actual_shape' which is known from the creation of
# this object.
if len(self.actual_shape): if len(self.actual_shape):
self.points_list = self.points_list.reshape(self.actual_shape) self.points_list = self.points_list.reshape(self.actual_shape)
h = shape[0] h = width_height_dimensions[0]
w = shape[1] w = width_height_dimensions[1]
self.points_list[:, 0] = self.points_list[:, 0] * w self.points_list[:, 0] = self.points_list[:, 0] * w
self.points_list[:, 1] = self.points_list[:, 1] * h self.points_list[:, 1] = self.points_list[:, 1] * h
...@@ -88,11 +91,13 @@ class AAMPoints(): ...@@ -88,11 +91,13 @@ class AAMPoints():
width) width)
""" """
assert self.points_list is not None, \ assert self.points_list is not None, \
'the list points already need to be scaled order to correctly work' 'the list points already need to be scaled order to correctly work,\
this requires that get_scaled_points is executed first.'
hull = cv2.convexHull(self.points_list, returnPoints=True) hull = cv2.convexHull(self.points_list, returnPoints=True)
return cv2.boundingRect(hull) return cv2.boundingRect(hull)
# TODO: impove by not using opencv but just min-max of the lists
def get_bounding_box_2(self): def get_bounding_box_2(self):
pass pass
#hull = cv2.convexHull(self.points_list, returnPoints=True) #hull = cv2.convexHull(self.points_list, returnPoints=True)
...@@ -103,7 +108,7 @@ class AAMPoints(): ...@@ -103,7 +108,7 @@ class AAMPoints():
def get_mean(vector): def get_mean(vector):
""" construct a mean from a matrix of x,y values """ construct a mean from a matrix of x,y values
Args: Args:
imm_points(numpy array) that follows the following structure: points(numpy array) that follows the following structure:
Returns: Returns:
mean_values (numpy array) mean_values (numpy array)
...@@ -187,8 +192,8 @@ def build_texture_feature_vectors(files, get_image_with_points, mean_points, tri ...@@ -187,8 +192,8 @@ def build_texture_feature_vectors(files, get_image_with_points, mean_points, tri
""" """
Args: Args:
files (list): list files files (list): list files
flattened (bool): Flatten the inner feature vectors, see get_image_with_points (function): That can return the image together
flatten_feature_vectors. with the location.
mean_points(AAMPoints): AAMPoints object mean_points(AAMPoints): AAMPoints object
Returns: Returns:
...@@ -197,8 +202,7 @@ def build_texture_feature_vectors(files, get_image_with_points, mean_points, tri ...@@ -197,8 +202,7 @@ def build_texture_feature_vectors(files, get_image_with_points, mean_points, tri
mean_texture = [] mean_texture = []
image, points = get_image_with_points(files[0]) image, points = get_image_with_points(files[0])
mean_points.get_scaled_points(image.shape) mean_points.get_scaled_points(image.shape) # improve this, see issue #1
x, y, w_slice, h_slice = mean_points.get_bounding_box() x, y, w_slice, h_slice = mean_points.get_bounding_box()
for i, f in enumerate(files): for i, f in enumerate(files):
......
...@@ -4,7 +4,7 @@ import pytest ...@@ -4,7 +4,7 @@ import pytest
import aam import aam
import pca import pca
import imm_points as imm import imm
from reconstruction import triangles as tri from reconstruction import triangles as tri
......
...@@ -10,7 +10,7 @@ import cv2 ...@@ -10,7 +10,7 @@ import cv2
# local imports # local imports
import pca import pca
import aam import aam
import imm_points as imm import imm
from reconstruction import reconstruction from reconstruction import reconstruction
...@@ -67,6 +67,11 @@ def add_parser_options(): ...@@ -67,6 +67,11 @@ def add_parser_options():
help='pca model file that contains or is going to contain the pca shape model' help='pca model file that contains or is going to contain the pca shape model'
) )
pca_group.add_argument(
'--shape_type', type=str, choices=['imm'],
help='type of shape, annotated dataset'
)
pca_group.add_argument( pca_group.add_argument(
'--model_texture_file', type=str, '--model_texture_file', type=str,
help='pca model file that contains or is going to contain the pca texture model' help='pca model file that contains or is going to contain the pca texture model'
...@@ -135,7 +140,8 @@ def save_pca_model_shape(args): ...@@ -135,7 +140,8 @@ def save_pca_model_shape(args):
assert args.model_shape_file, '--model_shape_file needs to be provided to save the pca model' assert args.model_shape_file, '--model_shape_file needs to be provided to save the pca model'
points = aam.build_shape_feature_vectors( points = aam.build_shape_feature_vectors(
args.files, imm.get_imm_points, flattened=True) args.files, imm.get_imm_points, flattened=True
)
mean_values = aam.get_mean(points) mean_values = aam.get_mean(points)
...@@ -213,6 +219,7 @@ def show_pca_model(args): ...@@ -213,6 +219,7 @@ def show_pca_model(args):
def generate_call_graph(args): def generate_call_graph(args):
"""Performance debug function, will be (re)moved later. """
assert args.model_shape_file, '--model_texture_file needs to be provided to save the pca model' assert args.model_shape_file, '--model_texture_file needs to be provided to save the pca model'
assert args.model_texture_file, '--model_texture_file needs to be provided to save the pca model' assert args.model_texture_file, '--model_texture_file needs to be provided to save the pca model'
......
...@@ -19,7 +19,7 @@ from kivy.graphics.context_instructions import Color ...@@ -19,7 +19,7 @@ from kivy.graphics.context_instructions import Color
from functools import partial from functools import partial
from math import cos, sin, pi from math import cos, sin, pi
import imm_points as imm import imm
from utils import utils from utils import utils
from utils.texture import fill_triangle from utils.texture import fill_triangle
#import IMMPoints, build_feature_vectors, \ #import IMMPoints, build_feature_vectors, \
......
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