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
801368ee
Commit
801368ee
authored
Sep 13, 2012
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring
parent
6f53be41
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
129 additions
and
123 deletions
+129
-123
softcascade.cpp
modules/objdetect/src/softcascade.cpp
+129
-123
No files found.
modules/objdetect/src/softcascade.cpp
View file @
801368ee
...
@@ -49,69 +49,93 @@
...
@@ -49,69 +49,93 @@
namespace
{
namespace
{
struct
Octave
struct
Octave
{
{
float
scale
;
float
scale
;
int
stages
;
int
stages
;
cv
::
Size
size
;
cv
::
Size
size
;
int
shrinkage
;
int
shrinkage
;
static
const
char
*
const
SC_OCT_SCALE
;
static
const
char
*
const
SC_OCT_STAGES
;
static
const
char
*
const
SC_OCT_SHRINKAGE
;
Octave
(){}
Octave
(
cv
::
Size
origObjSize
,
const
cv
::
FileNode
&
fn
)
:
scale
((
float
)
fn
[
SC_OCT_SCALE
]),
stages
((
int
)
fn
[
SC_OCT_STAGES
]),
size
(
cvRound
(
origObjSize
.
width
*
scale
),
cvRound
(
origObjSize
.
height
*
scale
)),
shrinkage
((
int
)
fn
[
SC_OCT_SHRINKAGE
])
{}
};
const
char
*
const
Octave
::
SC_OCT_SCALE
=
"scale"
;
static
const
char
*
const
SC_OCT_SCALE
;
const
char
*
const
Octave
::
SC_OCT_STAGES
=
"stageNum"
;
static
const
char
*
const
SC_OCT_STAGES
;
const
char
*
const
Octave
::
SC_OCT_SHRINKAGE
=
"shrinkingFactor"
;
static
const
char
*
const
SC_OCT_SHRINKAGE
;
Octave
()
:
scale
(
0
),
stages
(
0
),
size
(
cv
::
Size
()),
shrinkage
(
0
)
{}
Octave
(
cv
::
Size
origObjSize
,
const
cv
::
FileNode
&
fn
)
:
scale
((
float
)
fn
[
SC_OCT_SCALE
]),
stages
((
int
)
fn
[
SC_OCT_STAGES
]),
size
(
cvRound
(
origObjSize
.
width
*
scale
),
cvRound
(
origObjSize
.
height
*
scale
)),
shrinkage
((
int
)
fn
[
SC_OCT_SHRINKAGE
])
{}
};
struct
Stage
const
char
*
const
Octave
::
SC_OCT_SCALE
=
"scale"
;
{
const
char
*
const
Octave
::
SC_OCT_STAGES
=
"stageNum"
;
float
threshold
;
const
char
*
const
Octave
::
SC_OCT_SHRINKAGE
=
"shrinkingFactor"
;
static
const
char
*
const
SC_STAGE_THRESHOLD
;
Stage
(){}
struct
Stage
Stage
(
const
cv
::
FileNode
&
fn
)
:
threshold
((
float
)
fn
[
SC_STAGE_THRESHOLD
])
{
{
std
::
cout
<<
" stage: "
<<
threshold
<<
std
::
endl
;
}
float
threshold
;
};
const
char
*
const
Stage
::
SC_STAGE_THRESHOLD
=
"stageThreshold"
;
static
const
char
*
const
SC_STAGE_THRESHOLD
;
struct
Node
Stage
(){}
{
Stage
(
const
cv
::
FileNode
&
fn
)
:
threshold
((
float
)
fn
[
SC_STAGE_THRESHOLD
]){}
int
feature
;
};
float
threshold
;
Node
(){}
const
char
*
const
Stage
::
SC_STAGE_THRESHOLD
=
"stageThreshold"
;
Node
(
cv
::
FileNodeIterator
&
fIt
)
:
feature
((
int
)(
*
(
fIt
+=
2
)
++
)),
threshold
((
float
)(
*
(
fIt
++
)))
{
std
::
cout
<<
" Node: "
<<
feature
<<
" "
<<
threshold
<<
std
::
endl
;
}
struct
Node
};
{
int
feature
;
float
threshold
;
Node
(){}
Node
(
cv
::
FileNodeIterator
&
fIt
)
:
feature
((
int
)(
*
(
fIt
+=
2
)
++
)),
threshold
((
float
)(
*
(
fIt
++
))){}
};
struct
Feature
{
int
channel
;
cv
::
Rect
rect
;
struct
Feature
static
const
char
*
const
SC_F_CHANNEL
;
static
const
char
*
const
SC_F_RECT
;
Feature
()
{}
Feature
(
const
cv
::
FileNode
&
fn
)
:
channel
((
int
)
fn
[
SC_F_CHANNEL
])
{
{
int
channel
;
cv
::
FileNode
rn
=
fn
[
SC_F_RECT
];
cv
::
Rect
rect
;
cv
::
FileNodeIterator
r_it
=
rn
.
end
();
rect
=
cv
::
Rect
(
*
(
--
r_it
),
*
(
--
r_it
),
*
(
--
r_it
),
*
(
--
r_it
));
// std::cout << "feature: " << rect.x << " " << rect.y << " " << rect.width
//<< " " << rect.height << " " << channel << std::endl;
}
};
static
const
char
*
const
SC_F_CHANNEL
;
const
char
*
const
Feature
::
SC_F_CHANNEL
=
"channel"
;
static
const
char
*
const
SC_F_RECT
;
const
char
*
const
Feature
::
SC_F_RECT
=
"rect"
;
struct
Level
{
const
Octave
*
octave
;
float
origScale
;
float
relScale
;
float
shrScale
;
cv
::
Size
workRect
;
cv
::
Size
objSize
;
Feature
()
{}
Feature
(
const
cv
::
FileNode
&
fn
)
:
channel
((
int
)
fn
[
SC_F_CHANNEL
])
// TiDo not reounding
{
Level
(
const
Octave
&
oct
,
const
float
scale
,
const
int
shrinkage
,
const
int
w
,
const
int
h
)
cv
::
FileNode
rn
=
fn
[
SC_F_RECT
];
:
octave
(
&
oct
),
origScale
(
scale
),
relScale
(
scale
/
oct
.
scale
),
shrScale
(
relScale
/
shrinkage
),
cv
::
FileNodeIterator
r_it
=
rn
.
end
();
workRect
(
cv
::
Size
(
cvRound
(
w
/
(
float
)
shrinkage
),
cvRound
(
h
/
(
float
)
shrinkage
))),
rect
=
cv
::
Rect
(
*
(
--
r_it
),
*
(
--
r_it
),
*
(
--
r_it
),
*
(
--
r_it
));
objSize
(
cv
::
Size
(
cvRound
(
oct
.
size
.
width
*
relScale
),
cvRound
(
oct
.
size
.
height
*
relScale
)))
std
::
cout
<<
"feature: "
<<
rect
.
x
<<
" "
<<
rect
.
y
<<
" "
<<
rect
.
width
<<
" "
<<
rect
.
height
<<
" "
<<
channel
<<
std
::
endl
;
{}
}
};
// Feature rescale(float relScale)
// Feature rescale(float relScale)
// {
// {
...
@@ -121,10 +145,7 @@ namespace {
...
@@ -121,10 +145,7 @@ namespace {
// res.threshold = threshold * CascadeIntrinsics::getFor(channel, relScale);
// res.threshold = threshold * CascadeIntrinsics::getFor(channel, relScale);
// return res;
// return res;
// }
// }
};
const
char
*
const
Feature
::
SC_F_CHANNEL
=
"channel"
;
const
char
*
const
Feature
::
SC_F_RECT
=
"rect"
;
// // according to R. Benenson, M. Mathias, R. Timofte and L. Van Gool paper
// // according to R. Benenson, M. Mathias, R. Timofte and L. Van Gool paper
// struct CascadeIntrinsics
// struct CascadeIntrinsics
// {
// {
...
@@ -161,44 +182,6 @@ namespace {
...
@@ -161,44 +182,6 @@ namespace {
// {1, 2, 1, 2}
// {1, 2, 1, 2}
// };
// };
struct
Level
{
// int index;
// float factor;
// float logFactor;
// int width;
// int height;
// Octave octave;
// cv::Size objSize;
// cv::Size dWinSize;
// static const float shrinkage = 0.25;
// Level(int i,float f, float lf, int w, int h): index(i), factor(f), logFactor(lf), width(w), height(h), octave(Octave())
// {}
// void assign(const Octave& o, int detW, int detH)
// {
// octave = o;
// objSize = cv::Size(cv::saturate_cast<int>(detW * o.scale), cv::saturate_cast<int>(detH * o.scale));
// }
// float relScale() {return (factor / octave.scale); }
// float srScale() {return (factor / octave.scale * shrinkage); }
};
// struct Integral
// {
// cv::Mat magnitude;
// std::vector<cv::Mat> hist;
// cv::Mat luv;
// Integral(cv::Mat m, std::vector<cv::Mat> h, cv::Mat l) : magnitude(m), hist(h), luv(l) {}
// };
}
}
struct
cv
::
SoftCascade
::
Filds
struct
cv
::
SoftCascade
::
Filds
...
@@ -240,44 +223,70 @@ struct cv::SoftCascade::Filds
...
@@ -240,44 +223,70 @@ struct cv::SoftCascade::Filds
// }
// }
// }
// }
typedef
std
::
vector
<
Octave
>::
iterator
octIt_t
;
octIt_t
fitOctave
(
const
float
&
logFactor
)
{
float
minAbsLog
=
FLT_MAX
;
octIt_t
res
=
octaves
.
begin
();
for
(
octIt_t
oct
=
octaves
.
begin
();
oct
<
octaves
.
end
();
++
oct
)
{
const
Octave
&
octave
=*
oct
;
float
logOctave
=
log
(
octave
.
scale
);
float
logAbsScale
=
fabs
(
logFactor
-
logOctave
);
if
(
logAbsScale
<
minAbsLog
)
{
res
=
oct
;
minAbsLog
=
logAbsScale
;
}
}
return
res
;
}
// compute levels of full pyramid
// compute levels of full pyramid
void
calcLevels
(
int
frameW
,
int
frameH
,
int
scales
)
void
calcLevels
(
int
frameW
,
int
frameH
,
int
scales
)
{
{
CV_Assert
(
scales
>
1
);
CV_Assert
(
scales
>
1
);
levels
.
clear
();
levels
.
clear
();
//
float logFactor = (log(maxScale) - log(minScale)) / (scales -1);
float
logFactor
=
(
log
(
maxScale
)
-
log
(
minScale
))
/
(
scales
-
1
);
// float scale = minScale;
float
scale
=
minScale
;
// for (int sc = 0; sc < scales; ++sc)
for
(
int
sc
=
0
;
sc
<
scales
;
++
sc
)
// {
{
// Level level(sc, scale, log(scale), std::max(0.0f, frameW - (origObjWidth * scale)), std::max(0.0f, frameH - (origObjHeight * scale)));
int
width
=
std
::
max
(
0.0
f
,
frameW
-
(
origObjWidth
*
scale
));
// if (!level.width || !level.height)
int
height
=
std
::
max
(
0.0
f
,
frameH
-
(
origObjHeight
*
scale
));
// break;
// else
// levels.push_back(level);
// if (fabs(scale - maxScale) < FLT_EPSILON) break;
// scale = std::min(maxScale, expf(log(scale) + logFactor));
// }
// for (std::vector<Level>::iterator level = levels.begin(); level < levels.end(); ++level)
float
logScale
=
log
(
scale
);
// {
octIt_t
fit
=
fitOctave
(
logScale
);
// float minAbsLog = FLT_MAX;
// for (std::vector<Octave>::iterator oct = octaves.begin(); oct < octaves.end(); ++oct)
// {
// const Octave& octave =*oct;
// float logOctave = log(octave.scale);
// float logAbsScale = fabs((*level).logFactor - logOctave);
// if(logAbsScale < minAbsLog)
Level
level
(
*
fit
,
scale
,
shrinkage
,
width
,
height
);
// {
// printf("######### %f %f %f %f\n", octave.scale, logOctave, logAbsScale, (*level).logFactor);
if
(
!
width
||
!
height
)
// minAbsLog = logAbsScale;
break
;
// (*level).assign(octave, ORIG_OBJECT_WIDTH, ORIG_OBJECT_HEIGHT);
else
// }
levels
.
push_back
(
level
);
// }
// }
if
(
fabs
(
scale
-
maxScale
)
<
FLT_EPSILON
)
break
;
scale
=
std
::
min
(
maxScale
,
expf
(
log
(
scale
)
+
logFactor
));
// std::cout << "level scale "
// << levels[sc].origScale
// << " octeve "
// << levels[sc].octave->scale
// << " "
// << levels[sc].relScale
// << " " << levels[sc].shrScale
// << " [" << levels[sc].objSize.width
// << " " << levels[sc].objSize.height << "] ["
// << levels[sc].workRect.width << " " << levels[sc].workRect.height << std::endl;
}
return
;
std
::
cout
<<
std
::
endl
<<
std
::
endl
<<
std
::
endl
;
}
}
bool
fill
(
const
FileNode
&
root
,
const
float
mins
,
const
float
maxs
)
bool
fill
(
const
FileNode
&
root
,
const
float
mins
,
const
float
maxs
)
...
@@ -474,9 +483,6 @@ namespace {
...
@@ -474,9 +483,6 @@ namespace {
cv
::
cvtColor
(
colored
,
grey
,
CV_RGB2GRAY
);
cv
::
cvtColor
(
colored
,
grey
,
CV_RGB2GRAY
);
calcHistBins
(
grey
,
magnitude
,
hog
,
HOG_BINS
,
shrinkage
);
calcHistBins
(
grey
,
magnitude
,
hog
,
HOG_BINS
,
shrinkage
);
std
::
cout
<<
magnitude
.
cols
<<
" "
<<
magnitude
.
rows
<<
std
::
endl
;
cv
::
imshow
(
"1"
,
magnitude
);
cv
::
waitKey
(
0
);
}
}
};
};
}
}
...
...
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