Skip to content

Commit 3e46f4a

Browse files
committed
Add support for multiple color image encodings
1 parent bba08b1 commit 3e46f4a

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
path = nvblox
33
url = https://github.com/nvidia-isaac/nvblox.git
44
branch = public
5+
[submodule "cuda_image_convert"]
6+
path = cuda_image_convert
7+
url = [email protected]:nakai-omer/cuda_image_convert.git

cuda_image_convert

Submodule cuda_image_convert added at 0eb656a

nvblox_ros/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ find_package(message_filters REQUIRED)
3939
find_package(Threads REQUIRED)
4040
find_package(nvblox REQUIRED)
4141
find_package(glog REQUIRED)
42+
find_package(cuda_image_convert REQUIRED)
4243

4344
########
4445
# CUDA #
@@ -55,7 +56,7 @@ add_library(${PROJECT_NAME}_lib SHARED
5556
src/lib/transformer.cpp
5657
src/lib/nvblox_node.cpp
5758
)
58-
target_link_libraries(${PROJECT_NAME}_lib nvblox::nvblox_lib nvblox::nvblox_eigen)
59+
target_link_libraries(${PROJECT_NAME}_lib nvblox::nvblox_lib nvblox::nvblox_eigen cuda_image_convert)
5960
ament_target_dependencies(${PROJECT_NAME}_lib
6061
nvblox
6162
sensor_msgs
@@ -67,6 +68,7 @@ ament_target_dependencies(${PROJECT_NAME}_lib
6768
tf2_ros
6869
tf2_eigen
6970
message_filters
71+
cuda_image_convert
7072
)
7173
target_include_directories(${PROJECT_NAME}_lib PUBLIC
7274
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>

nvblox_ros/include/nvblox_ros/conversions.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <sensor_msgs/msg/camera_info.hpp>
2222
#include <sensor_msgs/msg/image.hpp>
2323
#include <sensor_msgs/msg/point_cloud2.hpp>
24+
#include <cudaColorspace.h>
25+
#include <cudaMappedMemory.h>
2426

2527
namespace nvblox
2628
{

nvblox_ros/package.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
1717
<description>NVBlox ROS2 interface</description>
1818

1919
<maintainer email="[email protected]">Helen Oleynikova</maintainer>
20-
<maintainer email="[email protected]">Hemal Shah</maintainer>
20+
<maintainer email="[email protected]">Hemal Shah</maintainer>
2121
<license>NVIDIA Isaac ROS Software License</license>
22-
<url type="website">https://developer.nvidia.com/isaac-ros-gems/</url>
22+
<url type="website">https://developer.nvidia.com/isaac-ros-gems/</url>
2323
<author>Helen Oleynikova</author>
2424
<author>Alexander Millane</author>
25-
25+
2626
<buildtool_depend>ament_cmake</buildtool_depend>
2727
<buildtool_depend>ament_cmake_auto</buildtool_depend>
2828

nvblox_ros/src/lib/conversions.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,35 @@ bool RosConverter::colorImageFromImageMessage(
3737
{
3838
CHECK_NOTNULL(color_image);
3939

40-
// First check if we actually have a valid image here.
40+
void* final_image = NULL;
41+
4142
if (image_msg->encoding != "rgb8") {
42-
return false;
43+
if(!cudaAllocMapped(&final_image, image_msg->width, image_msg->height, IMAGE_RGB8)) {
44+
return false;
45+
}
46+
47+
auto input_format = imageFormatFromStr(image_msg->encoding.c_str());
48+
void* inputCPU = NULL;
49+
void* inputGPU = NULL;
50+
auto input_size = imageFormatSize(input_format, image_msg->width, image_msg->height);
51+
52+
if (!cudaAllocMapped((void**)&inputCPU, (void**)&inputGPU, input_size)) {
53+
return false;
54+
}
55+
56+
memcpy(inputCPU, image_msg->data.data(), input_size);
57+
58+
if(CUDA_FAILED(cudaConvertColor(inputGPU, input_format, final_image, IMAGE_RGB8, image_msg->width, image_msg->height))) {
59+
return false;
60+
}
61+
}
62+
else {
63+
final_image = const_cast<uint8_t*>(&image_msg->data[0]);
4364
}
4465

4566
color_image->populateFromBuffer(
4667
image_msg->height, image_msg->width,
47-
reinterpret_cast<const Color *>(&image_msg->data[0]), MemoryType::kDevice);
68+
reinterpret_cast<const Color *>(final_image), MemoryType::kDevice);
4869

4970
return true;
5071
}

0 commit comments

Comments
 (0)