Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
4f2aeeff
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,发现更多精彩内容 >>
提交
4f2aeeff
编写于
11月 07, 2014
作者:
V
Vadim Pisarevsky
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3403 from vpisarev:moved_partition
上级
47838a4a
d58cadc1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
99 addition
and
107 deletion
+99
-107
modules/core/include/opencv2/core/operations.hpp
modules/core/include/opencv2/core/operations.hpp
+99
-0
modules/core/include/opencv2/core/private.hpp
modules/core/include/opencv2/core/private.hpp
+0
-107
未找到文件。
modules/core/include/opencv2/core/operations.hpp
浏览文件 @
4f2aeeff
...
...
@@ -526,6 +526,105 @@ void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, Ptr<_Tp>& v
}
/****************************************************************************************\
* Auxiliary algorithms *
\****************************************************************************************/
// This function splits the input sequence or set into one or more equivalence classes and
// returns the vector of labels - 0-based class indexes for each element.
// predicate(a,b) returns true if the two sequence elements certainly belong to the same class.
//
// The algorithm is described in "Introduction to Algorithms"
// by Cormen, Leiserson and Rivest, the chapter "Data structures for disjoint sets"
template
<
typename
_Tp
,
class
_EqPredicate
>
int
partition
(
const
std
::
vector
<
_Tp
>&
_vec
,
std
::
vector
<
int
>&
labels
,
_EqPredicate
predicate
=
_EqPredicate
())
{
int
i
,
j
,
N
=
(
int
)
_vec
.
size
();
const
_Tp
*
vec
=
&
_vec
[
0
];
const
int
PARENT
=
0
;
const
int
RANK
=
1
;
std
::
vector
<
int
>
_nodes
(
N
*
2
);
int
(
*
nodes
)[
2
]
=
(
int
(
*
)[
2
])
&
_nodes
[
0
];
// The first O(N) pass: create N single-vertex trees
for
(
i
=
0
;
i
<
N
;
i
++
)
{
nodes
[
i
][
PARENT
]
=-
1
;
nodes
[
i
][
RANK
]
=
0
;
}
// The main O(N^2) pass: merge connected components
for
(
i
=
0
;
i
<
N
;
i
++
)
{
int
root
=
i
;
// find root
while
(
nodes
[
root
][
PARENT
]
>=
0
)
root
=
nodes
[
root
][
PARENT
];
for
(
j
=
0
;
j
<
N
;
j
++
)
{
if
(
i
==
j
||
!
predicate
(
vec
[
i
],
vec
[
j
]))
continue
;
int
root2
=
j
;
while
(
nodes
[
root2
][
PARENT
]
>=
0
)
root2
=
nodes
[
root2
][
PARENT
];
if
(
root2
!=
root
)
{
// unite both trees
int
rank
=
nodes
[
root
][
RANK
],
rank2
=
nodes
[
root2
][
RANK
];
if
(
rank
>
rank2
)
nodes
[
root2
][
PARENT
]
=
root
;
else
{
nodes
[
root
][
PARENT
]
=
root2
;
nodes
[
root2
][
RANK
]
+=
rank
==
rank2
;
root
=
root2
;
}
CV_Assert
(
nodes
[
root
][
PARENT
]
<
0
);
int
k
=
j
,
parent
;
// compress the path from node2 to root
while
(
(
parent
=
nodes
[
k
][
PARENT
])
>=
0
)
{
nodes
[
k
][
PARENT
]
=
root
;
k
=
parent
;
}
// compress the path from node to root
k
=
i
;
while
(
(
parent
=
nodes
[
k
][
PARENT
])
>=
0
)
{
nodes
[
k
][
PARENT
]
=
root
;
k
=
parent
;
}
}
}
}
// Final O(N) pass: enumerate classes
labels
.
resize
(
N
);
int
nclasses
=
0
;
for
(
i
=
0
;
i
<
N
;
i
++
)
{
int
root
=
i
;
while
(
nodes
[
root
][
PARENT
]
>=
0
)
root
=
nodes
[
root
][
PARENT
];
// re-use the rank as the class label
if
(
nodes
[
root
][
RANK
]
>=
0
)
nodes
[
root
][
RANK
]
=
~
nclasses
++
;
labels
[
i
]
=
~
nodes
[
root
][
RANK
];
}
return
nclasses
;
}
}
// cv
...
...
modules/core/include/opencv2/core/private.hpp
浏览文件 @
4f2aeeff
...
...
@@ -301,111 +301,4 @@ typedef enum CvStatus
}
CvStatus
;
/****************************************************************************************\
* Auxiliary algorithms *
\****************************************************************************************/
namespace
cv
{
// This function splits the input sequence or set into one or more equivalence classes and
// returns the vector of labels - 0-based class indexes for each element.
// predicate(a,b) returns true if the two sequence elements certainly belong to the same class.
//
// The algorithm is described in "Introduction to Algorithms"
// by Cormen, Leiserson and Rivest, the chapter "Data structures for disjoint sets"
template
<
typename
_Tp
,
class
_EqPredicate
>
int
partition
(
const
std
::
vector
<
_Tp
>&
_vec
,
std
::
vector
<
int
>&
labels
,
_EqPredicate
predicate
=
_EqPredicate
())
{
int
i
,
j
,
N
=
(
int
)
_vec
.
size
();
const
_Tp
*
vec
=
&
_vec
[
0
];
const
int
PARENT
=
0
;
const
int
RANK
=
1
;
std
::
vector
<
int
>
_nodes
(
N
*
2
);
int
(
*
nodes
)[
2
]
=
(
int
(
*
)[
2
])
&
_nodes
[
0
];
// The first O(N) pass: create N single-vertex trees
for
(
i
=
0
;
i
<
N
;
i
++
)
{
nodes
[
i
][
PARENT
]
=-
1
;
nodes
[
i
][
RANK
]
=
0
;
}
// The main O(N^2) pass: merge connected components
for
(
i
=
0
;
i
<
N
;
i
++
)
{
int
root
=
i
;
// find root
while
(
nodes
[
root
][
PARENT
]
>=
0
)
root
=
nodes
[
root
][
PARENT
];
for
(
j
=
0
;
j
<
N
;
j
++
)
{
if
(
i
==
j
||
!
predicate
(
vec
[
i
],
vec
[
j
]))
continue
;
int
root2
=
j
;
while
(
nodes
[
root2
][
PARENT
]
>=
0
)
root2
=
nodes
[
root2
][
PARENT
];
if
(
root2
!=
root
)
{
// unite both trees
int
rank
=
nodes
[
root
][
RANK
],
rank2
=
nodes
[
root2
][
RANK
];
if
(
rank
>
rank2
)
nodes
[
root2
][
PARENT
]
=
root
;
else
{
nodes
[
root
][
PARENT
]
=
root2
;
nodes
[
root2
][
RANK
]
+=
rank
==
rank2
;
root
=
root2
;
}
CV_Assert
(
nodes
[
root
][
PARENT
]
<
0
);
int
k
=
j
,
parent
;
// compress the path from node2 to root
while
(
(
parent
=
nodes
[
k
][
PARENT
])
>=
0
)
{
nodes
[
k
][
PARENT
]
=
root
;
k
=
parent
;
}
// compress the path from node to root
k
=
i
;
while
(
(
parent
=
nodes
[
k
][
PARENT
])
>=
0
)
{
nodes
[
k
][
PARENT
]
=
root
;
k
=
parent
;
}
}
}
}
// Final O(N) pass: enumerate classes
labels
.
resize
(
N
);
int
nclasses
=
0
;
for
(
i
=
0
;
i
<
N
;
i
++
)
{
int
root
=
i
;
while
(
nodes
[
root
][
PARENT
]
>=
0
)
root
=
nodes
[
root
][
PARENT
];
// re-use the rank as the class label
if
(
nodes
[
root
][
RANK
]
>=
0
)
nodes
[
root
][
RANK
]
=
~
nclasses
++
;
labels
[
i
]
=
~
nodes
[
root
][
RANK
];
}
return
nclasses
;
}
}
// namespace cv
#endif // __OPENCV_CORE_PRIVATE_HPP__
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录