Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
eafdc8f3
A
apollo
项目概览
Pinoxchio
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eafdc8f3
编写于
9月 22, 2018
作者:
L
Liangliang Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Perception: added connected_component_analysis.
上级
b22476e6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
168 addition
and
0 deletion
+168
-0
modules/perception/common/graph/BUILD
modules/perception/common/graph/BUILD
+25
-0
modules/perception/common/graph/connected_component_analysis.h
...es/perception/common/graph/connected_component_analysis.h
+75
-0
modules/perception/common/graph/connected_component_analysis_test.cc
...ception/common/graph/connected_component_analysis_test.cc
+68
-0
未找到文件。
modules/perception/common/graph/BUILD
浏览文件 @
eafdc8f3
...
...
@@ -72,6 +72,7 @@ cc_test(
"@eigen"
,
],
)
cc_library
(
name
=
"hungarian_optimizer"
,
hdrs
=
[
...
...
@@ -94,4 +95,28 @@ cc_test(
"@gtest//:main"
,
],
)
cc_library
(
name
=
"connected_component_analysis"
,
hdrs
=
[
"connected_component_analysis.h"
,
],
deps
=
[
"//framework:cybertron"
,
],
)
cc_test
(
name
=
"connected_component_analysis_test"
,
size
=
"small"
,
srcs
=
[
"connected_component_analysis_test.cc"
,
],
deps
=
[
":connected_component_analysis"
,
"@eigen"
,
"@gtest//:main"
,
],
)
cpplint
()
modules/perception/common/graph/connected_component_analysis.h
0 → 100644
浏览文件 @
eafdc8f3
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#ifndef MODULES_PERCEPTION_COMMON_GRAPH_CONNECTED_COMPONENT_ANALYSIS_H_
#define MODULES_PERCEPTION_COMMON_GRAPH_CONNECTED_COMPONENT_ANALYSIS_H_
#include <queue>
#include <vector>
#include "cybertron/common/log.h"
namespace
apollo
{
namespace
perception
{
namespace
common
{
/*
* @brief: bfs based connected component analysis
* @params[IN] graph: input graph for connected component analysis
* @params[OUT] components: connected components of input graph
* @return nothing
* */
void
ConnectedComponentAnalysis
(
const
std
::
vector
<
std
::
vector
<
int
>>&
graph
,
std
::
vector
<
std
::
vector
<
int
>>*
components
)
{
CHECK_NOTNULL
(
components
);
int
num_item
=
graph
.
size
();
std
::
vector
<
int
>
visited
;
visited
.
resize
(
num_item
,
0
);
std
::
queue
<
int
>
que
;
std
::
vector
<
int
>
component
;
component
.
reserve
(
num_item
);
components
->
clear
();
for
(
int
index
=
0
;
index
<
num_item
;
++
index
)
{
if
(
visited
[
index
])
{
continue
;
}
component
.
push_back
(
index
);
que
.
push
(
index
);
visited
[
index
]
=
1
;
while
(
!
que
.
empty
())
{
int
current_id
=
que
.
front
();
que
.
pop
();
for
(
size_t
sub_index
=
0
;
sub_index
<
graph
[
current_id
].
size
();
++
sub_index
)
{
int
neighbor_id
=
graph
[
current_id
][
sub_index
];
if
(
visited
[
neighbor_id
]
==
0
)
{
component
.
push_back
(
neighbor_id
);
que
.
push
(
neighbor_id
);
visited
[
neighbor_id
]
=
1
;
}
}
}
components
->
push_back
(
component
);
component
.
clear
();
}
}
}
// namespace common
}
// namespace perception
}
// namespace apollo
#endif // MODULES_PERCEPTION_COMMON_GRAPH_CONNECTED_COMPONENT_ANALYSIS_H_
modules/perception/common/graph/connected_component_analysis_test.cc
0 → 100644
浏览文件 @
eafdc8f3
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/perception/common/graph/connected_component_analysis.h"
#include "Eigen/Core"
#include "gtest/gtest.h"
namespace
apollo
{
namespace
perception
{
namespace
common
{
class
ConnectedComponentAnalysisTest
:
public
testing
::
Test
{
protected:
ConnectedComponentAnalysisTest
()
=
default
;
virtual
~
ConnectedComponentAnalysisTest
()
=
default
;
void
SetUp
()
{}
void
TearDown
()
{}
};
// class ConnectedComponentAnalysisTest
TEST_F
(
ConnectedComponentAnalysisTest
,
test_ConnectedComponenetAnalysis
)
{
Eigen
::
MatrixXf
association_mat
(
3
,
4
);
association_mat
<<
0.3
,
1.2
,
4.0
,
3.0
,
0.9
,
2.0
,
3.0
,
8.0
,
4.0
,
3.0
,
0.3
,
0.1
;
const
float
connected_threshold
=
2.1
;
// Compute connected components within given threshold
int
no_track
=
association_mat
.
rows
();
int
no_obj
=
association_mat
.
cols
();
std
::
vector
<
std
::
vector
<
int
>>
nb_graph
;
nb_graph
.
resize
(
no_track
+
no_obj
);
for
(
int
i
=
0
;
i
<
no_track
;
i
++
)
{
for
(
int
j
=
0
;
j
<
no_obj
;
j
++
)
{
if
(
association_mat
(
i
,
j
)
<=
connected_threshold
)
{
nb_graph
[
i
].
push_back
(
no_track
+
j
);
nb_graph
[
j
+
no_track
].
push_back
(
i
);
}
}
}
std
::
vector
<
std
::
vector
<
int
>>
components
;
ConnectedComponentAnalysis
(
nb_graph
,
&
components
);
EXPECT_EQ
(
2
,
components
.
size
());
EXPECT_EQ
(
4
,
components
[
0
].
size
());
EXPECT_EQ
(
0
,
components
[
0
][
0
]);
EXPECT_EQ
(
3
,
components
[
0
][
1
]);
EXPECT_EQ
(
4
,
components
[
0
][
2
]);
EXPECT_EQ
(
1
,
components
[
0
][
3
]);
EXPECT_EQ
(
3
,
components
[
1
].
size
());
EXPECT_EQ
(
2
,
components
[
1
][
0
]);
EXPECT_EQ
(
5
,
components
[
1
][
1
]);
EXPECT_EQ
(
6
,
components
[
1
][
2
]);
}
}
// namespace common
}
// namespace perception
}
// namespace apollo
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录