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

Cannot convert rs2::frame into rs2::depth_frame when using callback method #6464

Closed
MoBaT opened this issue May 26, 2020 · 2 comments
Closed
Labels

Comments

@MoBaT
Copy link

MoBaT commented May 26, 2020

Required Info
Camera Model { D435i }
Firmware Version (0.2.0.926)
Operating System & Version { Ubuntu 18.04
Kernel Version (Linux Only) ( 5.3.0-51-generic )
Platform x86_64 Desktop
SDK Version { v2.34.0 }
Language { C++ }

Issue Description

When using rs2::pipe().start(cfg, [](const rs2::frame & frame){ }), I am unable to get a proper depth_frame pointer when converting a frame to depth_frame. When using the rs2::pipe().wait_for_frames(), it works properly.

#define CALLBACK_METHOD

int main(int argc, char * argv[]) try
{
    rs2::context ctx;
    rs2::pipeline pipe(ctx);
    rs2::config cfg;

#ifdef CALLBACK_METHOD
    pipe.start(cfg, [&](const rs2::frame & frame) {
        if(frame.get_profile().stream_type() == RS2_STREAM_DEPTH)
        {
            auto depth_frame = frame.as<rs2::depth_frame>();
            if(!depth_frame)
            {
                std::cout << "ERROR: BAD DEPTH FRAME." << std::endl;
            }
        }
    });

     while(true)
    {
        usleep(10000);
    }
#else
    pipe.start(cfg);

    while(true)
    {
        auto frames = pipe.wait_for_frames();
        for(auto && frame : frames)
        {
            if(frame.get_profile().stream_type() == RS2_STREAM_DEPTH)
            {
                auto depth_frame = frame.as<rs2::depth_frame>();
                if(!depth_frame)
                {
                    std::cout << "ERROR: BAD DEPTH FRAME." << std::endl;
                }
            }
        }
    }
#endif
}
@ev-mp
Copy link
Collaborator

ev-mp commented May 27, 2020

@MoBaT hello, the pipeline callbacks generally provide rs2::frameset objects types.
Therefore to extract the depth data use the following pattern

pipe.start(cfg, [&](const rs2::frame & frame) {
        //if(frame.get_profile().stream_type() == RS2_STREAM_DEPTH)  - This is not needed
        {
            if (rs2::frameset fs = frame.as<rs2::frameset>())
            {
                  // With callbacks, all the synchronized streams arrive in a single frameset
                 for (rs2::frame& f : fs)
                      ....
                 // Alternatively:
                 if (auto depth_frame = fs.get_depth_frame())
                      .....
           }
          else // // In case the rs2::frame is not cast-able to rs2::frameset
           { 
               ...
            }
    }

See the rs-callback example for more details

@ev-mp ev-mp added the software label May 27, 2020
@RealSenseSupport
Copy link
Collaborator

Hi,

Will you be needing further help with this? If we don’t hear from you in 7 days, this issue will be closed.

Thanks

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

No branches or pull requests

3 participants