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
0b4eb6a9
Commit
0b4eb6a9
authored
May 19, 2014
by
Vadim Pisarevsky
Committed by
OpenCV Buildbot
May 19, 2014
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2509 from euphrat:mog2_bgimg_gray
parents
988b1088
99029564
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
29 deletions
+23
-29
bgfg_gaussmix2.cpp
modules/video/src/bgfg_gaussmix2.cpp
+23
-29
No files found.
modules/video/src/bgfg_gaussmix2.cpp
View file @
0b4eb6a9
...
...
@@ -577,54 +577,48 @@ void BackgroundSubtractorMOG2::operator()(InputArray _image, OutputArray _fgmask
void
BackgroundSubtractorMOG2
::
getBackgroundImage
(
OutputArray
backgroundImage
)
const
{
int
nchannels
=
CV_MAT_CN
(
frameType
);
CV_Assert
(
nchannels
==
3
);
Mat
meanBackground
(
frameSize
,
CV_8UC3
,
Scalar
::
all
(
0
));
CV_Assert
(
nchannels
==
1
||
nchannels
==
3
);
Mat
meanBackground
(
frameSize
,
CV_MAKETYPE
(
CV_8U
,
nchannels
),
Scalar
::
all
(
0
));
int
firstGaussianIdx
=
0
;
const
GMM
*
gmm
=
(
GMM
*
)
bgmodel
.
data
;
const
Vec3f
*
mean
=
reinterpret_cast
<
const
Vec3f
*>
(
gmm
+
frameSize
.
width
*
frameSize
.
height
*
nmixtures
);
const
float
*
mean
=
reinterpret_cast
<
const
float
*>
(
gmm
+
frameSize
.
width
*
frameSize
.
height
*
nmixtures
);
std
::
vector
<
float
>
meanVal
(
nchannels
,
0.
f
);
for
(
int
row
=
0
;
row
<
meanBackground
.
rows
;
row
++
)
{
for
(
int
col
=
0
;
col
<
meanBackground
.
cols
;
col
++
)
{
int
nmodes
=
bgmodelUsedModes
.
at
<
uchar
>
(
row
,
col
);
Vec3f
meanVal
;
float
totalWeight
=
0.
f
;
for
(
int
gaussianIdx
=
firstGaussianIdx
;
gaussianIdx
<
firstGaussianIdx
+
nmodes
;
gaussianIdx
++
)
{
GMM
gaussian
=
gmm
[
gaussianIdx
];
meanVal
+=
gaussian
.
weight
*
mean
[
gaussianIdx
];
size_t
meanPosition
=
gaussianIdx
*
nchannels
;
for
(
int
chn
=
0
;
chn
<
nchannels
;
chn
++
)
{
meanVal
[
chn
]
+=
gaussian
.
weight
*
mean
[
meanPosition
+
chn
];
}
totalWeight
+=
gaussian
.
weight
;
if
(
totalWeight
>
backgroundRatio
)
break
;
}
meanVal
*=
(
1.
f
/
totalWeight
);
meanBackground
.
at
<
Vec3b
>
(
row
,
col
)
=
Vec3b
(
meanVal
);
float
invWeight
=
1.
f
/
totalWeight
;
switch
(
nchannels
)
{
case
1
:
meanBackground
.
at
<
uchar
>
(
row
,
col
)
=
(
uchar
)(
meanVal
[
0
]
*
invWeight
);
meanVal
[
0
]
=
0.
f
;
break
;
case
3
:
Vec3f
&
meanVec
=
*
reinterpret_cast
<
Vec3f
*>
(
&
meanVal
[
0
]);
meanBackground
.
at
<
Vec3b
>
(
row
,
col
)
=
Vec3b
(
meanVec
*
invWeight
);
meanVec
=
0.
f
;
break
;
}
firstGaussianIdx
+=
nmixtures
;
}
}
switch
(
CV_MAT_CN
(
frameType
))
{
case
1
:
{
vector
<
Mat
>
channels
;
split
(
meanBackground
,
channels
);
channels
[
0
].
copyTo
(
backgroundImage
);
break
;
}
case
3
:
{
meanBackground
.
copyTo
(
backgroundImage
);
break
;
}
default
:
CV_Error
(
CV_StsUnsupportedFormat
,
""
);
}
meanBackground
.
copyTo
(
backgroundImage
);
}
}
...
...
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