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
74300f5f
Commit
74300f5f
authored
Jul 27, 2010
by
Maria Dimashova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed compile errors on VS2008
parent
2122cde7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
52 deletions
+52
-52
features2d.hpp
modules/features2d/include/opencv2/features2d/features2d.hpp
+20
-20
calonder.cpp
modules/features2d/src/calonder.cpp
+32
-32
No files found.
modules/features2d/include/opencv2/features2d/features2d.hpp
View file @
74300f5f
...
@@ -628,12 +628,12 @@ class CV_EXPORTS RandomizedTree
...
@@ -628,12 +628,12 @@ class CV_EXPORTS RandomizedTree
public
:
public
:
friend
class
RTreeClassifier
;
friend
class
RTreeClassifier
;
static
const
int
PATCH_SIZE
=
32
;
static
const
uchar
PATCH_SIZE
=
32
;
static
const
int
DEFAULT_DEPTH
=
9
;
static
const
int
DEFAULT_DEPTH
=
9
;
static
const
int
DEFAULT_VIEWS
=
5000
;
static
const
int
DEFAULT_VIEWS
=
5000
;
static
const
size_t
DEFAULT_REDUCED_NUM_DIM
=
176
;
static
const
size_t
DEFAULT_REDUCED_NUM_DIM
=
176
;
static
const
float
LOWER_QUANT_PERC
=
.03
f
;
static
float
GET_LOWER_QUANT_PERC
()
{
return
.03
f
;
}
static
const
float
UPPER_QUANT_PERC
=
.92
f
;
static
float
GET_UPPER_QUANT_PERC
()
{
return
.92
f
;
}
RandomizedTree
();
RandomizedTree
();
~
RandomizedTree
();
~
RandomizedTree
();
...
@@ -646,13 +646,13 @@ public:
...
@@ -646,13 +646,13 @@ public:
// following two funcs are EXPERIMENTAL (do not use unless you know exactly what you do)
// following two funcs are EXPERIMENTAL (do not use unless you know exactly what you do)
static
void
quantizeVector
(
float
*
vec
,
int
dim
,
int
N
,
float
bnds
[
2
],
int
clamp_mode
=
0
);
static
void
quantizeVector
(
float
*
vec
,
int
dim
,
int
N
,
float
bnds
[
2
],
int
clamp_mode
=
0
);
static
void
quantizeVector
(
float
*
src
,
int
dim
,
int
N
,
float
bnds
[
2
],
u
int8_t
*
dst
);
static
void
quantizeVector
(
float
*
src
,
int
dim
,
int
N
,
float
bnds
[
2
],
u
char
*
dst
);
// patch_data must be a 32x32 array (no row padding)
// patch_data must be a 32x32 array (no row padding)
float
*
getPosterior
(
uchar
*
patch_data
);
float
*
getPosterior
(
uchar
*
patch_data
);
const
float
*
getPosterior
(
uchar
*
patch_data
)
const
;
const
float
*
getPosterior
(
uchar
*
patch_data
)
const
;
u
int8_t
*
getPosterior2
(
uchar
*
patch_data
);
u
char
*
getPosterior2
(
uchar
*
patch_data
);
const
u
int8_t
*
getPosterior2
(
uchar
*
patch_data
)
const
;
const
u
char
*
getPosterior2
(
uchar
*
patch_data
)
const
;
void
read
(
const
char
*
file_name
,
int
num_quant_bits
);
void
read
(
const
char
*
file_name
,
int
num_quant_bits
);
void
read
(
std
::
istream
&
is
,
int
num_quant_bits
);
void
read
(
std
::
istream
&
is
,
int
num_quant_bits
);
...
@@ -677,7 +677,7 @@ private:
...
@@ -677,7 +677,7 @@ private:
int
num_leaves_
;
int
num_leaves_
;
std
::
vector
<
RTreeNode
>
nodes_
;
std
::
vector
<
RTreeNode
>
nodes_
;
float
**
posteriors_
;
// 16-bytes aligned posteriors
float
**
posteriors_
;
// 16-bytes aligned posteriors
u
int8_t
**
posteriors2_
;
// 16-bytes aligned posteriors
u
char
**
posteriors2_
;
// 16-bytes aligned posteriors
std
::
vector
<
int
>
leaf_counts_
;
std
::
vector
<
int
>
leaf_counts_
;
void
createNodes
(
int
num_nodes
,
RNG
&
rng
);
void
createNodes
(
int
num_nodes
,
RNG
&
rng
);
...
@@ -689,8 +689,8 @@ private:
...
@@ -689,8 +689,8 @@ private:
int
getIndex
(
uchar
*
patch_data
)
const
;
int
getIndex
(
uchar
*
patch_data
)
const
;
inline
float
*
getPosteriorByIndex
(
int
index
);
inline
float
*
getPosteriorByIndex
(
int
index
);
inline
const
float
*
getPosteriorByIndex
(
int
index
)
const
;
inline
const
float
*
getPosteriorByIndex
(
int
index
)
const
;
inline
u
int8_t
*
getPosteriorByIndex2
(
int
index
);
inline
u
char
*
getPosteriorByIndex2
(
int
index
);
inline
const
u
int8_t
*
getPosteriorByIndex2
(
int
index
)
const
;
inline
const
u
char
*
getPosteriorByIndex2
(
int
index
)
const
;
//void makeRandomMeasMatrix(float *cs_phi, PHI_DISTR_TYPE dt, size_t reduced_num_dim);
//void makeRandomMeasMatrix(float *cs_phi, PHI_DISTR_TYPE dt, size_t reduced_num_dim);
void
convertPosteriorsToChar
();
void
convertPosteriorsToChar
();
void
makePosteriors2
(
int
num_quant_bits
);
void
makePosteriors2
(
int
num_quant_bits
);
...
@@ -714,12 +714,12 @@ inline const float* RandomizedTree::getPosteriorByIndex(int index) const
...
@@ -714,12 +714,12 @@ inline const float* RandomizedTree::getPosteriorByIndex(int index) const
return
posteriors_
[
index
];
return
posteriors_
[
index
];
}
}
inline
u
int8_t
*
RandomizedTree
::
getPosteriorByIndex2
(
int
index
)
inline
u
char
*
RandomizedTree
::
getPosteriorByIndex2
(
int
index
)
{
{
return
const_cast
<
u
int8_t
*>
(
const_cast
<
const
RandomizedTree
*>
(
this
)
->
getPosteriorByIndex2
(
index
));
return
const_cast
<
u
char
*>
(
const_cast
<
const
RandomizedTree
*>
(
this
)
->
getPosteriorByIndex2
(
index
));
}
}
inline
const
u
int8_t
*
RandomizedTree
::
getPosteriorByIndex2
(
int
index
)
const
inline
const
u
char
*
RandomizedTree
::
getPosteriorByIndex2
(
int
index
)
const
{
{
return
posteriors2_
[
index
];
return
posteriors2_
[
index
];
}
}
...
@@ -766,16 +766,16 @@ public:
...
@@ -766,16 +766,16 @@ public:
size_t
reduced_num_dim
=
RandomizedTree
::
DEFAULT_REDUCED_NUM_DIM
,
size_t
reduced_num_dim
=
RandomizedTree
::
DEFAULT_REDUCED_NUM_DIM
,
int
num_quant_bits
=
DEFAULT_NUM_QUANT_BITS
);
int
num_quant_bits
=
DEFAULT_NUM_QUANT_BITS
);
// sig must point to a memory block of at least classes()*sizeof(float|u
int8_t
) bytes
// sig must point to a memory block of at least classes()*sizeof(float|u
char
) bytes
void
getSignature
(
IplImage
*
patch
,
u
int8_t
*
sig
)
const
;
void
getSignature
(
IplImage
*
patch
,
u
char
*
sig
)
const
;
void
getSignature
(
IplImage
*
patch
,
float
*
sig
)
const
;
void
getSignature
(
IplImage
*
patch
,
float
*
sig
)
const
;
void
getSparseSignature
(
IplImage
*
patch
,
float
*
sig
,
float
thresh
)
const
;
void
getSparseSignature
(
IplImage
*
patch
,
float
*
sig
,
float
thresh
)
const
;
// TODO: deprecated in favor of getSignature overload, remove
// TODO: deprecated in favor of getSignature overload, remove
void
getFloatSignature
(
IplImage
*
patch
,
float
*
sig
)
const
{
getSignature
(
patch
,
sig
);
}
void
getFloatSignature
(
IplImage
*
patch
,
float
*
sig
)
const
{
getSignature
(
patch
,
sig
);
}
static
int
countNonZeroElements
(
float
*
vec
,
int
n
,
double
tol
=
1e-10
);
static
int
countNonZeroElements
(
float
*
vec
,
int
n
,
double
tol
=
1e-10
);
static
inline
void
safeSignatureAlloc
(
u
int8_t
**
sig
,
int
num_sig
=
1
,
int
sig_len
=
176
);
static
inline
void
safeSignatureAlloc
(
u
char
**
sig
,
int
num_sig
=
1
,
int
sig_len
=
176
);
static
inline
u
int8_t
*
safeSignatureAlloc
(
int
num_sig
=
1
,
int
sig_len
=
176
);
static
inline
u
char
*
safeSignatureAlloc
(
int
num_sig
=
1
,
int
sig_len
=
176
);
inline
int
classes
()
const
{
return
classes_
;
}
inline
int
classes
()
const
{
return
classes_
;
}
inline
int
original_num_classes
()
const
{
return
original_num_classes_
;
}
inline
int
original_num_classes
()
const
{
return
original_num_classes_
;
}
...
@@ -799,8 +799,8 @@ public:
...
@@ -799,8 +799,8 @@ public:
private
:
private
:
int
classes_
;
int
classes_
;
int
num_quant_bits_
;
int
num_quant_bits_
;
mutable
u
int8_t
**
posteriors_
;
mutable
u
char
**
posteriors_
;
mutable
u
int16_
t
*
ptemp_
;
mutable
u
nsigned
shor
t
*
ptemp_
;
int
original_num_classes_
;
int
original_num_classes_
;
bool
keep_floats_
;
bool
keep_floats_
;
};
};
...
@@ -1584,11 +1584,11 @@ void CalonderDescriptorExtractor<T>::compute( const cv::Mat& image,
...
@@ -1584,11 +1584,11 @@ void CalonderDescriptorExtractor<T>::compute( const cv::Mat& image,
}
}
template
<
typename
T
>
template
<
typename
T
>
void
CalonderDescriptorExtractor
<
T
>::
read
(
const
FileNode
&
fn
)
void
CalonderDescriptorExtractor
<
T
>::
read
(
const
FileNode
&
)
{}
{}
template
<
typename
T
>
template
<
typename
T
>
void
CalonderDescriptorExtractor
<
T
>::
write
(
FileStorage
&
f
s
)
const
void
CalonderDescriptorExtractor
<
T
>::
write
(
FileStorage
&
s
)
const
{}
{}
CV_EXPORTS
Ptr
<
DescriptorExtractor
>
createDescriptorExtractor
(
const
string
&
descriptorExtractorType
);
CV_EXPORTS
Ptr
<
DescriptorExtractor
>
createDescriptorExtractor
(
const
string
&
descriptorExtractorType
);
...
...
modules/features2d/src/calonder.cpp
View file @
74300f5f
...
@@ -105,18 +105,18 @@ float* CSMatrixGenerator::getCSMatrix(int m, int n, PHI_DISTR_TYPE dt)
...
@@ -105,18 +105,18 @@ float* CSMatrixGenerator::getCSMatrix(int m, int n, PHI_DISTR_TYPE dt)
if
(
dt
==
PDT_GAUSS
)
{
if
(
dt
==
PDT_GAUSS
)
{
float
par
=
(
float
)(
1.
/
m
);
float
par
=
(
float
)(
1.
/
m
);
for
(
int
i
=
0
;
i
<
m
*
n
;
++
i
)
for
(
int
i
=
0
;
i
<
m
*
n
;
++
i
)
*
cs_phi
++
=
rng
.
gaussian
(
par
);
*
cs_phi
++
=
(
float
)
rng
.
gaussian
(
par
);
}
}
else
if
(
dt
==
PDT_BERNOULLI
)
{
else
if
(
dt
==
PDT_BERNOULLI
)
{
float
par
=
(
float
)(
1.
/
sqrt
(
m
));
float
par
=
(
float
)(
1.
/
sqrt
(
(
float
)
m
));
for
(
int
i
=
0
;
i
<
m
*
n
;
++
i
)
for
(
int
i
=
0
;
i
<
m
*
n
;
++
i
)
*
cs_phi
++
=
(
rng
(
2
)
==
0
?
par
:
-
par
);
*
cs_phi
++
=
(
rng
(
2
)
==
0
?
par
:
-
par
);
}
}
else
if
(
dt
==
PDT_DBFRIENDLY
)
{
else
if
(
dt
==
PDT_DBFRIENDLY
)
{
float
par
=
(
float
)
sqrt
(
3.
/
m
);
float
par
=
(
float
)
sqrt
(
3.
/
m
);
for
(
int
i
=
0
;
i
<
m
*
n
;
++
i
)
{
for
(
int
i
=
0
;
i
<
m
*
n
;
++
i
)
{
int
i
=
rng
(
6
);
int
r
=
rng
(
6
);
*
cs_phi
++
=
(
i
==
0
?
par
:
(
i
==
1
?
-
par
:
0.
f
));
*
cs_phi
++
=
(
r
==
0
?
par
:
(
r
==
1
?
-
par
:
0.
f
));
}
}
}
}
else
else
...
@@ -151,7 +151,7 @@ inline void addVec(int size, const float* src1, const float* src2, float* dst)
...
@@ -151,7 +151,7 @@ inline void addVec(int size, const float* src1, const float* src2, float* dst)
// final shift is 2 bits right
// final shift is 2 bits right
// temp buffer should be twice as long as signature
// temp buffer should be twice as long as signature
// sig and buffer need not be initialized
// sig and buffer need not be initialized
inline
void
sum_50t_176c
(
u
int8_t
**
pp
,
uint8_t
*
sig
,
uint16_
t
*
temp
)
inline
void
sum_50t_176c
(
u
char
**
pp
,
uchar
*
sig
,
unsigned
shor
t
*
temp
)
{
{
#if CV_SSE2
#if CV_SSE2
__m128i
acc
,
*
acc1
,
*
acc2
,
*
acc3
,
*
acc4
,
tzero
;
__m128i
acc
,
*
acc1
,
*
acc2
,
*
acc3
,
*
acc4
,
tzero
;
...
@@ -293,10 +293,10 @@ void RandomizedTree::createNodes(int num_nodes, RNG &rng)
...
@@ -293,10 +293,10 @@ void RandomizedTree::createNodes(int num_nodes, RNG &rng)
{
{
nodes_
.
reserve
(
num_nodes
);
nodes_
.
reserve
(
num_nodes
);
for
(
int
i
=
0
;
i
<
num_nodes
;
++
i
)
{
for
(
int
i
=
0
;
i
<
num_nodes
;
++
i
)
{
nodes_
.
push_back
(
RTreeNode
(
rng
(
RandomizedTree
::
PATCH_SIZE
),
nodes_
.
push_back
(
RTreeNode
(
(
uchar
)
rng
(
RandomizedTree
::
PATCH_SIZE
),
rng
(
RandomizedTree
::
PATCH_SIZE
),
(
uchar
)
rng
(
RandomizedTree
::
PATCH_SIZE
),
rng
(
RandomizedTree
::
PATCH_SIZE
),
(
uchar
)
rng
(
RandomizedTree
::
PATCH_SIZE
),
rng
(
RandomizedTree
::
PATCH_SIZE
))
);
(
uchar
)
rng
(
RandomizedTree
::
PATCH_SIZE
))
);
}
}
}
}
...
@@ -352,10 +352,10 @@ void RandomizedTree::allocPosteriorsAligned(int num_leaves, int num_classes)
...
@@ -352,10 +352,10 @@ void RandomizedTree::allocPosteriorsAligned(int num_leaves, int num_classes)
memset
(
posteriors_
[
i
],
0
,
num_classes
*
sizeof
(
float
));
memset
(
posteriors_
[
i
],
0
,
num_classes
*
sizeof
(
float
));
}
}
posteriors2_
=
new
u
int8_t
*
[
num_leaves
];
posteriors2_
=
new
u
char
*
[
num_leaves
];
for
(
int
i
=
0
;
i
<
num_leaves
;
++
i
)
{
for
(
int
i
=
0
;
i
<
num_leaves
;
++
i
)
{
posteriors2_
[
i
]
=
(
u
int8_t
*
)
cvAlloc
(
num_classes
*
sizeof
(
posteriors2_
[
i
][
0
]));
posteriors2_
[
i
]
=
(
u
char
*
)
cvAlloc
(
num_classes
*
sizeof
(
posteriors2_
[
i
][
0
]));
memset
(
posteriors2_
[
i
],
0
,
num_classes
*
sizeof
(
u
int8_t
));
memset
(
posteriors2_
[
i
],
0
,
num_classes
*
sizeof
(
u
char
));
}
}
classes_
=
num_classes
;
classes_
=
num_classes
;
...
@@ -394,7 +394,7 @@ void RandomizedTree::init(int num_classes, int depth, RNG &rng)
...
@@ -394,7 +394,7 @@ void RandomizedTree::init(int num_classes, int depth, RNG &rng)
leaf_counts_
.
resize
(
num_leaves_
);
leaf_counts_
.
resize
(
num_leaves_
);
for
(
int
i
=
0
;
i
<
num_leaves_
;
++
i
)
for
(
int
i
=
0
;
i
<
num_leaves_
;
++
i
)
memset
((
void
*
)
posteriors2_
[
i
],
0
,
num_classes
*
sizeof
(
u
int8_t
));
memset
((
void
*
)
posteriors2_
[
i
],
0
,
num_classes
*
sizeof
(
u
char
));
createNodes
(
num_nodes
,
rng
);
createNodes
(
num_nodes
,
rng
);
}
}
...
@@ -510,8 +510,8 @@ void RandomizedTree::estimateQuantPercForPosteriors(float perc[2])
...
@@ -510,8 +510,8 @@ void RandomizedTree::estimateQuantPercForPosteriors(float perc[2])
assert
(
posteriors_
!=
NULL
);
assert
(
posteriors_
!=
NULL
);
perc
[
0
]
=
perc
[
1
]
=
.0
f
;
perc
[
0
]
=
perc
[
1
]
=
.0
f
;
for
(
int
i
=
0
;
i
<
num_leaves_
;
i
++
)
{
for
(
int
i
=
0
;
i
<
num_leaves_
;
i
++
)
{
perc
[
0
]
+=
percentile
(
posteriors_
[
i
],
classes_
,
LOWER_QUANT_PERC
);
perc
[
0
]
+=
percentile
(
posteriors_
[
i
],
classes_
,
GET_LOWER_QUANT_PERC
()
);
perc
[
1
]
+=
percentile
(
posteriors_
[
i
],
classes_
,
UPPER_QUANT_PERC
);
perc
[
1
]
+=
percentile
(
posteriors_
[
i
],
classes_
,
GET_UPPER_QUANT_PERC
()
);
}
}
perc
[
0
]
/=
num_leaves_
;
perc
[
0
]
/=
num_leaves_
;
perc
[
1
]
/=
num_leaves_
;
perc
[
1
]
/=
num_leaves_
;
...
@@ -528,12 +528,12 @@ const float* RandomizedTree::getPosterior(uchar* patch_data) const
...
@@ -528,12 +528,12 @@ const float* RandomizedTree::getPosterior(uchar* patch_data) const
return
getPosteriorByIndex
(
getIndex
(
patch_data
)
);
return
getPosteriorByIndex
(
getIndex
(
patch_data
)
);
}
}
u
int8_t
*
RandomizedTree
::
getPosterior2
(
uchar
*
patch_data
)
u
char
*
RandomizedTree
::
getPosterior2
(
uchar
*
patch_data
)
{
{
return
const_cast
<
u
int8_t
*>
(
const_cast
<
const
RandomizedTree
*>
(
this
)
->
getPosterior2
(
patch_data
));
return
const_cast
<
u
char
*>
(
const_cast
<
const
RandomizedTree
*>
(
this
)
->
getPosterior2
(
patch_data
));
}
}
const
u
int8_t
*
RandomizedTree
::
getPosterior2
(
uchar
*
patch_data
)
const
const
u
char
*
RandomizedTree
::
getPosterior2
(
uchar
*
patch_data
)
const
{
{
return
getPosteriorByIndex2
(
getIndex
(
patch_data
)
);
return
getPosteriorByIndex2
(
getIndex
(
patch_data
)
);
}
}
...
@@ -559,13 +559,13 @@ void RandomizedTree::quantizeVector(float *vec, int dim, int N, float bnds[2], i
...
@@ -559,13 +559,13 @@ void RandomizedTree::quantizeVector(float *vec, int dim, int N, float bnds[2], i
}
}
void
RandomizedTree
::
quantizeVector
(
float
*
vec
,
int
dim
,
int
N
,
float
bnds
[
2
],
u
int8_t
*
dst
)
void
RandomizedTree
::
quantizeVector
(
float
*
vec
,
int
dim
,
int
N
,
float
bnds
[
2
],
u
char
*
dst
)
{
{
int
map_bnd
[
2
]
=
{
0
,
N
};
// bounds of quantized target interval we're mapping to
int
map_bnd
[
2
]
=
{
0
,
N
};
// bounds of quantized target interval we're mapping to
int
tmp
;
int
tmp
;
for
(
int
k
=
0
;
k
<
dim
;
++
k
)
{
for
(
int
k
=
0
;
k
<
dim
;
++
k
)
{
tmp
=
int
((
*
vec
-
bnds
[
0
])
/
(
bnds
[
1
]
-
bnds
[
0
])
*
(
map_bnd
[
1
]
-
map_bnd
[
0
])
+
map_bnd
[
0
]);
tmp
=
int
((
*
vec
-
bnds
[
0
])
/
(
bnds
[
1
]
-
bnds
[
0
])
*
(
map_bnd
[
1
]
-
map_bnd
[
0
])
+
map_bnd
[
0
]);
*
dst
=
(
u
int8_t
)((
tmp
<
0
)
?
0
:
((
tmp
>
N
)
?
N
:
tmp
));
*
dst
=
(
u
char
)((
tmp
<
0
)
?
0
:
((
tmp
>
N
)
?
N
:
tmp
));
++
vec
;
++
vec
;
++
dst
;
++
dst
;
}
}
...
@@ -644,7 +644,7 @@ void RandomizedTree::savePosteriors2(std::string url, bool append)
...
@@ -644,7 +644,7 @@ void RandomizedTree::savePosteriors2(std::string url, bool append)
{
{
std
::
ofstream
file
(
url
.
c_str
(),
(
append
?
std
::
ios
::
app
:
std
::
ios
::
out
));
std
::
ofstream
file
(
url
.
c_str
(),
(
append
?
std
::
ios
::
app
:
std
::
ios
::
out
));
for
(
int
i
=
0
;
i
<
num_leaves_
;
i
++
)
{
for
(
int
i
=
0
;
i
<
num_leaves_
;
i
++
)
{
u
int8_t
*
post
=
posteriors2_
[
i
];
u
char
*
post
=
posteriors2_
[
i
];
for
(
int
i
=
0
;
i
<
classes_
;
i
++
)
for
(
int
i
=
0
;
i
<
classes_
;
i
++
)
file
<<
int
(
*
post
++
)
<<
(
i
<
classes_
-
1
?
" "
:
""
);
file
<<
int
(
*
post
++
)
<<
(
i
<
classes_
-
1
?
" "
:
""
);
file
<<
std
::
endl
;
file
<<
std
::
endl
;
...
@@ -767,7 +767,7 @@ void RTreeClassifier::getSignature(IplImage* patch, float *sig) const
...
@@ -767,7 +767,7 @@ void RTreeClassifier::getSignature(IplImage* patch, float *sig) const
#endif
#endif
}
}
void
RTreeClassifier
::
getSignature
(
IplImage
*
patch
,
u
int8_t
*
sig
)
const
void
RTreeClassifier
::
getSignature
(
IplImage
*
patch
,
u
char
*
sig
)
const
{
{
// Need pointer to 32x32 patch data
// Need pointer to 32x32 patch data
uchar
buffer
[
RandomizedTree
::
PATCH_SIZE
*
RandomizedTree
::
PATCH_SIZE
];
uchar
buffer
[
RandomizedTree
::
PATCH_SIZE
*
RandomizedTree
::
PATCH_SIZE
];
...
@@ -792,13 +792,13 @@ void RTreeClassifier::getSignature(IplImage* patch, uint8_t *sig) const
...
@@ -792,13 +792,13 @@ void RTreeClassifier::getSignature(IplImage* patch, uint8_t *sig) const
// get posteriors
// get posteriors
if
(
posteriors_
==
NULL
)
if
(
posteriors_
==
NULL
)
{
{
posteriors_
=
(
u
int8_t
**
)
cvAlloc
(
trees_
.
size
()
*
sizeof
(
posteriors_
[
0
])
);
posteriors_
=
(
u
char
**
)
cvAlloc
(
trees_
.
size
()
*
sizeof
(
posteriors_
[
0
])
);
ptemp_
=
(
u
int16_
t
*
)
cvAlloc
(
classes_
*
sizeof
(
ptemp_
[
0
])
);
ptemp_
=
(
u
nsigned
shor
t
*
)
cvAlloc
(
classes_
*
sizeof
(
ptemp_
[
0
])
);
}
}
/// @todo What is going on in the next 4 lines?
/// @todo What is going on in the next 4 lines?
u
int8_t
**
pp
=
posteriors_
;
u
char
**
pp
=
posteriors_
;
for
(
tree_it
=
trees_
.
begin
();
tree_it
!=
trees_
.
end
();
++
tree_it
,
pp
++
)
for
(
tree_it
=
trees_
.
begin
();
tree_it
!=
trees_
.
end
();
++
tree_it
,
pp
++
)
*
pp
=
const_cast
<
u
int8_t
*>
(
tree_it
->
getPosterior2
(
patch_data
));
*
pp
=
const_cast
<
u
char
*>
(
tree_it
->
getPosterior2
(
patch_data
));
pp
=
posteriors_
;
pp
=
posteriors_
;
#if 1
#if 1
...
@@ -808,19 +808,19 @@ void RTreeClassifier::getSignature(IplImage* patch, uint8_t *sig) const
...
@@ -808,19 +808,19 @@ void RTreeClassifier::getSignature(IplImage* patch, uint8_t *sig) const
static
bool
warned
=
false
;
static
bool
warned
=
false
;
memset
((
void
*
)
sig
,
0
,
classes_
*
sizeof
(
sig
[
0
]));
memset
((
void
*
)
sig
,
0
,
classes_
*
sizeof
(
sig
[
0
]));
u
int16_t
*
sig16
=
new
uint16_
t
[
classes_
];
// TODO: make member, no alloc here
u
nsigned
short
*
sig16
=
new
unsigned
shor
t
[
classes_
];
// TODO: make member, no alloc here
memset
((
void
*
)
sig16
,
0
,
classes_
*
sizeof
(
sig16
[
0
]));
memset
((
void
*
)
sig16
,
0
,
classes_
*
sizeof
(
sig16
[
0
]));
for
(
tree_it
=
trees_
.
begin
();
tree_it
!=
trees_
.
end
();
++
tree_it
,
pp
++
)
for
(
tree_it
=
trees_
.
begin
();
tree_it
!=
trees_
.
end
();
++
tree_it
,
pp
++
)
addVec
(
classes_
,
sig16
,
*
pp
,
sig16
);
addVec
(
classes_
,
sig16
,
*
pp
,
sig16
);
// squeeze signatures into an u
int8_t
// squeeze signatures into an u
char
const
bool
full_shifting
=
true
;
const
bool
full_shifting
=
true
;
int
shift
;
int
shift
;
if
(
full_shifting
)
{
if
(
full_shifting
)
{
float
num_add_bits_f
=
log
((
float
)
trees_
.
size
())
/
log
(
2.
f
);
// # additional bits required due to summation
float
num_add_bits_f
=
log
((
float
)
trees_
.
size
())
/
log
(
2.
f
);
// # additional bits required due to summation
int
num_add_bits
=
int
(
num_add_bits_f
);
int
num_add_bits
=
int
(
num_add_bits_f
);
if
(
num_add_bits_f
!=
float
(
num_add_bits
))
++
num_add_bits
;
if
(
num_add_bits_f
!=
float
(
num_add_bits
))
++
num_add_bits
;
shift
=
num_quant_bits_
+
num_add_bits
-
8
*
sizeof
(
u
int8_t
);
shift
=
num_quant_bits_
+
num_add_bits
-
8
*
sizeof
(
u
char
);
//shift = num_quant_bits_ + num_add_bits - 2;
//shift = num_quant_bits_ + num_add_bits - 2;
//shift = 6;
//shift = 6;
if
(
shift
>
0
)
if
(
shift
>
0
)
...
@@ -959,7 +959,7 @@ float RTreeClassifier::countZeroElements()
...
@@ -959,7 +959,7 @@ float RTreeClassifier::countZeroElements()
for
(
int
i
=
0
;
i
<
(
int
)
trees_
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
(
int
)
trees_
.
size
();
++
i
)
for
(
int
k
=
0
;
k
<
(
int
)
trees_
[
i
].
num_leaves_
;
++
k
)
{
for
(
int
k
=
0
;
k
<
(
int
)
trees_
[
i
].
num_leaves_
;
++
k
)
{
float
*
p
=
trees_
[
i
].
getPosteriorByIndex
(
k
);
float
*
p
=
trees_
[
i
].
getPosteriorByIndex
(
k
);
u
int8_t
*
p2
=
trees_
[
i
].
getPosteriorByIndex2
(
k
);
u
char
*
p2
=
trees_
[
i
].
getPosteriorByIndex2
(
k
);
assert
(
p
);
assert
(
p2
);
assert
(
p
);
assert
(
p2
);
for
(
int
j
=
0
;
j
<
num_elem
;
++
j
,
++
p
,
++
p2
)
{
for
(
int
j
=
0
;
j
<
num_elem
;
++
j
,
++
p
,
++
p2
)
{
if
(
*
p
==
0.
f
)
flt_zeros
++
;
if
(
*
p
==
0.
f
)
flt_zeros
++
;
...
@@ -967,8 +967,8 @@ float RTreeClassifier::countZeroElements()
...
@@ -967,8 +967,8 @@ float RTreeClassifier::countZeroElements()
}
}
}
}
num_elem
=
trees_
.
size
()
*
trees_
[
0
].
num_leaves_
*
num_elem
;
num_elem
=
trees_
.
size
()
*
trees_
[
0
].
num_leaves_
*
num_elem
;
float
flt_perc
=
100.
*
flt_zeros
/
num_elem
;
float
flt_perc
=
100.
f
*
flt_zeros
/
num_elem
;
float
ui8_perc
=
100.
*
ui8_zeros
/
num_elem
;
float
ui8_perc
=
100.
f
*
ui8_zeros
/
num_elem
;
printf
(
"[OK] RTC: overall %i/%i (%.3f%%) zeros in float leaves
\n
"
,
flt_zeros
,
num_elem
,
flt_perc
);
printf
(
"[OK] RTC: overall %i/%i (%.3f%%) zeros in float leaves
\n
"
,
flt_zeros
,
num_elem
,
flt_perc
);
printf
(
" overall %i/%i (%.3f%%) zeros in uint8 leaves
\n
"
,
ui8_zeros
,
num_elem
,
ui8_perc
);
printf
(
" overall %i/%i (%.3f%%) zeros in uint8 leaves
\n
"
,
ui8_zeros
,
num_elem
,
ui8_perc
);
...
...
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