File tree Expand file tree Collapse file tree 2 files changed +13
-16
lines changed Expand file tree Collapse file tree 2 files changed +13
-16
lines changed Original file line number Diff line number Diff line change @@ -73,16 +73,3 @@ struct rerun::CollectionAdapter<uint8_t, cv::Mat> {
73
73
return Collection<uint8_t >::take_ownership (std::move (img_vec));
74
74
}
75
75
};
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
- };
Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ std::vector<Eigen::Vector3f> generate_random_points_vector(int num_points) {
18
18
return points;
19
19
}
20
20
21
+ rerun::Collection<rerun::TensorDimension> tensor_shape (const cv::Mat& img) {
22
+ return {img.rows , img.cols , img.channels ()};
23
+ };
24
+
21
25
int main () {
22
26
const auto rec = rerun::RecordingStream (" rerun_example_cpp" );
23
27
rec.spawn ().exit_on_failure ();
@@ -64,9 +68,15 @@ int main() {
64
68
return 1 ;
65
69
}
66
70
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 )));
70
80
71
81
return 0 ;
72
82
}
You can’t perform that action at this time.
0 commit comments