Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
084ca5d7
Commit
084ca5d7
authored
Aug 10, 2014
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed facerec_demo compile errors
parent
cd0569a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
16 deletions
+11
-16
facerec_demo.cpp
modules/face/samples/facerec_demo.cpp
+10
-5
precomp.hpp
modules/face/src/precomp.hpp
+1
-11
No files found.
modules/face/samples/facerec_demo.cpp
View file @
084ca5d7
...
...
@@ -18,11 +18,14 @@
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/face.hpp"
#include "opencv2/core/utility.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>
using
namespace
cv
;
using
namespace
cv
::
face
;
...
...
@@ -30,7 +33,7 @@ using namespace std;
static
void
read_csv
(
const
string
&
filename
,
vector
<
Mat
>&
images
,
vector
<
int
>&
labels
,
std
::
map
<
int
,
string
>&
labelsInfo
,
char
separator
=
';'
)
{
ifstream
csv
(
filename
.
c_str
());
if
(
!
csv
)
CV_Error
(
CV_
StsBadArg
,
"No valid input file was given, please check the given filename."
);
if
(
!
csv
)
CV_Error
(
Error
::
StsBadArg
,
"No valid input file was given, please check the given filename."
);
string
line
,
path
,
classlabel
,
info
;
while
(
getline
(
csv
,
line
))
{
stringstream
liness
(
line
);
...
...
@@ -49,7 +52,7 @@ static void read_csv(const string& filename, vector<Mat>& images, vector<int>& l
glob
(
root
,
files
,
true
);
for
(
vector
<
String
>::
const_iterator
f
=
files
.
begin
();
f
!=
files
.
end
();
++
f
)
{
cout
<<
"
\t
"
<<
*
f
<<
endl
;
Mat
img
=
imread
(
*
f
,
CV_LOAD_IMAGE
_GRAYSCALE
);
Mat
img
=
imread
(
*
f
,
IMREAD
_GRAYSCALE
);
static
int
w
=-
1
,
h
=-
1
;
static
bool
showSmallSizeWarning
=
true
;
if
(
w
>
0
&&
h
>
0
&&
(
w
!=
img
.
cols
||
h
!=
img
.
rows
))
cout
<<
"
\t
* Warning: images should be of the same size!"
<<
endl
;
...
...
@@ -99,7 +102,7 @@ int main(int argc, const char *argv[]) {
// Quit if there are not enough images for this demo.
if
(
images
.
size
()
<=
1
)
{
string
error_message
=
"This demo needs at least 2 images to work. Please add more images to your data set!"
;
CV_Error
(
CV_
StsError
,
error_message
);
CV_Error
(
Error
::
StsError
,
error_message
);
}
// The following lines simply get the last images from
// your dataset and remove it from the vector. This is
...
...
@@ -107,7 +110,8 @@ int main(int argc, const char *argv[]) {
// cv::FaceRecognizer on) and the test data we test
// the model with, do not overlap.
Mat
testSample
=
images
[
images
.
size
()
-
1
];
int
testLabel
=
labels
[
labels
.
size
()
-
1
];
int
nlabels
=
(
int
)
labels
.
size
();
int
testLabel
=
labels
[
nlabels
-
1
];
images
.
pop_back
();
labels
.
pop_back
();
// The following lines create an Eigenfaces model for
...
...
@@ -125,7 +129,8 @@ int main(int argc, const char *argv[]) {
// cv::createEigenFaceRecognizer(10, 123.0);
//
Ptr
<
FaceRecognizer
>
model
=
createEigenFaceRecognizer
();
model
->
setLabelsInfo
(
labelsInfo
);
for
(
int
i
=
0
;
i
<
nlabels
;
i
++
)
model
->
setLabelInfo
(
i
,
labelsInfo
[
i
]);
model
->
train
(
images
,
labels
);
string
saveModelPath
=
"face-rec-model.txt"
;
cout
<<
"Saving the trained model to "
<<
saveModelPath
<<
endl
;
...
...
modules/face/src/precomp.hpp
View file @
084ca5d7
...
...
@@ -45,20 +45,10 @@
#include "opencv2/face.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/core.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/core/private.hpp"
#include <map>
#include <valarray>
namespace
cv
{
// special function to get pointer to constant valarray elements, since
// simple &arr[0] does not compile on VS2005/VS2008.
template
<
typename
T
>
inline
const
T
*
get_data
(
const
std
::
valarray
<
T
>&
arr
)
{
return
&
((
std
::
valarray
<
T
>&
)
arr
)[
0
];
}
}
#endif
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