|
| 1 | +// Copyright 2024 TIER IV, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef AUTOWARE__IMAGE_PROJECTION_BASED_FUSION__CAMERA_PROJECTION_HPP_ |
| 16 | +#define AUTOWARE__IMAGE_PROJECTION_BASED_FUSION__CAMERA_PROJECTION_HPP_ |
| 17 | + |
| 18 | +#define EIGEN_MPL2_ONLY |
| 19 | + |
| 20 | +#include <Eigen/Core> |
| 21 | +#include <opencv2/core/core.hpp> |
| 22 | + |
| 23 | +#include <sensor_msgs/msg/camera_info.hpp> |
| 24 | + |
| 25 | +#include <image_geometry/pinhole_camera_model.h> |
| 26 | + |
| 27 | +#include <memory> |
| 28 | + |
| 29 | +namespace autoware::image_projection_based_fusion |
| 30 | +{ |
| 31 | +struct PixelPos |
| 32 | +{ |
| 33 | + float x; |
| 34 | + float y; |
| 35 | +}; |
| 36 | + |
| 37 | +class CameraProjection |
| 38 | +{ |
| 39 | +public: |
| 40 | + explicit CameraProjection( |
| 41 | + const sensor_msgs::msg::CameraInfo & camera_info, const float grid_cell_width, |
| 42 | + const float grid_cell_height, const bool unrectify, const bool use_approximation); |
| 43 | + CameraProjection() : cell_width_(1.0), cell_height_(1.0), unrectify_(false) {} |
| 44 | + void initialize(); |
| 45 | + std::function<bool(const cv::Point3d &, Eigen::Vector2d &)> calcImageProjectedPoint; |
| 46 | + sensor_msgs::msg::CameraInfo getCameraInfo(); |
| 47 | + bool isOutsideHorizontalView(const float px, const float pz); |
| 48 | + bool isOutsideVerticalView(const float py, const float pz); |
| 49 | + bool isOutsideFOV(const float px, const float py, const float pz); |
| 50 | + |
| 51 | +protected: |
| 52 | + bool calcRectifiedImageProjectedPoint( |
| 53 | + const cv::Point3d & point3d, Eigen::Vector2d & projected_point); |
| 54 | + bool calcRawImageProjectedPoint(const cv::Point3d & point3d, Eigen::Vector2d & projected_point); |
| 55 | + bool calcRawImageProjectedPointWithApproximation( |
| 56 | + const cv::Point3d & point3d, Eigen::Vector2d & projected_point); |
| 57 | + void initializeCache(); |
| 58 | + |
| 59 | + sensor_msgs::msg::CameraInfo camera_info_; |
| 60 | + uint32_t image_height_, image_width_; |
| 61 | + double tan_h_x_, tan_h_y_; |
| 62 | + double fov_left_, fov_right_, fov_top_, fov_bottom_; |
| 63 | + |
| 64 | + uint32_t cache_size_; |
| 65 | + float cell_width_; |
| 66 | + float cell_height_; |
| 67 | + float inv_cell_width_; |
| 68 | + float inv_cell_height_; |
| 69 | + int grid_width_; |
| 70 | + int grid_height_; |
| 71 | + |
| 72 | + bool unrectify_; |
| 73 | + bool use_approximation_; |
| 74 | + |
| 75 | + std::unique_ptr<PixelPos[]> projection_cache_; |
| 76 | + image_geometry::PinholeCameraModel camera_model_; |
| 77 | +}; |
| 78 | + |
| 79 | +} // namespace autoware::image_projection_based_fusion |
| 80 | + |
| 81 | +#endif // AUTOWARE__IMAGE_PROJECTION_BASED_FUSION__CAMERA_PROJECTION_HPP_ |
0 commit comments