Go to the documentation of this file.00001
00002
00003
00005
00007
00008
00009 #include <librealsense/rs.hpp>
00010 #include <cstdio>
00011
00012 int main() try
00013 {
00014
00015 rs::context ctx;
00016 printf("There are %d connected RealSense devices.\n", ctx.get_device_count());
00017 if(ctx.get_device_count() == 0) return EXIT_FAILURE;
00018
00019
00020 rs::device * dev = ctx.get_device(0);
00021 printf("\nUsing device 0, an %s\n", dev->get_name());
00022 printf(" Serial number: %s\n", dev->get_serial());
00023 printf(" Firmware version: %s\n", dev->get_firmware_version());
00024
00025
00026 dev->enable_stream(rs::stream::depth, 640, 480, rs::format::z16, 30);
00027
00028 dev->start();
00029
00030
00031 const uint16_t one_meter = static_cast<uint16_t>(1.0f / dev->get_depth_scale());
00032
00033 while(true)
00034 {
00035
00036
00037 dev->wait_for_frames();
00038
00039
00040 const uint16_t * depth_frame = reinterpret_cast<const uint16_t *>(dev->get_frame_data(rs::stream::depth));
00041
00042
00043 char buffer[(640/10+1)*(480/20)+1];
00044 char * out = buffer;
00045 int coverage[64] = {};
00046 for(int y=0; y<480; ++y)
00047 {
00048 for(int x=0; x<640; ++x)
00049 {
00050 int depth = *depth_frame++;
00051 if(depth > 0 && depth < one_meter) ++coverage[x/10];
00052 }
00053
00054 if(y%20 == 19)
00055 {
00056 for(int & c : coverage)
00057 {
00058 *out++ = " .:nhBXWW"[c/25];
00059 c = 0;
00060 }
00061 *out++ = '\n';
00062 }
00063 }
00064 *out++ = 0;
00065 printf("\n%s", buffer);
00066 }
00067
00068 return EXIT_SUCCESS;
00069 }
00070 catch(const rs::error & e)
00071 {
00072
00073 printf("rs::error was thrown when calling %s(%s):\n", e.get_failed_function().c_str(), e.get_failed_args().c_str());
00074 printf(" %s\n", e.what());
00075 return EXIT_FAILURE;
00076 }