Apollo  6.0
Open source self driving car software
camera_util.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 #pragma once
17 
18 #include <memory>
19 #include <vector>
20 
25 
26 namespace apollo {
27 namespace perception {
28 namespace fusion {
29 
30 // @brief: get object eight vertices
31 // @param [in]: object
32 // @param [in/out]: vertices
33 void GetObjectEightVertices(std::shared_ptr<const base::Object> obj,
34  std::vector<Eigen::Vector3d>* vertices);
35 
36 template <typename VectorType>
37 bool IsPtInFrustum(const VectorType& pt, double width, double height) {
38  if (pt[0] < 0 || pt[0] > width || pt[1] < 0 || pt[1] > height) {
39  return false;
40  }
41  return true;
42 }
43 
44 template <typename Type>
46  const base::BBox2D<Type>& box2,
47  const Type& augmented_buffer) {
48  base::BBox2D<Type> augmented_box1 = box1;
49  augmented_box1.xmin -= augmented_buffer;
50  augmented_box1.ymin -= augmented_buffer;
51  augmented_box1.xmax += augmented_buffer;
52  augmented_box1.ymax += augmented_buffer;
53  base::BBox2D<Type> augmented_box2 = box2;
54  augmented_box2.xmin -= augmented_buffer;
55  augmented_box2.ymin -= augmented_buffer;
56  augmented_box2.xmax += augmented_buffer;
57  augmented_box2.ymax += augmented_buffer;
58  Type augmented_iou = common::CalculateIOUBBox(augmented_box1, augmented_box2);
59  return augmented_iou;
60 }
61 
62 // @brief: project 3d point to 2d point in camera
63 // @param [in]: pt3d
64 // @param [in]: world2camera_pose
65 // @param [in]: camera_model
66 // @param [in/out]: pt2d
67 // @return: true if local 3d point z > 0, else false
68 bool Pt3dToCamera2d(const Eigen::Vector3d& pt3d,
69  const Eigen::Matrix4d& world2camera_pose,
70  base::BaseCameraModelPtr camera_model,
71  Eigen::Vector2d* pt2d);
72 
73 // @brief: whether object eight vertices' local 3d point z < 0
74 // @param [in]: obj
75 // @param [in]: world2camera_pose
76 // @param [in]: camera_model
78  const std::shared_ptr<const base::Object>& obj,
79  const Eigen::Matrix4d& world2camera_pose,
80  base::BaseCameraModelPtr camera_model);
81 
82 // @brief: compute the ratio of object in camera view
83 // @param [in]: sensor_object
84 // @param [in]: camera_model
85 // @param [in]: camera_sensor2world_pose
86 // @param [in]: camera_timestamp
87 // @param [in]: camera_max_dist, the max distace can be detected by camera
88 // @param [in]: motion_compenseation
89 // @param [in]: all_in, if all_in is true, just return 0.0 or 1.0
90 float ObjectInCameraView(SensorObjectConstPtr sensor_object,
91  base::BaseCameraModelPtr camera_model,
92  const Eigen::Affine3d& camera_sensor2world_pose,
93  double camera_ts, double camera_max_dist,
94  bool motion_compensation, bool all_in);
95 
96 } // namespace fusion
97 } // namespace perception
98 } // namespace apollo
T ymin
Definition: box.h:154
float ObjectInCameraView(SensorObjectConstPtr sensor_object, base::BaseCameraModelPtr camera_model, const Eigen::Affine3d &camera_sensor2world_pose, double camera_ts, double camera_max_dist, bool motion_compensation, bool all_in)
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Eigen::Vector2d Vector2d
Definition: base_map_fwd.h:36
Eigen::Vector3d Vector3d
Definition: frame_transform.h:27
void GetObjectEightVertices(std::shared_ptr< const base::Object > obj, std::vector< Eigen::Vector3d > *vertices)
Eigen::Matrix4d Matrix4d
Definition: base_map_fwd.h:32
Type CalculateIOUBBox(const base::BBox2D< Type > &box1, const base::BBox2D< Type > &box2)
Definition: common.h:206
bool IsObjectEightVerticesAllBehindCamera(const std::shared_ptr< const base::Object > &obj, const Eigen::Matrix4d &world2camera_pose, base::BaseCameraModelPtr camera_model)
bool IsPtInFrustum(const VectorType &pt, double width, double height)
Definition: camera_util.h:37
T ymax
Definition: box.h:156
T xmin
Definition: box.h:153
T xmax
Definition: box.h:155
bool Pt3dToCamera2d(const Eigen::Vector3d &pt3d, const Eigen::Matrix4d &world2camera_pose, base::BaseCameraModelPtr camera_model, Eigen::Vector2d *pt2d)
Type CalculateAugmentedIOUBBox(const base::BBox2D< Type > &box1, const base::BBox2D< Type > &box2, const Type &augmented_buffer)
Definition: camera_util.h:45
std::shared_ptr< BaseCameraModel > BaseCameraModelPtr
Definition: camera.h:75
std::shared_ptr< const SensorObject > SensorObjectConstPtr
Definition: sensor_object.h:69
Eigen::Affine3d Affine3d
Definition: base_map_fwd.h:34