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
bfd9e610
Commit
bfd9e610
authored
Aug 09, 2012
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added updateBackgroundModel parameter and release method
parent
55f8310c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
16 deletions
+43
-16
background_segm.hpp
modules/video/include/opencv2/video/background_segm.hpp
+9
-2
bgfg_gmg.cpp
modules/video/src/bgfg_gmg.cpp
+31
-13
video_init.cpp
modules/video/src/video_init.cpp
+3
-1
No files found.
modules/video/include/opencv2/video/background_segm.hpp
View file @
bfd9e610
...
...
@@ -221,6 +221,11 @@ public:
*/
virtual
void
operator
()(
InputArray
image
,
OutputArray
fgmask
,
double
learningRate
=-
1.0
);
/**
* Releases all inner buffers.
*/
void
release
();
//! Total number of distinct colors to maintain in histogram.
int
maxFeatures
;
//! Set between 0.0 and 1.0, determines how quickly features are "forgotten" from histograms.
...
...
@@ -231,10 +236,12 @@ public:
int
quantizationLevels
;
//! Prior probability that any given pixel is a background pixel. A sensitivity parameter.
double
backgroundPrior
;
//!
v
alue above which pixel is determined to be FG.
//!
V
alue above which pixel is determined to be FG.
double
decisionThreshold
;
//!
s
moothing radius, in pixels, for cleaning up FG image.
//!
S
moothing radius, in pixels, for cleaning up FG image.
int
smoothingRadius
;
//! Perform background model update
bool
updateBackgroundModel
;
private
:
double
maxVal_
;
...
...
modules/video/src/bgfg_gmg.cpp
View file @
bfd9e610
...
...
@@ -60,6 +60,7 @@ cv::BackgroundSubtractorGMG::BackgroundSubtractorGMG()
backgroundPrior
=
0.8
;
decisionThreshold
=
0.8
;
smoothingRadius
=
7
;
updateBackgroundModel
=
true
;
}
cv
::
BackgroundSubtractorGMG
::~
BackgroundSubtractorGMG
()
...
...
@@ -199,11 +200,11 @@ namespace
public
:
GMG_LoopBody
(
const
cv
::
Mat
&
frame
,
const
cv
::
Mat
&
fgmask
,
const
cv
::
Mat_
<
int
>&
nfeatures
,
const
cv
::
Mat_
<
int
>&
colors
,
const
cv
::
Mat_
<
float
>&
weights
,
int
maxFeatures
,
double
learningRate
,
int
numInitializationFrames
,
int
quantizationLevels
,
double
backgroundPrior
,
double
decisionThreshold
,
double
maxVal
,
double
minVal
,
int
frameNum
)
:
double
maxVal
,
double
minVal
,
int
frameNum
,
bool
updateBackgroundModel
)
:
frame_
(
frame
),
fgmask_
(
fgmask
),
nfeatures_
(
nfeatures
),
colors_
(
colors
),
weights_
(
weights
),
maxFeatures_
(
maxFeatures
),
learningRate_
(
learningRate
),
numInitializationFrames_
(
numInitializationFrames
),
quantizationLevels_
(
quantizationLevels
),
backgroundPrior_
(
backgroundPrior
),
decisionThreshold_
(
decisionThreshold
),
maxVal_
(
maxVal
),
minVal_
(
minVal
),
frameNum_
(
frameNum
)
maxVal_
(
maxVal
),
minVal_
(
minVal
),
frameNum_
(
frameNum
)
,
updateBackgroundModel_
(
updateBackgroundModel
)
{
}
...
...
@@ -224,6 +225,7 @@ namespace
int
quantizationLevels_
;
double
backgroundPrior_
;
double
decisionThreshold_
;
bool
updateBackgroundModel_
;
double
maxVal_
;
double
minVal_
;
...
...
@@ -275,18 +277,21 @@ namespace
// update histogram.
for
(
int
i
=
0
;
i
<
nfeatures
;
++
i
)
weights
[
i
]
*=
1.0
f
-
learningRate_
;
if
(
updateBackgroundModel_
)
{
for
(
int
i
=
0
;
i
<
nfeatures
;
++
i
)
weights
[
i
]
*=
1.0
f
-
learningRate_
;
bool
inserted
=
insertFeature
(
newFeatureColor
,
learningRate_
,
colors
,
weights
,
nfeatures
,
maxFeatures_
);
bool
inserted
=
insertFeature
(
newFeatureColor
,
learningRate_
,
colors
,
weights
,
nfeatures
,
maxFeatures_
);
if
(
inserted
)
{
normalizeHistogram
(
weights
,
nfeatures
);
nfeatures_row
[
x
]
=
nfeatures
;
if
(
inserted
)
{
normalizeHistogram
(
weights
,
nfeatures
);
nfeatures_row
[
x
]
=
nfeatures
;
}
}
}
else
else
if
(
updateBackgroundModel_
)
{
// training-mode update
...
...
@@ -323,12 +328,25 @@ void cv::BackgroundSubtractorGMG::operator ()(InputArray _frame, OutputArray _fg
GMG_LoopBody
body
(
frame
,
fgmask
,
nfeatures_
,
colors_
,
weights_
,
maxFeatures
,
learningRate
,
numInitializationFrames
,
quantizationLevels
,
backgroundPrior
,
decisionThreshold
,
maxVal_
,
minVal_
,
frameNum_
);
maxVal_
,
minVal_
,
frameNum_
,
updateBackgroundModel
);
cv
::
parallel_for_
(
cv
::
Range
(
0
,
frame
.
rows
),
body
);
cv
::
medianBlur
(
fgmask
,
buf_
,
smoothingRadius
);
cv
::
swap
(
fgmask
,
buf_
);
if
(
smoothingRadius
>
0
)
{
cv
::
medianBlur
(
fgmask
,
buf_
,
smoothingRadius
);
cv
::
swap
(
fgmask
,
buf_
);
}
// keep track of how many frames we have processed
++
frameNum_
;
}
void
cv
::
BackgroundSubtractorGMG
::
release
()
{
frameSize_
=
cv
::
Size
();
nfeatures_
.
release
();
colors_
.
release
();
weights_
.
release
();
buf_
.
release
();
}
modules/video/src/video_init.cpp
View file @
bfd9e610
...
...
@@ -78,7 +78,9 @@ CV_INIT_ALGORITHM(BackgroundSubtractorGMG, "BackgroundSubtractor.GMG",
obj
.
info
()
->
addParam
(
obj
,
"smoothingRadius"
,
obj
.
smoothingRadius
,
false
,
0
,
0
,
"Radius of smoothing kernel to filter noise from FG mask image."
);
obj
.
info
()
->
addParam
(
obj
,
"decisionThreshold"
,
obj
.
decisionThreshold
,
false
,
0
,
0
,
"Threshold for FG decision rule. Pixel is FG if posterior probability exceeds threshold."
));
"Threshold for FG decision rule. Pixel is FG if posterior probability exceeds threshold."
);
obj
.
info
()
->
addParam
(
obj
,
"updateBackgroundModel"
,
obj
.
updateBackgroundModel
,
false
,
0
,
0
,
"Perform background model update."
));
bool
initModule_video
(
void
)
{
...
...
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