From d2a32e0ec152d199515f8dad24789c2d8630df00 Mon Sep 17 00:00:00 2001 From: John Zhao Date: Thu, 20 Dec 2018 17:10:18 +0800 Subject: [PATCH] refactor(*): change stream request and params interfaces --- include/mynteye/api/api.h | 54 ++++---- include/mynteye/device/callbacks.h | 4 +- include/mynteye/device/device.h | 58 ++++---- include/mynteye/device/utils.h | 15 ++- include/mynteye/types.h | 109 ++++++--------- samples/api/camera.cc | 10 +- samples/api/get_depth_with_region.cc | 8 +- samples/device/camera.cc | 14 +- samples/tutorials/control/auto_exposure.cc | 9 +- samples/tutorials/control/framerate.cc | 13 +- samples/tutorials/control/imu_range.cc | 8 +- samples/tutorials/control/manual_exposure.cc | 9 +- samples/tutorials/data/get_depth.cc | 8 +- samples/tutorials/data/get_device_info.cc | 3 +- samples/tutorials/data/get_disparity.cc | 8 +- samples/tutorials/data/get_from_callbacks.cc | 8 +- samples/tutorials/data/get_img_params.cc | 10 +- samples/tutorials/data/get_imu.cc | 8 +- samples/tutorials/data/get_imu_params.cc | 3 +- samples/tutorials/data/get_points.cc | 8 +- samples/tutorials/data/get_stereo.cc | 8 +- .../tutorials/data/get_stereo_rectified.cc | 8 +- samples/tutorials/data/get_with_plugin.cc | 8 +- .../intermediate/get_depth_and_points.cc | 8 +- src/mynteye/api/api.cc | 70 ++++------ src/mynteye/api/synthetic.cc | 2 +- src/mynteye/device/channels.cc | 84 ++++++------ src/mynteye/device/channels.h | 16 +-- src/mynteye/device/config.cc | 82 ++++++++---- src/mynteye/device/config.h | 7 +- src/mynteye/device/device.cc | 126 +++++++++++------- src/mynteye/device/device_s.cc | 6 +- src/mynteye/device/device_s.h | 1 + src/mynteye/device/utils.cc | 42 +++++- src/mynteye/types.cc | 9 +- tools/dataset/record.cc | 11 +- tools/dataset/record2.cc | 11 +- 37 files changed, 491 insertions(+), 375 deletions(-) diff --git a/include/mynteye/api/api.h b/include/mynteye/api/api.h index 09cf15b..77f6bcf 100644 --- a/include/mynteye/api/api.h +++ b/include/mynteye/api/api.h @@ -28,6 +28,8 @@ MYNTEYE_BEGIN_NAMESPACE +struct DeviceInfo; + class Device; class Synthetic; @@ -93,25 +95,6 @@ class MYNTEYE_API API { explicit API(std::shared_ptr device); virtual ~API(); - /** - * Create the API instance. - * @return the API instance. - * @note This will call device::select() to select a device. - */ - static std::shared_ptr Create(Resolution res); - /** - * Create the API instance. - * @param device the selected device. - * @return the API instance. - */ - static std::shared_ptr Create( - std::shared_ptr device, Resolution res); - /** - * Create the API instance. - * @param device the selected device. - * @return the API instance. - */ - static std::shared_ptr Create(std::shared_ptr device); /** * Create the API instance. * @param argc the arg count. @@ -130,7 +113,7 @@ class MYNTEYE_API API { * @note This will init glog with args. */ static std::shared_ptr Create( - int argc, char *argv[], std::shared_ptr device); + int argc, char *argv[], const std::shared_ptr &device); /** * Get the model. @@ -155,9 +138,10 @@ class MYNTEYE_API API { bool Supports(const AddOns &addon) const; /** - * set the stream request. + * Log all stream requests and prompt user to select one. */ - void SetStreamRequest(const Format &format, const FrameRate &rate); + StreamRequest SelectStreamRequest(bool *ok) const; + /** * Get all stream requests of the capability. */ @@ -168,7 +152,28 @@ class MYNTEYE_API API { */ void ConfigStreamRequest( const Capabilities &capability, const StreamRequest &request); + /** + * Get the config stream requests of the capability. + */ + const StreamRequest &GetStreamRequest(const Capabilities &capability) const; + /** + * Get all stream requests of the key stream capability. + */ + const std::vector &GetStreamRequests() const; + /** + * Config the stream request to the key stream capability. + */ + void ConfigStreamRequest(const StreamRequest &request); + /** + * Get the config stream requests of the key stream capability. + */ + const StreamRequest &GetStreamRequest() const; + + /** + * Get the device info. + */ + std::shared_ptr GetInfo() const; /** * Get the device info. */ @@ -214,11 +219,6 @@ class MYNTEYE_API API { */ bool RunOptionAction(const Option &option) const; - /** - * Init device resolution. - */ - void InitResolution(const Resolution &res); - /** * Set the callback of stream. */ diff --git a/include/mynteye/device/callbacks.h b/include/mynteye/device/callbacks.h index 0019433..19730f6 100644 --- a/include/mynteye/device/callbacks.h +++ b/include/mynteye/device/callbacks.h @@ -32,8 +32,8 @@ namespace device { typedef struct ImgParams { bool ok; - std::map in_left_map; - std::map in_right_map; + Intrinsics in_left; + Intrinsics in_right; Extrinsics ex_right_to_left; } img_params_t; diff --git a/include/mynteye/device/device.h b/include/mynteye/device/device.h index 4e9b6f3..3a416d4 100644 --- a/include/mynteye/device/device.h +++ b/include/mynteye/device/device.h @@ -104,14 +104,7 @@ class MYNTEYE_API Device { * Supports the addon or not. */ bool Supports(const AddOns &addon) const; - /** - * Init device resolution. - */ - void InitResolution(const Resolution &res); - /** - * set the stream request. - */ - void SetStreamRequest(const Format &format, const FrameRate &rate); + /** * Get all stream requests of the capability. */ @@ -122,6 +115,23 @@ class MYNTEYE_API Device { */ void ConfigStreamRequest( const Capabilities &capability, const StreamRequest &request); + /** + * Get the config stream requests of the capability. + */ + const StreamRequest &GetStreamRequest(const Capabilities &capability) const; + + /** + * Get all stream requests of the key stream capability. + */ + const std::vector &GetStreamRequests() const; + /** + * Config the stream request to the key stream capability. + */ + void ConfigStreamRequest(const StreamRequest &request); + /** + * Get the config stream requests of the key stream capability. + */ + const StreamRequest &GetStreamRequest() const; /** * Get the device info. @@ -241,15 +251,15 @@ class MYNTEYE_API Device { */ void WaitForStreams(); + /** + * Get the latest data of stream. + */ + device::StreamData GetStreamData(const Stream &stream); /** * Get the datas of stream. * @note default cache 4 datas at most. */ std::vector GetStreamDatas(const Stream &stream); - /** - * Get the latest data of stream. - */ - device::StreamData GetLatestStreamData(const Stream &stream); /** * Enable cache motion datas. @@ -263,10 +273,6 @@ class MYNTEYE_API Device { * Get the motion datas. */ std::vector GetMotionDatas(); - /** - * Get the device img params - */ - img_params_t GetImgParams(); protected: std::shared_ptr device() const { @@ -285,8 +291,6 @@ class MYNTEYE_API Device { return motions_; } - const StreamRequest &GetStreamRequest(const Capabilities &capability); - virtual void StartVideoStreaming(); virtual void StopVideoStreaming(); @@ -295,25 +299,33 @@ class MYNTEYE_API Device { virtual void OnStereoStreamUpdate(); + virtual Capabilities GetKeyStreamCapability() const = 0; virtual std::vector GetKeyStreams() const = 0; + std::map GetImgParams() const { + return all_img_params_; + } + device::imu_params_t GetImuParams() const { + return imu_params_; + } + bool video_streaming_; bool motion_tracking_; private: Model model_; - Resolution res_ = Resolution::RES_752x480; - StreamRequest request_; std::shared_ptr device_; std::shared_ptr device_info_; + std::map all_img_params_; + device::imu_params_t imu_params_; + std::map stream_intrinsics_; std::map> stream_from_extrinsics_; std::shared_ptr motion_intrinsics_; std::map motion_from_extrinsics_; - img_params_t img_params_; stream_callbacks_t stream_callbacks_; motion_callback_t motion_callback_; @@ -331,8 +343,8 @@ class MYNTEYE_API Device { std::shared_ptr motions_; void ReadAllInfos(); - - void ConfigIntrinsics(const Resolution &res); + void UpdateStreamIntrinsics( + const Capabilities &capability, const StreamRequest &request); void CallbackPushedStreamData(const Stream &stream); void CallbackMotionData(const device::MotionData &data); diff --git a/include/mynteye/device/utils.h b/include/mynteye/device/utils.h index 0b64ce1..82e3255 100644 --- a/include/mynteye/device/utils.h +++ b/include/mynteye/device/utils.h @@ -19,6 +19,7 @@ #include #include "mynteye/mynteye.h" +#include "mynteye/types.h" MYNTEYE_BEGIN_NAMESPACE @@ -39,6 +40,16 @@ namespace device { */ MYNTEYE_API std::shared_ptr select(); +/** + * @ingroup utils + * + * List stream requests and prompt user to select one. + * + * @return the selected request. + */ +MYNTEYE_API MYNTEYE_NAMESPACE::StreamRequest select_request( + const std::shared_ptr &device, bool *ok); + } // namespace device namespace utils { @@ -58,14 +69,14 @@ MYNTEYE_API float get_real_exposure_time( /** * @ingroup utils - * + * * Get sdk root dir. */ MYNTEYE_API std::string get_sdk_root_dir(); /** * @ingroup utils - * + * * Get sdk install dir. */ MYNTEYE_API std::string get_sdk_install_dir(); diff --git a/include/mynteye/types.h b/include/mynteye/types.h index 6b1c192..56e5a16 100644 --- a/include/mynteye/types.h +++ b/include/mynteye/types.h @@ -37,6 +37,8 @@ MYNTEYE_BEGIN_NAMESPACE enum class Model : std::uint8_t { /** Standard */ STANDARD, + /** Standard 2 */ + STANDARD2, /** Last guard */ LAST }; @@ -74,10 +76,10 @@ enum class Stream : std::uint8_t { enum class Capabilities : std::uint8_t { /** Provides stereo stream */ STEREO, + /** Provide stereo color stream */ + STEREO_COLOR, /** Provides color stream */ COLOR, - /** Provide stereo color stream */ - STEREO_COLOR, /** Provides depth stream */ DEPTH, /** Provides point cloud stream */ @@ -143,6 +145,7 @@ enum class Option : std::uint8_t { * range: [0,255], default: 127 */ CONTRAST, + /** * Image frame rate, must set IMU_FREQUENCY together * @@ -155,6 +158,7 @@ enum class Option : std::uint8_t { * values: {100,200,250,333,500}, default: 200 */ IMU_FREQUENCY, + /** * Exposure mode * @@ -174,12 +178,19 @@ enum class Option : std::uint8_t { * range: [0,1000], default: 333 */ MAX_EXPOSURE_TIME, + /** + * min exposure time, valid if auto-exposure + * + * range: [0,1000], default: 0 + */ + MIN_EXPOSURE_TIME, /** * Desired brightness, valid if auto-exposure * * range: [1,255], default: 122 */ DESIRED_BRIGHTNESS, + /** * IR control * @@ -193,16 +204,7 @@ enum class Option : std::uint8_t { * 1: 12-bit */ HDR_MODE, - /** Zero drift calibration */ - ZERO_DRIFT_CALIBRATION, - /** Erase chip */ - ERASE_CHIP, - /** - * min exposure time, valid if auto-exposure - * - * range: [0,1000], default: 0 - */ - MIN_EXPOSURE_TIME, + /** * The range of accelerometer * @@ -227,6 +229,12 @@ enum class Option : std::uint8_t { * values: {23,64}, default: 64 */ GYROSCOPE_LOW_PASS_FILTER, + + /** Zero drift calibration */ + ZERO_DRIFT_CALIBRATION, + /** Erase chip */ + ERASE_CHIP, + /** Last guard */ LAST }; @@ -259,40 +267,6 @@ enum class AddOns : std::uint8_t { LAST }; -/** - * @ingroup enumerations - * @brief Camera supported resolution. - */ -enum class Resolution : std::uint8_t { - /** 752x480 */ - RES_752x480, - /** 1280x400 */ - RES_1280x400, - /** 2560x800 */ - RES_2560x800, - /** Last guard */ - LAST -}; - -/** - * @ingroup enumerations - * @brief Camera supported frame rate. - */ -enum class FrameRate : std::uint8_t { - /** 10 fps */ - RATE_10_FPS = 10, - /** 20 fps */ - RATE_20_FPS = 20, - /** 20 fps */ - RATE_25_FPS = 25, - /** 30 fps */ - RATE_30_FPS = 30, - /** 60 fps */ - RATE_60_FPS = 60, - /** Last guard */ - LAST -}; - #define MYNTEYE_ENUM_HELPERS(TYPE) \ MYNTEYE_API const char *to_string(const TYPE &value); \ inline bool is_valid(const TYPE &value) { \ @@ -316,8 +290,6 @@ MYNTEYE_ENUM_HELPERS(Info) MYNTEYE_ENUM_HELPERS(Option) MYNTEYE_ENUM_HELPERS(Source) MYNTEYE_ENUM_HELPERS(AddOns) -MYNTEYE_ENUM_HELPERS(Resolution) -MYNTEYE_ENUM_HELPERS(FrameRate) #undef MYNTEYE_ENUM_HELPERS @@ -350,6 +322,26 @@ inline std::ostream &operator<<(std::ostream &os, const Format &value) { MYNTEYE_API std::size_t bytes_per_pixel(const Format &value); +/** + * Resolution. + */ +struct MYNTEYE_API Resolution { + /** Width */ + std::uint16_t width; + /** Height */ + std::uint16_t height; + + bool operator==(const Resolution &other) const { + return width == other.width && height == other.height; + } + bool operator!=(const Resolution &other) const { + return !(*this == other); + } + bool operator<(const Resolution &other) const { + return (width * height) < (other.width * other.height); + } +}; + /** * Stream request. */ @@ -370,25 +362,10 @@ struct MYNTEYE_API StreamRequest { std::uint16_t fps) : width(width), height(height), format(format), fps(fps) {} - StreamRequest(Resolution res, Format format, FrameRate rate) - : format(format) { - fps = static_cast(rate); + StreamRequest(const Resolution &res, Format format, std::uint16_t fps) + : width(res.width), height(res.height), format(format), fps(fps) {} - switch (res) { - case Resolution::RES_752x480: - width = 480, height = 752; - break; - case Resolution::RES_1280x400: - width = 1280, height = 400; - break; - case Resolution::RES_2560x800: - width = 2560, height = 800; - break; - default: - width = 480, height = 752; - break; - } - } + Resolution GetResolution() const { return {width, height}; } bool operator==(const StreamRequest &other) const { return width == other.width && height == other.height && diff --git a/samples/api/camera.cc b/samples/api/camera.cc index 8a18b8f..8678d31 100644 --- a/samples/api/camera.cc +++ b/samples/api/camera.cc @@ -21,9 +21,13 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; - api->SetStreamRequest(Format::BGR888, FrameRate::RATE_30_FPS); + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); + api->LogOptionInfos(); std::size_t left_count = 0; diff --git a/samples/api/get_depth_with_region.cc b/samples/api/get_depth_with_region.cc index 560b279..25fc417 100644 --- a/samples/api/get_depth_with_region.cc +++ b/samples/api/get_depth_with_region.cc @@ -144,8 +144,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); api->SetOptionValue(Option::IR_CONTROL, 80); diff --git a/samples/device/camera.cc b/samples/device/camera.cc index 62f26af..1fd4add 100644 --- a/samples/device/camera.cc +++ b/samples/device/camera.cc @@ -25,12 +25,14 @@ int main(int argc, char *argv[]) { glog_init _(argc, argv); auto &&device = device::select(); - if (!device) - return 1; + if (!device) return 1; + + bool ok; + auto &&request = device::select_request(device, &ok); + if (!ok) return 1; + device->ConfigStreamRequest(request); std::size_t left_count = 0; - device->InitResolution(Resolution::RES_1280x400); - device->SetStreamRequest(Format::BGR888, FrameRate::RATE_30_FPS); device->SetStreamCallback( Stream::LEFT, [&left_count](const device::StreamData &data) { CHECK_NOTNULL(data.img); @@ -77,8 +79,8 @@ int main(int argc, char *argv[]) { while (true) { device->WaitForStreams(); - device::StreamData left_data = device->GetLatestStreamData(Stream::LEFT); - device::StreamData right_data = device->GetLatestStreamData(Stream::RIGHT); + device::StreamData left_data = device->GetStreamData(Stream::LEFT); + device::StreamData right_data = device->GetStreamData(Stream::RIGHT); auto &&motion_datas = device->GetMotionDatas(); motion_count += motion_datas.size(); diff --git a/samples/tutorials/control/auto_exposure.cc b/samples/tutorials/control/auto_exposure.cc index bc233dd..1c768c4 100644 --- a/samples/tutorials/control/auto_exposure.cc +++ b/samples/tutorials/control/auto_exposure.cc @@ -22,9 +22,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; - api->SetStreamRequest(Format::BGR888, FrameRate::RATE_30_FPS); + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); // auto-exposure: 0 api->SetOptionValue(Option::EXPOSURE_MODE, 0); diff --git a/samples/tutorials/control/framerate.cc b/samples/tutorials/control/framerate.cc index 9867952..52ca904 100644 --- a/samples/tutorials/control/framerate.cc +++ b/samples/tutorials/control/framerate.cc @@ -22,11 +22,14 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { - auto &&api = API::Create(Resolution::RES_1280x400); - // auto &&api = API::Create(argc, argv); - if (!api) - return 1; - api->SetStreamRequest(Format::BGR888, FrameRate::RATE_30_FPS); + auto &&api = API::Create(argc, argv); + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); + // Count img std::atomic_uint img_count(0); api->SetStreamCallback( diff --git a/samples/tutorials/control/imu_range.cc b/samples/tutorials/control/imu_range.cc index 1830248..93f776c 100644 --- a/samples/tutorials/control/imu_range.cc +++ b/samples/tutorials/control/imu_range.cc @@ -23,8 +23,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); // ACCELEROMETER_RANGE values: 6, 12, 24, 32 api->SetOptionValue(Option::ACCELEROMETER_RANGE, 6); diff --git a/samples/tutorials/control/manual_exposure.cc b/samples/tutorials/control/manual_exposure.cc index f513a4a..daa6fb9 100644 --- a/samples/tutorials/control/manual_exposure.cc +++ b/samples/tutorials/control/manual_exposure.cc @@ -22,9 +22,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; - api->SetStreamRequest(Format::BGR888, FrameRate::RATE_30_FPS); + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); // manual-exposure: 1 api->SetOptionValue(Option::EXPOSURE_MODE, 1); diff --git a/samples/tutorials/data/get_depth.cc b/samples/tutorials/data/get_depth.cc index e973967..d2c4246 100644 --- a/samples/tutorials/data/get_depth.cc +++ b/samples/tutorials/data/get_depth.cc @@ -19,8 +19,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); api->EnableStreamData(Stream::DEPTH); diff --git a/samples/tutorials/data/get_device_info.cc b/samples/tutorials/data/get_device_info.cc index 5217c36..ddb3bd9 100644 --- a/samples/tutorials/data/get_device_info.cc +++ b/samples/tutorials/data/get_device_info.cc @@ -18,8 +18,7 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; LOG(INFO) << "Device name: " << api->GetInfo(Info::DEVICE_NAME); LOG(INFO) << "Serial number: " << api->GetInfo(Info::SERIAL_NUMBER); diff --git a/samples/tutorials/data/get_disparity.cc b/samples/tutorials/data/get_disparity.cc index 243d81e..582dc72 100644 --- a/samples/tutorials/data/get_disparity.cc +++ b/samples/tutorials/data/get_disparity.cc @@ -19,8 +19,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); // api->EnableStreamData(Stream::DISPARITY); api->EnableStreamData(Stream::DISPARITY_NORMALIZED); diff --git a/samples/tutorials/data/get_from_callbacks.cc b/samples/tutorials/data/get_from_callbacks.cc index 27c30a4..b1effcc 100644 --- a/samples/tutorials/data/get_from_callbacks.cc +++ b/samples/tutorials/data/get_from_callbacks.cc @@ -27,8 +27,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); // Attention: must not block the callbacks. diff --git a/samples/tutorials/data/get_img_params.cc b/samples/tutorials/data/get_img_params.cc index f84642e..41bfbce 100644 --- a/samples/tutorials/data/get_img_params.cc +++ b/samples/tutorials/data/get_img_params.cc @@ -18,9 +18,13 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; - api->SetStreamRequest(Format::BGR888, FrameRate::RATE_30_FPS); + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); + LOG(INFO) << "Intrinsics left: {" << api->GetIntrinsics(Stream::LEFT) << "}"; LOG(INFO) << "Intrinsics right: {" << api->GetIntrinsics(Stream::RIGHT) << "}"; diff --git a/samples/tutorials/data/get_imu.cc b/samples/tutorials/data/get_imu.cc index a449f6e..c09d225 100644 --- a/samples/tutorials/data/get_imu.cc +++ b/samples/tutorials/data/get_imu.cc @@ -22,8 +22,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); // Enable this will cache the motion datas until you get them. api->EnableMotionDatas(); diff --git a/samples/tutorials/data/get_imu_params.cc b/samples/tutorials/data/get_imu_params.cc index 7757611..092aaec 100644 --- a/samples/tutorials/data/get_imu_params.cc +++ b/samples/tutorials/data/get_imu_params.cc @@ -18,8 +18,7 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; LOG(INFO) << "Motion intrinsics: {" << api->GetMotionIntrinsics() << "}"; LOG(INFO) << "Motion extrinsics left to imu: {" diff --git a/samples/tutorials/data/get_points.cc b/samples/tutorials/data/get_points.cc index 28294f5..ef2d91f 100644 --- a/samples/tutorials/data/get_points.cc +++ b/samples/tutorials/data/get_points.cc @@ -21,8 +21,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); api->EnableStreamData(Stream::POINTS); diff --git a/samples/tutorials/data/get_stereo.cc b/samples/tutorials/data/get_stereo.cc index 391c53e..1dd024a 100644 --- a/samples/tutorials/data/get_stereo.cc +++ b/samples/tutorials/data/get_stereo.cc @@ -19,8 +19,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); api->Start(Source::VIDEO_STREAMING); diff --git a/samples/tutorials/data/get_stereo_rectified.cc b/samples/tutorials/data/get_stereo_rectified.cc index 10c0bf5..dadba65 100644 --- a/samples/tutorials/data/get_stereo_rectified.cc +++ b/samples/tutorials/data/get_stereo_rectified.cc @@ -19,8 +19,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); api->EnableStreamData(Stream::LEFT_RECTIFIED); api->EnableStreamData(Stream::RIGHT_RECTIFIED); diff --git a/samples/tutorials/data/get_with_plugin.cc b/samples/tutorials/data/get_with_plugin.cc index e8a0e05..af943b0 100644 --- a/samples/tutorials/data/get_with_plugin.cc +++ b/samples/tutorials/data/get_with_plugin.cc @@ -19,8 +19,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); api->EnablePlugin("plugins/linux-x86_64/libplugin_g_cuda9.1_opencv3.4.0.so"); diff --git a/samples/tutorials/intermediate/get_depth_and_points.cc b/samples/tutorials/intermediate/get_depth_and_points.cc index 5761c62..5a2d5d8 100644 --- a/samples/tutorials/intermediate/get_depth_and_points.cc +++ b/samples/tutorials/intermediate/get_depth_and_points.cc @@ -148,8 +148,12 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); - if (!api) - return 1; + if (!api) return 1; + + bool ok; + auto &&request = api->SelectStreamRequest(&ok); + if (!ok) return 1; + api->ConfigStreamRequest(request); api->SetOptionValue(Option::IR_CONTROL, 80); diff --git a/src/mynteye/api/api.cc b/src/mynteye/api/api.cc index a74df26..24d17dd 100644 --- a/src/mynteye/api/api.cc +++ b/src/mynteye/api/api.cc @@ -218,52 +218,15 @@ API::~API() { VLOG(2) << __func__; } -std::shared_ptr API::Create(Resolution res) { - auto &&device = device::select(); - if (!device) - return nullptr; - device->InitResolution(res); - return std::make_shared(device); -} - -std::shared_ptr API::Create( - std::shared_ptr device, Resolution res) { - if (!device) - return nullptr; - device->InitResolution(res); - return std::make_shared(device); -} - -// TODO(Kalman): Compatible with two generation -std::shared_ptr API::Create(std::shared_ptr device) { - return Create(device, Resolution::RES_2560x800); -} - std::shared_ptr API::Create(int argc, char *argv[]) { auto &&device = device::select(); + if (!device) return nullptr; return Create(argc, argv, device); } -// TODO(Kalman): Compatible with two generation std::shared_ptr API::Create( - int argc, char *argv[], std::shared_ptr device) { + int argc, char *argv[], const std::shared_ptr &device) { static glog_init _(argc, argv); - int index = 0; - if (argc >= 2) { - try { - index = std::stoi(argv[1]); - } catch (...) { - LOG(WARNING) << "Unexpected index."; - } - } - if (!device) - return nullptr; - if (index == 0) - device->InitResolution(Resolution::RES_1280x400); - else if (index == 1) - device->InitResolution(Resolution::RES_2560x800); - else - device->InitResolution(Resolution::RES_1280x400); return std::make_shared(device); } @@ -287,12 +250,8 @@ bool API::Supports(const AddOns &addon) const { return device_->Supports(addon); } -void API::InitResolution(const Resolution &res) { - return device_->InitResolution(res); -} - -void API::SetStreamRequest(const Format &format, const FrameRate &rate) { - device_->SetStreamRequest(format, rate); +StreamRequest API::SelectStreamRequest(bool *ok) const { + return device::select_request(device_, ok); } const std::vector &API::GetStreamRequests( @@ -305,6 +264,27 @@ void API::ConfigStreamRequest( device_->ConfigStreamRequest(capability, request); } +const StreamRequest &API::GetStreamRequest( + const Capabilities &capability) const { + return device_->GetStreamRequest(capability); +} + +const std::vector &API::GetStreamRequests() const { + return device_->GetStreamRequests(); +} + +void API::ConfigStreamRequest(const StreamRequest &request) { + device_->ConfigStreamRequest(request); +} + +const StreamRequest &API::GetStreamRequest() const { + return device_->GetStreamRequest(); +} + +std::shared_ptr API::GetInfo() const { + return device_->GetInfo(); +} + std::string API::GetInfo(const Info &info) const { return device_->GetInfo(info); } diff --git a/src/mynteye/api/synthetic.cc b/src/mynteye/api/synthetic.cc index 296e5af..04f1ca9 100644 --- a/src/mynteye/api/synthetic.cc +++ b/src/mynteye/api/synthetic.cc @@ -161,7 +161,7 @@ api::StreamData Synthetic::GetStreamData(const Stream &stream) { auto &&mode = GetStreamEnabledMode(stream); if (mode == MODE_NATIVE) { auto &&device = api_->device(); - return data2api(device->GetLatestStreamData(stream)); + return data2api(device->GetStreamData(stream)); } else if (mode == MODE_SYNTHETIC) { if (stream == Stream::LEFT_RECTIFIED || stream == Stream::RIGHT_RECTIFIED) { static std::shared_ptr output = nullptr; diff --git a/src/mynteye/device/channels.cc b/src/mynteye/device/channels.cc index 48a0998..5450eac 100644 --- a/src/mynteye/device/channels.cc +++ b/src/mynteye/device/channels.cc @@ -563,44 +563,43 @@ std::size_t from_data( return i; } -// TODO(Kalman): Is there a more elegant way? std::size_t from_data( - device::img_params_t *img_params, const std::uint8_t *data, + Channels::img_params_t *img_params, const std::uint8_t *data, const Version *spec_version) { std::size_t i = 0; + // TODO(JohnZhao) + Intrinsics in_left, in_right; + Extrinsics ex_right_to_left; + if (spec_version->major() == 1) { if (spec_version->minor() == 0) { - i += from_data( - &img_params->in_left_map[Resolution::RES_752x480], data + i, - spec_version); - i += from_data( - &img_params->in_right_map[Resolution::RES_752x480], data + i, - spec_version); + i += from_data(&in_left, data + i, spec_version); + i += from_data(&in_right, data + i, spec_version); + i += from_data(&ex_right_to_left, data + i, spec_version); + (*img_params)[{752, 480}] = {true, in_left, in_right, ex_right_to_left}; } if (spec_version->minor() == 1) { - i += from_data( - &img_params->in_left_map[Resolution::RES_1280x400], data + i, - spec_version); - i += from_data( - &img_params->in_right_map[Resolution::RES_1280x400], data + i, - spec_version); - i += from_data( - &img_params->in_left_map[Resolution::RES_2560x800], data + i, - spec_version); - i += from_data( - &img_params->in_right_map[Resolution::RES_2560x800], data + i, - spec_version); + i += from_data(&in_left, data + i, spec_version); + i += from_data(&in_right, data + i, spec_version); + (*img_params)[{1280, 400}] = {true, in_left, in_right, ex_right_to_left}; + + i += from_data(&in_left, data + i, spec_version); + i += from_data(&in_right, data + i, spec_version); + (*img_params)[{2560, 800}] = {true, in_left, in_right, ex_right_to_left}; + + i += from_data(&ex_right_to_left, data + i, spec_version); + (*img_params)[{1280, 400}].ex_right_to_left = ex_right_to_left; + (*img_params)[{2560, 800}].ex_right_to_left = ex_right_to_left; } } - i += from_data(&img_params->ex_right_to_left, data + i, spec_version); return i; } std::size_t from_data( - device::imu_params_t *imu_params, const std::uint8_t *data, + Channels::imu_params_t *imu_params, const std::uint8_t *data, const Version *spec_version) { std::size_t i = 0; i += from_data(&imu_params->in_accel, data + i, spec_version); @@ -674,8 +673,7 @@ bool Channels::GetFiles( CheckSpecVersion(spec_ver); } break; case FID_IMG_PARAMS: { - img_params->ok = file_size > 0; - if (img_params->ok) { + if (file_size > 0) { CheckSpecVersion(spec_ver); from_data(img_params, data + i, spec_ver); // Considering the upgrade, comment this @@ -864,38 +862,34 @@ std::size_t to_data( } std::size_t to_data( - const device::img_params_t *img_params, std::uint8_t *data, + const Channels::img_params_t *img_params, std::uint8_t *data, const Version *spec_version) { std::size_t i = 3; // skip id, size + // TODO(JohnZhao) if (spec_version->major() == 1) { if (spec_version->minor() == 0) { - i += to_data( - &img_params->in_left_map.at(Resolution::RES_752x480), data + i, - spec_version); - i += to_data( - &img_params->in_right_map.at(Resolution::RES_752x480), data + i, - spec_version); + auto &¶ms = (*img_params).at({752, 480}); + i += to_data(¶ms.in_left, data + i, spec_version); + i += to_data(¶ms.in_right, data + i, spec_version); + i += to_data(¶ms.ex_right_to_left, data + i, spec_version); } if (spec_version->minor() == 1) { - i += to_data( - &img_params->in_left_map.at(Resolution::RES_1280x400), data + i, - spec_version); - i += to_data( - &img_params->in_right_map.at(Resolution::RES_1280x400), data + i, - spec_version); - - i += to_data( - &img_params->in_left_map.at(Resolution::RES_2560x800), data + i, - spec_version); - i += to_data( - &img_params->in_right_map.at(Resolution::RES_2560x800), data + i, - spec_version); + { + auto &¶ms = (*img_params).at({1280, 400}); + i += to_data(¶ms.in_left, data + i, spec_version); + i += to_data(¶ms.in_right, data + i, spec_version); + } + { + auto &¶ms = (*img_params).at({2560, 800}); + i += to_data(¶ms.in_left, data + i, spec_version); + i += to_data(¶ms.in_right, data + i, spec_version); + i += to_data(¶ms.ex_right_to_left, data + i, spec_version); + } } } - i += to_data(&img_params->ex_right_to_left, data + i, spec_version); // others std::size_t size = i - 3; data[0] = Channels::FID_IMG_PARAMS; diff --git a/src/mynteye/device/channels.h b/src/mynteye/device/channels.h index 86dccdb..3c42c65 100644 --- a/src/mynteye/device/channels.h +++ b/src/mynteye/device/channels.h @@ -68,23 +68,9 @@ class MYNTEYE_API Channels { using device_info_t = DeviceInfo; + using img_params_t = std::map; using imu_params_t = device::imu_params_t; - using img_params_t = device::img_params_t; -/* - typedef struct ImgParams { - bool ok; - std::map in_left_map; - std::map in_right_map; - Extrinsics ex_right_to_left; - } img_params_t; - typedef struct ImuParams { - bool ok; - ImuIntrinsics in_accel; - ImuIntrinsics in_gyro; - Extrinsics ex_left_to_imu; - } imu_params_t; -*/ explicit Channels(std::shared_ptr device); ~Channels(); diff --git a/src/mynteye/device/config.cc b/src/mynteye/device/config.cc index 4b867d8..115e243 100644 --- a/src/mynteye/device/config.cc +++ b/src/mynteye/device/config.cc @@ -16,39 +16,65 @@ MYNTEYE_BEGIN_NAMESPACE const std::map stream_supports_map = { - {Model::STANDARD, {Stream::LEFT, Stream::RIGHT}}}; + {Model::STANDARD, {Stream::LEFT, Stream::RIGHT}}, + {Model::STANDARD2, {Stream::LEFT, Stream::RIGHT}} +}; const std::map capabilities_supports_map = { - {Model::STANDARD, {Capabilities::STEREO_COLOR, Capabilities::IMU}}}; + {Model::STANDARD, {Capabilities::STEREO, Capabilities::IMU}}, + {Model::STANDARD2, {Capabilities::STEREO_COLOR, Capabilities::IMU}} +}; -// TODO(Kalman): Compatible with two generation const std::map option_supports_map = { - {Model::STANDARD, - {Option::BRIGHTNESS, Option::EXPOSURE_MODE, Option::MAX_GAIN, - Option::MAX_EXPOSURE_TIME, Option::DESIRED_BRIGHTNESS, - Option::MIN_EXPOSURE_TIME, Option::ERASE_CHIP, - Option::ACCELEROMETER_RANGE, Option::GYROSCOPE_RANGE, - Option::ACCELEROMETER_LOW_PASS_FILTER, - Option::GYROSCOPE_LOW_PASS_FILTER}}}; + {Model::STANDARD, { + Option::GAIN, Option::BRIGHTNESS, Option::CONTRAST, + Option::FRAME_RATE, Option::IMU_FREQUENCY, + Option::EXPOSURE_MODE, Option::MAX_GAIN, Option::MAX_EXPOSURE_TIME, + Option::DESIRED_BRIGHTNESS, + Option::IR_CONTROL, + Option::HDR_MODE, + Option::ACCELEROMETER_RANGE, Option::GYROSCOPE_RANGE, + Option::ZERO_DRIFT_CALIBRATION, + Option::ERASE_CHIP} + }, + {Model::STANDARD2, { + Option::BRIGHTNESS, + Option::EXPOSURE_MODE, Option::MAX_GAIN, Option::MAX_EXPOSURE_TIME, + Option::MIN_EXPOSURE_TIME, Option::DESIRED_BRIGHTNESS, + Option::ACCELEROMETER_RANGE, Option::GYROSCOPE_RANGE, + Option::ACCELEROMETER_LOW_PASS_FILTER, Option::GYROSCOPE_LOW_PASS_FILTER, + Option::ERASE_CHIP} + } +}; const std::map> - stream_requests_map = { - {Model::STANDARD, - {{Capabilities::STEREO, {{480, 752, Format::YUYV, 25}}}, - {Capabilities::STEREO_COLOR, - {// {1280, 400, Format::YUYV, 10}, - // {1280, 400, Format::YUYV, 20}, - // {1280, 400, Format::YUYV, 30}, - // {1280, 400, Format::YUYV, 60}, - // {2560, 800, Format::YUYV, 10}, - // {2560, 800, Format::YUYV, 20}, - // {2560, 800, Format::YUYV, 30}, - {1280, 400, Format::BGR888, 10}, - {1280, 400, Format::BGR888, 20}, - {1280, 400, Format::BGR888, 30}, - {1280, 400, Format::BGR888, 60}, - {2560, 800, Format::BGR888, 10}, - {2560, 800, Format::BGR888, 20}, - {2560, 800, Format::BGR888, 30}}}}}}; +stream_requests_map = { + {Model::STANDARD, + {{Capabilities::STEREO, { + {752, 480, Format::YUYV, 10}, + {752, 480, Format::YUYV, 15}, + {752, 480, Format::YUYV, 20}, + {752, 480, Format::YUYV, 25}, + {752, 480, Format::YUYV, 30}, + {752, 480, Format::YUYV, 35}, + {752, 480, Format::YUYV, 40}, + {752, 480, Format::YUYV, 45}, + {752, 480, Format::YUYV, 50}, + {752, 480, Format::YUYV, 55}, + {752, 480, Format::YUYV, 60}} + }} + }, + {Model::STANDARD2, + {{Capabilities::STEREO_COLOR, { + {1280, 400, Format::BGR888, 10}, + {1280, 400, Format::BGR888, 20}, + {1280, 400, Format::BGR888, 30}, + {1280, 400, Format::BGR888, 60}, + {2560, 800, Format::BGR888, 10}, + {2560, 800, Format::BGR888, 20}, + {2560, 800, Format::BGR888, 30}} + }} + } +}; MYNTEYE_END_NAMESPACE diff --git a/src/mynteye/device/config.h b/src/mynteye/device/config.h index a4f8dba..f38dab0 100644 --- a/src/mynteye/device/config.h +++ b/src/mynteye/device/config.h @@ -27,18 +27,13 @@ MYNTEYE_BEGIN_NAMESPACE using StreamSupports = std::set; using CapabilitiesSupports = std::set; using OptionSupports = std::set