how to load .JSON file to RealSense D435 camera using C++ and intel API how to load .JSON file to RealSense D435 camera using C++ and intel API json json

how to load .JSON file to RealSense D435 camera using C++ and intel API


I found out how to do it and here is the code snippet including some extra image retrieving code that has to be put in Main():

// Obtain a list of devices currently present on the systemcontext ctx;auto devices = ctx.query_devices();size_t device_count = devices.size();if (!device_count){    cout <<"No device detected. Is it plugged in?\n";    return EXIT_SUCCESS;}// Get the first connected deviceauto dev = devices[0];// Enter advanced mode   if (dev.is<rs400::advanced_mode>())   {       // Get the advanced mode functionality       auto advanced_mode_dev = dev.as<rs400::advanced_mode>();       // Load and configure .json file to device       ifstream t("./presets/ShortRangePreset.json");       string str((istreambuf_iterator<char>(t)), istreambuf_iterator<char>());       advanced_mode_dev.load_json(str);   }   else   {       cout << "Current device doesn't support advanced-mode!\n";       return EXIT_FAILURE;   }//Contruct a pipeline which abstracts the device    rs2::pipeline pipe;    rs2::device selected_device = dev;    auto depth_sensor = selected_device.first<rs2::depth_sensor>();    //Create a configuration for configuring the pipeline with a non default profile    rs2::config cfg;    //Add desired streams to configuration    cfg.enable_stream(RS2_STREAM_INFRARED,  ImageWidth_px, ImageHeight_px, RS2_FORMAT_Y8, FrameRate);    cfg.enable_stream(RS2_STREAM_DEPTH,     ImageWidth_px, ImageHeight_px, RS2_FORMAT_Z16, FrameRate);    //Instruct pipeline to start streaming with the requested configuration    pipe.start(cfg);    // Camera warmup - dropping several first frames to let auto-exposure stabilize    rs2::frameset frames;    for(int i = 0; i < 5; i++)    {        //Wait for all configured streams to produce a frame        frames = pipe.wait_for_frames();    }    bool quit = false;    char key;    while (!quit){        frames = pipe.wait_for_frames();        //Get each frame        rs2::frame          ir_frame    = frames.first(RS2_STREAM_INFRARED);        rs2::depth_frame    depth_frame = frames.get_depth_frame();        // Creating OpenCV matrix from IR image        Mat ir      (Size(ImageWidth_px, ImageHeight_px), CV_8UC1,  (void*)ir_frame.get_data(),     Mat::AUTO_STEP);        Mat depth   (Size(ImageWidth_px, ImageHeight_px), CV_16UC1, (void*)depth_frame.get_data(),  Mat::AUTO_STEP);        // etc the rest of your code on how you want to edit/process the images        }