Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
py-3d-face-reconstruction
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Richard Torenvliet
py-3d-face-reconstruction
Commits
059f1949
Commit
059f1949
authored
Jul 13, 2016
by
Richard Torenvliet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update viewer app, moved to static file server and only websockets for reconstruction image
parent
b6cef93a
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
141 additions
and
99 deletions
+141
-99
src/aam.py
src/aam.py
+16
-0
src/server.py
src/server.py
+9
-4
viewer/app/components/.gitkeep
viewer/app/components/.gitkeep
+0
-0
viewer/app/components/images-loader.js
viewer/app/components/images-loader.js
+30
-53
viewer/app/components/three-js-reconstruction.js
viewer/app/components/three-js-reconstruction.js
+16
-6
viewer/app/controllers/.gitkeep
viewer/app/controllers/.gitkeep
+0
-0
viewer/app/controllers/reconstruction.js
viewer/app/controllers/reconstruction.js
+19
-21
viewer/app/helpers/.gitkeep
viewer/app/helpers/.gitkeep
+0
-0
viewer/app/models/.gitkeep
viewer/app/models/.gitkeep
+0
-0
viewer/app/routes/.gitkeep
viewer/app/routes/.gitkeep
+0
-0
viewer/app/routes/application.js
viewer/app/routes/application.js
+4
-0
viewer/app/routes/reconstruction.js
viewer/app/routes/reconstruction.js
+7
-0
viewer/app/templates/application.hbs
viewer/app/templates/application.hbs
+6
-0
viewer/app/templates/components/.gitkeep
viewer/app/templates/components/.gitkeep
+0
-0
viewer/app/templates/components/images-loader.hbs
viewer/app/templates/components/images-loader.hbs
+4
-0
viewer/app/templates/components/three-js-reconstruction.hbs
viewer/app/templates/components/three-js-reconstruction.hbs
+2
-2
viewer/app/templates/reconstruction.hbs
viewer/app/templates/reconstruction.hbs
+5
-13
viewer/config/environment.js
viewer/config/environment.js
+1
-0
viewer/tests/unit/routes/application-test.js
viewer/tests/unit/routes/application-test.js
+11
-0
viewer/tests/unit/routes/reconstruction-test.js
viewer/tests/unit/routes/reconstruction-test.js
+11
-0
No files found.
src/aam.py
View file @
059f1949
...
@@ -21,6 +21,18 @@ class AAMPoints():
...
@@ -21,6 +21,18 @@ class AAMPoints():
these points transparent.
these points transparent.
"""
"""
def
__init__
(
self
,
normalized_flattened_points_list
=
None
,
points_list
=
None
,
actual_shape
=
()):
def
__init__
(
self
,
normalized_flattened_points_list
=
None
,
points_list
=
None
,
actual_shape
=
()):
"""
Args:
normalized_flattened_points_list(ndarray): flattened list of points.
This means that if the points consist of x,y coordinates, then all this
list will be: [x1, y1, x2, y2, ... xi, yi]
points_list(ndarray): this list is the same points but then not
flattened, [[x1, y1], [x2, y2], ... [xi, yi]]. You either create
this object with this argument or the normalized_flattened_points_list
actual_shape(tuple): this is important if you want to reconstruct
the original list, see get_scaled_points() for usage.
"""
self
.
normalized_flattened_points_list
=
normalized_flattened_points_list
self
.
normalized_flattened_points_list
=
normalized_flattened_points_list
self
.
points_list
=
points_list
self
.
points_list
=
points_list
self
.
actual_shape
=
actual_shape
self
.
actual_shape
=
actual_shape
...
@@ -29,6 +41,10 @@ class AAMPoints():
...
@@ -29,6 +41,10 @@ class AAMPoints():
def
get_bounding_box
(
self
):
def
get_bounding_box
(
self
):
"""
"""
Get the bounding box around the points.
Get the bounding box around the points.
Returns:
OpenCV rectangle:
x, y, w, h
"""
"""
if
self
.
bounding_box
is
None
:
if
self
.
bounding_box
is
None
:
return
self
.
calculate_bounding_box
()
return
self
.
calculate_bounding_box
()
...
...
src/server.py
View file @
059f1949
import
json
import
json
import
os.path
import
base64
import
base64
from
glob
import
glob
from
glob
import
glob
from
tornado
import
websocket
,
web
,
ioloop
from
tornado
import
websocket
,
web
,
ioloop
,
autoreload
import
imm_points
as
imm
import
imm_points
as
imm
BASE
=
'../viewer/app'
BASE
=
'../viewer/app'
FILES_DIR
=
'../data/'
FILES_DIR
=
'../data/'
FACE_DB
=
'{}{}'
.
format
(
FILES_DIR
,
'imm_face_db'
)
FACE_DB_NAME
=
'imm_face_db'
FACE_DB
=
'{}{}'
.
format
(
FILES_DIR
,
FACE_DB_NAME
)
class
ImageWebSocketHandler
(
websocket
.
WebSocketHandler
):
class
ImageWebSocketHandler
(
websocket
.
WebSocketHandler
):
...
@@ -105,7 +107,7 @@ class FaceHandler(ApiHandler):
...
@@ -105,7 +107,7 @@ class FaceHandler(ApiHandler):
'type'
:
'faces'
,
'type'
:
'faces'
,
'id'
:
id
,
'id'
:
id
,
'attributes'
:
{
'attributes'
:
{
'filename'
:
filename
,
'filename'
:
'{}/{}'
.
format
(
FACE_DB_NAME
,
os
.
path
.
basename
(
self
.
images
[
id
]))
,
'shape'
:
Points
.
get_scaled_points
(
shape
=
(
480
,
640
)).
tolist
()
'shape'
:
Points
.
get_scaled_points
(
shape
=
(
480
,
640
)).
tolist
()
}
}
})
})
...
@@ -120,9 +122,12 @@ class FaceHandler(ApiHandler):
...
@@ -120,9 +122,12 @@ class FaceHandler(ApiHandler):
app
=
web
.
Application
([
app
=
web
.
Application
([
(
r'/reconstruction[\
/
0-9]?'
,
ImageWebSocketHandler
),
(
r'/reconstruction[\
/
0-9]?'
,
ImageWebSocketHandler
),
(
r'/api/v1/faces[\
/
0-9]?'
,
FaceHandler
),
(
r'/api/v1/faces[\
/
0-9]?'
,
FaceHandler
),
(
r'/data/(.*)'
,
web
.
StaticFileHandler
,
{
'path'
:
'../data'
}),
])
])
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
app
.
listen
(
8888
)
app
.
listen
(
8888
)
ioloop
.
IOLoop
.
instance
().
start
()
ioloop
=
ioloop
.
IOLoop
.
instance
()
autoreload
.
start
(
ioloop
)
ioloop
.
start
()
viewer/app/components/.gitkeep
deleted
100644 → 0
View file @
b6cef93a
viewer/app/components/images-loader.js
View file @
059f1949
import
Ember
from
'
ember
'
;
import
Ember
from
'
ember
'
;
import
ENV
from
'
viewer/config/environment
'
;
export
default
Ember
.
Component
.
extend
({
const
ImageLoaderComponent
=
Ember
.
Component
.
extend
({
websockets
:
inject
.
service
(),
store
:
Ember
.
inject
.
service
(),
socketRef
:
null
,
current_face
:
null
,
images
:
null
,
init
()
{
imageIndexChanged
:
Ember
.
observer
(
'
image_index
'
,
function
()
{
/*
this
.
send
(
'
updateCurrentFace
'
);
* 2) The next step you need to do is to create your actual websocket. Calling socketFor
}),
* will retrieve a cached websocket if one exists or in this case it
* will create a new one for us.
*/
const
socket
=
get
(
this
,
'
websockets
'
).
socketFor
(
'
ws://localhost:8888/reconstruction/images
'
);
/*
* 3) The next step is to define your event handlers. All event handlers
* are added via the `on` method and take 3 arguments: event name, callback
* function, and the context in which to invoke the callback. All 3 arguments
* are required.
*/
socket
.
on
(
'
open
'
,
this
.
openHandler
,
this
);
socket
.
on
(
'
message
'
,
this
.
messageHandler
,
this
);
socket
.
on
(
'
close
'
,
this
.
closeHandler
,
this
);
this
.
set
(
'
socketRef
'
,
socket
);
loadFaces
:
Ember
.
on
(
'
didInsertElement
'
,
function
()
{
},
this
.
get
(
'
store
'
).
findAll
(
'
face
'
).
then
((
faces
)
=>
{
this
.
set
(
'
faces
'
,
faces
);
this
.
send
(
'
updateCurrentFace
'
);
});
}),
willDestroyElement
()
{
faces
:
Ember
.
computed
(
'
params.[]
'
,
function
(){
const
socket
=
this
.
get
(
'
socketRef
'
);
return
this
.
get
(
'
params
'
)[
1
];
}),
/*
actions
:
{
* 4) The final step is to remove all of the listeners you have setup.
/**
* Update the current face given the current index
*/
*/
socket
.
off
(
'
open
'
,
this
.
openHandler
);
updateCurrentFace
()
{
socket
.
off
(
'
message
'
,
this
.
messageHandler
);
var
face
=
this
.
get
(
'
faces
'
).
objectAt
(
this
.
get
(
'
image_index
'
));
socket
.
off
(
'
close
'
,
this
.
closeHandler
);
},
openHandler
(
event
)
{
console
.
log
(
`On open event has been called:
${
event
}
`
);
},
messageHandler
(
event
)
{
var
message
=
JSON
.
parse
(
event
.
data
);
this
.
set
(
'
image
'
,
message
.
image
);
console
.
log
(
`Message:
${
'
received image
'
}
`
);
this
.
set
(
'
current_face
'
,
face
);
},
this
.
set
(
'
current_face_filename
'
,
ENV
.
APP
.
staticURL
+
face
.
get
(
'
filename
'
));
}
closeHandler
(
event
)
{
console
.
log
(
`On close event has been called:
${
event
}
`
);
},
actions
:
{
get_image
()
{
const
socket
=
this
.
get
(
'
socketRef
'
);
socket
.
send
(
JSON
.
stringify
({
image_index
:
1
}
));
},
}
}
});
});
ImageLoaderComponent
.
reopenClass
({
positionalParams
:
[
'
params
'
]
});
export
default
ImageLoaderComponent
;
viewer/app/components/three-js-reconstruction.js
View file @
059f1949
...
@@ -2,8 +2,10 @@ import Ember from 'ember';
...
@@ -2,8 +2,10 @@ import Ember from 'ember';
import
THREE
from
'
npm:three
'
;
import
THREE
from
'
npm:three
'
;
import
dat
from
'
npm:dat-gui
'
;
import
dat
from
'
npm:dat-gui
'
;
export
default
Ember
.
Component
.
extend
({
const
ThreeComponent
=
Ember
.
Component
.
extend
({
store
:
Ember
.
inject
.
service
(),
store
:
Ember
.
inject
.
service
(),
scene
:
null
,
willRender
()
{
willRender
()
{
if
(
this
.
scene
)
{
if
(
this
.
scene
)
{
...
@@ -25,6 +27,11 @@ export default Ember.Component.extend({
...
@@ -25,6 +27,11 @@ export default Ember.Component.extend({
this
.
set
(
'
camera
'
,
camera
);
this
.
set
(
'
camera
'
,
camera
);
this
.
set
(
'
renderer
'
,
renderer
);
this
.
set
(
'
renderer
'
,
renderer
);
this
.
set
(
'
gui
'
,
gui
);
this
.
set
(
'
gui
'
,
gui
);
this
.
get
(
'
store
'
).
findAll
(
'
face
'
).
then
((
faces
)
=>
{
this
.
set
(
'
faces
'
,
faces
);
this
.
addSliders
();
});
},
},
/**
/**
...
@@ -32,17 +39,15 @@ export default Ember.Component.extend({
...
@@ -32,17 +39,15 @@ export default Ember.Component.extend({
* the threejs container.
* the threejs container.
* TODO: try to not use appendChild
* TODO: try to not use appendChild
*/
*/
loadGui
:
Ember
.
on
(
'
didInsertElement
'
,
function
()
{
loadGui
:
Ember
.
computed
(
'
faces
'
,
function
()
{
//var container = document.getElementById('threejs-container');
//var container = document.getElementById('threejs-container');
//container.appendChild(this.get('renderer').domElement);
//container.appendChild(this.get('renderer').domElement);
this
.
addSliders
();
}),
}),
addSliders
()
{
addSliders
()
{
var
self
=
this
;
var
self
=
this
;
var
gui
=
this
.
get
(
'
gui
'
);
var
gui
=
this
.
get
(
'
gui
'
);
var
obj
=
{
var
obj
=
{
name
:
"
Image filename
"
,
name
:
"
Image filename
"
,
index
:
0
index
:
0
...
@@ -53,13 +58,18 @@ export default Ember.Component.extend({
...
@@ -53,13 +58,18 @@ export default Ember.Component.extend({
components
:
0
components
:
0
};
};
var
length
=
this
.
get
(
'
faces
'
).
get
(
'
length
'
);
var
imagesSlider
=
gui
.
add
(
obj
,
"
index
"
).
min
(
0
).
max
(
var
imagesSlider
=
gui
.
add
(
obj
,
"
index
"
).
min
(
0
).
max
(
this
.
n_images
-
1
).
step
(
1
);
length
-
1
).
step
(
1
);
gui
.
add
(
components
,
"
components
"
).
min
(
0
).
max
(
this
.
n_images
-
1
).
step
(
1
);
gui
.
add
(
components
,
"
components
"
).
min
(
0
).
max
(
length
-
1
).
step
(
1
);
imagesSlider
.
onChange
(
function
(
newValue
)
{
imagesSlider
.
onChange
(
function
(
newValue
)
{
self
.
set
(
'
image_index
'
,
newValue
);
self
.
set
(
'
image_index
'
,
newValue
);
self
.
sendAction
(
'
update
'
,
newValue
);
});
});
}
}
});
});
export
default
ThreeComponent
;
viewer/app/controllers/.gitkeep
deleted
100644 → 0
View file @
b6cef93a
viewer/app/controllers/reconstruction.js
View file @
059f1949
...
@@ -5,16 +5,15 @@ const { get, inject } = Ember;
...
@@ -5,16 +5,15 @@ const { get, inject } = Ember;
export
default
Ember
.
Controller
.
extend
({
export
default
Ember
.
Controller
.
extend
({
title
:
'
title
'
,
title
:
'
title
'
,
websockets
:
inject
.
service
(),
websockets
:
inject
.
service
(),
socketRef
:
null
,
faces
:
null
,
image
:
null
,
image
:
null
,
reconstructed
:
null
,
n_images
:
null
,
n_components
:
null
,
image_index
:
0
,
image_index
:
0
,
n_components
:
null
,
n_images
:
null
,
reconstructed
:
null
,
imageIndexChanged
:
Ember
.
observer
(
'
image_index
'
,
function
()
{
socketRef
:
null
,
this
.
send
(
'
getImage
'
);
}),
init
()
{
init
()
{
const
socket
=
get
(
this
,
'
websockets
'
).
socketFor
(
'
ws://localhost:8888/reconstruction
'
);
const
socket
=
get
(
this
,
'
websockets
'
).
socketFor
(
'
ws://localhost:8888/reconstruction
'
);
...
@@ -24,15 +23,6 @@ export default Ember.Controller.extend({
...
@@ -24,15 +23,6 @@ export default Ember.Controller.extend({
socket
.
on
(
'
close
'
,
this
.
closeHandler
,
this
);
socket
.
on
(
'
close
'
,
this
.
closeHandler
,
this
);
this
.
set
(
'
socketRef
'
,
socket
);
this
.
set
(
'
socketRef
'
,
socket
);
this
.
get
(
'
store
'
).
findAll
(
'
face
'
).
then
(
function
(
faces
)
{
var
face
=
faces
.
objectAt
(
0
);
this
.
send
(
'
getImage
'
,
face
);
},
function
(
reason
)
{
console
.
log
(
'
fail
'
);
console
.
log
(
reason
);
});
},
},
willDestroyElement
()
{
willDestroyElement
()
{
...
@@ -47,7 +37,6 @@ export default Ember.Controller.extend({
...
@@ -47,7 +37,6 @@ export default Ember.Controller.extend({
},
},
openHandler
(
event
)
{
openHandler
(
event
)
{
console
.
log
(
event
);
console
.
log
(
`On open event has been called:
${
event
}
`
);
console
.
log
(
`On open event has been called:
${
event
}
`
);
},
},
...
@@ -58,9 +47,9 @@ export default Ember.Controller.extend({
...
@@ -58,9 +47,9 @@ export default Ember.Controller.extend({
this
.
set
(
'
n_images
'
,
message
.
n_images
);
this
.
set
(
'
n_images
'
,
message
.
n_images
);
}
}
if
(
message
.
image
)
{
//
if (message.image) {
this
.
set
(
'
image
'
,
message
.
image
);
//
this.set('image', message.image);
}
//
}
if
(
message
.
reconstructed
)
{
if
(
message
.
reconstructed
)
{
this
.
set
(
'
reconstructed
'
,
message
.
reconstructed
);
this
.
set
(
'
reconstructed
'
,
message
.
reconstructed
);
...
@@ -76,6 +65,10 @@ export default Ember.Controller.extend({
...
@@ -76,6 +65,10 @@ export default Ember.Controller.extend({
//});
//});
},
},
getReconstruction
:
Ember
.
computed
(
'
faces
'
,
function
()
{
console
.
log
(
this
.
get
(
'
faces
'
));
}),
closeHandler
(
event
)
{
closeHandler
(
event
)
{
console
.
log
(
`On close event has been called:
${
event
}
`
);
console
.
log
(
`On close event has been called:
${
event
}
`
);
},
},
...
@@ -84,7 +77,6 @@ export default Ember.Controller.extend({
...
@@ -84,7 +77,6 @@ export default Ember.Controller.extend({
getImage
(
faceModel
)
{
getImage
(
faceModel
)
{
var
filename
=
faceModel
.
get
(
'
filename
'
);
var
filename
=
faceModel
.
get
(
'
filename
'
);
const
socket
=
this
.
get
(
'
socketRef
'
);
const
socket
=
this
.
get
(
'
socketRef
'
);
console
.
log
(
socket
);
socket
.
send
(
socket
.
send
(
JSON
.
stringify
({
filename
:
filename
})
JSON
.
stringify
({
filename
:
filename
})
...
@@ -97,6 +89,12 @@ export default Ember.Controller.extend({
...
@@ -97,6 +89,12 @@ export default Ember.Controller.extend({
socket
.
send
(
socket
.
send
(
JSON
.
stringify
({
reconstruction_index
:
this
.
get
(
'
image_index
'
)}
JSON
.
stringify
({
reconstruction_index
:
this
.
get
(
'
image_index
'
)}
));
));
},
// connects components together
// handles the upate action passed to a component
updateComponentConnector
(
index
)
{
this
.
set
(
'
image_index
'
,
index
);
}
}
}
}
});
});
viewer/app/helpers/.gitkeep
deleted
100644 → 0
View file @
b6cef93a
viewer/app/models/.gitkeep
deleted
100644 → 0
View file @
b6cef93a
viewer/app/routes/.gitkeep
deleted
100644 → 0
View file @
b6cef93a
viewer/app/routes/application.js
0 → 100644
View file @
059f1949
import
Ember
from
'
ember
'
;
export
default
Ember
.
Route
.
extend
({
});
viewer/app/routes/reconstruction.js
0 → 100644
View file @
059f1949
import
Ember
from
'
ember
'
;
export
default
Ember
.
Route
.
extend
({
model
()
{
//return this.get('store').findAll('face');
}
});
viewer/app/templates/application.hbs
0 → 100644
View file @
059f1949
<nav
class=
"clearfix white bg-black"
>
{{#
link-to
"index"
class
=
"btn py2"
}}
Index
{{/
link-to
}}
{{#
link-to
"reconstruction"
class
=
"btn py2"
}}
Reconstruction
{{/
link-to
}}
</nav>
{{
outlet
}}
viewer/app/templates/components/.gitkeep
deleted
100644 → 0
View file @
b6cef93a
viewer/app/templates/components/images-loader.hbs
View file @
059f1949
{{#
if
current_face_filename
}}
<img
src=
'
{{
current_face_filename
}}
'
alt=
'missing original'
>
{{/if}}
{{
yield
}}
{{
yield
}}
viewer/app/templates/components/three-js-reconstruction.hbs
View file @
059f1949
<div
id=
"threejs-container"
>
<div
id=
"threejs-container"
>
</div>
</div>
{{
yield
}}
viewer/app/templates/reconstruction.hbs
View file @
059f1949
<h1>
Reconstruction
</h1>
<h1>
Reconstruction
</h1>
<div
class=
"container"
>
<div
class=
"container"
>
<div
class=
"clearfix"
>
<div
class=
"clearfix"
>
<div
class=
"col col-6"
>
<div
class=
"col col-6"
>
{{#if
image
}}
{{
images-loader
image_index
=
image_index
}}
<img
src=
'data:image/jpg;base64,
{{
image
}}
'
alt=
'missing image'
>
{{/if}}
</div>
</div>
<div
class=
"col col-6"
>
<div
class=
"col col-6"
>
{{#if
reconstructed
}}
{{#if
reconstructed
}}
<img
src=
'data:image/jpg;base64,
{{
reconstructed
}}
'
alt=
'missing image'
>
<img
src=
'data:image/jpg;base64,
{{
reconstructed
}}
'
alt=
'missing image'
>
{{/if}}
{{/if}}
</div>
</div>
</div>
</div>
<div
class=
"col col-12 px2"
>
<div
class=
"col col-12 px2"
>
{{#if
n_images
}}
{{
three-js-reconstruction
update
=
(
action
'updateComponentConnector'
)
}}
{{
three-js-reconstruction
n_images
=
n_images
image_index
=
image_index
n_components
=
n_components
}}
{{/if}}
</div>
</div>
</div>
</div>
...
...
viewer/config/environment.js
View file @
059f1949
...
@@ -20,6 +20,7 @@ module.exports = function(environment) {
...
@@ -20,6 +20,7 @@ module.exports = function(environment) {
};
};
if
(
environment
===
'
development
'
)
{
if
(
environment
===
'
development
'
)
{
ENV
.
APP
.
staticURL
=
'
http://localhost:8888/data/
'
;
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS = true;
...
...
viewer/tests/unit/routes/application-test.js
0 → 100644
View file @
059f1949
import
{
moduleFor
,
test
}
from
'
ember-qunit
'
;
moduleFor
(
'
route:application
'
,
'
Unit | Route | application
'
,
{
// Specify the other units that are required for this test.
// needs: ['controller:foo']
});
test
(
'
it exists
'
,
function
(
assert
)
{
let
route
=
this
.
subject
();
assert
.
ok
(
route
);
});
viewer/tests/unit/routes/reconstruction-test.js
0 → 100644
View file @
059f1949
import
{
moduleFor
,
test
}
from
'
ember-qunit
'
;
moduleFor
(
'
route:reconstruction
'
,
'
Unit | Route | reconstruction
'
,
{
// Specify the other units that are required for this test.
// needs: ['controller:foo']
});
test
(
'
it exists
'
,
function
(
assert
)
{
let
route
=
this
.
subject
();
assert
.
ok
(
route
);
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment