Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
62edeeed
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
62edeeed
编写于
5月 07, 2013
作者:
V
Vladislav Vinogradov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactored FGD algorithm
上级
69779309
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
420 addition
and
493 deletion
+420
-493
modules/gpubgsegm/include/opencv2/gpubgsegm.hpp
modules/gpubgsegm/include/opencv2/gpubgsegm.hpp
+40
-68
modules/gpubgsegm/perf/perf_bgsegm.cpp
modules/gpubgsegm/perf/perf_bgsegm.cpp
+7
-6
modules/gpubgsegm/src/cuda/fgd.cu
modules/gpubgsegm/src/cuda/fgd.cu
+1
-1
modules/gpubgsegm/src/cuda/fgd.hpp
modules/gpubgsegm/src/cuda/fgd.hpp
+1
-1
modules/gpubgsegm/src/fgd.cpp
modules/gpubgsegm/src/fgd.cpp
+346
-376
modules/gpubgsegm/test/test_bgsegm.cpp
modules/gpubgsegm/test/test_bgsegm.cpp
+13
-30
samples/gpu/bgfg_segm.cpp
samples/gpu/bgfg_segm.cpp
+4
-5
samples/gpu/performance/tests.cpp
samples/gpu/performance/tests.cpp
+8
-6
未找到文件。
modules/gpubgsegm/include/opencv2/gpubgsegm.hpp
浏览文件 @
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,76 +102,51 @@ 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
{
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.
// Used to allow the first N1c vectors to adapt over time to changing background.
int
Lcc
;
// Quantized levels per 'color co-occurrence' component. Power of two, typically 16, 32 or 64.
int
N1cc
;
// Number of color co-occurrence vectors used to model normal background color variation at a given pixel.
int
N2cc
;
// Number of color co-occurrence vectors retained at given pixel. Must be > N1cc, typically ~ 5/3 of N1cc.
// Used to allow the first N1cc vectors to adapt over time to changing background.
bool
is_obj_without_holes
;
// If TRUE we ignore holes within foreground blobs. Defaults to TRUE.
int
perform_morphing
;
// Number of erode-dilate-erode foreground-blob cleanup iterations.
// These erase one-pixel junk blobs and merge almost-touching blobs. Default value is 1.
float
alpha1
;
// How quickly we forget old background pixel values seen. Typically set to 0.1.
float
alpha2
;
// "Controls speed of feature learning". Depends on T. Typical value circa 0.005.
float
alpha3
;
// Alternate to alpha2, used (e.g.) for quicker initial convergence. Typical value 0.1.
float
delta
;
// Affects color and color co-occurrence quantization, typically set to 2.
float
T
;
// A percentage value which determines when new features can be recognized as new background. (Typically 0.9).
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
&
);
virtual
void
getForegroundRegions
(
OutputArrayOfArrays
foreground_regions
)
=
0
;
};
class
Impl
;
std
::
auto_ptr
<
Impl
>
impl_
;
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.
// Used to allow the first N1c vectors to adapt over time to changing background.
int
Lcc
;
// Quantized levels per 'color co-occurrence' component. Power of two, typically 16, 32 or 64.
int
N1cc
;
// Number of color co-occurrence vectors used to model normal background color variation at a given pixel.
int
N2cc
;
// Number of color co-occurrence vectors retained at given pixel. Must be > N1cc, typically ~ 5/3 of N1cc.
// Used to allow the first N1cc vectors to adapt over time to changing background.
bool
is_obj_without_holes
;
// If TRUE we ignore holes within foreground blobs. Defaults to TRUE.
int
perform_morphing
;
// Number of erode-dilate-erode foreground-blob cleanup iterations.
// These erase one-pixel junk blobs and merge almost-touching blobs. Default value is 1.
float
alpha1
;
// How quickly we forget old background pixel values seen. Typically set to 0.1.
float
alpha2
;
// "Controls speed of feature learning". Depends on T. Typical value circa 0.005.
float
alpha3
;
// Alternate to alpha2, used (e.g.) for quicker initial convergence. Typical value 0.1.
float
delta
;
// Affects color and color co-occurrence quantization, typically set to 2.
float
T
;
// A percentage value which determines when new features can be recognized as new background. (Typically 0.9).
float
minArea
;
// Discard foreground blobs whose bounding box is smaller than this threshold.
// default Params
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
62edeeed
...
...
@@ -45,7 +45,7 @@
#include "opencv2/core/gpu_types.hpp"
namespace
bgfg
namespace
fgd
{
struct
BGPixelStat
{
...
...
modules/gpubgsegm/src/fgd.cpp
浏览文件 @
62edeeed
此差异已折叠。
点击以展开。
modules/gpubgsegm/test/test_bgsegm.cpp
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录