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
ff85575b
Commit
ff85575b
authored
Aug 05, 2013
by
Mathieu Barnachon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding read/write functions to PCA class. Update PCA test.
parent
4ed9b1ca
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
0 deletions
+51
-0
core.hpp
modules/core/include/opencv2/core.hpp
+4
-0
matmul.cpp
modules/core/src/matmul.cpp
+21
-0
test_mat.cpp
modules/core/test/test_mat.cpp
+26
-0
No files found.
modules/core/include/opencv2/core.hpp
View file @
ff85575b
...
...
@@ -670,6 +670,10 @@ public:
//! reconstructs the original vector from the projection
void
backProject
(
InputArray
vec
,
OutputArray
result
)
const
;
//! write and load PCA matrix
void
write
(
FileStorage
&
fs
)
const
;
void
read
(
const
FileNode
&
fs
);
Mat
eigenvectors
;
//!< eigenvectors of the covariation matrix
Mat
eigenvalues
;
//!< eigenvalues of the covariation matrix
Mat
mean
;
//!< mean value subtracted before the projection and added after the back projection
...
...
modules/core/src/matmul.cpp
View file @
ff85575b
...
...
@@ -2896,6 +2896,27 @@ PCA& PCA::operator()(InputArray _data, InputArray __mean, int flags, int maxComp
return
*
this
;
}
void
PCA
::
write
(
FileStorage
&
fs
)
const
{
CV_Assert
(
fs
.
isOpened
()
);
fs
<<
"name"
<<
"PCA"
;
fs
<<
"vectors"
<<
eigenvectors
;
fs
<<
"values"
<<
eigenvalues
;
fs
<<
"mean"
<<
mean
;
}
void
PCA
::
read
(
const
FileNode
&
fs
)
{
CV_Assert
(
!
fs
.
empty
()
);
String
name
=
(
String
)
fs
[
"name"
];
CV_Assert
(
name
==
"PCA"
);
cv
::
read
(
fs
[
"vectors"
],
eigenvectors
);
cv
::
read
(
fs
[
"values"
],
eigenvalues
);
cv
::
read
(
fs
[
"mean"
],
mean
);
}
template
<
typename
T
>
int
computeCumulativeEnergy
(
const
Mat
&
eigenvalues
,
double
retainedVariance
)
{
...
...
modules/core/test/test_mat.cpp
View file @
ff85575b
...
...
@@ -510,6 +510,32 @@ protected:
return
;
}
#endif
// Test read and write
FileStorage
fs
(
"PCA_store.yml"
,
FileStorage
::
WRITE
);
rPCA
.
write
(
fs
);
fs
.
release
();
PCA
lPCA
;
fs
.
open
(
"PCA_store.yml"
,
FileStorage
::
READ
);
lPCA
.
read
(
fs
.
root
()
);
err
=
norm
(
rPCA
.
eigenvectors
,
lPCA
.
eigenvectors
,
CV_RELATIVE_L2
);
if
(
err
>
0
)
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"bad accuracy of write/load functions (YML); err = %f
\n
"
,
err
);
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_BAD_ACCURACY
);
}
err
=
norm
(
rPCA
.
eigenvalues
,
lPCA
.
eigenvalues
,
CV_RELATIVE_L2
);
if
(
err
>
0
)
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"bad accuracy of write/load functions (YML); err = %f
\n
"
,
err
);
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_BAD_ACCURACY
);
}
err
=
norm
(
rPCA
.
mean
,
lPCA
.
mean
,
CV_RELATIVE_L2
);
if
(
err
>
0
)
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"bad accuracy of write/load functions (YML); err = %f
\n
"
,
err
);
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_BAD_ACCURACY
);
}
}
};
...
...
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