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
86973f8e
Commit
86973f8e
authored
Dec 06, 2012
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feature pool generation:
- use random from tr1 extension - extend cv::Boost
parent
948365b1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
248 additions
and
44 deletions
+248
-44
common.hpp
apps/sft/include/sft/common.hpp
+4
-0
octave.hpp
apps/sft/include/sft/octave.hpp
+47
-2
random.hpp
apps/sft/include/sft/random.hpp
+76
-0
octave.cpp
apps/sft/octave.cpp
+79
-2
sft.cpp
apps/sft/sft.cpp
+42
-40
No files found.
apps/sft/include/sft/common.hpp
View file @
86973f8e
...
...
@@ -48,6 +48,9 @@
namespace
sft
{
using
cv
::
Mat
;
struct
ICF
;
typedef
std
::
vector
<
ICF
>
Icfvector
;
}
#endif
\ No newline at end of file
apps/sft/include/sft/octave.hpp
View file @
86973f8e
...
...
@@ -44,18 +44,63 @@
#define __SFT_OCTAVE_HPP__
#include <opencv2/ml/ml.hpp>
#include <sft/common.hpp>
namespace
sft
{
struct
ICF
{
ICF
(
int
x
,
int
y
,
int
w
,
int
h
,
int
ch
)
:
bb
(
cv
::
Rect
(
x
,
y
,
w
,
h
)),
channel
(
ch
)
{}
bool
operator
==
(
ICF
b
)
{
return
bb
==
b
.
bb
&&
channel
==
b
.
channel
;
}
bool
operator
!=
(
ICF
b
)
{
return
bb
!=
b
.
bb
||
channel
!=
b
.
channel
;
}
private
:
cv
::
Rect
bb
;
int
channel
;
};
class
FeaturePool
{
public
:
FeaturePool
(
cv
::
Size
model
,
int
nfeatures
);
~
FeaturePool
();
private
:
void
fill
(
int
desired
);
cv
::
Size
model
;
int
nfeatures
;
Mat
integrals
;
Mat
responces
;
Icfvector
pool
;
static
const
unsigned
int
seed
=
0
;
enum
{
N_CHANNELS
=
10
};
};
// used for traning single octave scale
class
Octave
:
public
cv
::
Boost
class
Octave
:
cv
::
Boost
{
public
:
Octave
();
~
Octave
();
virtual
~
Octave
();
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
());
private
:
CvBoostParams
params
;
};
}
...
...
apps/sft/include/sft/random.hpp
0 → 100644
View file @
86973f8e
#ifndef __SFT_RANDOM_HPP__
#define __SFT_RANDOM_HPP__
#if defined(_MSC_VER) && _MSC_VER >= 1600
# include <random>
namespace
sft
{
struct
Random
{
typedef
std
::
mt19937
engine
;
typedef
std
::
uniform_int
<
int
>
uniform
;
};
}
#elif (__GNUC__) && __GNUC__ > 3 && __GNUC_MINOR__ > 1
# if defined (__cplusplus) && __cplusplus > 201100L
# include <random>
namespace
sft
{
struct
Random
{
typedef
std
::
mt19937
engine
;
typedef
std
::
uniform_int
<
int
>
uniform
;
};
}
# else
# include <tr1/random>
namespace
sft
{
struct
Random
{
typedef
std
::
tr1
::
mt19937
engine
;
typedef
std
::
tr1
::
uniform_int
<
int
>
uniform
;
};
}
# endif
#else
#include <opencv2/core/core.hpp>
namespace
rnd
{
typedef
cv
::
RNG
engine
;
template
<
typename
T
>
struct
uniform_int
{
uniform_int
(
const
int
_min
,
const
int
_max
)
:
min
(
_min
),
max
(
_max
)
{}
T
operator
()
(
engine
&
eng
,
const
int
bound
)
const
{
return
(
T
)
eng
.
uniform
(
min
,
bound
);
}
T
operator
()
(
engine
&
eng
)
const
{
return
(
T
)
eng
.
uniform
(
min
,
max
);
}
private
:
int
min
;
int
max
;
};
}
namespace
sft
{
struct
Random
{
typedef
rnd
::
engine
engine
;
typedef
rnd
::
uniform_int
<
int
>
uniform
;
};
}
#endif
#endif
\ No newline at end of file
apps/sft/octave.cpp
View file @
86973f8e
...
...
@@ -41,7 +41,84 @@
//M*/
#include <sft/octave.hpp>
#include <sft/random.hpp>
#if defined VISUALIZE_GENERATION
# include <opencv2/highgui/highgui.hpp>
# define show(a, b) \
do { \
cv::imshow(a,b); \
cv::waitkey(0); \
} while(0)
#else
# define show(a, b)
#endif
// ============ Octave ============ //
sft
::
Octave
::
Octave
(){}
sft
::
Octave
::~
Octave
(){}
\ No newline at end of file
sft
::
Octave
::~
Octave
(){}
bool
sft
::
Octave
::
train
(
const
cv
::
Mat
&
trainData
,
const
cv
::
Mat
&
responses
,
const
cv
::
Mat
&
varIdx
,
const
cv
::
Mat
&
sampleIdx
,
const
cv
::
Mat
&
varType
,
const
cv
::
Mat
&
missingDataMask
)
{
bool
update
=
false
;
return
cv
::
Boost
::
train
(
trainData
,
CV_COL_SAMPLE
,
responses
,
varIdx
,
sampleIdx
,
varType
,
missingDataMask
,
params
,
update
);
}
// ========= FeaturePool ========= //
sft
::
FeaturePool
::
FeaturePool
(
cv
::
Size
m
,
int
n
)
:
model
(
m
),
nfeatures
(
n
)
{
CV_Assert
(
m
!=
cv
::
Size
()
&&
n
>
0
);
fill
(
nfeatures
);
}
sft
::
FeaturePool
::~
FeaturePool
(){}
void
sft
::
FeaturePool
::
fill
(
int
desired
)
{
int
mw
=
model
.
width
;
int
mh
=
model
.
height
;
int
maxPoolSize
=
(
mw
-
1
)
*
mw
/
2
*
(
mh
-
1
)
*
mh
/
2
*
N_CHANNELS
;
nfeatures
=
std
::
min
(
desired
,
maxPoolSize
);
pool
.
reserve
(
nfeatures
);
sft
::
Random
::
engine
eng
(
seed
);
sft
::
Random
::
engine
eng_ch
(
seed
);
sft
::
Random
::
uniform
chRand
(
0
,
N_CHANNELS
-
1
);
sft
::
Random
::
uniform
xRand
(
0
,
model
.
width
-
2
);
sft
::
Random
::
uniform
yRand
(
0
,
model
.
height
-
2
);
sft
::
Random
::
uniform
wRand
(
1
,
model
.
width
-
1
);
sft
::
Random
::
uniform
hRand
(
1
,
model
.
height
-
1
);
while
(
pool
.
size
()
<
size_t
(
nfeatures
))
{
int
x
=
xRand
(
eng
);
int
y
=
yRand
(
eng
);
int
w
=
1
+
wRand
(
eng
,
model
.
width
-
x
-
1
);
int
h
=
1
+
hRand
(
eng
,
model
.
height
-
y
-
1
);
CV_Assert
(
w
>
0
);
CV_Assert
(
h
>
0
);
CV_Assert
(
w
+
x
<
model
.
width
);
CV_Assert
(
h
+
y
<
model
.
height
);
int
ch
=
chRand
(
eng_ch
);
sft
::
ICF
f
(
x
,
y
,
w
,
h
,
ch
);
if
(
std
::
find
(
pool
.
begin
(),
pool
.
end
(),
f
)
==
pool
.
end
())
pool
.
push_back
(
f
);
}
}
\ No newline at end of file
apps/sft/sft.cpp
View file @
86973f8e
...
...
@@ -52,63 +52,65 @@ int main(int argc, char** argv)
int
npositives
=
10
;
int
nnegatives
=
10
;
int
nsamples
=
npositives
+
nnegatives
;
cv
::
Size
model
(
64
,
128
);
sft
::
Octave
boost
;
cv
::
Mat
train_data
(
nfeatures
,
nsamples
,
CV_32FC1
);
// cv::RNG rng
;
sft
::
FeaturePool
pool
(
model
,
nfeatures
)
;
// for (int y = 0; y < nfeatures; ++y)
// for (int x = 0; x < nsamples; ++x)
// train_data.at<float>(y, x) = rng.uniform(0.f, 1.f);
cv
::
RNG
rng
;
// int tflag = CV_COL_SAMPLE;
// Mat responses(nsamples, 1, CV_32FC1);
// for (int y = 0; y < nsamples; ++y)
// responses.at<float>(y, 0) = (y < npositives) ? 1.f : 0.f;
for
(
int
y
=
0
;
y
<
nfeatures
;
++
y
)
for
(
int
x
=
0
;
x
<
nsamples
;
++
x
)
train_data
.
at
<
float
>
(
y
,
x
)
=
rng
.
uniform
(
0.
f
,
1.
f
);
int
tflag
=
CV_COL_SAMPLE
;
cv
::
Mat
responses
(
nsamples
,
1
,
CV_32FC1
);
for
(
int
y
=
0
;
y
<
nsamples
;
++
y
)
responses
.
at
<
float
>
(
y
,
0
)
=
(
y
<
npositives
)
?
1.
f
:
0.
f
;
// Mat var_idx(1, nfeatures, CV_32SC1);
// for (int x = 0; x < nfeatures; ++x)
// var_idx.at<int>(0, x) = x;
// // Mat sample_idx;
// Mat sample_idx(1, nsamples, CV_32SC1);
// for (int x = 0; x < nsamples; ++x)
// sample_idx.at<int>(0, x) = x;
cv
::
Mat
var_idx
(
1
,
nfeatures
,
CV_32SC1
);
for
(
int
x
=
0
;
x
<
nfeatures
;
++
x
)
var_idx
.
at
<
int
>
(
0
,
x
)
=
x
;
// Mat var_type(1, nfeatures + 1, CV_8UC1);
// for (int x = 0; x < nfeatures; ++x)
// var_type.at<uchar>(0, x) = CV_VAR_ORDERED;
// Mat sample_idx;
cv
::
Mat
sample_idx
(
1
,
nsamples
,
CV_32SC1
);
for
(
int
x
=
0
;
x
<
nsamples
;
++
x
)
sample_idx
.
at
<
int
>
(
0
,
x
)
=
x
;
// var_type.at<uchar>(0, nfeatures) = CV_VAR_CATEGORICAL;
cv
::
Mat
var_type
(
1
,
nfeatures
+
1
,
CV_8UC1
);
for
(
int
x
=
0
;
x
<
nfeatures
;
++
x
)
var_type
.
at
<
uchar
>
(
0
,
x
)
=
CV_VAR_ORDERED
;
// Mat missing_mask
;
var_type
.
at
<
uchar
>
(
0
,
nfeatures
)
=
CV_VAR_CATEGORICAL
;
// CvBoostParams params;
// {
// params.max_categories = 10;
// params.max_depth = 2;
// params.min_sample_count = 2;
// params.cv_folds = 0;
// params.truncate_pruned_tree = false;
cv
::
Mat
missing_mask
;
// /// ??????????????????
// params.regression_accuracy = 0.01;
// params.use_surrogates = false;
// params.use_1se_rule = false;
CvBoostParams
params
;
{
params
.
max_categories
=
10
;
params
.
max_depth
=
2
;
params
.
min_sample_count
=
2
;
params
.
cv_folds
=
0
;
params
.
truncate_pruned_tree
=
false
;
// ///////// boost params
// params.boost_type = CvBoost::GENTLE;
// params.weak_count = 1;
// params.split_criteria = CvBoost::SQERR;
// params.weight_trim_rate = 0.95;
// }
/// ??????????????????
params
.
regression_accuracy
=
0.01
;
params
.
use_surrogates
=
false
;
params
.
use_1se_rule
=
false
;
// bool update = false;
///////// boost params
params
.
boost_type
=
CvBoost
::
GENTLE
;
params
.
weak_count
=
1
;
params
.
split_criteria
=
CvBoost
::
SQERR
;
params
.
weight_trim_rate
=
0.95
;
}
// boost.train(train_data, tflag, responses,
// var_idx, sample_idx, var_type, missing_mask, params, update);
bool
update
=
false
;
boost
.
train
(
train_data
,
responses
,
var_idx
,
sample_idx
,
var_type
,
missing_mask
);
// CvFileStorage* fs = cvOpenFileStorage( "/home/kellan/train_res.xml", 0, CV_STORAGE_WRITE );
// boost.write(fs, "test_res");
...
...
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