Skip to content

Commit a9d8650

Browse files
committed
show image logging with and without image data
1 parent 2e6876c commit a9d8650

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/collection_adapters.hpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,3 @@ struct rerun::CollectionAdapter<uint8_t, cv::Mat> {
7373
return Collection<uint8_t>::take_ownership(std::move(img_vec));
7474
}
7575
};
76-
77-
// Adapter for extracting tensor dimensions from an OpenCV matrix.
78-
template <>
79-
struct rerun::CollectionAdapter<rerun::TensorDimension, cv::Mat> {
80-
/// Only overload the const& operator since there is no way of borrowing the dimensions anyways.
81-
Collection<rerun::TensorDimension> operator()(const cv::Mat& img) {
82-
return {
83-
static_cast<size_t>(img.rows),
84-
static_cast<size_t>(img.cols),
85-
static_cast<size_t>(img.channels()),
86-
};
87-
}
88-
};

src/main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ std::vector<Eigen::Vector3f> generate_random_points_vector(int num_points) {
1818
return points;
1919
}
2020

21+
rerun::Collection<rerun::TensorDimension> tensor_shape(const cv::Mat& img) {
22+
return {img.rows, img.cols, img.channels()};
23+
};
24+
2125
int main() {
2226
const auto rec = rerun::RecordingStream("rerun_example_cpp");
2327
rec.spawn().exit_on_failure();
@@ -64,9 +68,15 @@ int main() {
6468
return 1;
6569
}
6670

67-
// Log image to Rerun
68-
cv::cvtColor(img, img, cv::COLOR_BGR2RGB); // Rerun expects RGB format
69-
rec.log("image", rerun::Image(img, rerun::TensorBuffer::u8(img)));
71+
// Rerun expects RGB format
72+
cv::cvtColor(img, img, cv::COLOR_BGR2RGB);
73+
74+
// Log image to rerun using the tensor buffer adapter defined in `collection_adapters.hpp`.
75+
rec.log("image0", rerun::Image(tensor_shape(img), rerun::TensorBuffer::u8(img)));
76+
77+
// Or by passing a pointer to the image data.
78+
// The pointer cast here is redundant since `data` is already uint8_t in this case, but if you have e.g. a float image it may be necessary to cast to float*.
79+
rec.log("image1", rerun::Image(tensor_shape(img), reinterpret_cast<const uint8_t*>(img.data)));
7080

7181
return 0;
7282
}

0 commit comments

Comments
 (0)