How to change RGB stream to Grayscale?
I am a freshman of realsense sdk 2.0 and I am learning it from the example capture. I need to change the output from RGB to Grayscale . I think it might have something to do with the class colorizer, but I don't know how to set about. Can you please give me some advice?
Below are the codes of the example:
#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API #include "example.hpp" // Include short list of convenience functions for rendering
// Capture Example demonstrates how to // capture depth and color video streams and render them to the screen int main(int argc, char * argv[]) try { // Create a simple OpenGL window for rendering: window app(1280, 720, "RealSense Capture Example"); // Declare two textures on the GPU, one for color and one for depth texture depth_image, color_image;
// Declare depth colorizer for pretty visualization of depth data
rs2::colorizer color_map;
// Declare RealSense pipeline, encapsulating the actual device and sensors
rs2::pipeline pipe;
// Start streaming with default recommended configuration
pipe.start();
while(app) // Application still alive?
{
rs2::frameset data = pipe.wait_for_frames(); // Wait for next set of frames from the camera
// rs2::frame depth = color_map(data.get_depth_frame()); // Find and colorize the depth data
rs2::frame depth = color_map(data.get_depth_frame());
rs2::frame color = data.get_color_frame(); // Find the color data
// Render depth on to the first half of the screen and color on to the second
depth_image.render(depth, { 0, 0, app.width() / 2, app.height() });
color_image.render(color, { app.width() / 2, 0, app.width() / 2, app.height() });
}
return EXIT_SUCCESS;
} catch (const rs2::error & e) { std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl; return EXIT_FAILURE; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; return EXIT_FAILURE; }
Hi @xzyxzy29 Could you clarify if you are referring to the output of the depth or the color sensor?
Well, the output of the depth.
@dorodnic
[Realsense Customer Engineering Team Comment] The RGB sensor also support Y16 format, this is a grayscale, as below screenshot you can see that. You can set the image format to Y16 as follows. // Declare RealSense pipeline, encapsulating the actual device and sensors rs2::pipeline pipe; rs2::config c; c.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_Y16, 30); pipe.start(c); Of course, you also need to modify the rendering method in the sample you mentioned to display the grayscale image.
[Realsense Customer Engineering Team Comment] @xzyxzy29 Do you still have any further question about this ticket?