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
8e5a7e83
Commit
8e5a7e83
authored
Apr 18, 2016
by
Richard Torenvliet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored a little and add a script to generate and store the model
parent
bafb7dbd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
12 deletions
+50
-12
makefile
makefile
+6
-0
scripts/imm_test_set.sh
scripts/imm_test_set.sh
+5
-0
scripts/imm_train_set.sh
scripts/imm_train_set.sh
+5
-0
src/main.py
src/main.py
+34
-12
No files found.
makefile
View file @
8e5a7e83
...
@@ -10,6 +10,12 @@ data/imm_face_db: data/imm_face_db.tar.gz
...
@@ -10,6 +10,12 @@ data/imm_face_db: data/imm_face_db.tar.gz
data/imm_face_db.tar.gz
:
data/imm_face_db.tar.gz
:
(
cd
data
;
wget http://www.imm.dtu.dk/~aam/datasets/imm_face_db.tar.gz
)
(
cd
data
;
wget http://www.imm.dtu.dk/~aam/datasets/imm_face_db.tar.gz
)
generate_test_model
:
python src/main.py
\
--store_pca
\
--asf
data/imm_face_db/
*
.asf
\
--file
data/pca_test_model
test
:
test
:
py.test
-f
src/
*
_test.py
py.test
-f
src/
*
_test.py
scripts/imm_test_set.sh
0 → 100755
View file @
8e5a7e83
files
=
`
ls
data/imm_face_db/ |
grep
-E
"^[0-2][0-9].*.asf"
`
for
f
in
$files
;
do
echo
"data/imm_face_db/
$f
"
done
scripts/imm_train_set.sh
0 → 100755
View file @
8e5a7e83
files
=
`
ls
data/imm_face_db/ |
grep
-E
"^[3-4][0-9].*.asf"
`
for
f
in
$files
;
do
echo
"data/imm_face_db/
$f
"
done
src/main.py
View file @
8e5a7e83
import
copy
import
copy
import
argparse
import
argparse
import
logging
import
cv2
import
cv2
import
numpy
as
np
import
numpy
as
np
from
pca
import
pca
,
reconstruct
import
pca
from
aam
import
get_mean
from
aam
import
get_mean
from
imm_points
import
IMMPoints
,
build_feature_vectors
,
\
from
imm_points
import
IMMPoints
,
build_feature_vectors
,
\
flatten_feature_vectors
flatten_feature_vectors
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
'%(asctime)s %(levelname)s %(name)s: %(message)s'
)
logger
=
logging
.
getLogger
(
__name__
)
def
nothing
(
_
):
pass
def
add_parser_options
():
def
add_parser_options
():
...
@@ -21,12 +23,12 @@ def add_parser_options():
...
@@ -21,12 +23,12 @@ def add_parser_options():
pca_group
.
add_argument
(
pca_group
.
add_argument
(
'--store_pca'
,
action
=
'store_true'
,
'--store_pca'
,
action
=
'store_true'
,
help
=
'
number of principle components to keep and are able to manipulate
'
help
=
'
Store the pca model
'
)
)
pca_group
.
add_argument
(
pca_group
.
add_argument
(
'--show_pca'
,
action
=
'store_true'
,
'--show_pca'
,
action
=
'store_true'
,
help
=
'
number of principle components to keep and are able to manipulate
'
help
=
'
Show and manipulate the stored PCA model
'
)
)
# asf files
# asf files
...
@@ -47,6 +49,10 @@ def add_parser_options():
...
@@ -47,6 +49,10 @@ def add_parser_options():
return
parser
return
parser
def
nothing
(
_
):
pass
def
init_eigenvalue_trackbars
(
n_components
,
s
):
def
init_eigenvalue_trackbars
(
n_components
,
s
):
cv2
.
namedWindow
(
'eigenvalues'
)
cv2
.
namedWindow
(
'eigenvalues'
)
...
@@ -54,10 +60,24 @@ def init_eigenvalue_trackbars(n_components, s):
...
@@ -54,10 +60,24 @@ def init_eigenvalue_trackbars(n_components, s):
cv2
.
createTrackbar
(
'{}'
.
format
(
i
),
'eigenvalues'
,
500
,
1000
,
nothing
)
cv2
.
createTrackbar
(
'{}'
.
format
(
i
),
'eigenvalues'
,
500
,
1000
,
nothing
)
def
store_model
(
args
):
def
store_
pca_
model
(
args
):
"""
"""
Store the U, s, Vt and mean of all the asf datafiles given by the asf
Store the U, s, Vt and mean of all the asf datafiles given by the asf
files.
files.
It is stored in the following way:
np.load(filename, np.assary([U, s, Vt, mean_values])
And accessed by:
UsVtm = np.load(args.file)
U = UsVtm[0]
s = UsVtm[1]
Vt = UsVtm[2]
mean_values = UsVtm[3]
"""
"""
assert
args
.
asf
,
'--asf files should be given'
assert
args
.
asf
,
'--asf files should be given'
assert
args
.
file
,
'--file needs to be provided to store the pca model'
assert
args
.
file
,
'--file needs to be provided to store the pca model'
...
@@ -65,12 +85,13 @@ def store_model(args):
...
@@ -65,12 +85,13 @@ def store_model(args):
imm_points
=
build_feature_vectors
(
args
.
asf
,
flattened
=
True
)
imm_points
=
build_feature_vectors
(
args
.
asf
,
flattened
=
True
)
mean_values
=
get_mean
(
imm_points
)
mean_values
=
get_mean
(
imm_points
)
U
,
s
,
Vt
=
pca
(
imm_points
,
mean_values
)
U
,
s
,
Vt
=
pca
.
pca
(
imm_points
,
mean_values
)
np
.
save
(
args
.
file
,
np
.
asarray
([
U
,
s
,
Vt
,
mean_values
]))
np
.
save
(
args
.
file
,
np
.
asarray
([
U
,
s
,
Vt
,
mean_values
]))
logger
.
info
(
'Stored pca model in %s'
,
args
.
file
)
def
show_pca
(
args
):
def
show_pca
_model
(
args
):
assert
args
.
asf
,
'--asf files should be given to allow the image to be shown'
assert
args
.
asf
,
'--asf files should be given to allow the image to be shown'
assert
args
.
file
,
'--file needs to be provided to get the pca model'
assert
args
.
file
,
'--file needs to be provided to get the pca model'
...
@@ -80,7 +101,6 @@ def show_pca(args):
...
@@ -80,7 +101,6 @@ def show_pca(args):
U
=
UsVtm
[
0
]
U
=
UsVtm
[
0
]
s
=
UsVtm
[
1
]
s
=
UsVtm
[
1
]
Vt
=
UsVtm
[
2
]
Vt
=
UsVtm
[
2
]
mean_values
=
UsVtm
[
3
]
mean_values
=
UsVtm
[
3
]
# init trackbars
# init trackbars
...
@@ -95,7 +115,7 @@ def show_pca(args):
...
@@ -95,7 +115,7 @@ def show_pca(args):
s_copy
=
copy
.
copy
(
s
)
s_copy
=
copy
.
copy
(
s
)
while
True
:
while
True
:
projection
=
reconstruct
(
U
,
s_copy
,
Vt
,
n_components
)
projection
=
pca
.
reconstruct
(
U
,
s_copy
,
Vt
,
n_components
)
X_reconstructed
=
(
projection
[
index
]
+
mean_values
).
reshape
((
58
,
2
))
X_reconstructed
=
(
projection
[
index
]
+
mean_values
).
reshape
((
58
,
2
))
imm
=
IMMPoints
(
points
=
X_reconstructed
)
imm
=
IMMPoints
(
points
=
X_reconstructed
)
...
@@ -122,9 +142,11 @@ def main():
...
@@ -122,9 +142,11 @@ def main():
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
if
args
.
show_pca
:
if
args
.
show_pca
:
show_pca
(
args
)
show_pca
_model
(
args
)
elif
args
.
store_pca
:
elif
args
.
store_pca
:
store_model
(
args
)
store_pca_model
(
args
)
elif
args
.
reconstruct
:
reconstruct_with_model
(
args
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
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