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
bafb7dbd
Commit
bafb7dbd
authored
Apr 17, 2016
by
Richard Torenvliet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a way to store the pca model and add the pca model itself
parent
75db1611
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
6 deletions
+43
-6
data/pca_model.npy
data/pca_model.npy
+0
-0
src/main.py
src/main.py
+43
-6
No files found.
data/pca_model.npy
0 → 100644
View file @
bafb7dbd
File added
src/main.py
View file @
bafb7dbd
...
@@ -10,7 +10,6 @@ from imm_points import IMMPoints, build_feature_vectors, \
...
@@ -10,7 +10,6 @@ from imm_points import IMMPoints, build_feature_vectors, \
flatten_feature_vectors
flatten_feature_vectors
def
nothing
(
_
):
def
nothing
(
_
):
pass
pass
...
@@ -20,6 +19,11 @@ def add_parser_options():
...
@@ -20,6 +19,11 @@ def add_parser_options():
pca_group
=
parser
.
add_argument_group
(
'show_pca'
)
pca_group
=
parser
.
add_argument_group
(
'show_pca'
)
pca_group
.
add_argument
(
'--store_pca'
,
action
=
'store_true'
,
help
=
'number of principle components to keep and are able to manipulate'
)
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
=
'number of principle components to keep and are able to manipulate'
...
@@ -35,6 +39,11 @@ def add_parser_options():
...
@@ -35,6 +39,11 @@ def add_parser_options():
help
=
'number of principle components to keep and are able to manipulate'
help
=
'number of principle components to keep and are able to manipulate'
)
)
pca_group
.
add_argument
(
'--file'
,
type
=
str
,
help
=
'pca model file that contains or is going to contain the pca model'
)
return
parser
return
parser
...
@@ -45,14 +54,35 @@ def init_eigenvalue_trackbars(n_components, s):
...
@@ -45,14 +54,35 @@ def init_eigenvalue_trackbars(n_components, s):
cv2
.
createTrackbar
(
'{}'
.
format
(
i
),
'eigenvalues'
,
500
,
1000
,
nothing
)
cv2
.
createTrackbar
(
'{}'
.
format
(
i
),
'eigenvalues'
,
500
,
1000
,
nothing
)
def
show_pca
():
def
store_model
(
args
):
assert
args
.
asf
,
'--asf files should be supplied'
"""
Store the U, s, Vt and mean of all the asf datafiles given by the asf
files.
"""
assert
args
.
asf
,
'--asf files should be given'
assert
args
.
file
,
'--file needs to be provided to store the pca model'
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
(
imm_points
,
mean_values
)
np
.
save
(
args
.
file
,
np
.
asarray
([
U
,
s
,
Vt
,
mean_values
]))
def
show_pca
(
args
):
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'
# load the stored model file
UsVtm
=
np
.
load
(
args
.
file
)
U
=
UsVtm
[
0
]
s
=
UsVtm
[
1
]
Vt
=
UsVtm
[
2
]
mean_values
=
UsVtm
[
3
]
# init trackbars
# init trackbars
index
=
0
index
=
0
cv2
.
namedWindow
(
'index'
)
cv2
.
namedWindow
(
'index'
)
...
@@ -73,7 +103,8 @@ def show_pca():
...
@@ -73,7 +103,8 @@ def show_pca():
imm
.
show_on_img
(
img
)
imm
.
show_on_img
(
img
)
for
i
in
range
(
n_components
):
for
i
in
range
(
n_components
):
s_copy
[
i
]
=
s
[
i
]
*
((
cv2
.
getTrackbarPos
(
str
(
i
),
'eigenvalues'
)
-
500
)
/
10.0
)
s_copy
[
i
]
=
s
[
i
]
*
(
(
cv2
.
getTrackbarPos
(
str
(
i
),
'eigenvalues'
)
-
500
)
/
10.0
)
index
=
cv2
.
getTrackbarPos
(
'index'
,
'index'
)
index
=
cv2
.
getTrackbarPos
(
'index'
,
'index'
)
imm
=
IMMPoints
(
filename
=
args
.
asf
[
index
])
imm
=
IMMPoints
(
filename
=
args
.
asf
[
index
])
...
@@ -86,9 +117,15 @@ def show_pca():
...
@@ -86,9 +117,15 @@ def show_pca():
cv2
.
destroyAllWindows
()
cv2
.
destroyAllWindows
()
if
__name__
==
'__main__'
:
def
main
()
:
parser
=
add_parser_options
()
parser
=
add_parser_options
()
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
if
args
.
show_pca
:
if
args
.
show_pca
:
show_pca
()
show_pca
(
args
)
elif
args
.
store_pca
:
store_model
(
args
)
if
__name__
==
'__main__'
:
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