-
Notifications
You must be signed in to change notification settings - Fork 870
feat(BEVFusion): add gpu-based image undistortion to the bevfusion node #12279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KSeangTan
wants to merge
46
commits into
autowarefoundation:main
Choose a base branch
from
KSeangTan:feat/add_undistortion_to_bevfusion_camera
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+909
−190
Open
Changes from 25 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
dcfd2b7
Update maintaner name in streampetr
KSeangTan 22ef15e
Merge branch 'main' of github.com:KSeangTan/autoware_universe
KSeangTan 9560c59
Update maintaner name in streampetr
KSeangTan 2853bbd
Merge branch 'autowarefoundation:main' into main
KSeangTan 51d98be
Merge branch 'autowarefoundation:main' into main
KSeangTan b251476
Merge branch 'autowarefoundation:main' into main
KSeangTan 27214b9
Merge branch 'autowarefoundation:main' into main
KSeangTan 01ee3d0
Merge branch 'autowarefoundation:main' into main
KSeangTan 062c6b6
Merge branch 'autowarefoundation:main' into main
KSeangTan 9998c05
Merge branch 'autowarefoundation:main' into main
KSeangTan eed5473
Merge branch 'autowarefoundation:main' into main
KSeangTan 66e4c98
Merge branch 'autowarefoundation:main' into main
KSeangTan e000ea5
Add camera_data to bevfusion
KSeangTan 8332d94
Update CMakeList in bevfusion
KSeangTan a51e3ed
Update CMakeList in bevfusion
KSeangTan 68f32a1
Add camera_data in bevfusion
KSeangTan da57f46
Add camera_data in bevfusion
KSeangTan 6e66a55
Add camera_data in bevfusion
KSeangTan d0c7f19
Add camera_data in bevfusion
KSeangTan 82cb665
Add camera_data in bevfusion
KSeangTan 4fdca91
Add camera_matrices in bevfusion
KSeangTan 1b0b95b
Add camera_matrices in bevfusion
KSeangTan 191ab67
Add undistrotion_image_buffer_d_ in bevfusion
KSeangTan 051e692
Fix json schema in bevfusion
KSeangTan 5506a37
Merge branch 'main' into feat/add_undistortion_to_bevfusion_camera
KSeangTan 7436d81
Fix json schema in bevfusion
KSeangTan 6e2bc5a
Resolve double deletion
KSeangTan f800394
Convert tabs to spaces
KSeangTan aa8ac26
Merge branch 'main' into feat/add_undistortion_to_bevfusion_camera
KSeangTan b69d6ed
Merge branch 'main' into feat/add_undistortion_to_bevfusion_camera
KSeangTan 96d3f8f
Convert tabs to spaces
KSeangTan 3f33721
Merge branch 'main' into feat/add_undistortion_to_bevfusion_camera
KSeangTan c5074e7
Merge branch 'main' into feat/add_undistortion_to_bevfusion_camera
KSeangTan 2ebce5c
Merge branch 'autowarefoundation:main' into main
KSeangTan b27adaa
Merge branch 'main' into feat/add_undistortion_to_bevfusion_camera
KSeangTan 6055c69
Remove flip_image_channels
KSeangTan 43c7028
Remove flip_image_channels
KSeangTan c8abebf
Remove lib/camera_matrices.cpp
KSeangTan 302eef7
Add sanity check to check input image shape and ImagePreProcessingPar…
KSeangTan 9337210
Add sanity check to check input image shape and ImagePreProcessingPar…
KSeangTan 669ad9b
Update error message
KSeangTan 33c3331
Add CHECK_CUDA_ERROR for cuda function
KSeangTan 3507a58
Add checkImageCameraMatricesReady and check sensor_fusion before proc…
KSeangTan bcbb6dc
Add checkImageCameraMatricesReady and check sensor_fusion before proc…
KSeangTan ded3664
Remove cv_bridge and opencv hpp
KSeangTan a904e4c
Merge branch 'main' into feat/add_undistortion_to_bevfusion_camera
KSeangTan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,3 +24,4 @@ | |
| features_width: 72 | ||
| num_depth_features: 95 | ||
| image_feature_channel: 256 | ||
| flip_image_channels: true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,3 +24,4 @@ | |
| features_width: 0 | ||
| num_depth_features: 0 | ||
| image_feature_channel: 0 | ||
| flip_image_channels: false | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
perception/autoware_bevfusion/include/autoware/bevfusion/camera/camera_data.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // Copyright 2026 TIER IV | ||
| // | ||
| // 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 AUTOWARE__BEVFUSION__CAMERA__CAMERA_DATA_HPP_ | ||
| #define AUTOWARE__BEVFUSION__CAMERA__CAMERA_DATA_HPP_ | ||
|
|
||
| #include "autoware/bevfusion/camera/camera_matrices.hpp" | ||
| #include "autoware/bevfusion/camera/camera_preprocess.hpp" | ||
|
|
||
| #include <autoware/cuda_utils/cuda_check_error.hpp> | ||
| #include <autoware/cuda_utils/cuda_unique_ptr.hpp> | ||
| #include <rclcpp/rclcpp.hpp> | ||
|
|
||
| #include <sensor_msgs/msg/camera_info.hpp> | ||
| #include <sensor_msgs/msg/compressed_image.hpp> | ||
| #include <sensor_msgs/msg/image.hpp> | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| namespace autoware::bevfusion | ||
| { | ||
| using autoware::cuda_utils::CudaUniquePtr; | ||
|
|
||
| struct ImagePreProcessingParams | ||
| { | ||
| std::int64_t original_image_height; | ||
| std::int64_t original_image_width; | ||
| std::int64_t roi_height; | ||
| std::int64_t roi_width; | ||
| float image_aug_scale_y; | ||
| float image_aug_scale_x; | ||
| bool run_image_undistortion; | ||
| bool flip_image_channels; | ||
| std::int64_t crop_height; | ||
| std::int64_t crop_width; | ||
| std::int64_t resized_height; | ||
| std::int64_t resized_width; | ||
| std::int64_t roi_start_y; | ||
| std::int64_t roi_start_x; | ||
|
|
||
| ImagePreProcessingParams( | ||
| const std::int64_t original_image_height, const std::int64_t original_image_width, | ||
| const std::int64_t roi_height, const std::int64_t roi_width, const float image_aug_scale_y, | ||
| const float image_aug_scale_x, const bool run_image_undistortion, | ||
| const bool flip_image_channels); | ||
| }; | ||
|
|
||
| class CameraData | ||
| { | ||
| public: | ||
| CameraData( | ||
| rclcpp::Node * node, const int camera_id, | ||
| const ImagePreProcessingParams & image_pre_processing_params, | ||
| const std::shared_ptr<CameraMatrices> & camera_matrices_ptr); | ||
| ~CameraData(); | ||
|
|
||
| void update_image_msg(const sensor_msgs::msg::Image::ConstSharedPtr & input_camera_image_msg); | ||
| void update_camera_info(const sensor_msgs::msg::CameraInfo & input_camera_info_msg); | ||
| std::optional<sensor_msgs::msg::CameraInfo> camera_info() const; | ||
| sensor_msgs::msg::CameraInfo camera_info_value() const; | ||
|
|
||
| sensor_msgs::msg::Image::ConstSharedPtr image_msg() const; | ||
| bool is_image_msg_available() const; | ||
| bool is_camera_info_available() const; | ||
ktro2828 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| std::size_t output_img_offset() const; | ||
|
|
||
| void preprocess_image(std::uint8_t * output_img); | ||
| bool is_camera_matrices_ready() const; | ||
| cudaError_t sync_cuda_stream(); | ||
|
|
||
| private: | ||
| // Camera info buffer | ||
| std::optional<sensor_msgs::msg::CameraInfo> camera_info_; | ||
|
|
||
| // Image buffer | ||
| // TODO(KokSeang): Remove this once we move preprocessing to subscribers | ||
| sensor_msgs::msg::Image::ConstSharedPtr image_msg_; | ||
|
|
||
| // GPU Memory for preprocessed image | ||
| // image buffers | ||
| CudaUniquePtr<std::uint8_t[]> image_buffer_d_{nullptr}; | ||
| CudaUniquePtr<std::uint8_t[]> undistorted_image_buffer_d_{nullptr}; | ||
|
|
||
| rclcpp::Logger logger_; | ||
| int camera_id_; | ||
| ImagePreProcessingParams image_pre_processing_params_; | ||
| std::size_t output_img_offset_; | ||
|
|
||
| cudaStream_t stream_{nullptr}; | ||
| std::unique_ptr<CameraPreprocess> camera_preprocess_ptr_{nullptr}; | ||
| std::shared_ptr<CameraMatrices> camera_matrices_ptr_{nullptr}; | ||
| }; | ||
| } // namespace autoware::bevfusion | ||
| #endif // AUTOWARE__BEVFUSION__CAMERA__CAMERA_DATA_HPP_ | ||
52 changes: 52 additions & 0 deletions
52
perception/autoware_bevfusion/include/autoware/bevfusion/camera/camera_matrices.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Copyright 2026 TIER IV | ||
| // | ||
| // 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 AUTOWARE__BEVFUSION__CAMERA__CAMERA_MATRICES_HPP_ | ||
| #define AUTOWARE__BEVFUSION__CAMERA__CAMERA_MATRICES_HPP_ | ||
|
|
||
| #include <autoware/cuda_utils/cuda_unique_ptr.hpp> | ||
|
|
||
| #include <sensor_msgs/msg/camera_info.hpp> | ||
|
|
||
| #if __has_include(<cv_bridge/cv_bridge.hpp>) | ||
| #include <cv_bridge/cv_bridge.hpp> | ||
| #else | ||
| #include <cv_bridge/cv_bridge.h> | ||
| #endif | ||
| #include <opencv2/opencv.hpp> | ||
|
|
||
| namespace autoware::bevfusion | ||
| { | ||
| using autoware::cuda_utils::CudaUniquePtr; | ||
|
|
||
| // Helper struct for camera matrices | ||
| struct CameraMatrices | ||
| { | ||
| cv::Mat K; | ||
| cv::Mat D; | ||
| cv::Mat P; | ||
| int map_width; | ||
| int map_height; | ||
| bool matrices_ready{false}; | ||
|
|
||
| // GPU Memory for undistortion maps and they only need to be computed once for each camera | ||
| CudaUniquePtr<float[]> undistorted_map_x_d_{nullptr}; | ||
| CudaUniquePtr<float[]> undistorted_map_y_d_{nullptr}; | ||
|
|
||
| CameraMatrices(); | ||
| void update_camera_matrices(const sensor_msgs::msg::CameraInfo & camera_info); | ||
| void compute_undistorted_map_x_y(); | ||
| }; | ||
| } // namespace autoware::bevfusion | ||
| #endif // AUTOWARE__BEVFUSION__CAMERA__CAMERA_MATRICES_HPP_ |
53 changes: 53 additions & 0 deletions
53
perception/autoware_bevfusion/include/autoware/bevfusion/camera/camera_preprocess.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright 2026 TIER IV | ||
| // | ||
| // 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 AUTOWARE__BEVFUSION__CAMERA__CAMERA_PREPROCESS_HPP_ | ||
| #define AUTOWARE__BEVFUSION__CAMERA__CAMERA_PREPROCESS_HPP_ | ||
|
|
||
| #include "autoware/bevfusion/utils.hpp" | ||
|
|
||
| #include <autoware/cuda_utils/cuda_check_error.hpp> | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace autoware::bevfusion | ||
| { | ||
|
|
||
| class CameraPreprocess | ||
| { | ||
| public: | ||
| CameraPreprocess(cudaStream_t stream, const int camera_id); | ||
| ~CameraPreprocess(); | ||
|
|
||
| cudaError_t resizeAndExtractRoi_launch( | ||
| const std::uint8_t * input_img, std::uint8_t * output_img, int H, | ||
| int W, // Original image dimensions | ||
| int H2, int W2, // Resized image dimensions | ||
| int H3, int W3, // ROI dimensions | ||
| int y_start, int x_start, // ROI top-left coordinates in resized image | ||
| bool flip_image_channels // Set to True if the image channels are to be flipped, for example, | ||
| // BGR to RGB | ||
| ); | ||
| cudaError_t remap_launch( | ||
| const std::uint8_t * input_img, std::uint8_t * output_img, int output_height, | ||
| int output_width, // Output (destination) image dimensions | ||
| int input_height, int input_width, // Input (source) image dimensions | ||
| const float * map_x, const float * map_y); | ||
|
|
||
| private: | ||
| cudaStream_t stream_; | ||
| int camera_id_; | ||
| }; | ||
| } // namespace autoware::bevfusion | ||
| #endif // AUTOWARE__BEVFUSION__CAMERA__CAMERA_PREPROCESS_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as previous comment, but let's keep this comment with memo:
This comment can be only resolved if maintainer provide link to
awf/autowarePR with updated artifacts.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the comment above, I have removed the parameter here:
6055c69
43c7028