4
4
#include < opencv2/core.hpp>
5
5
#include < opencv2/highgui.hpp>
6
6
#include < opencv2/imgcodecs.hpp>
7
+ #include < opencv2/imgproc.hpp>
7
8
#include < rerun.hpp>
8
9
9
10
template <>
@@ -78,7 +79,9 @@ int main() {
78
79
projection_matrix (1 , 2 ) = (height - 1 ) / 2.0 ;
79
80
rec.log (
80
81
" 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
+ ))
82
85
.with_resolution (rerun::components::Resolution ({width, height}))
83
86
);
84
87
Eigen::Vector3f camera_position{0.0 , -1.0 , 0.0 };
@@ -92,20 +95,34 @@ int main() {
92
95
rec.log (
93
96
" world/camera" ,
94
97
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 () ))
97
100
)
98
101
);
99
102
100
- // Image
103
+ // Read image
101
104
std::string image_path = " rerun-logo.png" ;
102
105
cv::Mat img = imread (image_path, cv::IMREAD_COLOR);
103
106
if (img.empty ()) {
104
107
std::cout << " Could not read the image: " << image_path << std::endl;
105
108
return 1 ;
106
109
}
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
+ );
109
126
110
127
return 0 ;
111
128
}
0 commit comments