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
cd345ea8
Commit
cd345ea8
authored
Mar 04, 2017
by
berak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
datasets: remove face dependancy
parent
ab63d35d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
71 deletions
+32
-71
CMakeLists.txt
modules/datasets/CMakeLists.txt
+1
-1
fr_lfw_benchmark.cpp
modules/datasets/samples/fr_lfw_benchmark.cpp
+31
-70
No files found.
modules/datasets/CMakeLists.txt
View file @
cd345ea8
set
(
the_description
"datasets framework"
)
ocv_define_module
(
datasets opencv_core opencv_
face opencv_
ml opencv_flann opencv_text WRAP python
)
ocv_define_module
(
datasets opencv_core opencv_ml opencv_flann opencv_text WRAP python
)
ocv_warnings_disable
(
CMAKE_CXX_FLAGS /wd4267
)
# flann, Win64
modules/datasets/samples/fr_lfw_benchmark.cpp
View file @
cd345ea8
...
...
@@ -41,38 +41,17 @@
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/face.hpp"
#include "opencv2/datasets/fr_lfw.hpp"
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <map>
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
::
datasets
;
using
namespace
cv
::
face
;
map
<
string
,
int
>
people
;
int
getLabel
(
const
string
&
imagePath
);
int
getLabel
(
const
string
&
imagePath
)
{
size_t
pos
=
imagePath
.
find
(
'/'
);
string
curr
=
imagePath
.
substr
(
0
,
pos
);
map
<
string
,
int
>::
iterator
it
=
people
.
find
(
curr
);
if
(
people
.
end
()
==
it
)
{
people
.
insert
(
make_pair
(
curr
,
(
int
)
people
.
size
()));
it
=
people
.
find
(
curr
);
}
return
(
*
it
).
second
;
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
...
...
@@ -90,9 +69,8 @@ int main(int argc, const char *argv[])
}
string
trainMethod
(
parser
.
get
<
string
>
(
"train"
));
// These vectors hold the images and corresponding labels.
vector
<
Mat
>
images
;
vector
<
int
>
labels
;
// our trained threshold for "same":
double
threshold
=
0
;
// load dataset
Ptr
<
FR_lfw
>
dataset
=
FR_lfw
::
create
();
...
...
@@ -106,33 +84,26 @@ int main(int argc, const char *argv[])
printf
(
"train size: %u
\n
"
,
(
numSplits
-
1
)
*
(
unsigned
int
)
dataset
->
getTest
().
size
());
printf
(
"test size: %u
\n
"
,
(
unsigned
int
)
dataset
->
getTest
().
size
());
// 2200 pairsDevTrain, first split: correct: 373, from: 600 -> 62.1667%
Ptr
<
FaceRecognizer
>
model
=
createLBPHFaceRecognizer
();
// 2200 pairsDevTrain, first split: correct: correct: 369, from: 600 -> 61.5%
//Ptr<FaceRecognizer> model = createEigenFaceRecognizer();
// 2200 pairsDevTrain, first split: correct: 372, from: 600 -> 62%
//Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
if
(
trainMethod
==
"dev"
)
// train on personsDevTrain.txt
{
// collect average same-distances:
double
avg
=
0
;
int
count
=
0
;
for
(
unsigned
int
i
=
0
;
i
<
dataset
->
getTrain
().
size
();
++
i
)
{
FR_lfwObj
*
example
=
static_cast
<
FR_lfwObj
*>
(
dataset
->
getTrain
()[
i
].
get
());
int
currNum
=
getLabel
(
example
->
image1
);
Mat
img
=
imread
(
path
+
example
->
image1
,
IMREAD_GRAYSCALE
);
images
.
push_back
(
img
);
labels
.
push_back
(
currNum
);
currNum
=
getLabel
(
example
->
image2
);
img
=
imread
(
path
+
example
->
image2
,
IMREAD_GRAYSCALE
);
images
.
push_back
(
img
);
labels
.
push_back
(
currNum
);
Mat
a
=
imread
(
path
+
example
->
image1
,
IMREAD_GRAYSCALE
);
Mat
b
=
imread
(
path
+
example
->
image2
,
IMREAD_GRAYSCALE
);
double
dist
=
norm
(
a
,
b
);
if
(
example
->
same
)
{
avg
+=
dist
;
count
++
;
}
}
model
->
train
(
images
,
labels
);
//string saveModelPath = "face-rec-model.txt";
//cout << "Saving the trained model to " << saveModelPath << endl;
//model->save(saveModelPath);
threshold
=
avg
/
count
;
}
vector
<
double
>
p
;
...
...
@@ -140,8 +111,8 @@ int main(int argc, const char *argv[])
{
if
(
trainMethod
==
"split"
)
// train on the remaining 9 splits from pairs.txt
{
images
.
clear
()
;
labels
.
clear
()
;
double
avg
=
0
;
int
count
=
0
;
for
(
unsigned
int
j2
=
0
;
j2
<
numSplits
;
++
j2
)
{
if
(
j
==
j2
)
continue
;
// skip test split for training
...
...
@@ -150,19 +121,17 @@ int main(int argc, const char *argv[])
for
(
unsigned
int
i
=
0
;
i
<
curr
.
size
();
++
i
)
{
FR_lfwObj
*
example
=
static_cast
<
FR_lfwObj
*>
(
curr
[
i
].
get
());
int
currNum
=
getLabel
(
example
->
image1
);
Mat
img
=
imread
(
path
+
example
->
image1
,
IMREAD_GRAYSCALE
);
images
.
push_back
(
img
);
labels
.
push_back
(
currNum
);
currNum
=
getLabel
(
example
->
image2
);
img
=
imread
(
path
+
example
->
image2
,
IMREAD_GRAYSCALE
);
images
.
push_back
(
img
);
labels
.
push_back
(
currNum
);
Mat
a
=
imread
(
path
+
example
->
image1
,
IMREAD_GRAYSCALE
);
Mat
b
=
imread
(
path
+
example
->
image2
,
IMREAD_GRAYSCALE
);
double
dist
=
norm
(
a
,
b
);
if
(
example
->
same
)
{
avg
+=
dist
;
count
++
;
}
}
}
model
->
train
(
images
,
labels
)
;
threshold
=
avg
/
count
;
}
unsigned
int
incorrect
=
0
,
correct
=
0
;
...
...
@@ -171,26 +140,18 @@ int main(int argc, const char *argv[])
{
FR_lfwObj
*
example
=
static_cast
<
FR_lfwObj
*>
(
curr
[
i
].
get
());
//int currNum = getLabel(example->image1);
Mat
img
=
imread
(
path
+
example
->
image1
,
IMREAD_GRAYSCALE
);
int
predictedLabel1
=
model
->
predict
(
img
);
//currNum = getLabel(example->image2);
img
=
imread
(
path
+
example
->
image2
,
IMREAD_GRAYSCALE
);
int
predictedLabel2
=
model
->
predict
(
img
);
if
((
predictedLabel1
==
predictedLabel2
&&
example
->
same
)
||
(
predictedLabel1
!=
predictedLabel2
&&
!
example
->
same
))
{
Mat
a
=
imread
(
path
+
example
->
image1
,
IMREAD_GRAYSCALE
);
Mat
b
=
imread
(
path
+
example
->
image2
,
IMREAD_GRAYSCALE
);
bool
same
=
(
norm
(
a
,
b
)
<=
threshold
);
if
(
same
==
example
->
same
)
correct
++
;
}
else
{
else
incorrect
++
;
}
}
p
.
push_back
(
1.0
*
correct
/
(
correct
+
incorrect
));
printf
(
"correct: %u, from: %u -> %f
\n
"
,
correct
,
correct
+
incorrect
,
p
.
back
());
}
double
mu
=
0.0
;
for
(
vector
<
double
>::
iterator
it
=
p
.
begin
();
it
!=
p
.
end
();
++
it
)
{
...
...
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