Commit f718b904 authored by Richard Torenvliet's avatar Richard Torenvliet

Removed KivY dependency and code #3

parent beedf9a5
......@@ -63,14 +63,6 @@ graph_reconstruction:
--shape_type imm \
--n_components 6
show_kivy:
python src/main.py \
--show_kivy \
--files data/imm_face_db/*.asf \
--model_texture_file data/pca_texture_model.npy \
--model_shape_file data/pca_shape_model.npy \
--n_components 6
test:
python -m py.test -f src/test/*_test.py
......
cycler==0.10.0
Cython==0.24
Kivy==1.9.1
Kivy-Garden==0.1.4
matplotlib==1.5.1
numpy==1.11.0
pyparsing==2.1.2
......
......@@ -2,7 +2,6 @@
# python std
import argparse
import logging
import sys
import importlib
# installed packages
......@@ -29,11 +28,6 @@ def add_parser_options():
help='Reconstruct one face with a given pca model'
)
pca_group.add_argument(
'--show_kivy', action='store_true',
help='Reconstruct using kivy as a GUI'
)
pca_group.add_argument(
'--generate_call_graph', action='store_true',
help='Generate call graph from the reconstruction'
......@@ -166,39 +160,6 @@ def save_pca_model_shape(args):
logger.info('shape pca model saved in %s', args.model_shape_file + '_shape')
def reconstruct_with_model(args):
assert args.files, '--files should be given to allow the image to be shown'
assert args.model_shape_file, '--model_shape_file needs to be provided to get the pca model'
assert args.shape_type, '--shape_type the type of dataset, see datasets module'
dataset_module = import_dataset_module(args.shape_type)
# clear sys args. arguments are conflicting with parseargs
# kivy will parse args upon import and will crash if it finds our
# 'unsupported by kivy' arguments.
sys.argv[1:] = []
from view.reconstruct import ReconstructApp
Vt_shape, s, n_shape_components, mean_value_points, triangles = pca.load(args.model_shape_file)
Vt_texture, s_texture, n_texture_components, mean_values_texture, _ = pca.load(args.model_texture_file)
app = ReconstructApp()
app.set_values(
args=args,
eigenv_shape=Vt_shape,
eigenv_texture=Vt_texture,
mean_value_points=mean_value_points,
n_shape_components=n_shape_components,
mean_values_texture=mean_values_texture,
n_texture_components=n_texture_components,
triangles=triangles
)
app.run()
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'
......@@ -284,10 +245,7 @@ def main():
elif args.save_pca_texture:
save_pca_model_texture(args)
elif args.reconstruct:
#reconstruct_with_model(args)
show_reconstruction(args)
elif args.show_kivy:
reconstruct_with_model(args)
elif args.generate_call_graph:
generate_call_graph(args)
......
This diff is collapsed.
'''
Mesh test
=========
This demonstrates the use of a mesh mode to distort an image. You should see
a line of buttons across the bottom of a canvas. Pressing them displays
the mesh, a small circle of points, with different mesh.mode settings.
'''
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
from kivy.graphics import Mesh
from functools import partial
from math import cos, sin, pi
class MeshTestApp(App):
def change_mode(self, mode, *largs):
self.mesh.mode = mode
def build_mesh(self):
""" returns a Mesh of a rough circle. """
vertices = []
indices = []
step = 10
istep = (pi * 2) / float(step)
x = [200, 200, 300, 340]
y = [400, 200, 300, 340]
for i in range(4):
vertices.extend([x[i], y[i], 0, 0])
indices.append(i)
indices = [0, 1, 2, 3]
#for i in range(step):
# x = 300 + cos(istep * i) * 100
# y = 300 + sin(istep * i) * 100
# vertices.extend([x, y, 0, 0])
# indices.append(i)
return Mesh(vertices=vertices, indices=indices)
def build(self):
wid = Widget()
with wid.canvas:
self.mesh = self.build_mesh()
layout = BoxLayout(size_hint=(1, None), height=50)
for mode in ('points', 'line_strip', 'line_loop', 'lines',
'triangle_strip', 'triangle_fan', 'triangles'):
button = Button(text=mode)
button.bind(on_release=partial(self.change_mode, mode))
layout.add_widget(button)
root = BoxLayout(orientation='vertical')
root.add_widget(wid)
root.add_widget(layout)
return root
if __name__ == '__main__':
MeshTestApp().run()
'''
Line (SmoothLine) Experiment
============================
This demonstrates the experimental and unfinished SmoothLine feature
for fast line drawing. You should see a multi-segment
path at the top of the screen, and sliders and buttons along the bottom.
You can click to add new points to the segment, change the transparency
and width of the line, or hit 'Animate' to see a set of sine and cosine
animations. The Cap and Joint buttons don't work: SmoothLine has not
implemented these features yet.
'''
from kivy.app import App
from kivy.properties import OptionProperty, NumericProperty, ListProperty, \
BooleanProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
from kivy.clock import Clock
from math import cos, sin
Builder.load_string('''
<LinePlayground>:
canvas:
Color:
rgba: .4, .4, 1, root.alpha
SmoothLine:
points: self.points
joint: self.joint
cap: self.cap
width: self.linewidth
close: self.close
Color:
rgba: .8, .8, .8, root.alpha_controlline
SmoothLine:
points: self.points
close: self.close
Color:
rgba: 1, .4, .4, root.alpha
SmoothLine:
points: self.points2
joint: self.joint
cap: self.cap
width: self.linewidth
close: self.close
GridLayout:
cols: 2
size_hint: 1, None
height: 44 * 5
GridLayout:
cols: 2
Label:
text: 'Alpha'
Slider:
value: root.alpha
on_value: root.alpha = float(args[1])
min: 0.
max: 1.
Label:
text: 'Alpha Control Line'
Slider:
value: root.alpha_controlline
on_value: root.alpha_controlline = float(args[1])
min: 0.
max: 1.
Label:
text: 'Width'
Slider:
value: root.linewidth
on_value: root.linewidth = args[1]
min: 1
max: 40
Label:
text: 'Cap'
GridLayout:
rows: 1
ToggleButton:
group: 'cap'
text: 'none'
on_press: root.cap = self.text
ToggleButton:
group: 'cap'
text: 'round'
on_press: root.cap = self.text
ToggleButton:
group: 'cap'
text: 'square'
on_press: root.cap = self.text
Label:
text: 'Joint'
GridLayout:
rows: 1
ToggleButton:
group: 'joint'
text: 'none'
on_press: root.joint = self.text
ToggleButton:
group: 'joint'
text: 'round'
on_press: root.joint = self.text
ToggleButton:
group: 'joint'
text: 'miter'
on_press: root.joint = self.text
ToggleButton:
group: 'joint'
text: 'bevel'
on_press: root.joint = self.text
Label:
text: 'Close'
ToggleButton:
text: 'Close line'
on_press: root.close = self.state == 'down'
AnchorLayout:
GridLayout:
cols: 1
size_hint: None, None
size: self.minimum_size
ToggleButton:
size_hint: None, None
size: 100, 44
text: 'Animate'
on_state: root.animate(self.state == 'down')
Button:
size_hint: None, None
size: 100, 44
text: 'Clear'
on_press: root.points = root.points2 = []
''')
class LinePlayground(FloatLayout):
alpha_controlline = NumericProperty(1.0)
alpha = NumericProperty(0.5)
close = BooleanProperty(False)
points = ListProperty([(500, 500),
[300, 300, 500, 300],
[500, 400, 600, 400]])
points2 = ListProperty([])
joint = OptionProperty('none', options=('round', 'miter', 'bevel', 'none'))
cap = OptionProperty('none', options=('round', 'square', 'none'))
linewidth = NumericProperty(10.0)
dt = NumericProperty(0)
def on_touch_down(self, touch):
if super(LinePlayground, self).on_touch_down(touch):
return True
touch.grab(self)
self.points.append(touch.pos)
return True
def on_touch_move(self, touch):
if touch.grab_current is self:
self.points[-1] = touch.pos
return True
return super(LinePlayground, self).on_touch_move(touch)
def on_touch_up(self, touch):
if touch.grab_current is self:
touch.ungrab(self)
return True
return super(LinePlayground, self).on_touch_up(touch)
def animate(self, do_animation):
if do_animation:
Clock.schedule_interval(self.update_points_animation, 0)
else:
Clock.unschedule(self.update_points_animation)
def update_points_animation(self, dt):
cy = self.height * 0.6
cx = self.width * 0.1
w = self.width * 0.8
step = 20
points = []
points2 = []
self.dt += dt
for i in range(int(w / step)):
x = i * step
points.append(cx + x)
points.append(cy + cos(x / w * 8. + self.dt) * self.height * 0.2)
points2.append(cx + x)
points2.append(cy + sin(x / w * 8. + self.dt) * self.height * 0.2)
self.points = points
self.points2 = points2
class TestLineApp(App):
def build(self):
return LinePlayground()
if __name__ == '__main__':
TestLineApp().run()
# Draw lines between widgets for easy debugging
# <Widget>
# canvas.after:
# Line:
# rectangle: self.x+1,self.y+1,self.width-1,self.height-1
# dash_offset: 5
# dash_length: 3
<ImageCanvas>
<RootWidget>
BoxLayout:
orientation: 'vertical'
BoxLayout:
ImageCanvas
id: image_viewer
ReconstructCanvas
id: reconstruct_viewer
BoxLayout:
orientation: 'vertical'
BoxLayout:
orientation: 'vertical'
size_hint_y: 0.5
Label:
text: "Image {}".format(int(image_slider.value))
Slider:
id: image_slider
min: 0
max: 100
value: 0
Label:
text: "Using {} components".format(int(n_shape_components.value))
Slider:
id: n_shape_components
min: 0
max: 58
value: 0
BoxLayout:
BoxLayout:
orientation: 'vertical'
id: texture_eigenvalues
BoxLayout:
orientation: 'vertical'
id: eigenvalues
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