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
9efd668a
Commit
9efd668a
authored
Dec 24, 2012
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
a bit refactored soft cascade
parent
f1b4b13e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
43 deletions
+37
-43
softcascade.cpp
modules/objdetect/src/softcascade.cpp
+37
-43
No files found.
modules/objdetect/src/softcascade.cpp
View file @
9efd668a
...
...
@@ -223,7 +223,7 @@ struct cv::SCascade::Fields
int
shrinkage
;
std
::
vector
<
Octave
>
octaves
;
std
::
vector
<
Weak
>
stage
s
;
std
::
vector
<
Weak
>
weak
s
;
std
::
vector
<
Node
>
nodes
;
std
::
vector
<
float
>
leaves
;
std
::
vector
<
Feature
>
features
;
...
...
@@ -233,47 +233,46 @@ struct cv::SCascade::Fields
cv
::
Size
frameSize
;
typedef
std
::
vector
<
Octave
>::
iterator
octIt_t
;
typedef
std
::
vector
<
Detection
>
dvector
;
void
detectAt
(
const
int
dx
,
const
int
dy
,
const
Level
&
level
,
const
ChannelStorage
&
storage
,
std
::
vector
<
Detection
>&
detections
)
const
void
detectAt
(
const
int
dx
,
const
int
dy
,
const
Level
&
level
,
const
ChannelStorage
&
storage
,
dvector
&
detections
)
const
{
float
detectionScore
=
0.
f
;
const
Octave
&
octave
=
*
(
level
.
octave
);
int
stBegin
=
octave
.
index
*
octave
.
weaks
,
stEnd
=
stBegin
+
((
octave
.
index
)
?
1024
:
416
)
;
int
stBegin
=
octave
.
index
*
octave
.
weaks
,
stEnd
=
stBegin
+
octave
.
weaks
;
int
st
=
stBegin
;
int
offset
=
(
octave
.
index
)
?
-
2
:
0
;
for
(;
st
<
stEnd
;
++
st
)
for
(
int
st
=
stBegin
;
st
<
stEnd
;
++
st
)
{
const
Weak
&
stage
=
stages
[
st
];
{
int
nId
=
st
*
3
+
offset
;
const
Weak
&
weak
=
weaks
[
st
];
// work with root node
const
Node
&
node
=
nodes
[
nId
];
const
Feature
&
feature
=
features
[
node
.
feature
+
offset
];
cv
::
Rect
scaledRect
(
feature
.
rect
);
int
nId
=
st
*
3
;
float
threshold
=
level
.
rescale
(
scaledRect
,
node
.
threshold
,(
int
)(
feature
.
channel
>
6
))
*
feature
.
rarea
;
float
sum
=
storage
.
get
(
feature
.
channel
,
scaledRect
)
;
int
next
=
(
sum
>=
threshold
)
?
2
:
1
;
// work with root node
const
Node
&
node
=
nodes
[
nId
]
;
const
Feature
&
feature
=
features
[
node
.
feature
]
;
// leaves
const
Node
&
leaf
=
nodes
[
nId
+
next
];
const
Feature
&
fLeaf
=
features
[
leaf
.
feature
+
offset
];
cv
::
Rect
scaledRect
(
feature
.
rect
);
scaledRect
=
fLeaf
.
rect
;
threshold
=
level
.
rescale
(
scaledRect
,
leaf
.
threshold
,
(
int
)(
fLeaf
.
channel
>
6
))
*
fLeaf
.
rarea
;
sum
=
storage
.
get
(
fLeaf
.
channel
,
scaledRect
)
;
float
threshold
=
level
.
rescale
(
scaledRect
,
node
.
threshold
,
(
int
)(
feature
.
channel
>
6
))
*
feature
.
rarea
;
float
sum
=
storage
.
get
(
feature
.
channel
,
scaledRect
)
;
int
next
=
(
sum
>=
threshold
)
?
2
:
1
;
int
lShift
=
(
next
-
1
)
*
2
+
((
sum
>=
threshold
)
?
1
:
0
);
float
impact
=
leaves
[(
st
*
4
+
offset
)
+
lShift
];
// leaves
const
Node
&
leaf
=
nodes
[
nId
+
next
];
const
Feature
&
fLeaf
=
features
[
leaf
.
feature
];
detectionScore
+=
impact
;
}
if
(
detectionScore
<=
stage
.
threshold
)
return
;
scaledRect
=
fLeaf
.
rect
;
threshold
=
level
.
rescale
(
scaledRect
,
leaf
.
threshold
,
(
int
)(
fLeaf
.
channel
>
6
))
*
fLeaf
.
rarea
;
sum
=
storage
.
get
(
fLeaf
.
channel
,
scaledRect
);
int
lShift
=
(
next
-
1
)
*
2
+
((
sum
>=
threshold
)
?
1
:
0
);
float
impact
=
leaves
[(
st
*
4
)
+
lShift
];
detectionScore
+=
impact
;
if
(
detectionScore
<=
weak
.
threshold
)
return
;
}
if
(
detectionScore
>
0
)
...
...
@@ -346,13 +345,14 @@ struct cv::SCascade::Fields
static
const
char
*
const
SC_ORIG_H
=
"height"
;
static
const
char
*
const
SC_OCTAVES
=
"octaves"
;
static
const
char
*
const
SC_
STAGES
=
"stag
es"
;
static
const
char
*
const
SC_
TREES
=
"tre
es"
;
static
const
char
*
const
SC_FEATURES
=
"features"
;
static
const
char
*
const
SC_WEEK
=
"weakClassifiers"
;
static
const
char
*
const
SC_INTERNAL
=
"internalNodes"
;
static
const
char
*
const
SC_LEAF
=
"leafValues"
;
static
const
char
*
const
SC_SHRINKAGE
=
"shrinkage"
;
// only Ada Boost supported
std
::
string
stageTypeStr
=
(
string
)
root
[
SC_STAGE_TYPE
];
CV_Assert
(
stageTypeStr
==
SC_BOOST
);
...
...
@@ -364,17 +364,14 @@ struct cv::SCascade::Fields
origObjWidth
=
(
int
)
root
[
SC_ORIG_W
];
origObjHeight
=
(
int
)
root
[
SC_ORIG_H
];
shrinkage
=
(
int
)
root
[
"shrinkage"
];
shrinkage
=
(
int
)
root
[
SC_SHRINKAGE
];
FileNode
fn
=
root
[
SC_OCTAVES
];
if
(
fn
.
empty
())
return
false
;
FileNodeIterator
it
=
fn
.
begin
(),
it_end
=
fn
.
end
();
int
feature_offset
=
0
;
int
octIndex
=
0
;
// for each octave
for
(;
it
!=
it_end
;
++
it
)
FileNodeIterator
it
=
fn
.
begin
(),
it_end
=
fn
.
end
();
for
(
int
octIndex
=
0
;
it
!=
it_end
;
++
it
,
++
octIndex
)
{
FileNode
fns
=
*
it
;
Octave
octave
(
octIndex
,
cv
::
Size
(
origObjWidth
,
origObjHeight
),
fns
);
...
...
@@ -384,19 +381,18 @@ struct cv::SCascade::Fields
FileNode
ffs
=
fns
[
SC_FEATURES
];
if
(
ffs
.
empty
())
return
false
;
fns
=
fns
[
"trees"
];
fns
=
fns
[
SC_TREES
];
if
(
fn
.
empty
())
return
false
;
// for each tree (~ decision tree with H = 2)
FileNodeIterator
st
=
fns
.
begin
(),
st_end
=
fns
.
end
();
for
(;
st
!=
st_end
;
++
st
)
{
stage
s
.
push_back
(
Weak
(
*
st
));
weak
s
.
push_back
(
Weak
(
*
st
));
fns
=
(
*
st
)[
SC_INTERNAL
];
FileNodeIterator
inIt
=
fns
.
begin
(),
inIt_end
=
fns
.
end
();
for
(;
inIt
!=
inIt_end
;)
nodes
.
push_back
(
Node
(
feature
_offset
,
inIt
));
nodes
.
push_back
(
Node
(
feature
s
.
size
()
,
inIt
));
fns
=
(
*
st
)[
SC_LEAF
];
inIt
=
fns
.
begin
(),
inIt_end
=
fns
.
end
();
...
...
@@ -408,10 +404,8 @@ struct cv::SCascade::Fields
st
=
ffs
.
begin
(),
st_end
=
ffs
.
end
();
for
(;
st
!=
st_end
;
++
st
)
features
.
push_back
(
Feature
(
*
st
));
feature_offset
+=
octave
.
weaks
*
3
;
++
octIndex
;
}
return
true
;
}
};
...
...
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