Skip to content

Commit e3968f2

Browse files
committed
Add fetch install, image loading and reinterpret_casts
1 parent 2ec1553 commit e3968f2

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

CMakeLists.txt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,13 @@ if(NOT DEFINED CMAKE_CXX_STANDARD)
88
set(CMAKE_CXX_STANDARD 17)
99
endif()
1010

11+
include(FetchContent)
12+
FetchContent_Declare(rerun_sdk URL https://build.rerun.io/commit/f3a5ae2/rerun_cpp_sdk.zip)
13+
FetchContent_MakeAvailable(rerun_sdk)
14+
1115
find_package(Eigen3 REQUIRED)
1216
find_package(OpenCV REQUIRED)
1317
find_package(Arrow REQUIRED)
14-
# find_package(rerun_sdk REQUIRED) # this would be nice (i.e., installable rerun_sdk)
15-
16-
# assume rerun_sdk has been build beforehand
17-
add_library(rerun_sdk INTERFACE)
18-
target_include_directories(rerun_sdk INTERFACE /home/leo/code/rerun/rerun_cpp/src/)
19-
target_link_libraries(rerun_sdk INTERFACE /home/leo/code/rerun/build/rerun_cpp/librerun_sdk.a)
20-
target_link_libraries(rerun_sdk INTERFACE /home/leo/code/rerun/target/release/librerun_c.a)
21-
if(ARROW_LINK_SHARED)
22-
target_link_libraries(rerun_sdk INTERFACE Arrow::arrow_shared)
23-
else()
24-
target_link_libraries(rerun_sdk INTERFACE Arrow::arrow_static)
25-
endif()
26-
2718

2819
add_executable(rerun_ext_example src/main.cpp)
2920

src/main.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <opencv2/core.hpp>
55
#include <opencv2/highgui.hpp>
66
#include <opencv2/imgcodecs.hpp>
7+
#include <opencv2/imgproc.hpp>
78
#include <rerun.hpp>
89

910
template <>
@@ -78,7 +79,9 @@ int main() {
7879
projection_matrix(1, 2) = (height - 1) / 2.0;
7980
rec.log(
8081
"world/camera",
81-
rerun::Pinhole(rerun::components::PinholeProjection(projection_matrix.data()))
82+
rerun::Pinhole(rerun::components::PinholeProjection(
83+
*reinterpret_cast<float(*)[9]>(projection_matrix.data())
84+
))
8285
.with_resolution(rerun::components::Resolution({width, height}))
8386
);
8487
Eigen::Vector3f camera_position{0.0, -1.0, 0.0};
@@ -92,20 +95,34 @@ int main() {
9295
rec.log(
9396
"world/camera",
9497
rerun::Transform3D(
95-
rerun::datatypes::Vec3D(camera_position.data()),
96-
rerun::datatypes::Mat3x3(camera_orientation.data())
98+
rerun::datatypes::Vec3D(*reinterpret_cast<float(*)[3]>(camera_position.data())),
99+
rerun::datatypes::Mat3x3(*reinterpret_cast<float(*)[9]>(camera_orientation.data()))
97100
)
98101
);
99102

100-
// Image
103+
// Read image
101104
std::string image_path = "rerun-logo.png";
102105
cv::Mat img = imread(image_path, cv::IMREAD_COLOR);
103106
if (img.empty()) {
104107
std::cout << "Could not read the image: " << image_path << std::endl;
105108
return 1;
106109
}
107-
imshow("Display window", img);
108-
cv::waitKey(0);
110+
111+
// Log image to Rerun
112+
cv::cvtColor(img, img, cv::COLOR_BGR2RGB); // Rerun expects RGB format
113+
// NOTE currently we need to construct a vector to log an image, this will change in the future
114+
// see https://github.com/rerun-io/rerun/issues/3794
115+
std::vector<uint8_t> img_vec(img.total() * img.channels());
116+
img_vec.assign(img.data, img.data + img.total() * img.channels());
117+
rec.log(
118+
"image",
119+
rerun::Image(
120+
{static_cast<size_t>(img.rows),
121+
static_cast<size_t>(img.cols),
122+
static_cast<size_t>(img.channels())},
123+
std::move(img_vec)
124+
)
125+
);
109126

110127
return 0;
111128
}

0 commit comments

Comments
 (0)