Last active
May 23, 2018 12:25
-
-
Save knorth55/007fab438d0c790b47c9de4ed76a9c29 to your computer and use it in GitHub Desktop.
Processing 32FC1 image by pixel, convert it to uint8 array and put data in to ROS sensor_msgs/Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sensor_msgs::Image depth_image; | |
std::vector<uint8_t> depth_image_vector; | |
int32_t width = 320; // width example | |
int32_t height = 240; // height example | |
float* depth_data; //original data | |
depth_image.step = 4*width; // one pixel data size of 32FC1 is 4 bytes; | |
for (int count=0; count < width * height; count++) | |
{ | |
float depth_pixel = depth_data[count]; | |
// add process here | |
uint8_t *depth_pixel_array = reinterpret_cast<uint8_t *>(&depth_pixel); | |
std::vector<uint8_t> depth_pixel_vector (depth_pixel_array, depth_pixel_array + 4); | |
depth_image_vector.insert(depth_image_vector.end(), depth_pixel_vector.begin(), depth_pixel_vector.end()); | |
} | |
depth_image.data.clear(); | |
depth_image.data = depth_image_vector; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment