// License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2015 Intel Corporation. All Rights Reserved. #include #include #include int main() try { rs::context ctx; if(ctx.get_device_count() == 0) return EXIT_FAILURE; rs::device * dev = ctx.get_device(0); //dev->enable_stream(rs::stream::depth, rs::preset::best_quality); //dev->enable_stream(rs::stream::color, rs::preset::best_quality); dev->enable_stream(rs::stream::infrared, rs::preset::best_quality); //dev->enable_stream(rs::stream::infrared2, rs::preset::best_quality); // Set callbacks prior to calling start() auto depth_callback = [](rs::frame f) { std::cout << "Depth stream called back"; std::cout << ":: " << f.get_width() << "x" << f.get_height() << " " << f.get_format() << "\t " << f.get_frame_number() << "\tat t = " << f.get_timestamp() << " ms" << std::endl; }; auto color_callback = [](rs::frame f) { std::cout << "Color stream called back"; std::cout << ":: " << f.get_width() << "x" << f.get_height() << " " << f.get_format() << "\t " << f.get_frame_number() << "\tat t = " << f.get_timestamp() << " ms" << std::endl; }; auto ir_callback = [](rs::frame f) { std::cout << "IR stream called back"; std::cout << ":: " << f.get_width() << "x" << f.get_height() << " " << f.get_format() << "\t " << f.get_frame_number() << "\tat t = " << f.get_timestamp() << " ms" << std::endl; }; auto ir2_callback = [](rs::frame f) { std::cout << "IR2 stream called back"; std::cout << ":: " << f.get_width() << "x" << f.get_height() << " " << f.get_format() << "\t " << f.get_frame_number() << "\tat t = " << f.get_timestamp() << " ms" << std::endl; }; dev->set_frame_callback(rs::stream::depth, depth_callback); dev->set_frame_callback(rs::stream::color, color_callback); dev->set_frame_callback(rs::stream::infrared, ir_callback); dev->set_frame_callback(rs::stream::infrared2, ir2_callback); std::cout << "Starting only IR stream" << std::endl; // Between start() and stop(), you will receive calls to the specified callbacks from background threads dev->start(); std::this_thread::sleep_for(std::chrono::seconds(1)); // NOTE: No need to call wait_for_frames() or poll_for_frames(), though they should still work as designed dev->stop(); std::cout << std::endl; std::cout << "Starting only IR2 stream" << std::endl; dev->disable_stream(rs::stream::infrared); dev->enable_stream(rs::stream::infrared2, rs::preset::best_quality); dev->set_frame_callback(rs::stream::depth, depth_callback); dev->set_frame_callback(rs::stream::color, color_callback); dev->set_frame_callback(rs::stream::infrared, ir_callback); dev->set_frame_callback(rs::stream::infrared2, ir2_callback); // Between start() and stop(), you will receive calls to the specified callbacks from background threads dev->start(); std::this_thread::sleep_for(std::chrono::seconds(1)); // NOTE: No need to call wait_for_frames() or poll_for_frames(), though they should still work as designed dev->stop(); return EXIT_SUCCESS; } catch(const rs::error & e) { std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl; return EXIT_FAILURE; }