unit-tests-live-ivcam-common.cpp
Go to the documentation of this file.
00001 // License: Apache 2.0. See LICENSE file in root directory.
00002 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
00003 
00005 // This set of tests is valid only for the R200 camera //
00007 
00008 #if !defined(MAKEFILE)
00009 
00010 #define CATCH_CONFIG_MAIN
00011 #include "catch/catch.hpp"
00012 
00013 #include "unit-tests-common.h"
00014 
00015 #include <climits>
00016 #include <sstream>
00017 
00018 TEST_CASE( "R200 metadata enumerates correctly", "[live] [r200]" )
00019 {
00020     // Require at least one device to be plugged in
00021     safe_context ctx;
00022     const int device_count = rs_get_device_count(ctx, require_no_error());
00023     REQUIRE(device_count > 0);
00024 
00025     // For each device
00026     for(int i=0; i<device_count; ++i)
00027     {
00028         rs_device * dev = rs_get_device(ctx, 0, require_no_error());    
00029         REQUIRE(dev != nullptr);
00030 
00031         SECTION( "device name is Intel RealSense R200" )
00032         {
00033             const char * name = rs_get_device_name(dev, require_no_error());
00034             REQUIRE(name == std::string("Intel RealSense R200"));
00035         }
00036 
00037         SECTION( "device serial number has ten decimal digits" )
00038         {
00039             const char * serial = rs_get_device_serial(dev, require_no_error());
00040             REQUIRE(strlen(serial) == 10);
00041             for(int i=0; i<10; ++i) REQUIRE(isdigit(serial[i]));
00042         }
00043     }
00044 }
00045 
00046 TEST_CASE( "R200 devices support all required options", "[live] [r200]" )
00047 {
00048     // Require at least one device to be plugged in
00049     safe_context ctx;
00050     const int device_count = rs_get_device_count(ctx, require_no_error());
00051     REQUIRE(device_count > 0);
00052 
00053     // For each device
00054     for(int i=0; i<device_count; ++i)
00055     {
00056         rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00057         REQUIRE(dev != nullptr);
00058 
00059         SECTION( "device supports standard picture options and R200 extension options, and nothing else" )
00060         {
00061             const int supported_options[] = {
00062                 RS_OPTION_COLOR_BACKLIGHT_COMPENSATION,
00063                 RS_OPTION_COLOR_BRIGHTNESS,
00064                 RS_OPTION_COLOR_CONTRAST,
00065                 RS_OPTION_COLOR_EXPOSURE,
00066                 RS_OPTION_COLOR_GAIN,
00067                 RS_OPTION_COLOR_GAMMA,
00068                 RS_OPTION_COLOR_HUE,
00069                 RS_OPTION_COLOR_SATURATION,
00070                 RS_OPTION_COLOR_SHARPNESS,
00071                 RS_OPTION_COLOR_WHITE_BALANCE,
00072                 RS_OPTION_COLOR_ENABLE_AUTO_EXPOSURE,
00073                 RS_OPTION_COLOR_ENABLE_AUTO_WHITE_BALANCE,
00074                 RS_OPTION_R200_LR_AUTO_EXPOSURE_ENABLED,
00075                 RS_OPTION_R200_LR_GAIN,
00076                 RS_OPTION_R200_LR_EXPOSURE,
00077                 RS_OPTION_R200_EMITTER_ENABLED,
00078                 RS_OPTION_R200_DEPTH_UNITS,
00079                 RS_OPTION_R200_DEPTH_CLAMP_MIN,
00080                 RS_OPTION_R200_DEPTH_CLAMP_MAX,
00081                 RS_OPTION_R200_DISPARITY_MULTIPLIER,
00082                 RS_OPTION_R200_DISPARITY_SHIFT,
00083                 RS_OPTION_R200_AUTO_EXPOSURE_MEAN_INTENSITY_SET_POINT,
00084                 RS_OPTION_R200_AUTO_EXPOSURE_BRIGHT_RATIO_SET_POINT,
00085                 RS_OPTION_R200_AUTO_EXPOSURE_KP_GAIN,
00086                 RS_OPTION_R200_AUTO_EXPOSURE_KP_EXPOSURE,
00087                 RS_OPTION_R200_AUTO_EXPOSURE_KP_DARK_THRESHOLD,
00088                 RS_OPTION_R200_AUTO_EXPOSURE_TOP_EDGE,
00089                 RS_OPTION_R200_AUTO_EXPOSURE_BOTTOM_EDGE,
00090                 RS_OPTION_R200_AUTO_EXPOSURE_LEFT_EDGE,
00091                 RS_OPTION_R200_AUTO_EXPOSURE_RIGHT_EDGE,
00092                 RS_OPTION_R200_DEPTH_CONTROL_ESTIMATE_MEDIAN_DECREMENT,
00093                 RS_OPTION_R200_DEPTH_CONTROL_ESTIMATE_MEDIAN_INCREMENT,
00094                 RS_OPTION_R200_DEPTH_CONTROL_MEDIAN_THRESHOLD,
00095                 RS_OPTION_R200_DEPTH_CONTROL_SCORE_MINIMUM_THRESHOLD,
00096                 RS_OPTION_R200_DEPTH_CONTROL_SCORE_MAXIMUM_THRESHOLD,
00097                 RS_OPTION_R200_DEPTH_CONTROL_TEXTURE_COUNT_THRESHOLD,
00098                 RS_OPTION_R200_DEPTH_CONTROL_TEXTURE_DIFFERENCE_THRESHOLD,
00099                 RS_OPTION_R200_DEPTH_CONTROL_SECOND_PEAK_THRESHOLD,
00100                 RS_OPTION_R200_DEPTH_CONTROL_NEIGHBOR_THRESHOLD,
00101                 RS_OPTION_R200_DEPTH_CONTROL_LR_THRESHOLD
00102             };
00103 
00104             for(int i=0; i<RS_OPTION_COUNT; ++i)
00105             {
00106                 if(std::find(std::begin(supported_options), std::end(supported_options), i) != std::end(supported_options))
00107                 {
00108                     REQUIRE(rs_device_supports_option(dev, (rs_option)i, require_no_error()) == 1);
00109                 }
00110                 else
00111                 {
00112                     REQUIRE(rs_device_supports_option(dev, (rs_option)i, require_no_error()) == 0);
00113                 }
00114             }
00115         }
00116     }
00117 }
00118 
00120 // Calibration information tests //
00122 
00123 TEST_CASE( "R200 device extrinsics are within expected parameters", "[live] [r200]" )
00124 {
00125     // Require at least one device to be plugged in
00126     safe_context ctx;
00127     const int device_count = rs_get_device_count(ctx, require_no_error());
00128     REQUIRE(device_count > 0);
00129 
00130     // For each device
00131     for(int i=0; i<device_count; ++i)
00132     {
00133         rs_device * dev = rs_get_device(ctx, 0, require_no_error());    
00134         REQUIRE(dev != nullptr);
00135 
00136         SECTION( "no extrinsic transformation between DEPTH and INFRARED" )
00137         {
00138             rs_extrinsics extrin;
00139             rs_get_device_extrinsics(dev, RS_STREAM_DEPTH, RS_STREAM_INFRARED, &extrin, require_no_error());
00140 
00141             require_identity_matrix(extrin.rotation);
00142             require_zero_vector(extrin.translation);
00143         }
00144 
00145         SECTION( "only x-axis translation (~70 mm) between DEPTH and INFRARED2" )
00146         {
00147             rs_extrinsics extrin;
00148             rs_get_device_extrinsics(dev, RS_STREAM_DEPTH, RS_STREAM_INFRARED2, &extrin, require_no_error());
00149 
00150             require_identity_matrix(extrin.rotation);
00151             REQUIRE( extrin.translation[0] < -0.06f ); // Some variation is allowed, but should report at least 60 mm in all cases
00152             REQUIRE( extrin.translation[0] > -0.08f ); // Some variation is allowed, but should report at most 80 mm in all cases
00153             REQUIRE( extrin.translation[1] == 0.0f );
00154             REQUIRE( extrin.translation[2] == 0.0f );
00155         }
00156 
00157         SECTION( "only translation between DEPTH and RECTIFIED_COLOR" )
00158         {
00159             rs_extrinsics extrin;
00160             rs_get_device_extrinsics(dev, RS_STREAM_DEPTH, RS_STREAM_RECTIFIED_COLOR, &extrin, require_no_error());
00161 
00162             require_identity_matrix(extrin.rotation);
00163         }
00164 
00165         SECTION( "depth scale is 0.001 (by default)" )
00166         {
00167             REQUIRE( rs_get_device_depth_scale(dev, require_no_error()) == 0.001f );
00168         }
00169     }
00170 }
00171 
00172 TEST_CASE( "R200 infrared2 streaming modes exactly match infrared streaming modes", "[live] [r200]" )
00173 {
00174     // Require at least one device to be plugged in
00175     safe_context ctx;
00176     const int device_count = rs_get_device_count(ctx, require_no_error());
00177     REQUIRE(device_count > 0);
00178 
00179     // For each device
00180     for(int i=0; i<device_count; ++i)
00181     {
00182         rs_device * dev = rs_get_device(ctx, 0, require_no_error());    
00183         REQUIRE(dev != nullptr);
00184 
00185         // Require that there are a nonzero amount of infrared modes, and that infrared2 has the same number of modes
00186         const int infrared_mode_count = rs_get_stream_mode_count(dev, RS_STREAM_INFRARED, require_no_error());
00187         REQUIRE( infrared_mode_count > 0 );
00188         REQUIRE( rs_get_stream_mode_count(dev, RS_STREAM_INFRARED2, require_no_error()) == infrared_mode_count );
00189 
00190         // For each streaming mode
00191         for(int j=0; j<infrared_mode_count; ++j)
00192         {
00193             // Require that INFRARED and INFRARED2 streaming modes are exactly identical
00194             int infrared_width = 0, infrared_height = 0, infrared_framerate = 0; rs_format infrared_format = RS_FORMAT_ANY;
00195             rs_get_stream_mode(dev, RS_STREAM_INFRARED, j, &infrared_width, &infrared_height, &infrared_format, &infrared_framerate, require_no_error());
00196 
00197             int infrared2_width = 0, infrared2_height = 0, infrared2_framerate = 0; rs_format infrared2_format = RS_FORMAT_ANY;
00198             rs_get_stream_mode(dev, RS_STREAM_INFRARED2, j, &infrared2_width, &infrared2_height, &infrared2_format, &infrared2_framerate, require_no_error());
00199 
00200             REQUIRE( infrared_width == infrared2_width );
00201             REQUIRE( infrared_height == infrared2_height );
00202             REQUIRE( infrared_format == infrared2_format );
00203             REQUIRE( infrared_framerate == infrared2_framerate );
00204 
00205             // Require that the intrinsics for these streaming modes match exactly
00206             rs_enable_stream(dev, RS_STREAM_INFRARED, infrared_width, infrared_height, infrared_format, infrared_framerate, require_no_error());
00207             rs_enable_stream(dev, RS_STREAM_INFRARED2, infrared2_width, infrared2_height, infrared2_format, infrared2_framerate, require_no_error());
00208 
00209             REQUIRE( rs_get_stream_format(dev, RS_STREAM_INFRARED, require_no_error()) == rs_get_stream_format(dev, RS_STREAM_INFRARED2, require_no_error()) );
00210             REQUIRE( rs_get_stream_framerate(dev, RS_STREAM_INFRARED, require_no_error()) == rs_get_stream_framerate(dev, RS_STREAM_INFRARED2, require_no_error()) );
00211 
00212             rs_intrinsics infrared_intrin = {}, infrared2_intrin = {};
00213             rs_get_stream_intrinsics(dev, RS_STREAM_INFRARED, &infrared_intrin, require_no_error());
00214             rs_get_stream_intrinsics(dev, RS_STREAM_INFRARED2, &infrared2_intrin, require_no_error());
00215             REQUIRE( infrared_intrin.width  == infrared_intrin.width  );
00216             REQUIRE( infrared_intrin.height == infrared_intrin.height );
00217             REQUIRE( infrared_intrin.ppx    == infrared_intrin.ppx    );
00218             REQUIRE( infrared_intrin.ppy    == infrared_intrin.ppy    );
00219             REQUIRE( infrared_intrin.fx     == infrared_intrin.fx     );
00220             REQUIRE( infrared_intrin.fy     == infrared_intrin.fy     );
00221             REQUIRE( infrared_intrin.model  == infrared_intrin.model  );
00222             for(int k=0; k<5; ++k) REQUIRE( infrared_intrin.coeffs[k]  == infrared_intrin.coeffs[k] );
00223         }
00224     }
00225 }
00226 
00228 // Streaming tests //
00230 
00231 inline void test_r200_streaming(std::initializer_list<stream_mode> modes)
00232 {
00233     safe_context ctx;   
00234     REQUIRE(rs_get_device_count(ctx, require_no_error()) == 1);
00235 
00236     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00237     REQUIRE(dev != nullptr);
00238     REQUIRE(rs_get_device_name(dev, require_no_error()) == std::string("Intel RealSense R200"));
00239 
00240     test_streaming(dev, modes);
00241 }
00242 
00244 // Depth streaming tests //
00246 
00247 TEST_CASE( "R200 streams 480x360 depth", "[live] [r200] [one-camera]" )
00248 {
00249     test_r200_streaming({{RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60}});
00250 }
00251 
00252 TEST_CASE( "R200 streams 628x468 depth", "[live] [r200] [one-camera]" )
00253 {
00254     test_r200_streaming({{RS_STREAM_DEPTH, 628, 468, RS_FORMAT_Z16, 60}});
00255 }
00256 
00257 TEST_CASE( "R200 streams 320x240 depth", "[live] [r200] [one-camera]" )
00258 {
00259     test_r200_streaming({{RS_STREAM_DEPTH, 320, 240, RS_FORMAT_Z16, 60}});
00260 }
00261 
00262 TEST_CASE( "R200 streams 480x360 depth (30 fps)", "[live] [r200] [one-camera]" )
00263 {
00264     test_r200_streaming({{RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 30}});
00265 }
00266 
00267 TEST_CASE( "R200 streams 628x468 depth (30 fps)", "[live] [r200] [one-camera]" )
00268 {
00269     test_r200_streaming({{RS_STREAM_DEPTH, 628, 468, RS_FORMAT_Z16, 30}});
00270 }
00271 
00272 TEST_CASE( "R200 streams 320x240 depth (30 fps)", "[live] [r200] [one-camera]" )
00273 {
00274     test_r200_streaming({{RS_STREAM_DEPTH, 320, 240, RS_FORMAT_Z16, 30}});
00275 }
00276 
00277 TEST_CASE( "R200 streams 480x360 depth (90 fps)", "[live] [r200] [one-camera]" )
00278 {
00279     test_r200_streaming({{RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 90}});
00280 }
00281 
00282 TEST_CASE( "R200 streams 628x468 depth (90 fps)", "[live] [r200] [one-camera]" )
00283 {
00284     test_r200_streaming({{RS_STREAM_DEPTH, 628, 468, RS_FORMAT_Z16, 90}});
00285 }
00286 
00287 TEST_CASE( "R200 streams 320x240 depth (90 fps)", "[live] [r200] [one-camera]" )
00288 {
00289     test_r200_streaming({{RS_STREAM_DEPTH, 320, 240, RS_FORMAT_Z16, 90}});
00290 }
00291 
00293 // Color streaming tests //
00295 
00296 TEST_CASE( "R200 streams HD color", "[live] [r200] [one-camera]" )
00297 {
00298     test_r200_streaming({{RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_YUYV, 30}});
00299 }
00300 
00301 TEST_CASE( "R200 streams VGA color", "[live] [r200] [one-camera]" )
00302 {
00303     test_r200_streaming({{RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30}});
00304 }
00305 
00306 TEST_CASE( "R200 streams VGA color (60 fps)", "[live] [r200] [one-camera]" )
00307 {
00308     test_r200_streaming({{RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 60}});
00309 }
00310 
00311 TEST_CASE( "R200 streams 480x360 depth and HD color", "[live] [r200] [one-camera]" )
00312 {
00313     test_r200_streaming({{RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60},
00314                          {RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_YUYV, 30}});
00315 }
00316 
00317 TEST_CASE( "R200 streams 628x468 depth and HD color", "[live] [r200] [one-camera]" )
00318 {
00319     test_r200_streaming({{RS_STREAM_DEPTH, 628, 468, RS_FORMAT_Z16, 60},
00320                          {RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_YUYV, 30}});
00321 }
00322 
00323 TEST_CASE( "R200 streams 320x240 depth and HD color", "[live] [r200] [one-camera]" )
00324 {
00325     test_r200_streaming({{RS_STREAM_DEPTH, 320, 240, RS_FORMAT_Z16, 60},
00326                          {RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_YUYV, 30}});
00327 }
00328 
00329 TEST_CASE( "R200 streams 480x360 depth and VGA color", "[live] [r200] [one-camera]" )
00330 {
00331     test_r200_streaming({{RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60},
00332                          {RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30}});
00333 }
00334 
00335 TEST_CASE( "R200 streams 628x468 depth and VGA color", "[live] [r200] [one-camera]" )
00336 {
00337     test_r200_streaming({{RS_STREAM_DEPTH, 628, 468, RS_FORMAT_Z16, 60},
00338                          {RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30}});
00339 }
00340 
00341 TEST_CASE( "R200 streams 320x240 depth and VGA color", "[live] [r200] [one-camera]" )
00342 {
00343     test_r200_streaming({{RS_STREAM_DEPTH, 320, 240, RS_FORMAT_Z16, 60},
00344                          {RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30}});
00345 }
00346 
00347 TEST_CASE( "R200 streams 480x360 depth and VGA color (60 fps)", "[live] [r200] [one-camera]" )
00348 {
00349     test_r200_streaming({{RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60},
00350                          {RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 60}});
00351 }
00352 
00353 TEST_CASE( "R200 streams HD Raw10", "[live] [r200] [one-camera]" )
00354 {
00355     test_r200_streaming({{RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_RAW10, 30}});
00356 }
00357 
00359 // Infrared streaming tests //
00361 
00362 TEST_CASE( "R200 streams 640x480 infrared (left 8 bit)", "[live] [r200] [one-camera]" )
00363 {
00364     test_r200_streaming({{RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y8, 60}});
00365 }
00366 
00367 TEST_CASE( "R200 streams 640x480 infrared (left 16 bit)", "[live] [r200] [one-camera]" )
00368 {
00369     test_r200_streaming({{RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 60}});
00370 }
00371 
00372 TEST_CASE( "R200 streams 640x480 infrared (right 8 bit)", "[live] [r200] [one-camera]" )
00373 {
00374     test_r200_streaming({{RS_STREAM_INFRARED2, 640, 480, RS_FORMAT_Y8, 60}});
00375 }
00376 
00377 TEST_CASE( "R200 streams 640x480 infrared (right 16 bit)", "[live] [r200] [one-camera]" )
00378 {
00379     test_r200_streaming({{RS_STREAM_INFRARED2, 640, 480, RS_FORMAT_Y16, 60}});
00380 }
00381 
00382 TEST_CASE( "R200 streams 640x480 infrared (left+right 8 bit)", "[live] [r200] [one-camera]" )
00383 {
00384     test_r200_streaming({{RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y8, 60},
00385                          {RS_STREAM_INFRARED2, 640, 480, RS_FORMAT_Y8, 60}});
00386 }
00387 
00388 TEST_CASE( "R200 streams 640x480 infrared (left+right 16 bit)", "[live] [r200] [one-camera]" )
00389 {
00390     test_r200_streaming({{RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 60},
00391                          {RS_STREAM_INFRARED2, 640, 480, RS_FORMAT_Y16, 60}});
00392 }
00393 
00394 TEST_CASE( "R200 streams 480x360 depth and 492x372 infrared (left+right 16 bit)", "[live] [r200] [one-camera]" )
00395 {
00396     test_r200_streaming({{RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60},
00397                          {RS_STREAM_INFRARED, 492, 372, RS_FORMAT_Y16, 60},
00398                          {RS_STREAM_INFRARED2, 492, 372, RS_FORMAT_Y16, 60}});
00399 }
00400 
00401 TEST_CASE( "R200 streams 480x360 depth, VGA color, and 492x372 infrared", "[live] [r200] [one-camera]" )
00402 {
00403     test_r200_streaming({{RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60},
00404                          {RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30},
00405                          {RS_STREAM_INFRARED, 492, 372, RS_FORMAT_Y16, 60},
00406                          {RS_STREAM_INFRARED2, 492, 372, RS_FORMAT_Y16, 60}});
00407 }
00408 
00409 TEST_CASE( "R200 streams 628x468 depth, VGA color, and 640x480 infrared", "[live] [r200] [one-camera]" )
00410 {
00411     test_r200_streaming({{RS_STREAM_DEPTH, 628, 468, RS_FORMAT_Z16, 60},
00412                          {RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30},
00413                          {RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 60},
00414                          {RS_STREAM_INFRARED2, 640, 480, RS_FORMAT_Y16, 60}});
00415 }
00416 
00417 TEST_CASE( "R200 streams 320x240 depth, VGA color, and 332x252 infrared", "[live] [r200] [one-camera]" )
00418 {
00419     test_r200_streaming({{RS_STREAM_DEPTH, 320, 240, RS_FORMAT_Z16, 60},
00420                          {RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30},
00421                          {RS_STREAM_INFRARED, 332, 252, RS_FORMAT_Y16, 60},
00422                          {RS_STREAM_INFRARED2, 332, 252, RS_FORMAT_Y16, 60}});
00423 }
00424 
00426 // Cropped and padded modes //
00428 
00429 TEST_CASE( "R200 streams 640x480 depth and infrared", "[live] [r200] [one-camera]" )
00430 {
00431     test_r200_streaming({{RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60},
00432                          {RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y8, 60},
00433                          {RS_STREAM_INFRARED2, 640, 480, RS_FORMAT_Y8, 60}});
00434 }
00435 
00436 TEST_CASE( "R200 streams 628x468 depth and infrared", "[live] [r200] [one-camera]" )
00437 {
00438     test_r200_streaming({{RS_STREAM_DEPTH, 628, 468, RS_FORMAT_Z16, 60},
00439                          {RS_STREAM_INFRARED, 628, 468, RS_FORMAT_Y8, 60},
00440                          {RS_STREAM_INFRARED2, 628, 468, RS_FORMAT_Y8, 60}});
00441 }
00442 
00443 TEST_CASE( "R200 streams 492x372 depth and infrared", "[live] [r200] [one-camera]" )
00444 {
00445     test_r200_streaming({{RS_STREAM_DEPTH, 492, 372, RS_FORMAT_Z16, 60},
00446                          {RS_STREAM_INFRARED, 492, 372, RS_FORMAT_Y8, 60},
00447                          {RS_STREAM_INFRARED2, 492, 372, RS_FORMAT_Y8, 60}});
00448 }
00449 
00450 TEST_CASE( "R200 streams 480x360 depth and infrared", "[live] [r200] [one-camera]" )
00451 {
00452     test_r200_streaming({{RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60},
00453                          {RS_STREAM_INFRARED, 480, 360, RS_FORMAT_Y8, 60},
00454                          {RS_STREAM_INFRARED2, 480, 360, RS_FORMAT_Y8, 60}});
00455 }
00456 
00457 TEST_CASE( "R200 streams 332x252 depth and infrared", "[live] [r200] [one-camera]" )
00458 {
00459     test_r200_streaming({{RS_STREAM_DEPTH, 332, 252, RS_FORMAT_Z16, 60},
00460                          {RS_STREAM_INFRARED, 332, 252, RS_FORMAT_Y8, 60},
00461                          {RS_STREAM_INFRARED2, 332, 252, RS_FORMAT_Y8, 60}});
00462 }
00463 
00464 TEST_CASE( "R200 streams 320x240 depth and infrared", "[live] [r200] [one-camera]" )
00465 {
00466     test_r200_streaming({{RS_STREAM_DEPTH, 320, 240, RS_FORMAT_Z16, 60},
00467                          {RS_STREAM_INFRARED, 320, 240, RS_FORMAT_Y8, 60},
00468                          {RS_STREAM_INFRARED2, 320, 240, RS_FORMAT_Y8, 60}});
00469 }
00470 
00472 // Options //
00474 
00475 enum { BEFORE_START_DEVICE = 1, AFTER_START_DEVICE = 2 };
00476 inline void test_r200_option(rs_option option, std::initializer_list<int> values, int when)
00477 {
00478     safe_context ctx;   
00479     REQUIRE(rs_get_device_count(ctx, require_no_error()) == 1);
00480 
00481     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00482     REQUIRE(dev != nullptr);
00483     REQUIRE(rs_get_device_name(dev, require_no_error()) == std::string("Intel RealSense R200"));
00484 
00485     if(when & BEFORE_START_DEVICE)
00486     {
00487         test_option(dev, option, values, {});
00488     }
00489 
00490     if(when & AFTER_START_DEVICE)
00491     {
00492         rs_enable_stream_preset(dev, RS_STREAM_DEPTH, RS_PRESET_BEST_QUALITY, require_no_error());
00493         rs_start_device(dev, rs_source::RS_SOURCE_VIDEO, require_no_error());
00494 
00495         // Currently, setting/getting options immediately after streaming frequently raises hardware errors
00496         // todo - Internally block or retry failed calls within the first few seconds after streaming
00497         std::this_thread::sleep_for(std::chrono::seconds(1));
00498         test_option(dev, option, values, {});
00499     }
00500 }
00501 
00502 TEST_CASE( "R200 supports RS_OPTION_R200_LR_AUTO_EXPOSURE_ENABLED", "[live] [r200]" )
00503 {
00504     test_r200_option(RS_OPTION_R200_LR_AUTO_EXPOSURE_ENABLED, {0, 1}, BEFORE_START_DEVICE | AFTER_START_DEVICE);
00505 }
00506 
00507 TEST_CASE( "R200 supports RS_OPTION_R200_LR_GAIN", "[live] [r200]" )
00508 {
00509     test_r200_option(RS_OPTION_R200_LR_GAIN, {100, 200, 400, 800, 1600}, BEFORE_START_DEVICE | AFTER_START_DEVICE); // Gain percentage   
00510 }
00511 
00512 TEST_CASE( "R200 supports RS_OPTION_R200_LR_EXPOSURE", "[live] [r200]" )
00513 {
00514     test_r200_option(RS_OPTION_R200_LR_EXPOSURE, {40, 80, 160}, BEFORE_START_DEVICE | AFTER_START_DEVICE); // Tenths of milliseconds   
00515 }
00516 
00517 // Note: The R200 firmware has some complications regarding emitter state before the device has been started
00518 // The emitter will never be on if the device is not streaming, but the firmware will remember and respect any
00519 // specified preferences for emitter enabled that are specified prior to streaming.
00520 
00521 TEST_CASE( "R200 emitter defaults to off if depth is not enabled/streamed", "[live] [r200]" )
00522 {
00523     safe_context ctx;   
00524     REQUIRE(rs_get_device_count(ctx, require_no_error()) == 1);
00525 
00526     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00527     REQUIRE(dev != nullptr);
00528     REQUIRE(rs_get_device_name(dev, require_no_error()) == std::string("Intel RealSense R200"));
00529 
00530     // Emitter enabled defaults to false
00531     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 0);
00532 
00533     // Enabling non-depth streams does not change the emitter's state
00534     rs_enable_stream_preset(dev, RS_STREAM_COLOR, RS_PRESET_BEST_QUALITY, require_no_error());
00535     rs_enable_stream_preset(dev, RS_STREAM_INFRARED, RS_PRESET_BEST_QUALITY, require_no_error());
00536     rs_enable_stream_preset(dev, RS_STREAM_INFRARED2, RS_PRESET_BEST_QUALITY, require_no_error());
00537     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 0);
00538 
00539     // Starting the device does not change the emitter's state
00540     rs_start_device(dev, rs_source::RS_SOURCE_VIDEO, require_no_error());
00541     std::this_thread::sleep_for(std::chrono::seconds(1));
00542     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 0);
00543 }
00544 
00545 TEST_CASE( "R200 emitter defaults to on if depth is enabled/streamed", "[live] [r200]" )
00546 {
00547     safe_context ctx;   
00548     REQUIRE(rs_get_device_count(ctx, require_no_error()) == 1);
00549 
00550     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00551     REQUIRE(dev != nullptr);
00552     REQUIRE(rs_get_device_name(dev, require_no_error()) == std::string("Intel RealSense R200"));
00553 
00554     // Emitter enabled defaults to false
00555     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 0);
00556 
00557     // Enabling depth stream causes the emitter to be enabled
00558     rs_enable_stream_preset(dev, RS_STREAM_DEPTH, RS_PRESET_BEST_QUALITY, require_no_error());
00559     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 1);
00560 
00561     // Starting the device does not change the emitter's state
00562     rs_start_device(dev, rs_source::RS_SOURCE_VIDEO, require_no_error());
00563     std::this_thread::sleep_for(std::chrono::seconds(1));
00564     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 1);
00565 }
00566 
00567 TEST_CASE( "R200 emitter can be enabled even if depth is not enabled/streamed", "[live] [r200]" )
00568 {
00569     safe_context ctx;   
00570     REQUIRE(rs_get_device_count(ctx, require_no_error()) == 1);
00571 
00572     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00573     REQUIRE(dev != nullptr);
00574     REQUIRE(rs_get_device_name(dev, require_no_error()) == std::string("Intel RealSense R200"));
00575 
00576     // Emitter enabled defaults to false
00577     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 0);
00578 
00579     // Enabling non-depth streams does not change the emitter's state
00580     rs_enable_stream_preset(dev, RS_STREAM_COLOR, RS_PRESET_BEST_QUALITY, require_no_error());
00581     rs_enable_stream_preset(dev, RS_STREAM_INFRARED, RS_PRESET_BEST_QUALITY, require_no_error());
00582     rs_enable_stream_preset(dev, RS_STREAM_INFRARED2, RS_PRESET_BEST_QUALITY, require_no_error());
00583     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 0);
00584 
00585     // The emitter can be turned on even though no depth is streamed
00586     rs_set_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, 1, require_no_error());
00587     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 1);
00588 
00589     // Starting the device does not change the emitter's state
00590     rs_start_device(dev, rs_source::RS_SOURCE_VIDEO, require_no_error());
00591     std::this_thread::sleep_for(std::chrono::seconds(1));
00592     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 1);
00593 }
00594 
00595 TEST_CASE( "R200 emitter can be turned off even if depth is enabled/streamed", "[live] [r200]" )
00596 {
00597     safe_context ctx;   
00598     REQUIRE(rs_get_device_count(ctx, require_no_error()) == 1);
00599 
00600     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00601     REQUIRE(dev != nullptr);
00602     REQUIRE(rs_get_device_name(dev, require_no_error()) == std::string("Intel RealSense R200"));
00603 
00604     // Emitter enabled defaults to false
00605     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 0);
00606 
00607     // Enabling depth stream causes the emitter to be enabled
00608     rs_enable_stream_preset(dev, RS_STREAM_DEPTH, RS_PRESET_BEST_QUALITY, require_no_error());
00609     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 1);
00610 
00611     // The emitter can be turned off even though depth is streamed
00612     rs_set_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, 0, require_no_error());
00613     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 0);
00614 
00615     // Starting the device does not change the emitter's state
00616     rs_start_device(dev, rs_source::RS_SOURCE_VIDEO, require_no_error());
00617     std::this_thread::sleep_for(std::chrono::seconds(1));
00618     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 0);
00619 }
00620 
00621 TEST_CASE( "R200 emitter can be turned on and off after streaming has begun", "[live] [r200]" )
00622 {
00623     safe_context ctx;   
00624     REQUIRE(rs_get_device_count(ctx, require_no_error()) == 1);
00625 
00626     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00627     REQUIRE(dev != nullptr);
00628     REQUIRE(rs_get_device_name(dev, require_no_error()) == std::string("Intel RealSense R200"));
00629 
00630     // The emitter defaults to on when depth is streamed
00631     rs_enable_stream_preset(dev, RS_STREAM_DEPTH, RS_PRESET_BEST_QUALITY, require_no_error());
00632     rs_start_device(dev, rs_source::RS_SOURCE_VIDEO, require_no_error());
00633     std::this_thread::sleep_for(std::chrono::seconds(1));
00634     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 1);
00635 
00636     // The emitter can be turned off
00637     rs_set_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, 0, require_no_error());
00638     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 0);
00639 
00640     // The emitter can be turned back on
00641     rs_set_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, 1, require_no_error());
00642     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_EMITTER_ENABLED, require_no_error()) == 1);
00643 }
00644 
00645 TEST_CASE( "R200 supports RS_OPTION_R200_DEPTH_UNITS", "[live] [r200]" )
00646 {
00647     safe_context ctx;   
00648     REQUIRE(rs_get_device_count(ctx, require_no_error()) == 1);
00649 
00650     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00651     REQUIRE(dev != nullptr);
00652     REQUIRE(rs_get_device_name(dev, require_no_error()) == std::string("Intel RealSense R200"));
00653 
00654     // By default, depth unit is 1000 micrometers (1 mm)
00655     REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_DEPTH_UNITS, require_no_error()) == 1000);
00656     REQUIRE(rs_get_device_depth_scale(dev, require_no_error()) == 0.001f);
00657 
00658     for(int value : {100, 500, 1000, 2000, 10000})
00659     {
00660         // Set depth units (specified in micrometers) and verify that depth scale (specified in meters) changes appropriately
00661         rs_set_device_option(dev, RS_OPTION_R200_DEPTH_UNITS, value, require_no_error());
00662         REQUIRE(rs_get_device_option(dev, RS_OPTION_R200_DEPTH_UNITS, require_no_error()) == value);
00663         REQUIRE(rs_get_device_depth_scale(dev, require_no_error()) == (float)value/1000000);
00664     }
00665 }
00666 
00667 TEST_CASE( "R200 supports RS_OPTION_R200_DEPTH_CLAMP_MIN", "[live] [r200]" )
00668 {
00669     test_r200_option(RS_OPTION_R200_DEPTH_CLAMP_MIN, {0, 500, 1000, 2000}, BEFORE_START_DEVICE);
00670 }
00671 
00672 TEST_CASE( "R200 supports RS_OPTION_R200_DEPTH_CLAMP_MAX", "[live] [r200]" )
00673 {
00674     test_r200_option(RS_OPTION_R200_DEPTH_CLAMP_MAX, {500, 1000, 2000, USHRT_MAX}, BEFORE_START_DEVICE);
00675 }
00676 
00678 // Stop, reconfigure, and restart tests //
00680 
00681 TEST_CASE( "a single R200 can stream a variety of reasonable streaming mode combinations", "[live] [r200] [one-camera]" )
00682 {
00683     safe_context ctx;
00684 
00685     SECTION( "exactly one device is connected" )
00686     {
00687         int device_count = rs_get_device_count(ctx, require_no_error());
00688         REQUIRE(device_count == 1);
00689     }
00690 
00691     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00692     REQUIRE(dev != nullptr);
00693 
00694     SECTION( "device name is Intel RealSense R200" )
00695     {
00696         const char * name = rs_get_device_name(dev, require_no_error());
00697         REQUIRE(name == std::string("Intel RealSense R200"));
00698     }
00699 
00700     SECTION( "streaming is possible in some reasonable configurations" )
00701     {
00702         SECTION( "streaming DEPTH 480, 360, RS_FORMAT_Z16, 60" )
00703         {
00704             test_streaming(dev, {
00705                 {RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60}
00706             });
00707         }
00708 
00709         SECTION( "streaming [DEPTH,480,360,Z16,60] [COLOR,480,360,RGB8,60]" )
00710         {
00711             test_streaming(dev, {
00712                 {RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60},
00713                 {RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60}
00714             });
00715         }
00716 
00717         SECTION( "streaming [DEPTH,480,360,Z16,60] [IR,480,360,Y8,60]" )
00718         {
00719             test_streaming(dev, {
00720                 {RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60},
00721                 {RS_STREAM_INFRARED, 480, 360, RS_FORMAT_Y8, 60}
00722             });
00723         }
00724 
00725         SECTION( "streaming [IR,492,372,Y16,60] [IR2,492,372,Y16,60]" )
00726         {
00727             test_streaming(dev, {
00728                 {RS_STREAM_INFRARED, 492, 372, RS_FORMAT_Y16, 60},
00729                 {RS_STREAM_INFRARED2, 492, 372, RS_FORMAT_Y16, 60}
00730             });
00731         }
00732 
00733         SECTION( "streaming [DEPTH,480,360,Z16,60] [COLOR,640,480,RGB8,60] [IR,480,360,Y8,60] [IR2,480,360,Y8,60]" )
00734         {
00735             test_streaming(dev, {
00736                 {RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60},
00737                 {RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60},
00738                 {RS_STREAM_INFRARED, 480, 360, RS_FORMAT_Y8, 60},
00739                 {RS_STREAM_INFRARED2, 480, 360, RS_FORMAT_Y8, 60}
00740             });
00741         }
00742     }
00743 }
00744 
00745 TEST_CASE( "streaming five configurations sequentionally", "[live] [r200] [one-camera]" )
00746 {
00747     safe_context ctx;
00748 
00749     int device_count = rs_get_device_count(ctx, require_no_error());
00750     REQUIRE(device_count == 1);
00751 
00752     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00753     REQUIRE(dev != nullptr);
00754 
00755     const char * name = rs_get_device_name(dev, require_no_error());
00756     REQUIRE(name == std::string("Intel RealSense R200"));
00757 
00758     test_streaming(dev, {
00759         {RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60}
00760     });
00761 
00762     test_streaming(dev, {
00763         {RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60},
00764         {RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60}
00765     });
00766 
00767     test_streaming(dev, {
00768         {RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60}
00769     });
00770 
00771     test_streaming(dev, {
00772         {RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60},
00773         {RS_STREAM_INFRARED, 480, 360, RS_FORMAT_Y8, 60}
00774     });
00775 
00776     test_streaming(dev, {
00777         {RS_STREAM_INFRARED, 492, 372, RS_FORMAT_Y16, 60},
00778         {RS_STREAM_INFRARED2, 492, 372, RS_FORMAT_Y16, 60}
00779     });
00780 
00781     test_streaming(dev, {
00782         {RS_STREAM_INFRARED, 492, 372, RS_FORMAT_Y16, 60},
00783         {RS_STREAM_INFRARED2, 492, 372, RS_FORMAT_Y16, 60}
00784     });
00785 
00786     test_streaming(dev, {
00787         {RS_STREAM_DEPTH, 480, 360, RS_FORMAT_Z16, 60},
00788         {RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60},
00789         {RS_STREAM_INFRARED, 480, 360, RS_FORMAT_Y8, 60},
00790         {RS_STREAM_INFRARED2, 480, 360, RS_FORMAT_Y8, 60}
00791     });
00792 
00793 }
00794 
00795 #endif /* !defined(MAKEFILE) */


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Tue Jun 25 2019 19:54:39