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
0b039f3c
Commit
0b039f3c
authored
Jan 30, 2013
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor feature pool
parent
b4aa33b6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
28 deletions
+33
-28
fpool.cpp
apps/sft/fpool.cpp
+0
-6
fpool.hpp
apps/sft/include/sft/fpool.hpp
+0
-3
sft.cpp
apps/sft/sft.cpp
+1
-1
softcascade.hpp
...s/softcascade/include/opencv2/softcascade/softcascade.hpp
+1
-4
soft_cascade_octave.cpp
modules/softcascade/src/soft_cascade_octave.cpp
+31
-14
No files found.
apps/sft/fpool.cpp
View file @
0b039f3c
...
...
@@ -53,12 +53,6 @@ sft::ICFFeaturePool::ICFFeaturePool(cv::Size m, int n) : FeaturePool(), model(m)
{
CV_Assert
(
m
!=
cv
::
Size
()
&&
n
>
0
);
fill
(
nfeatures
);
builder
=
cv
::
ChannelFeatureBuilder
::
create
();
}
void
sft
::
ICFFeaturePool
::
preprocess
(
cv
::
InputArray
frame
,
cv
::
OutputArray
integrals
)
const
{
(
*
builder
)(
frame
,
integrals
);
}
float
sft
::
ICFFeaturePool
::
apply
(
int
fi
,
int
si
,
const
Mat
&
integrals
)
const
...
...
apps/sft/include/sft/fpool.hpp
View file @
0b039f3c
...
...
@@ -61,7 +61,6 @@ public:
virtual
int
size
()
const
{
return
(
int
)
pool
.
size
();
}
virtual
float
apply
(
int
fi
,
int
si
,
const
cv
::
Mat
&
integrals
)
const
;
virtual
void
preprocess
(
cv
::
InputArray
_frame
,
cv
::
OutputArray
_integrals
)
const
;
virtual
void
write
(
cv
::
FileStorage
&
fs
,
int
index
)
const
;
virtual
~
ICFFeaturePool
();
...
...
@@ -77,8 +76,6 @@ private:
static
const
unsigned
int
seed
=
0
;
cv
::
Ptr
<
cv
::
ChannelFeatureBuilder
>
builder
;
enum
{
N_CHANNELS
=
10
};
};
...
...
apps/sft/sft.cpp
View file @
0b039f3c
...
...
@@ -130,7 +130,7 @@ int main(int argc, char** argv)
typedef
cv
::
SoftCascadeOctave
Octave
;
cv
::
Ptr
<
Octave
>
boost
=
Octave
::
create
(
boundingBox
,
npositives
,
nnegatives
,
*
it
,
shrinkage
);
cv
::
Ptr
<
Octave
>
boost
=
Octave
::
create
(
boundingBox
,
npositives
,
nnegatives
,
*
it
,
shrinkage
,
nfeatures
);
std
::
string
path
=
cfg
.
trainPath
;
sft
::
ScaledDataset
dataset
(
path
,
*
it
);
...
...
modules/softcascade/include/opencv2/softcascade/softcascade.hpp
View file @
0b039f3c
...
...
@@ -71,9 +71,6 @@ public:
virtual
int
size
()
const
=
0
;
virtual
float
apply
(
int
fi
,
int
si
,
const
Mat
&
integrals
)
const
=
0
;
virtual
void
write
(
cv
::
FileStorage
&
fs
,
int
index
)
const
=
0
;
virtual
void
preprocess
(
InputArray
frame
,
OutputArray
integrals
)
const
=
0
;
virtual
~
FeaturePool
();
};
...
...
@@ -196,7 +193,7 @@ public:
virtual
~
SoftCascadeOctave
();
static
cv
::
Ptr
<
SoftCascadeOctave
>
create
(
cv
::
Rect
boundingBox
,
int
npositives
,
int
nnegatives
,
int
logScale
,
int
shrinkage
);
int
logScale
,
int
shrinkage
,
int
poolSize
);
virtual
bool
train
(
const
Dataset
*
dataset
,
const
FeaturePool
*
pool
,
int
weaks
,
int
treeDepth
)
=
0
;
virtual
void
setRejectThresholds
(
OutputArray
thresholds
)
=
0
;
...
...
modules/softcascade/src/soft_cascade_octave.cpp
View file @
0b039f3c
...
...
@@ -64,11 +64,15 @@ using cv::Mat;
cv
::
FeaturePool
::~
FeaturePool
(){}
cv
::
Dataset
::~
Dataset
(){}
namespace
{
class
BoostedSoftCascadeOctave
:
public
cv
::
Boost
,
public
cv
::
SoftCascadeOctave
{
public
:
BoostedSoftCascadeOctave
(
cv
::
Rect
boundingBox
=
cv
::
Rect
(),
int
npositives
=
0
,
int
nnegatives
=
0
,
int
logScale
=
0
,
int
shrinkage
=
1
);
BoostedSoftCascadeOctave
(
cv
::
Rect
boundingBox
=
cv
::
Rect
(),
int
npositives
=
0
,
int
nnegatives
=
0
,
int
logScale
=
0
,
int
shrinkage
=
1
,
int
poolSize
=
0
);
virtual
~
BoostedSoftCascadeOctave
();
virtual
cv
::
AlgorithmInfo
*
info
()
const
;
virtual
bool
train
(
const
Dataset
*
dataset
,
const
FeaturePool
*
pool
,
int
weaks
,
int
treeDepth
);
...
...
@@ -80,8 +84,8 @@ protected:
virtual
bool
train
(
const
cv
::
Mat
&
trainData
,
const
cv
::
Mat
&
responses
,
const
cv
::
Mat
&
varIdx
=
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
generateNegatives
(
const
Dataset
*
dataset
,
const
FeaturePool
*
pool
);
void
processPositives
(
const
Dataset
*
dataset
);
void
generateNegatives
(
const
Dataset
*
dataset
);
float
predict
(
const
Mat
&
_sample
,
const
cv
::
Range
range
)
const
;
private
:
...
...
@@ -102,9 +106,11 @@ private:
CvBoostParams
params
;
Mat
trainData
;
cv
::
Ptr
<
cv
::
ChannelFeatureBuilder
>
builder
;
};
BoostedSoftCascadeOctave
::
BoostedSoftCascadeOctave
(
cv
::
Rect
bb
,
int
np
,
int
nn
,
int
ls
,
int
shr
)
BoostedSoftCascadeOctave
::
BoostedSoftCascadeOctave
(
cv
::
Rect
bb
,
int
np
,
int
nn
,
int
ls
,
int
shr
,
int
poolSize
)
:
logScale
(
ls
),
boundingBox
(
bb
),
npositives
(
np
),
nnegatives
(
nn
),
shrinkage
(
shr
)
{
int
maxSample
=
npositives
+
nnegatives
;
...
...
@@ -132,6 +138,13 @@ BoostedSoftCascadeOctave::BoostedSoftCascadeOctave(cv::Rect bb, int np, int nn,
}
params
=
_params
;
builder
=
cv
::
ChannelFeatureBuilder
::
create
();
int
w
=
boundingBox
.
width
;
int
h
=
boundingBox
.
height
;
integrals
.
create
(
poolSize
,
(
w
/
shrinkage
+
1
)
*
(
h
/
shrinkage
*
10
+
1
),
CV_32SC1
);
}
BoostedSoftCascadeOctave
::~
BoostedSoftCascadeOctave
(){}
...
...
@@ -191,12 +204,11 @@ void BoostedSoftCascadeOctave::setRejectThresholds(cv::OutputArray _thresholds)
}
}
void
BoostedSoftCascadeOctave
::
processPositives
(
const
Dataset
*
dataset
,
const
FeaturePool
*
pool
)
void
BoostedSoftCascadeOctave
::
processPositives
(
const
Dataset
*
dataset
)
{
int
w
=
boundingBox
.
width
;
int
h
=
boundingBox
.
height
;
integrals
.
create
(
pool
->
size
(),
(
w
/
shrinkage
+
1
)
*
(
h
/
shrinkage
*
10
+
1
),
CV_32SC1
)
;
cv
::
ChannelFeatureBuilder
&
_builder
=
*
builder
;
int
total
=
0
;
for
(
int
curr
=
0
;
curr
<
dataset
->
available
(
Dataset
::
POSITIVE
);
++
curr
)
...
...
@@ -206,7 +218,7 @@ void BoostedSoftCascadeOctave::processPositives(const Dataset* dataset, const Fe
cv
::
Mat
channels
=
integrals
.
row
(
total
).
reshape
(
0
,
h
/
shrinkage
*
10
+
1
);
sample
=
sample
(
boundingBox
);
pool
->
preprocess
(
sample
,
channels
);
_builder
(
sample
,
channels
);
responses
.
ptr
<
float
>
(
total
)[
0
]
=
1.
f
;
if
(
++
total
>=
npositives
)
break
;
...
...
@@ -238,7 +250,7 @@ void BoostedSoftCascadeOctave::processPositives(const Dataset* dataset, const Fe
#undef USE_LONG_SEEDS
void
BoostedSoftCascadeOctave
::
generateNegatives
(
const
Dataset
*
dataset
,
const
FeaturePool
*
pool
)
void
BoostedSoftCascadeOctave
::
generateNegatives
(
const
Dataset
*
dataset
)
{
// ToDo: set seed, use offsets
sft
::
Random
::
engine
eng
(
DX_DY_SEED
);
...
...
@@ -251,6 +263,8 @@ void BoostedSoftCascadeOctave::generateNegatives(const Dataset* dataset, const F
int
total
=
0
;
Mat
sum
;
cv
::
ChannelFeatureBuilder
&
_builder
=
*
builder
;
for
(
int
i
=
npositives
;
i
<
nnegatives
+
npositives
;
++
total
)
{
int
curr
=
iRand
(
idxEng
);
...
...
@@ -269,7 +283,7 @@ void BoostedSoftCascadeOctave::generateNegatives(const Dataset* dataset, const F
frame
=
frame
(
cv
::
Rect
(
dx
,
dy
,
boundingBox
.
width
,
boundingBox
.
height
));
cv
::
Mat
channels
=
integrals
.
row
(
i
).
reshape
(
0
,
h
/
shrinkage
*
10
+
1
);
pool
->
preprocess
(
frame
,
channels
);
_builder
(
frame
,
channels
);
dprintf
(
"generated %d %d
\n
"
,
dx
,
dy
);
// // if (predict(sum))
...
...
@@ -392,8 +406,8 @@ bool BoostedSoftCascadeOctave::train(const Dataset* dataset, const FeaturePool*
params
.
weak_count
=
weaks
;
// 1. fill integrals and classes
processPositives
(
dataset
,
pool
);
generateNegatives
(
dataset
,
pool
);
processPositives
(
dataset
);
generateNegatives
(
dataset
);
// 2. only simple case (all features used)
int
nfeatures
=
pool
->
size
();
...
...
@@ -462,13 +476,16 @@ void BoostedSoftCascadeOctave::write( CvFileStorage* fs, std::string _name) cons
CvBoost
::
write
(
fs
,
_name
.
c_str
());
}
}
CV_INIT_ALGORITHM
(
BoostedSoftCascadeOctave
,
"SoftCascadeOctave.BoostedSoftCascadeOctave"
,
);
cv
::
SoftCascadeOctave
::~
SoftCascadeOctave
(){}
cv
::
Ptr
<
cv
::
SoftCascadeOctave
>
cv
::
SoftCascadeOctave
::
create
(
cv
::
Rect
boundingBox
,
int
npositives
,
int
nnegatives
,
int
logScale
,
int
shrinkage
)
int
logScale
,
int
shrinkage
,
int
poolSize
)
{
cv
::
Ptr
<
cv
::
SoftCascadeOctave
>
octave
(
new
BoostedSoftCascadeOctave
(
boundingBox
,
npositives
,
nnegatives
,
logScale
,
shrinkage
));
cv
::
Ptr
<
cv
::
SoftCascadeOctave
>
octave
(
new
BoostedSoftCascadeOctave
(
boundingBox
,
npositives
,
nnegatives
,
logScale
,
shrinkage
,
poolSize
));
return
octave
;
}
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