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
20492cc6
Commit
20492cc6
authored
Sep 07, 2016
by
Richard Torenvliet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update server to use the ibug reconstruction method
parent
67f1b14e
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
18 deletions
+59
-18
src/aam.py
src/aam.py
+1
-1
src/datasets/ibug.py
src/datasets/ibug.py
+7
-3
src/server.py
src/server.py
+14
-9
src/settings.py
src/settings.py
+2
-1
viewer/app/components/images-loader.js
viewer/app/components/images-loader.js
+29
-1
viewer/app/components/three-js-reconstruction.js
viewer/app/components/three-js-reconstruction.js
+3
-1
viewer/app/controllers/reconstruction.js
viewer/app/controllers/reconstruction.js
+3
-2
No files found.
src/aam.py
View file @
20492cc6
...
...
@@ -248,7 +248,7 @@ def build_texture_feature_vectors(
x
,
y
,
w_slice
,
h_slice
=
mean_points
.
get_bounding_box
()
for
i
,
f
in
enumerate
(
files
[:
10
]
):
for
i
,
f
in
enumerate
(
files
):
image
,
points
=
get_image_with_points
(
f
)
Points
=
AAMPoints
(
...
...
src/datasets/ibug.py
View file @
20492cc6
...
...
@@ -18,7 +18,7 @@ class IBUGPoints(aam.AAMPoints):
SHAPE
=
(
68
,
2
)
"""IBUG datapoints abstraction"""
def
__init__
(
self
,
filename
=
None
,
points_list
=
None
):
def
__init__
(
self
,
filename
=
None
,
image
=
None
,
points_list
=
None
):
"""
Args:
filename: optional image file
...
...
@@ -30,7 +30,11 @@ class IBUGPoints(aam.AAMPoints):
self
.
filename
=
filename
if
self
.
filename
:
if
image
is
None
:
self
.
__get_image
()
else
:
self
.
image
=
image
self
.
detector
=
landmarks
.
Detector
()
points_list
=
self
.
detector
.
detect_shape
(
self
.
image
)[
0
]
points_list
=
np
.
asarray
(
points_list
,
dtype
=
np
.
float32
)
...
...
@@ -114,7 +118,7 @@ def get_points(files):
points
=
[]
total_files
=
len
(
files
)
for
i
,
filename
in
enumerate
(
files
[:
10
]
):
for
i
,
filename
in
enumerate
(
files
):
t1
=
time
()
ibug
=
IBUGPoints
(
filename
=
filename
)
points
.
append
(
ibug
.
get_points
())
...
...
src/server.py
View file @
20492cc6
import
json
import
traceback
import
os.path
import
base64
from
glob
import
glob
...
...
@@ -7,6 +8,7 @@ import cv2
import
numpy
as
np
from
tornado
import
websocket
,
web
,
ioloop
,
autoreload
import
pca
from
datasets
import
imm
from
reconstruction
import
reconstruction
...
...
@@ -30,8 +32,8 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
self
.
asf
=
glob
(
'{}/*.asf'
.
format
(
FACE_DB
))
# todo get from settings
model_texture_file
=
'{}/pca_texture_model.npy'
.
format
(
FILES_DIR
)
model_shape_file
=
'{}/pca_shape_model.npy'
.
format
(
FILES_DIR
)
model_texture_file
=
'{}/pca_
ibug_
texture_model.npy'
.
format
(
FILES_DIR
)
model_shape_file
=
'{}/pca_
ibug_
shape_model.npy'
.
format
(
FILES_DIR
)
self
.
shape_model
=
pca
.
PCAModel
(
model_shape_file
)
self
.
texture_model
=
pca
.
PCAModel
(
model_texture_file
)
...
...
@@ -63,6 +65,8 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
image_as_background
=
message
.
get
(
'background_image'
,
True
)
shape_components
=
message
.
get
(
'shape_components'
,
58
)
shape_eigenvalues_multiplier
=
message
.
get
(
'shape_eigenvalues'
)
#image = message.get('image')
#input_image = base64.b64decode(image)
shape_eigenvalues_multiplier
=
np
.
asarray
(
shape_eigenvalues_multiplier
,
dtype
=
np
.
float32
...
...
@@ -70,13 +74,13 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
logger
.
info
(
'using %s shape_components'
,
shape_components
)
asf_filename
=
self
.
asf
[
image_index
]
image_filename
=
self
.
images
[
image_index
]
dataset_module
=
import_dataset_module
(
args
.
shape_type
)
input_points
=
imm
.
IMMPoints
(
filename
=
asf
_filename
)
dataset_module
=
import_dataset_module
(
'ibug'
)
input_points
=
dataset_module
.
factory
(
filename
=
image
_filename
)
input_image
=
input_points
.
get_image
()
mean_points
=
dataset_module
.
factory
(
points_list
=
shape_model
.
mean_values
)
mean_points
=
dataset_module
.
factory
(
points_list
=
s
elf
.
s
hape_model
.
mean_values
)
mean_points
.
get_scaled_points
(
input_image
.
shape
)
# set dst image to an empty image if value is None
...
...
@@ -86,7 +90,7 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
else
:
dst_image
=
input_image
output_points
=
imm
.
IMMPoints
(
output_points
=
dataset_module
.
factory
(
points_list
=
input_points
.
get_points
()
)
...
...
@@ -99,8 +103,7 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
reconstruction
.
reconstruct_shape
(
output_points
,
self
.
shape_model
,
shape_Vt
=
shape_Vt
,
# overwrite by scaled Vt
n_components
=
shape_components
shape_Vt
=
shape_Vt
# overwrite by scaled Vt
)
reconstruction
.
reconstruct_texture
(
...
...
@@ -131,6 +134,7 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
for
m
in
message
.
keys
():
try
:
handler
=
getattr
(
self
,
self
.
handlers
[
m
])
print
handler
handler
(
message
[
m
])
except
(
AttributeError
,
KeyError
)
as
e
:
msg
=
'no handler for {}'
.
format
(
m
)
...
...
@@ -140,6 +144,7 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
msg
=
'no handler for {}'
.
format
(
m
)
print
(
msg
,
e
)
self
.
__return_error
(
msg
)
traceback
.
print_exc
()
def
on_close
(
self
):
print
(
"WebSocket closed"
)
...
...
src/settings.py
View file @
20492cc6
...
...
@@ -9,7 +9,8 @@ import logging.config
import
os
LANDMARK_DETECTOR_PATH
=
'data/shape_predictor_68_face_landmarks.dat'
dir_path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
LANDMARK_DETECTOR_PATH
=
dir_path
+
'/../data/shape_predictor_68_face_landmarks.dat'
#logging.basicConfig(level=logging.INFO,
# format='%(asctime)s %(levelname)s %(name)s: %(message)s')
...
...
viewer/app/components/images-loader.js
View file @
20492cc6
...
...
@@ -20,15 +20,43 @@ const ImageLoaderComponent = Ember.Component.extend({
return
this
.
get
(
'
params
'
)[
1
];
}),
convertFilenameToBase64
:
function
(
fileUrl
,
resolve
)
{
var
image
=
new
Image
();
image
.
crossOrigin
=
'
Anonymous
'
;
image
.
onload
=
function
()
{
var
canvas
=
document
.
createElement
(
'
CANVAS
'
);
var
ctx
=
canvas
.
getContext
(
'
2d
'
);
var
dataURL
;
canvas
.
height
=
this
.
height
;
canvas
.
width
=
this
.
width
;
ctx
.
drawImage
(
this
,
0
,
0
);
dataURL
=
canvas
.
toDataURL
(
'
image/jpeg
'
);
console
.
log
(
dataUrl
);
resolve
(
dataURL
);
canvas
=
null
;
};
image
.
src
=
fileUrl
;
},
actions
:
{
/**
* Update the current face given the current index
*/
updateCurrentFace
()
{
var
face
=
this
.
get
(
'
faces
'
).
objectAt
(
this
.
get
(
'
image_index
'
));
var
filename
=
face
.
get
(
'
filename
'
);
//var that = this;
//var requestConversion = new Ember.RSVP.Promise(function(resolve, reject) {
// that.convertFilenameToBase64(filename, resolve);
//});
//requestConversion.then((base64Image) => {
this
.
set
(
'
current_face
'
,
face
);
this
.
set
(
'
current_face_filename
'
,
ENV
.
APP
.
staticURL
+
face
.
get
(
'
filename
'
));
//this.set('current_face_base64', base64Image);
this
.
set
(
'
current_face_filename
'
,
ENV
.
APP
.
staticURL
+
filename
);
}
}
});
...
...
viewer/app/components/three-js-reconstruction.js
View file @
20492cc6
...
...
@@ -8,7 +8,9 @@ const ThreeComponent = Ember.Component.extend({
scene
:
null
,
willRender
()
{
if
(
this
.
scene
)
{
return
;
}
if
(
this
.
scene
)
{
return
;
}
var
scene
=
new
THREE
.
Scene
();
var
gui
=
new
dat
.
GUI
();
...
...
viewer/app/controllers/reconstruction.js
View file @
20492cc6
...
...
@@ -79,7 +79,6 @@ export default Ember.Controller.extend({
getReconstruction
:
Ember
.
observer
(
'
image_index
'
,
'
background_image
'
,
'
shape_components
'
,
'
shape_eigenvalues
'
,
function
()
{
console
.
log
(
'
updating
'
);
this
.
send
(
'
getReconstruction
'
);
}),
...
...
@@ -91,6 +90,7 @@ export default Ember.Controller.extend({
getImage
(
faceModel
)
{
this
.
set
(
'
loading
'
,
true
);
var
filename
=
faceModel
.
get
(
'
filename
'
);
const
socket
=
this
.
get
(
'
socketRef
'
);
socket
.
send
(
...
...
@@ -101,6 +101,7 @@ export default Ember.Controller.extend({
getReconstruction
()
{
this
.
set
(
'
loading
'
,
true
);
const
socket
=
this
.
get
(
'
socketRef
'
);
console
.
log
(
this
.
get
(
'
current_face_base64
'
));
socket
.
send
(
JSON
.
stringify
({
...
...
@@ -138,7 +139,7 @@ export default Ember.Controller.extend({
this
.
send
(
'
getReconstruction
'
);
},
resetShapeEigenValues
(
gui
)
{
resetShapeEigenValues
(
/*gui*/
)
{
this
.
initShapeEigenValues
(
15
);
}
}
...
...
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