Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change RGB stream to Grayscale? #1554

Closed
xuzhiyuan29 opened this issue Apr 16, 2018 · 5 comments
Closed

How to change RGB stream to Grayscale? #1554

xuzhiyuan29 opened this issue Apr 16, 2018 · 5 comments
Assignees

Comments

@xuzhiyuan29
Copy link

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;
}

@dorodnic
Copy link
Contributor

Hi @xzyxzy29
Could you clarify if you are referring to the output of the depth or the color sensor?

@xuzhiyuan29
Copy link
Author

Well, the output of the depth.

@xuzhiyuan29
Copy link
Author

@dorodnic

@RealSense-Customer-Engineering
Copy link
Collaborator

[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
Copy link
Collaborator

[Realsense Customer Engineering Team Comment]
@xzyxzy29 Do you still have any further question about this ticket?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants