Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
c0a41054
Commit
c0a41054
authored
Jul 30, 2012
by
Philipp Wagner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
facerec_demo.py: Shortened code. Final version.
parent
4a7e29b3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
facerec_demo.py
samples/python2/facerec_demo.py
+6
-6
No files found.
samples/python2/facerec_demo.py
View file @
c0a41054
...
@@ -133,24 +133,24 @@ if __name__ == "__main__":
...
@@ -133,24 +133,24 @@ if __name__ == "__main__":
eigenvectors
=
model
.
getMat
(
"eigenvectors"
)
eigenvectors
=
model
.
getMat
(
"eigenvectors"
)
cv2
.
imwrite
(
"test.png"
,
X
[
0
])
cv2
.
imwrite
(
"test.png"
,
X
[
0
])
# We'll save the mean, by first normalizing it:
# We'll save the mean, by first normalizing it:
mean_norm
=
normalize
(
mean
,
0
,
255
)
mean_norm
=
normalize
(
mean
,
0
,
255
,
dtype
=
np
.
uint8
)
mean_resized
=
mean_norm
.
reshape
(
X
[
0
]
.
shape
)
mean_resized
=
mean_norm
.
reshape
(
X
[
0
]
.
shape
)
if
out_dir
is
None
:
if
out_dir
is
None
:
cv2
.
imshow
(
"mean"
,
np
.
asarray
(
mean_resized
,
dtype
=
np
.
uint8
)
)
cv2
.
imshow
(
"mean"
,
mean_resized
)
else
:
else
:
cv2
.
imwrite
(
"
%
s/mean.png"
%
(
out_dir
),
np
.
asarray
(
mean_resized
,
dtype
=
np
.
uint8
)
)
cv2
.
imwrite
(
"
%
s/mean.png"
%
(
out_dir
),
mean_resized
)
# Turn the first (at most) 16 eigenvectors into grayscale
# Turn the first (at most) 16 eigenvectors into grayscale
# images. You could also use cv::normalize here, but sticking
# images. You could also use cv::normalize here, but sticking
# to NumPy is much easier for now.
# to NumPy is much easier for now.
# Note: eigenvectors are stored by column:
# Note: eigenvectors are stored by column:
for
i
in
xrange
(
min
(
len
(
X
),
16
)):
for
i
in
xrange
(
min
(
len
(
X
),
16
)):
eigenvector_i
=
eigenvectors
[:,
i
]
.
reshape
(
X
[
0
]
.
shape
)
eigenvector_i
=
eigenvectors
[:,
i
]
.
reshape
(
X
[
0
]
.
shape
)
eigenvector_i_norm
=
normalize
(
eigenvector_i
,
0
,
255
)
eigenvector_i_norm
=
normalize
(
eigenvector_i
,
0
,
255
,
dtype
=
np
.
uint8
)
# Show or save the images:
# Show or save the images:
if
out_dir
is
None
:
if
out_dir
is
None
:
cv2
.
imshow
(
"
%
s/eigen
vector_
%
d"
%
(
out_dir
,
i
),
np
.
asarray
(
eigenvector_i_norm
,
dtype
=
np
.
uint8
)
)
cv2
.
imshow
(
"
%
s/eigen
face_
%
d"
%
(
out_dir
,
i
),
eigenvector_i_norm
)
else
:
else
:
cv2
.
imwrite
(
"
%
s/eigen
vector_
%
d.png"
%
(
out_dir
,
i
),
np
.
asarray
(
eigenvector_i_norm
,
dtype
=
np
.
uint8
)
)
cv2
.
imwrite
(
"
%
s/eigen
face_
%
d.png"
%
(
out_dir
,
i
),
eigenvector_i_norm
)
# Show the images:
# Show the images:
if
out_dir
is
None
:
if
out_dir
is
None
:
cv2
.
waitKey
(
0
)
cv2
.
waitKey
(
0
)
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