Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
762cf182
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
762cf182
编写于
11月 11, 2010
作者:
M
Maria Dimashova
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modified grabCut: noise is added only if covariance determinant = 0
上级
ef3171dc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
36 deletion
+14
-36
modules/imgproc/src/grabcut.cpp
modules/imgproc/src/grabcut.cpp
+14
-36
未找到文件。
modules/imgproc/src/grabcut.cpp
浏览文件 @
762cf182
...
...
@@ -51,35 +51,6 @@ This is implementation of image segmentation algorithm GrabCut described in
Carsten Rother, Vladimir Kolmogorov, Andrew Blake.
*/
class
Noise3DGenerator
{
public:
Noise3DGenerator
(
float
var
=
0.1
f
)
:
rng
(
theRNG
())
{
var
=
std
::
min
(
std
::
max
(
0.01
f
,
var
),
1.
f
)
;
double
meanData
[]
=
{
0.
,
0.
,
0.
};
double
covData
[]
=
{
var
,
0.
,
0.
,
0.
,
var
,
0.
,
0.
,
0.
,
var
};
Mat
(
1
,
3
,
CV_64FC1
,
meanData
).
copyTo
(
mean
);
Mat
(
3
,
3
,
CV_64FC1
,
covData
).
copyTo
(
cov
);
}
Vec3d
generateNoise
()
{
Mat
noise
(
1
,
3
,
CV_64FC1
);
rng
.
fill
(
noise
,
RNG
::
NORMAL
,
Scalar
::
all
(
0.0
),
Scalar
(
1.0
)
);
noise
=
noise
*
cov
+
mean
;
return
Vec3d
(
noise
.
ptr
<
double
>
()
);
}
private:
RNG
&
rng
;
Mat
mean
;
Mat
cov
;
};
/*
GMM - Gaussian Mixture Model
*/
...
...
@@ -111,8 +82,6 @@ private:
double
prods
[
componentsCount
][
3
][
3
];
int
sampleCounts
[
componentsCount
];
int
totalSampleCount
;
Noise3DGenerator
noiseGenerator
;
};
GMM
::
GMM
(
Mat
&
_model
)
...
...
@@ -194,17 +163,17 @@ void GMM::initLearning()
void
GMM
::
addSample
(
int
ci
,
const
Vec3d
color
)
{
Vec3d
nClr
=
color
+
noiseGenerator
.
generateNoise
();
sums
[
ci
][
0
]
+=
nClr
[
0
];
sums
[
ci
][
1
]
+=
nClr
[
1
];
sums
[
ci
][
2
]
+=
nClr
[
2
];
prods
[
ci
][
0
][
0
]
+=
nClr
[
0
]
*
nClr
[
0
];
prods
[
ci
][
0
][
1
]
+=
nClr
[
0
]
*
nClr
[
1
];
prods
[
ci
][
0
][
2
]
+=
nClr
[
0
]
*
nClr
[
2
];
prods
[
ci
][
1
][
0
]
+=
nClr
[
1
]
*
nClr
[
0
];
prods
[
ci
][
1
][
1
]
+=
nClr
[
1
]
*
nClr
[
1
];
prods
[
ci
][
1
][
2
]
+=
nClr
[
1
]
*
nClr
[
2
];
prods
[
ci
][
2
][
0
]
+=
nClr
[
2
]
*
nClr
[
0
];
prods
[
ci
][
2
][
1
]
+=
nClr
[
2
]
*
nClr
[
1
];
prods
[
ci
][
2
][
2
]
+=
nClr
[
2
]
*
nClr
[
2
];
sums
[
ci
][
0
]
+=
color
[
0
];
sums
[
ci
][
1
]
+=
color
[
1
];
sums
[
ci
][
2
]
+=
color
[
2
];
prods
[
ci
][
0
][
0
]
+=
color
[
0
]
*
color
[
0
];
prods
[
ci
][
0
][
1
]
+=
color
[
0
]
*
color
[
1
];
prods
[
ci
][
0
][
2
]
+=
color
[
0
]
*
color
[
2
];
prods
[
ci
][
1
][
0
]
+=
color
[
1
]
*
color
[
0
];
prods
[
ci
][
1
][
1
]
+=
color
[
1
]
*
color
[
1
];
prods
[
ci
][
1
][
2
]
+=
color
[
1
]
*
color
[
2
];
prods
[
ci
][
2
][
0
]
+=
color
[
2
]
*
color
[
0
];
prods
[
ci
][
2
][
1
]
+=
color
[
2
]
*
color
[
1
];
prods
[
ci
][
2
][
2
]
+=
color
[
2
]
*
color
[
2
];
sampleCounts
[
ci
]
++
;
totalSampleCount
++
;
}
void
GMM
::
endLearning
()
{
const
double
variance
=
0.01
;
for
(
int
ci
=
0
;
ci
<
componentsCount
;
ci
++
)
{
int
n
=
sampleCounts
[
ci
];
...
...
@@ -222,6 +191,15 @@ void GMM::endLearning()
c
[
3
]
=
prods
[
ci
][
1
][
0
]
/
n
-
m
[
1
]
*
m
[
0
];
c
[
4
]
=
prods
[
ci
][
1
][
1
]
/
n
-
m
[
1
]
*
m
[
1
];
c
[
5
]
=
prods
[
ci
][
1
][
2
]
/
n
-
m
[
1
]
*
m
[
2
];
c
[
6
]
=
prods
[
ci
][
2
][
0
]
/
n
-
m
[
2
]
*
m
[
0
];
c
[
7
]
=
prods
[
ci
][
2
][
1
]
/
n
-
m
[
2
]
*
m
[
1
];
c
[
8
]
=
prods
[
ci
][
2
][
2
]
/
n
-
m
[
2
]
*
m
[
2
];
double
dtrm
=
c
[
0
]
*
(
c
[
4
]
*
c
[
8
]
-
c
[
5
]
*
c
[
7
])
-
c
[
1
]
*
(
c
[
3
]
*
c
[
8
]
-
c
[
5
]
*
c
[
6
])
+
c
[
2
]
*
(
c
[
3
]
*
c
[
7
]
-
c
[
4
]
*
c
[
6
]);
if
(
dtrm
<
std
::
numeric_limits
<
double
>::
epsilon
()
)
{
// Adds the white noise to avoid singular covariance matrix.
c
[
0
]
+=
variance
;
c
[
4
]
+=
variance
;
c
[
8
]
+=
variance
;
}
calcInverseCovAndDeterm
(
ci
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录