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
f6e3e3f0
Commit
f6e3e3f0
authored
Dec 06, 2012
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add negatives generation
parent
a3888846
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
14 deletions
+69
-14
octave.hpp
apps/sft/include/sft/octave.hpp
+3
-1
octave.cpp
apps/sft/octave.cpp
+64
-12
sft.cpp
apps/sft/sft.cpp
+2
-1
No files found.
apps/sft/include/sft/octave.hpp
View file @
f6e3e3f0
...
@@ -102,7 +102,7 @@ private:
...
@@ -102,7 +102,7 @@ private:
class
Octave
:
cv
::
Boost
class
Octave
:
cv
::
Boost
{
{
public
:
public
:
Octave
(
int
npositives
,
int
nnegatives
,
int
logScale
,
int
shrinkage
);
Octave
(
cv
::
Rect
boundingBox
,
int
npositives
,
int
nnegatives
,
int
logScale
,
int
shrinkage
);
virtual
~
Octave
();
virtual
~
Octave
();
virtual
bool
train
(
const
Dataset
&
dataset
,
const
FeaturePool
&
pool
);
virtual
bool
train
(
const
Dataset
&
dataset
,
const
FeaturePool
&
pool
);
...
@@ -114,7 +114,9 @@ protected:
...
@@ -114,7 +114,9 @@ protected:
const
cv
::
Mat
&
sampleIdx
=
cv
::
Mat
(),
const
cv
::
Mat
&
varType
=
cv
::
Mat
(),
const
cv
::
Mat
&
missingDataMask
=
cv
::
Mat
());
const
cv
::
Mat
&
sampleIdx
=
cv
::
Mat
(),
const
cv
::
Mat
&
varType
=
cv
::
Mat
(),
const
cv
::
Mat
&
missingDataMask
=
cv
::
Mat
());
void
processPositives
(
const
Dataset
&
dataset
,
const
FeaturePool
&
pool
);
void
processPositives
(
const
Dataset
&
dataset
,
const
FeaturePool
&
pool
);
void
generateNegatives
(
const
Dataset
&
dataset
);
private
:
private
:
cv
::
Rect
boundingBox
;
int
npositives
;
int
npositives
;
int
nnegatives
;
int
nnegatives
;
...
...
apps/sft/octave.cpp
View file @
f6e3e3f0
...
@@ -58,8 +58,8 @@
...
@@ -58,8 +58,8 @@
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/highgui/highgui.hpp>
// ============ Octave ============ //
// ============ Octave ============ //
sft
::
Octave
::
Octave
(
int
np
,
int
nn
,
int
ls
,
int
shr
)
sft
::
Octave
::
Octave
(
cv
::
Rect
bb
,
int
np
,
int
nn
,
int
ls
,
int
shr
)
:
logScale
(
ls
),
npositives
(
np
),
nnegatives
(
nn
),
shrinkage
(
shr
)
:
logScale
(
ls
),
boundingBox
(
bb
),
npositives
(
np
),
nnegatives
(
nn
),
shrinkage
(
shr
)
{
{
int
maxSample
=
npositives
+
nnegatives
;
int
maxSample
=
npositives
+
nnegatives
;
responses
.
create
(
maxSample
,
1
,
CV_32FC1
);
responses
.
create
(
maxSample
,
1
,
CV_32FC1
);
...
@@ -137,41 +137,93 @@ public:
...
@@ -137,41 +137,93 @@ public:
}
}
// ToDo: parallelize it
// ToDo: parallelize it
// ToDo: sunch model size and shrinced model size usage/ Now model size mean already shrinked model
void
sft
::
Octave
::
processPositives
(
const
Dataset
&
dataset
,
const
FeaturePool
&
pool
)
void
sft
::
Octave
::
processPositives
(
const
Dataset
&
dataset
,
const
FeaturePool
&
pool
)
{
{
Preprocessor
prepocessor
(
shrinkage
);
Preprocessor
prepocessor
(
shrinkage
);
int
cols
=
(
64
*
pow
(
2
,
logScale
)
+
1
)
*
(
128
*
pow
(
2
,
logScale
)
+
1
);
int
w
=
64
*
pow
(
2
,
logScale
)
/
shrinkage
;
integrals
.
create
(
pool
.
size
(),
cols
,
CV_32SC1
);
int
h
=
128
*
pow
(
2
,
logScale
)
/
shrinkage
*
10
;
integrals
.
create
(
pool
.
size
(),
(
w
+
1
)
*
(
h
+
1
),
CV_32SC1
);
int
total
=
0
;
int
total
=
0
;
// float* responce = responce.ptr<float>(0);
for
(
svector
::
const_iterator
it
=
dataset
.
pos
.
begin
();
it
!=
dataset
.
pos
.
end
();
++
it
)
for
(
svector
::
const_iterator
it
=
dataset
.
pos
.
begin
();
it
!=
dataset
.
pos
.
end
();
++
it
)
{
{
const
string
&
curr
=
*
it
;
const
string
&
curr
=
*
it
;
dprintf
(
"Process candidate positive image %s
\n
"
,
curr
.
c_str
());
dprintf
(
"Process candidate positive image %s
\n
"
,
curr
.
c_str
());
cv
::
Mat
channels
=
integrals
.
col
(
total
).
reshape
(
0
,
(
128
*
pow
(
2
,
logScale
)
+
1
));
cv
::
Mat
sample
=
cv
::
imread
(
curr
);
cv
::
Mat
channels
=
integrals
.
col
(
total
).
reshape
(
0
,
h
+
1
);
cv
::
Mat
sample
=
cv
::
imread
(
curr
);
prepocessor
.
apply
(
sample
,
channels
);
prepocessor
.
apply
(
sample
,
channels
);
responses
.
ptr
<
float
>
(
total
)[
0
]
=
1.
f
;
responses
.
ptr
<
float
>
(
total
)[
0
]
=
1.
f
;
++
total
;
if
(
++
total
>=
npositives
)
break
;
if
(
total
>=
npositives
)
break
;
}
}
dprintf
(
"Processing positives finished:
\n\t
requested %d positives, collected %d samples.
\n
"
,
npositives
,
total
);
dprintf
(
"Processing positives finished:
\n\t
requested %d positives, collected %d samples.
\n
"
,
npositives
,
total
);
npositives
=
total
;
npositives
=
total
;
nnegatives
*=
total
/
(
float
)
npositives
;
nnegatives
=
cvRound
(
nnegatives
*
total
/
(
double
)
npositives
);
}
void
sft
::
Octave
::
generateNegatives
(
const
Dataset
&
dataset
)
{
// ToDo: set seed, use offsets
sft
::
Random
::
engine
eng
;
sft
::
Random
::
engine
idxEng
;
Preprocessor
prepocessor
(
shrinkage
);
int
nimages
=
(
int
)
dataset
.
neg
.
size
();
sft
::
Random
::
uniform
iRand
(
0
,
nimages
-
1
);
int
total
=
0
;
Mat
sum
;
for
(
int
i
=
npositives
;
i
<
nnegatives
+
npositives
;
++
total
)
{
int
curr
=
iRand
(
idxEng
);
dprintf
(
"View %d-th sample
\n
"
,
curr
);
dprintf
(
"Process %s
\n
"
,
dataset
.
neg
[
curr
].
c_str
());
Mat
frame
=
cv
::
imread
(
dataset
.
neg
[
curr
]);
prepocessor
.
apply
(
frame
,
sum
);
int
maxW
=
frame
.
cols
-
2
*
boundingBox
.
x
-
boundingBox
.
width
;
int
maxH
=
frame
.
rows
-
2
*
boundingBox
.
y
-
boundingBox
.
height
;
sft
::
Random
::
uniform
wRand
(
0
,
maxW
);
sft
::
Random
::
uniform
hRand
(
0
,
maxH
);
int
dx
=
wRand
(
eng
);
int
dy
=
hRand
(
eng
);
sum
=
sum
(
cv
::
Rect
(
dx
,
dy
,
boundingBox
.
width
,
boundingBox
.
height
));
dprintf
(
"generated %d %d
\n
"
,
dx
,
dy
);
if
(
predict
(
sum
))
{
responses
.
ptr
<
float
>
(
i
)[
0
]
=
0.
f
;
sum
=
sum
.
reshape
(
0
,
1
);
sum
.
copyTo
(
integrals
.
col
(
i
));
++
i
;
}
}
dprintf
(
"Processing negatives finished:
\n\t
requested %d negatives, viewed %d samples.
\n
"
,
nnegatives
,
total
);
}
}
bool
sft
::
Octave
::
train
(
const
Dataset
&
dataset
,
const
FeaturePool
&
pool
)
bool
sft
::
Octave
::
train
(
const
Dataset
&
dataset
,
const
FeaturePool
&
pool
)
{
{
// 1. fill integrals and classes
// 1. fill integrals and classes
processPositives
(
dataset
,
pool
);
generateNegatives
(
dataset
);
return
false
;
return
false
;
}
}
...
...
apps/sft/sft.cpp
View file @
f6e3e3f0
...
@@ -59,7 +59,8 @@ int main(int argc, char** argv)
...
@@ -59,7 +59,8 @@ int main(int argc, char** argv)
cv
::
Size
model
(
64
,
128
);
cv
::
Size
model
(
64
,
128
);
std
::
string
path
=
"/home/kellan/cuda-dev/opencv_extra/testdata/sctrain/rescaled-train-2012-10-27-19-02-52"
;
std
::
string
path
=
"/home/kellan/cuda-dev/opencv_extra/testdata/sctrain/rescaled-train-2012-10-27-19-02-52"
;
sft
::
Octave
boost
(
npositives
,
nnegatives
,
octave
,
shrinkage
);
cv
::
Rect
boundingBox
(
5
,
5
,
16
,
32
);
sft
::
Octave
boost
(
boundingBox
,
npositives
,
nnegatives
,
octave
,
shrinkage
);
sft
::
FeaturePool
pool
(
model
,
nfeatures
);
sft
::
FeaturePool
pool
(
model
,
nfeatures
);
sft
::
Dataset
dataset
(
path
,
boost
.
logScale
);
sft
::
Dataset
dataset
(
path
,
boost
.
logScale
);
...
...
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