31namespace trafficlight {
37 AERROR <<
"no cameras to be projected";
41 algorithm::SensorManager::Instance();
42 if (!sensor_manager->
Init()) {
43 AERROR <<
"sensor_manager init failed";
46 for (
size_t i = 0; i < options.
camera_names.size(); ++i) {
47 const std::string& cur_camera_name = options.
camera_names.at(i);
48 AINFO <<
"init camera " << cur_camera_name;
51 AERROR <<
"sensor " << cur_camera_name <<
" do not exist";
54 camera_models_[cur_camera_name] =
55 std::dynamic_pointer_cast<base::BrownCameraDistortionModel>(
57 if (!(camera_models_[cur_camera_name])) {
58 AERROR <<
"get null camera_model, camera_name: " << cur_camera_name;
61 camera_names_.push_back(cur_camera_name);
64 std::sort(camera_names_.begin(), camera_names_.end(),
65 [&](
const std::string& lhs,
const std::string& rhs) {
66 const auto lhs_cam_intrinsics =
67 camera_models_[lhs]->get_intrinsic_params();
68 const auto rhs_cam_intrinsics =
69 camera_models_[rhs]->get_intrinsic_params();
70 auto lhs_focal_length =
71 0.5 * (lhs_cam_intrinsics(0, 0) + lhs_cam_intrinsics(1, 1));
72 auto rhs_focal_length =
73 0.5 * (rhs_cam_intrinsics(0, 0) + rhs_cam_intrinsics(1, 1));
74 return lhs_focal_length > rhs_focal_length;
76 AINFO <<
"camera_names sorted by descending focal lengths: "
77 << std::accumulate(camera_names_.begin(), camera_names_.end(),
79 [](std::string& sum,
const std::string& s) {
94 Eigen::Matrix4d c2w_pose;
103 ret = BoundaryBasedProject(camera_models_.at(option.
camera_name), c2w_pose,
107 AWARN <<
"Projection failed projection the traffic light. "
116 std::find(camera_names_.begin(), camera_names_.end(), camera_name);
117 return iter != camera_names_.end() &&
118 camera_models_.find(camera_name) != camera_models_.end();
122 const std::string& camera_name)
const {
124 AERROR <<
"getImageWidth failed, camera_name: " << camera_name;
127 return static_cast<int>(camera_models_.at(camera_name)->get_width());
131 const std::string& camera_name)
const {
133 AERROR <<
"getImageHeight failed, camera_name: " << camera_name;
136 return static_cast<int>(camera_models_.at(camera_name)->get_height());
139bool MultiCamerasProjection::BoundaryBasedProject(
141 const Eigen::Matrix4d& c2w_pose,
142 const std::vector<base::PointXYZID>& points,
144 if (camera_model.get() ==
nullptr) {
145 AERROR <<
"camera_model is not available.";
148 int width =
static_cast<int>(camera_model->get_width());
149 int height =
static_cast<int>(camera_model->get_height());
150 int bound_size =
static_cast<int>(points.size());
151 if (bound_size < 4) {
152 AERROR <<
"invalid bound_size " << bound_size;
155 EigenVector<Eigen::Vector2i> pts2d(bound_size);
156 auto c2w_pose_inverse = c2w_pose.inverse();
158 for (
int i = 0; i < bound_size; ++i) {
159 const auto& pt3d_world = points.at(i);
160 Eigen::Vector3d pt3d_cam =
162 Eigen::Vector4d(pt3d_world.x, pt3d_world.y, pt3d_world.z, 1.0))
164 if (std::islessequal(pt3d_cam[2], 0.0)) {
165 AWARN <<
"light bound point behind the car: " << pt3d_cam;
168 pts2d[i] = camera_model->Project(pt3d_cam.cast<
float>()).cast<int>();
171 int min_x = std::numeric_limits<int>::max();
172 int max_x = std::numeric_limits<int>::min();
173 int min_y = std::numeric_limits<int>::max();
174 int max_y = std::numeric_limits<int>::min();
175 for (
const auto& pt : pts2d) {
176 min_x = std::min(pt[0], min_x);
177 max_x = std::max(pt[0], max_x);
178 min_y = std::min(pt[1], min_y);
179 max_y = std::max(pt[1], max_y);
184 AWARN <<
"Projection get ROI outside the image. ";
bool IsSensorExist(const std::string &name) const
std::shared_ptr< BaseCameraDistortionModel > GetDistortCameraModel(const std::string &name) const
EigenMap< std::string, Eigen::Matrix4d > c2w_poses_
bool Project(const camera::CarPose &pose, const ProjectOption &option, base::TrafficLight *light) const
Boundary projection based on vehicle position and traffic lights.
bool Init(const MultiCamerasInitOption &options)
multicamera project initialization parameters.
bool HasCamera(const std::string &camera_name) const
Determine whether the camera exists.
int getImageWidth(const std::string &camera_name) const
Get the image width object.
int getImageHeight(const std::string &camera_name) const
Get the image height object.
std::vector< EigenType, Eigen::aligned_allocator< EigenType > > EigenVector
std::shared_ptr< BrownCameraDistortionModel > BrownCameraDistortionModelPtr
bool OutOfValidRegion(const base::BBox2D< T > box, const T width, const T height, const T border_size=0)
Rect< int > projection_roi
std::vector< base::PointXYZID > points
std::vector< std::string > camera_names