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
62edeeed
Commit
62edeeed
authored
May 07, 2013
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored FGD algorithm
parent
69779309
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
52 additions
and
95 deletions
+52
-95
gpubgsegm.hpp
modules/gpubgsegm/include/opencv2/gpubgsegm.hpp
+18
-46
perf_bgsegm.cpp
modules/gpubgsegm/perf/perf_bgsegm.cpp
+7
-6
fgd.cu
modules/gpubgsegm/src/cuda/fgd.cu
+1
-1
fgd.hpp
modules/gpubgsegm/src/cuda/fgd.hpp
+1
-1
fgd.cpp
modules/gpubgsegm/src/fgd.cpp
+0
-0
test_bgsegm.cpp
modules/gpubgsegm/test/test_bgsegm.cpp
+13
-30
bgfg_segm.cpp
samples/gpu/bgfg_segm.cpp
+4
-5
tests.cpp
samples/gpu/performance/tests.cpp
+8
-6
No files found.
modules/gpubgsegm/include/opencv2/gpubgsegm.hpp
View file @
62edeeed
...
...
@@ -50,9 +50,6 @@
#include "opencv2/core/gpu.hpp"
#include "opencv2/video/background_segm.hpp"
#include <memory>
#include "opencv2/gpufilters.hpp"
namespace
cv
{
namespace
gpu
{
////////////////////////////////////////////////////
...
...
@@ -105,22 +102,22 @@ public:
CV_EXPORTS
Ptr
<
gpu
::
BackgroundSubtractorGMG
>
createBackgroundSubtractorGMG
(
int
initializationFrames
=
120
,
double
decisionThreshold
=
0.8
);
// Foreground Object Detection from Videos Containing Complex Background.
// Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian.
// ACM MM2003 9p
class
CV_EXPORTS
FGDStatModel
////////////////////////////////////////////////////
// FGD
/**
* Foreground Object Detection from Videos Containing Complex Background.
* Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian.
* ACM MM2003 9p
*/
class
CV_EXPORTS
BackgroundSubtractorFGD
:
public
cv
::
BackgroundSubtractor
{
public
:
struct
CV_EXPORTS
Params
{
virtual
void
getForegroundRegions
(
OutputArrayOfArrays
foreground_regions
)
=
0
;
};
struct
CV_EXPORTS
FGDParams
{
int
Lc
;
// Quantized levels per 'color' component. Power of two, typically 32, 64 or 128.
int
N1c
;
// Number of color vectors used to model normal background color variation at a given pixel.
int
N2c
;
// Number of color vectors retained at given pixel. Must be > N1c, typically ~ 5/3 of N1c.
...
...
@@ -144,37 +141,12 @@ public:
float
minArea
;
// Discard foreground blobs whose bounding box is smaller than this threshold.
// default Params
Params
();
};
// out_cn - channels count in output result (can be 3 or 4)
// 4-channels require more memory, but a bit faster
explicit
FGDStatModel
(
int
out_cn
=
3
);
explicit
FGDStatModel
(
const
cv
::
gpu
::
GpuMat
&
firstFrame
,
const
Params
&
params
=
Params
(),
int
out_cn
=
3
);
~
FGDStatModel
();
void
create
(
const
cv
::
gpu
::
GpuMat
&
firstFrame
,
const
Params
&
params
=
Params
());
void
release
();
int
update
(
const
cv
::
gpu
::
GpuMat
&
curFrame
);
//8UC3 or 8UC4 reference background image
cv
::
gpu
::
GpuMat
background
;
//8UC1 foreground image
cv
::
gpu
::
GpuMat
foreground
;
std
::
vector
<
std
::
vector
<
cv
::
Point
>
>
foreground_regions
;
private
:
FGDStatModel
(
const
FGDStatModel
&
);
FGDStatModel
&
operator
=
(
const
FGDStatModel
&
);
class
Impl
;
std
::
auto_ptr
<
Impl
>
impl_
;
FGDParams
();
};
CV_EXPORTS
Ptr
<
gpu
::
BackgroundSubtractorFGD
>
createBackgroundSubtractorFGD
(
const
FGDParams
&
params
=
FGDParams
());
}}
// namespace cv { namespace gpu {
#endif
/* __OPENCV_GPUBGSEGM_HPP__ */
modules/gpubgsegm/perf/perf_bgsegm.cpp
View file @
62edeeed
...
...
@@ -42,6 +42,7 @@
#include "perf_precomp.hpp"
#include "opencv2/legacy.hpp"
#include "opencv2/gpuimgproc.hpp"
using
namespace
std
;
using
namespace
testing
;
...
...
@@ -90,10 +91,10 @@ PERF_TEST_P(Video, FGDStatModel,
if
(
PERF_RUN_GPU
())
{
cv
::
gpu
::
GpuMat
d_frame
(
frame
);
cv
::
gpu
::
GpuMat
d_frame
(
frame
)
,
foreground
,
background3
,
background
;
cv
::
gpu
::
FGDStatModel
d_model
(
4
);
d_
model
.
create
(
d_frame
);
cv
::
Ptr
<
cv
::
gpu
::
BackgroundSubtractorFGD
>
d_fgd
=
cv
::
gpu
::
createBackgroundSubtractorFGD
(
);
d_
fgd
->
apply
(
d_frame
,
foreground
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
...
...
@@ -103,12 +104,12 @@ PERF_TEST_P(Video, FGDStatModel,
d_frame
.
upload
(
frame
);
startTimer
();
next
();
d_
model
.
update
(
d_frame
);
d_
fgd
->
apply
(
d_frame
,
foreground
);
stopTimer
();
}
const
cv
::
gpu
::
GpuMat
background
=
d_model
.
background
;
c
onst
cv
::
gpu
::
GpuMat
foreground
=
d_model
.
foreground
;
d_fgd
->
getBackgroundImage
(
background3
)
;
c
v
::
gpu
::
cvtColor
(
background3
,
background
,
cv
::
COLOR_BGR2BGRA
)
;
GPU_SANITY_CHECK
(
background
,
1e-2
,
ERROR_RELATIVE
);
GPU_SANITY_CHECK
(
foreground
,
1e-2
,
ERROR_RELATIVE
);
...
...
modules/gpubgsegm/src/cuda/fgd.cu
View file @
62edeeed
...
...
@@ -53,7 +53,7 @@
using namespace cv::gpu;
using namespace cv::gpu::cudev;
namespace
bgfg
namespace
fgd
{
////////////////////////////////////////////////////////////////////////////
// calcDiffHistogram
...
...
modules/gpubgsegm/src/cuda/fgd.hpp
View file @
62edeeed
...
...
@@ -45,7 +45,7 @@
#include "opencv2/core/gpu_types.hpp"
namespace
bgfg
namespace
fgd
{
struct
BGPixelStat
{
...
...
modules/gpubgsegm/src/fgd.cpp
View file @
62edeeed
This diff is collapsed.
Click to expand it.
modules/gpubgsegm/test/test_bgsegm.cpp
View file @
62edeeed
...
...
@@ -72,11 +72,10 @@ namespace cv
}
}
PARAM_TEST_CASE
(
FGDStatModel
,
cv
::
gpu
::
DeviceInfo
,
std
::
string
,
Channels
)
PARAM_TEST_CASE
(
FGDStatModel
,
cv
::
gpu
::
DeviceInfo
,
std
::
string
)
{
cv
::
gpu
::
DeviceInfo
devInfo
;
std
::
string
inputFile
;
int
out_cn
;
virtual
void
SetUp
()
{
...
...
@@ -84,8 +83,6 @@ PARAM_TEST_CASE(FGDStatModel, cv::gpu::DeviceInfo, std::string, Channels)
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
inputFile
=
std
::
string
(
cvtest
::
TS
::
ptr
()
->
get_data_path
())
+
"video/"
+
GET_PARAM
(
1
);
out_cn
=
GET_PARAM
(
2
);
}
};
...
...
@@ -102,15 +99,10 @@ GPU_TEST_P(FGDStatModel, Update)
cv
::
Ptr
<
CvBGStatModel
>
model
(
cvCreateFGDStatModel
(
&
ipl_frame
));
cv
::
gpu
::
GpuMat
d_frame
(
frame
);
cv
::
gpu
::
FGDStatModel
d_model
(
out_cn
);
d_model
.
create
(
d_frame
);
cv
::
Mat
h_background
;
cv
::
Mat
h_foreground
;
cv
::
Mat
h_background3
;
cv
::
Mat
backgroundDiff
;
cv
::
Mat
foregroundDiff
;
cv
::
Ptr
<
cv
::
gpu
::
BackgroundSubtractorFGD
>
d_fgd
=
cv
::
gpu
::
createBackgroundSubtractorFGD
();
cv
::
gpu
::
GpuMat
d_foreground
,
d_background
;
std
::
vector
<
std
::
vector
<
cv
::
Point
>
>
foreground_regions
;
d_fgd
->
apply
(
d_frame
,
d_foreground
);
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
...
...
@@ -121,32 +113,23 @@ GPU_TEST_P(FGDStatModel, Update)
int
gold_count
=
cvUpdateBGStatModel
(
&
ipl_frame
,
model
);
d_frame
.
upload
(
frame
);
int
count
=
d_model
.
update
(
d_frame
);
ASSERT_EQ
(
gold_count
,
count
);
d_fgd
->
apply
(
d_frame
,
d_foreground
);
d_fgd
->
getBackgroundImage
(
d_background
);
d_fgd
->
getForegroundRegions
(
foreground_regions
);
int
count
=
(
int
)
foreground_regions
.
size
(
);
cv
::
Mat
gold_background
=
cv
::
cvarrToMat
(
model
->
background
);
cv
::
Mat
gold_foreground
=
cv
::
cvarrToMat
(
model
->
foreground
);
if
(
out_cn
==
3
)
d_model
.
background
.
download
(
h_background3
);
else
{
d_model
.
background
.
download
(
h_background
);
cv
::
cvtColor
(
h_background
,
h_background3
,
cv
::
COLOR_BGRA2BGR
);
}
d_model
.
foreground
.
download
(
h_foreground
);
ASSERT_MAT_NEAR
(
gold_background
,
h_background3
,
1.0
);
ASSERT_MAT_NEAR
(
gold_foreground
,
h_foreground
,
0.0
);
ASSERT_MAT_NEAR
(
gold_background
,
d_background
,
1.0
);
ASSERT_MAT_NEAR
(
gold_foreground
,
d_foreground
,
0.0
);
ASSERT_EQ
(
gold_count
,
count
);
}
}
INSTANTIATE_TEST_CASE_P
(
GPU_BgSegm
,
FGDStatModel
,
testing
::
Combine
(
ALL_DEVICES
,
testing
::
Values
(
std
::
string
(
"768x576.avi"
)),
testing
::
Values
(
Channels
(
3
),
Channels
(
4
))));
testing
::
Values
(
std
::
string
(
"768x576.avi"
))));
#endif
...
...
samples/gpu/bgfg_segm.cpp
View file @
62edeeed
...
...
@@ -78,7 +78,7 @@ int main(int argc, const char** argv)
Ptr
<
BackgroundSubtractor
>
mog
=
gpu
::
createBackgroundSubtractorMOG
();
Ptr
<
BackgroundSubtractor
>
mog2
=
gpu
::
createBackgroundSubtractorMOG2
();
Ptr
<
BackgroundSubtractor
>
gmg
=
gpu
::
createBackgroundSubtractorGMG
(
40
);
FGDStatModel
fgd_stat
;
Ptr
<
BackgroundSubtractor
>
fgd
=
gpu
::
createBackgroundSubtractorFGD
()
;
GpuMat
d_fgmask
;
GpuMat
d_fgimg
;
...
...
@@ -103,7 +103,7 @@ int main(int argc, const char** argv)
break
;
case
FGD_STAT
:
fgd
_stat
.
create
(
d_frame
);
fgd
->
apply
(
d_frame
,
d_fgmask
);
break
;
}
...
...
@@ -142,9 +142,8 @@ int main(int argc, const char** argv)
break
;
case
FGD_STAT
:
fgd_stat
.
update
(
d_frame
);
d_fgmask
=
fgd_stat
.
foreground
;
d_bgimg
=
fgd_stat
.
background
;
fgd
->
apply
(
d_frame
,
d_fgmask
);
fgd
->
getBackgroundImage
(
d_bgimg
);
break
;
}
...
...
samples/gpu/performance/tests.cpp
View file @
62edeeed
...
...
@@ -1271,14 +1271,14 @@ TEST(FGDStatModel)
{
const
std
::
string
inputFile
=
abspath
(
"768x576.avi"
);
cv
::
VideoCapture
cap
(
inputFile
);
VideoCapture
cap
(
inputFile
);
if
(
!
cap
.
isOpened
())
throw
runtime_error
(
"can't open 768x576.avi"
);
cv
::
Mat
frame
;
Mat
frame
;
cap
>>
frame
;
IplImage
ipl_frame
=
frame
;
cv
::
Ptr
<
CvBGStatModel
>
model
(
cvCreateFGDStatModel
(
&
ipl_frame
));
Ptr
<
CvBGStatModel
>
model
(
cvCreateFGDStatModel
(
&
ipl_frame
));
while
(
!
TestSystem
::
instance
().
stop
())
{
...
...
@@ -1297,8 +1297,10 @@ TEST(FGDStatModel)
cap
>>
frame
;
cv
::
gpu
::
GpuMat
d_frame
(
frame
);
cv
::
gpu
::
FGDStatModel
d_model
(
d_frame
);
gpu
::
GpuMat
d_frame
(
frame
),
d_fgmask
;
Ptr
<
BackgroundSubtractor
>
d_fgd
=
gpu
::
createBackgroundSubtractorFGD
();
d_fgd
->
apply
(
d_frame
,
d_fgmask
);
while
(
!
TestSystem
::
instance
().
stop
())
{
...
...
@@ -1307,7 +1309,7 @@ TEST(FGDStatModel)
TestSystem
::
instance
().
gpuOn
();
d_
model
.
update
(
d_frame
);
d_
fgd
->
apply
(
d_frame
,
d_fgmask
);
TestSystem
::
instance
().
gpuOff
();
}
...
...
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