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 configure RGB format #4218

Closed
YH53 opened this issue Jun 16, 2019 · 3 comments
Closed

How to configure RGB format #4218

YH53 opened this issue Jun 16, 2019 · 3 comments

Comments

@YH53
Copy link

YH53 commented Jun 16, 2019

Required Info
| Camera Model | { D415 } |
| Operating System & Version | {Win 10 |

| SDK Version | 2.0 |
| Language | C++ |
Platform: visual studio 2015

When I show color stream in this way:

rs2::frameset data = pipe.wait_for_frames();
rs2::frame color = data.get_color_frame();

const int w = color.as<rs2::video_frame>().get_width();
const int h = color.as<rs2::video_frame>().get_height();
Mat image(Size(w, h), CV_8UC3, (void*)color.get_data(), Mat::AUTO_STEP);
imshow(window_name, image);

the color it shows might be wrong.blue things will turn yellow.

Where can I configure for color? How to configure RGB format for it? Thanks!

@dorodnic
Copy link
Contributor

Default format used by OpenCV is BGR
Default format used by librealsense is RGB
You can select format using config.enable_stream:

config cfg;
cfg.enable_stream(RS2_STREAM_DEPTH);
cfg.enable_stream(RS2_STREAM_COLOR, RS2_FORMAT_BGR8);
pipeline p;
p.start(cfg);

@YH53
Copy link
Author

YH53 commented Jun 17, 2019

@dorodnic Thanks,I've done it.

@YH53 YH53 closed this as completed Jun 17, 2019
@akmaldeen
Copy link

akmaldeen commented Jan 18, 2021

I had the same issue, I have solved it with codes here.

Complete code for the requirement:

int main()
{
config cfg;
cfg.enable_stream(RS2_STREAM_DEPTH);
cfg.enable_stream(RS2_STREAM_COLOR, RS2_FORMAT_BGR8);
pipeline p;
p.start(cfg);

while (true)
{
    // Block program until frames arrive
    rs2::frameset frames = p.wait_for_frames();

    // Try to get a frame of a depth image
    rs2::video_frame depth = frames.get_color_frame();

    // Get the depth frame's dimensions
    const int w = depth.get_width();
    const int h = depth.get_height();
    Mat image(Size(w, h), CV_8UC3, (void*)depth.get_data(), Mat::AUTO_STEP);

imshow("window_name", image);
waitKey(0);

}

}

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

No branches or pull requests

3 participants