unit-tests-live-sr300.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 SR300 camera //
00007 
00008 #if !defined(MAKEFILE) || ( defined(LIVE_TEST) && defined(SR300_TEST) )
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 #include <algorithm>
00018 
00019 TEST_CASE( "SR300 metadata enumerates correctly", "[live] [sr300]" )
00020 {
00021     // Require at least one device to be plugged in
00022     safe_context ctx;
00023     const int device_count = rs_get_device_count(ctx, require_no_error());
00024     REQUIRE(device_count > 0);
00025 
00026     // For each device
00027     for(int i=0; i<device_count; ++i)
00028     {
00029         rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00030         REQUIRE(dev != nullptr);
00031 
00032         SECTION( "device name is Intel RealSense SR300" )
00033         {
00034             const char * name = rs_get_device_name(dev, require_no_error());
00035             REQUIRE(name == std::string("Intel RealSense SR300"));
00036         }
00037     }
00038 }
00039 
00040 TEST_CASE( "SR300 devices support all required options", "[live] [sr300]" )
00041 {
00042     // Require at least one device to be plugged in
00043     safe_context ctx;
00044     const int device_count = rs_get_device_count(ctx, require_no_error());
00045     REQUIRE(device_count > 0);
00046 
00047     // For each device
00048     for(int i=0; i<device_count; ++i)
00049     {
00050         rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00051         REQUIRE(dev != nullptr);
00052 
00053         SECTION( "device supports standard picture options and SR300 extension options, and nothing else" )
00054         {
00055             std::vector<rs_option> supported_options{
00056                 RS_OPTION_COLOR_BACKLIGHT_COMPENSATION,
00057                 RS_OPTION_COLOR_BRIGHTNESS,
00058                 RS_OPTION_COLOR_CONTRAST,
00059                 RS_OPTION_COLOR_EXPOSURE,
00060                 RS_OPTION_COLOR_GAIN,
00061                 RS_OPTION_COLOR_GAMMA,
00062                 RS_OPTION_COLOR_HUE,
00063                 RS_OPTION_COLOR_SATURATION,
00064                 RS_OPTION_COLOR_SHARPNESS,
00065                 RS_OPTION_COLOR_WHITE_BALANCE,
00066                 RS_OPTION_COLOR_ENABLE_AUTO_EXPOSURE,
00067                 RS_OPTION_COLOR_ENABLE_AUTO_WHITE_BALANCE,
00068                 RS_OPTION_F200_LASER_POWER,
00069                 RS_OPTION_F200_ACCURACY,
00070                 RS_OPTION_F200_MOTION_RANGE,
00071                 RS_OPTION_F200_FILTER_OPTION,
00072                 RS_OPTION_F200_CONFIDENCE_THRESHOLD,                
00073                 RS_OPTION_SR300_AUTO_RANGE_ENABLE_MOTION_VERSUS_RANGE,
00074                 RS_OPTION_SR300_AUTO_RANGE_ENABLE_LASER,
00075                 RS_OPTION_SR300_AUTO_RANGE_MIN_MOTION_VERSUS_RANGE,
00076                 RS_OPTION_SR300_AUTO_RANGE_MAX_MOTION_VERSUS_RANGE,
00077                 RS_OPTION_SR300_AUTO_RANGE_START_MOTION_VERSUS_RANGE,
00078                 RS_OPTION_SR300_AUTO_RANGE_MIN_LASER,
00079                 RS_OPTION_SR300_AUTO_RANGE_MAX_LASER,
00080                 RS_OPTION_SR300_AUTO_RANGE_START_LASER,
00081                 RS_OPTION_SR300_AUTO_RANGE_UPPER_THRESHOLD,
00082                 RS_OPTION_SR300_AUTO_RANGE_LOWER_THRESHOLD,
00083                 RS_OPTION_FRAMES_QUEUE_SIZE,
00084                 RS_OPTION_HARDWARE_LOGGER_ENABLED
00085             };
00086 
00087             for(int i=0; i<RS_OPTION_COUNT; ++i)
00088             {
00089                 if(std::find(std::begin(supported_options), std::end(supported_options), i) != std::end(supported_options))
00090                 {
00091                     REQUIRE(rs_device_supports_option(dev, (rs_option)i, require_no_error()) == 1);
00092                 }
00093                 else
00094                 {
00095                     REQUIRE(rs_device_supports_option(dev, (rs_option)i, require_no_error()) == 0);
00096                 }
00097             }
00098         }
00099     }
00100 }
00101 
00103 // Calibration information tests //
00105 
00106 TEST_CASE( "SR300 device extrinsics are within expected parameters", "[live] [sr300]" )
00107 {
00108     // Require at least one device to be plugged in
00109     safe_context ctx;
00110     const int device_count = rs_get_device_count(ctx, require_no_error());
00111     REQUIRE(device_count > 0);
00112 
00113     // For each device
00114     for(int i=0; i<device_count; ++i)
00115     {
00116         rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00117         REQUIRE(dev != nullptr);
00118 
00119         SECTION( "no extrinsic transformation between DEPTH and INFRARED" )
00120         {
00121             rs_extrinsics extrin;
00122             rs_get_device_extrinsics(dev, RS_STREAM_DEPTH, RS_STREAM_INFRARED, &extrin, require_no_error());
00123 
00124             require_identity_matrix(extrin.rotation);
00125             require_zero_vector(extrin.translation);
00126         }
00127 
00128         // TODO: Expected depth/color baseline
00129 
00130         SECTION( "depth scale is 0.000125 (by default)" )
00131         {
00132             REQUIRE( rs_get_device_depth_scale(dev, require_no_error()) == Approx(0.000125f) );
00133         }
00134     }
00135 }
00136 
00138 // Streaming tests //
00140 
00141 inline void test_sr300_streaming(std::initializer_list<stream_mode> modes)
00142 {
00143     safe_context ctx;
00144     REQUIRE(rs_get_device_count(ctx, require_no_error()) == 1);
00145 
00146     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00147     REQUIRE(dev != nullptr);
00148     REQUIRE(rs_get_device_name(dev, require_no_error()) == std::string("Intel RealSense SR300"));
00149 
00150     test_streaming(dev, modes);
00151 }
00153 // Color streaming tests //
00155 
00156 TEST_CASE("SR300 streams 1080p color", "[live] [sr300] [one-camera]")
00157 {
00158     test_sr300_streaming({ { RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_YUYV, 30 } });
00159 }
00160 
00161 TEST_CASE("SR300 streams 720p color", "[live] [sr300] [one-camera]")
00162 {
00163     test_sr300_streaming({ { RS_STREAM_COLOR, 1280, 720, RS_FORMAT_YUYV, 30 } });
00164 }
00165 
00166 TEST_CASE("SR300 streams VGA color", "[live] [sr300] [one-camera]")
00167 {
00168     test_sr300_streaming({ { RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30 } });
00169 }
00170 
00171 TEST_CASE("SR300 streams 720p color (60 fps)", "[live] [sr300] [one-camera]")
00172 {
00173     test_sr300_streaming({ { RS_STREAM_COLOR, 1280, 720, RS_FORMAT_YUYV, 60 } });
00174 }
00175 
00176 TEST_CASE("SR300 streams VGA color (60 fps)", "[live] [sr300] [one-camera]")
00177 {
00178     test_sr300_streaming({ { RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 60 } });
00179 }
00180 
00181 TEST_CASE("SR300 streams VGA depth and HD color", "[live] [sr300] [one-camera]")
00182 {
00183     test_sr300_streaming({ { RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60 },
00184     { RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_YUYV, 30 } });
00185 }
00186 
00187 TEST_CASE("SR300 streams HVGA depth and HD color", "[live] [sr300] [one-camera]")
00188 {
00189     test_sr300_streaming({ { RS_STREAM_DEPTH, 640, 240, RS_FORMAT_Z16, 60 },
00190     { RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_YUYV, 30 } });
00191 }
00192 
00193 TEST_CASE("SR300 streams VGA depth and VGA color", "[live] [sr300] [one-camera]")
00194 {
00195     test_sr300_streaming({ { RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60 },
00196     { RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30 } });
00197 }
00198 
00199 TEST_CASE("SR300 streams HVGA depth and VGA color", "[live] [sr300] [one-camera]")
00200 {
00201     test_sr300_streaming({ { RS_STREAM_DEPTH, 640, 240, RS_FORMAT_Z16, 60 },
00202     { RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30 } });
00203 }
00204 
00205 TEST_CASE("SR300 streams VGA depth and VGA color (60 fps)", "[live] [sr300] [one-camera]")
00206 {
00207     test_sr300_streaming({ { RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60 },
00208     { RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 60 } });
00209 }
00210 
00211 TEST_CASE("SR300 streams HVGA depth and VGA color (60 fps)", "[live] [sr300] [one-camera]")
00212 {
00213     test_sr300_streaming({ { RS_STREAM_DEPTH, 640, 240, RS_FORMAT_Z16, 60 },
00214     { RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 60 } });
00215 }
00216 
00218 // Depth streaming tests //
00220 
00221 TEST_CASE("SR300 depth stream (Z16)", "[live] [sr300] [one-camera]")
00222 {
00223     SECTION("SR300 streams depth 640x480 (VGA), [10,30,60] fps")
00224     {
00225         for (auto & fps : { 10,30,60 })
00226         {
00227             INFO("Testing " << fps << " fps")
00228             test_sr300_streaming({ { RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, fps } });
00229         }
00230     }
00231 
00232     SECTION("SR300 streams depth 640x240 (HVGA), [10,30,60,110] fps")
00233     {
00234         for (auto & fps : { 10,30,60,110 })
00235         {
00236             INFO("Testing " << fps << " fps")
00237             test_sr300_streaming({ { RS_STREAM_DEPTH, 640, 240, RS_FORMAT_Z16, fps } });
00238         }
00239     }
00240 }
00241 
00243 // Infrared streaming tests //
00245 
00246 TEST_CASE( "SR300 infrared stream (Y16)", "[live] [sr300] [one-camera]" )
00247 {
00248     SECTION("SR300 streams infrared 640x240 depth (VGA), [30,60,120,200] fps")
00249     {
00250         for (auto & fps : { 30,60,120,200 })
00251         {
00252             INFO("Testing " << fps << " fps")
00253             test_sr300_streaming({ { RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, fps } });
00254         }
00255     }
00256 }
00257 
00259 // Multiple-stream configurations tests //
00261 
00262 TEST_CASE( "SR300 streams 640x480 depth and infrared", "[live] [sr300] [one-camera]" )
00263 {
00264     test_sr300_streaming({{RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60},
00265                           {RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 60}});
00266 }
00267 
00268 TEST_CASE( "SR300 streams 640x240 depth and infrared", "[live] [sr300] [one-camera]" )
00269 {
00270     test_sr300_streaming({{RS_STREAM_DEPTH, 640, 240, RS_FORMAT_Z16, 60},
00271                           {RS_STREAM_INFRARED, 640, 240, RS_FORMAT_Y16, 60}});
00272 }
00273 
00274 TEST_CASE( "SR300 streams 640x240 depth and infrared (110 fps)", "[live] [sr300] [one-camera]" )
00275 {
00276     test_sr300_streaming({{RS_STREAM_DEPTH, 640, 240, RS_FORMAT_Z16, 110},
00277                           {RS_STREAM_INFRARED, 640, 240, RS_FORMAT_Y16, 110}});
00278 }
00279 
00280 TEST_CASE( "SR300 streams 640x480 depth, infrared, and color", "[live] [sr300] [one-camera]" )
00281 {
00282     test_sr300_streaming({{RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60},
00283                           {RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 60},
00284                           {RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60}});
00285 }
00286 
00287 TEST_CASE( "SR300 streams 640x240 depth and infrared (110 fps), and 1080P color (30 fps)", "[live] [sr300] [one-camera]" )
00288 {
00289     test_sr300_streaming({{RS_STREAM_DEPTH, 640, 240, RS_FORMAT_Z16, 110},
00290                           {RS_STREAM_INFRARED, 640, 240, RS_FORMAT_Y16, 110},
00291                           {RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_RGB8, 30}});
00292 }
00293 
00294 TEST_CASE( "SR300 streams 640x480 infrared (200 fps), and VGA color (60 fps)", "[live] [sr300] [one-camera]" )
00295 {
00296     test_sr300_streaming({{RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 200},
00297                           {RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60}});
00298 }
00299 
00300 TEST_CASE( "SR300 streams 640x480 infrared (200 fps), and 1080P color (30 fps)", "[live] [sr300] [one-camera]" )
00301 {
00302     test_sr300_streaming({{RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 200},
00303                           {RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_RGB8, 30}});
00304 }
00305 
00307 // Options //
00309 
00310 enum { BEFORE_START_DEVICE = 1, AFTER_START_DEVICE = 2 };
00311 inline void test_sr300_option(rs_option option, std::initializer_list<int> values, int when)
00312 {
00313     safe_context ctx;
00314     REQUIRE(rs_get_device_count(ctx, require_no_error()) == 1);
00315 
00316     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00317     REQUIRE(dev != nullptr);
00318     REQUIRE(rs_get_device_name(dev, require_no_error()) == std::string("Intel RealSense SR300"));
00319 
00320     if(when & BEFORE_START_DEVICE)
00321     {
00322         test_option(dev, option, values, {});
00323     }
00324 
00325     if(when & AFTER_START_DEVICE)
00326     {
00327         rs_enable_stream_preset(dev, RS_STREAM_DEPTH, RS_PRESET_BEST_QUALITY, require_no_error());
00328         rs_start_device(dev, require_no_error());
00329 
00330         // Currently, setting/getting options immediately after streaming frequently raises hardware errors
00331         // todo - Internally block or retry failed calls within the first few seconds after streaming
00332         std::this_thread::sleep_for(std::chrono::seconds(1));
00333         test_option(dev, option, values, {});
00334     }
00335 }
00336 
00337 TEST_CASE( "SR300 supports RS_OPTION_F200_LASER_POWER", "[live] [sr300]" )
00338 {
00339     test_sr300_option(RS_OPTION_F200_LASER_POWER, {0, 1, 2, 4, 8, 15}, AFTER_START_DEVICE);
00340 }
00341 
00342 TEST_CASE( "SR300 supports RS_OPTION_F200_ACCURACY", "[live] [sr300]" )
00343 {
00344     test_sr300_option(RS_OPTION_F200_ACCURACY, { 1, 2, 3}, AFTER_START_DEVICE);
00345 }
00346 
00347 TEST_CASE( "SR300 supports RS_OPTION_F200_MOTION_RANGE", "[live] [sr300]" )
00348 {
00349     test_sr300_option(RS_OPTION_F200_MOTION_RANGE, {0, 1, 8, 25, 50, 100}, AFTER_START_DEVICE);
00350 }
00351 
00352 TEST_CASE( "SR300 supports RS_OPTION_F200_FILTER_OPTION", "[live] [sr300]" )
00353 {
00354     test_sr300_option(RS_OPTION_F200_FILTER_OPTION, {0, 1, 2, 3, 4, 5, 6, 7}, AFTER_START_DEVICE);
00355 }
00356 
00357 TEST_CASE( "SR300 supports RS_OPTION_F200_CONFIDENCE_THRESHOLD", "[live] [sr300]" )
00358 {
00359     test_sr300_option(RS_OPTION_F200_CONFIDENCE_THRESHOLD, {0, 1, 2, 4, 8, 15}, AFTER_START_DEVICE);
00360 }
00361 
00363 // Stop, reconfigure, and restart tests //
00365 
00366 TEST_CASE( "a single SR300 can stream a variety of reasonable streaming mode combinations", "[live] [sr300] [one-camera]" )
00367 {
00368     safe_context ctx;
00369 
00370     SECTION( "exactly one device is connected" )
00371     {
00372         int device_count = rs_get_device_count(ctx, require_no_error());
00373         REQUIRE(device_count == 1);
00374     }
00375 
00376     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00377     REQUIRE(dev != nullptr);
00378 
00379     SECTION( "device name is Intel RealSense SR300" )
00380     {
00381         const char * name = rs_get_device_name(dev, require_no_error());
00382         REQUIRE(name == std::string("Intel RealSense SR300"));
00383     }
00384 
00385     SECTION( "streaming is possible in some reasonable configurations" )
00386     {
00387         INFO("Streaming Z16, 60 fps");
00388         test_streaming(dev, {
00389             {RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60}
00390         });
00391 
00392         INFO("Streaming Depth + Color 60 fps");
00393         test_streaming(dev, {
00394             {RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60},
00395             {RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60}
00396         });
00397 
00398         INFO("Streaming Depth + Infrared 60 fps");
00399         test_streaming(dev, {
00400             {RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60},
00401             {RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 60}
00402         });
00403 
00404         INFO("Streaming Depth + Infrared + Color 60 fps");
00405         test_streaming(dev, {
00406             {RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60},
00407             {RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60},
00408             {RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 60}
00409         });
00410     }
00411 }
00412 
00413 inline void test_options(rs_device * device, rs_option* option_list, size_t options, std::vector<double> good_values, std::vector<double> bad_values, std::vector<double> &ret_values, const std::string & expected_success_msg, const std::string & expected_error_msg, bool bWrite)
00414 {    
00415     if (bWrite)
00416     {
00417         // Test setting good values
00418         if (good_values.size() == options)
00419         {
00420             if (expected_success_msg.size())
00421                 rs_set_device_options(device, option_list, (unsigned int)options, good_values.data(), require_error(expected_success_msg));
00422             else
00423                 rs_set_device_options(device, option_list, (unsigned int)options, good_values.data(), require_no_error());
00424         }
00425 
00426         if (bad_values.size() == options)
00427         {
00428             if (expected_error_msg.size())
00429                 rs_set_device_options(device, option_list, (unsigned int)options, bad_values.data(), require_error(expected_error_msg));
00430             else
00431                 rs_set_device_options(device, option_list, (unsigned int)options, bad_values.data(), require_no_error());
00432         }
00433     }
00434     else // Read command
00435     {
00436         std::vector<double> vretVal;
00437         vretVal.resize(options);
00438         if (expected_success_msg.size())
00439             rs_get_device_options(device, option_list, (unsigned int)options, vretVal.data(), require_error(expected_success_msg));
00440         else
00441             rs_get_device_options(device, option_list, (unsigned int)options, vretVal.data(), require_no_error());
00442 
00443         // Results to be returned
00444         ret_values = vretVal;
00445     }
00446 }
00447 
00448 inline void test_sr300_command(rs_device *dev, std::vector<rs_option> options_list,
00449     std::vector<double> good_values, std::vector<double> bad_values, std::vector<double>& ret_values, const std::string& expected_success_msg, const std::string& expected_error_msg, int when, bool write_cmd)
00450 {    
00451     REQUIRE(dev != nullptr);
00452 
00453     for (auto opt : options_list)
00454     {
00455         REQUIRE(rs_device_supports_option(dev, opt, require_no_error()) == 1);
00456     }
00457 
00458     if (when & BEFORE_START_DEVICE)
00459     {
00460         test_options(dev, options_list.data(), options_list.size(), good_values, bad_values, ret_values, expected_success_msg, expected_error_msg, write_cmd);
00461     }
00462 
00463     if (when & AFTER_START_DEVICE)
00464     {
00465         rs_enable_stream_preset(dev, RS_STREAM_DEPTH, RS_PRESET_BEST_QUALITY, require_no_error());
00466         rs_start_device(dev, require_no_error());
00467 
00468         // Currently, setting/getting options immediately after streaming frequently raises hardware errors
00469         // todo - Internally block or retry failed calls within the first few seconds after streaming
00470         std::this_thread::sleep_for(std::chrono::milliseconds(50));
00471         test_options(dev, options_list.data(), options_list.size(), good_values, bad_values, ret_values, expected_success_msg, expected_error_msg, write_cmd);
00472 
00473         std::this_thread::sleep_for(std::chrono::milliseconds(50));
00474         rs_stop_device(dev, require_no_error());
00475     }
00476 }
00477 
00478 #endif /* !defined(MAKEFILE) || ( defined(LIVE_TEST) && defined(SR300_TEST) ) */


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