提交 00cce4ac 编写于 作者: L Liangliang Zhang 提交者: Jiangtao Hu

Perception: added lidar_object_util.

上级 479fa5d2
......@@ -63,4 +63,18 @@ cc_library(
],
)
cc_library(
name = "lidar_object_util",
srcs = [
"lidar_object_util.cc",
],
hdrs = [
"lidar_object_util.h",
],
deps = [
"//modules/perception/base",
":lidar_log",
],
)
cpplint()
......@@ -14,14 +14,23 @@
* limitations under the License.
*****************************************************************************/
#include "modules/perception/lidar/common/lidar_object_util.h"
#include <algorithm>
#include "modules/perception/base/point_cloud_types.h"
#include "modules/perception/lidar/common/lidar_log.h"
namespace apollo {
namespace perception {
namespace lidar {
void GetBoundingBox2d(const base::ObjectPtr object, base::PolygonDType* box,
double expand) {
using base::Object;
using base::PointF;
using base::PointD;
using base::PointCloud;
void GetBoundingBox2d(const std::shared_ptr<Object> object,
PointCloud<PointD>* box, double expand) {
box->clear();
box->resize(4);
......@@ -48,15 +57,15 @@ void GetBoundingBox2d(const base::ObjectPtr object, base::PolygonDType* box,
object->center(1);
}
void ComputeObjectShapeFromPolygon(base::ObjectPtr object,
void ComputeObjectShapeFromPolygon(std::shared_ptr<Object> object,
bool use_world_cloud) {
const base::PolygonDType& polygon = object->polygon;
const base::PointFCloud& cloud = object->lidar_supplement.cloud;
const base::PointDCloud& world_cloud = object->lidar_supplement.cloud_world;
const PointCloud<PointD>& polygon = object->polygon;
const PointCloud<PointF>& cloud = object->lidar_supplement.cloud;
const PointCloud<PointD>& world_cloud = object->lidar_supplement.cloud_world;
if (polygon.size() == 0 || cloud.size() == 0) {
LOG_INFO << "Failed to compute box, polygon size: " << polygon.size()
<< " cloud size: " << cloud.size();
AINFO << "Failed to compute box, polygon size: " << polygon.size()
<< " cloud size: " << cloud.size();
return;
}
......@@ -73,7 +82,7 @@ void ComputeObjectShapeFromPolygon(base::ObjectPtr object,
// note we keep this offset to avoid numeric precision issues in world frame
Eigen::Vector2d offset(object->polygon[0].x, object->polygon[0].y);
for (const auto& point : object->polygon) {
for (const auto& point : object->polygon.points()) {
polygon_xy << point.x, point.y;
polygon_xy -= offset;
projected_polygon_xy(0) = direction.dot(polygon_xy);
......@@ -89,14 +98,14 @@ void ComputeObjectShapeFromPolygon(base::ObjectPtr object,
if (use_world_cloud) {
min_z = world_cloud[0].z;
max_z = world_cloud[0].z;
for (const auto& point : world_cloud) {
for (const auto& point : world_cloud.points()) {
min_z = std::min(min_z, point.z);
max_z = std::max(max_z, point.z);
}
} else {
min_z = cloud[0].z;
max_z = cloud[0].z;
for (const auto& point : cloud) {
for (const auto& point : cloud.points()) {
min_z = std::min(min_z, static_cast<double>(point.z));
max_z = std::max(max_z, static_cast<double>(point.z));
}
......
......@@ -15,8 +15,11 @@
*****************************************************************************/
#ifndef MODULES_PERCEPTION_LIDAR_COMMON_LIDAR_OBJECT_UTIL_H_
#define MODULES_PERCEPTION_LIDAR_COMMON_LIDAR_OBJECT_UTIL_H_
#include "modules/perception/base/object.h"
#include <memory>
namespace apollo {
namespace perception {
namespace lidar {
......@@ -25,13 +28,13 @@ namespace lidar {
// @param [in]: object
// @param [in]: expand valud, in meter
// @param [out]: bounding box vertices(4 in xy plane)
void GetBoundingBox2d(const base::ObjectPtr object, base::PolygonDType* box,
double expand = 0.0);
void GetBoundingBox2d(const std::shared_ptr<base::Object> object,
base::PointCloud<base::PointD>* box, double expand = 0.0);
// @brief: compute object shape(center, size) from given direction and polygon
// @param [in/out]: input object, center and size will be updated
// @param [in]: whether use world cloud or local cloud
void ComputeObjectShapeFromPolygon(base::ObjectPtr object,
void ComputeObjectShapeFromPolygon(std::shared_ptr<base::Object> object,
bool use_world_cloud = false);
} // namespace lidar
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册