From ed2398fedc8c06c60a8b22e38b3028e639d333bc Mon Sep 17 00:00:00 2001 From: TinyO Date: Fri, 30 Aug 2019 15:03:36 +0800 Subject: [PATCH] refactor(*): doc and samples update tools contents. --- docs/src/sdk/control/auto_exposure.rst | 6 +- docs/src/sdk/control/framerate.rst | 6 +- docs/src/sdk/control/iic_address.rst | 4 +- docs/src/sdk/control/imu_low_pass_filter.rst | 4 +- docs/src/sdk/control/imu_range.rst | 6 +- docs/src/sdk/control/infrared.rst | 4 +- docs/src/sdk/control/manual_exposure.rst | 6 +- docs/src/sdk/data/contents.rst | 1 - docs/src/sdk/data/get_depth.rst | 4 +- docs/src/sdk/data/get_device_info.rst | 4 +- docs/src/sdk/data/get_disparity.rst | 2 +- docs/src/sdk/data/get_from_callbacks.rst | 2 +- docs/src/sdk/data/get_img_params.rst | 4 +- docs/src/sdk/data/get_imu.rst | 11 +- docs/src/sdk/data/get_imu_correspondence.rst | 4 +- docs/src/sdk/data/get_imu_params.rst | 2 +- docs/src/sdk/data/get_points.rst | 57 -- docs/src/sdk/data/get_stereo.rst | 2 +- docs/src/sdk/data/get_stereo_rectified.rst | 2 +- docs/src/sdk/data/get_with_plugin.rst | 2 +- docs/src/sdk/data/save_params.rst | 8 +- docs/src/sdk/data/save_single_image.rst | 2 +- docs/src/sdk/data/write_img_params.rst | 12 +- docs/src/sdk/data/write_imu_params.rst | 8 +- docs/src/sdk/project/cmake.rst | 2 +- docs/src/sdk/project/vs2017.rst | 2 +- samples/CMakeLists.txt | 36 ++ .../config/S1030/deprecated/img.params.old | 41 ++ .../config/S1030/deprecated/img.params.old2 | 30 + .../config/S1030/deprecated/img.params.old3 | 33 + .../config/S1030/deprecated/imu.params.old | 24 + samples/config/S1030/device.info | 10 + samples/config/S1030/img.params.equidistant | 28 + samples/config/S1030/img.params.pinhole | 38 ++ samples/config/S1030/imu.params | 33 + .../config/S210A/deprecated/img.params.old | 62 ++ .../config/S210A/deprecated/imu.params.old | 15 + samples/config/S210A/device.info | 12 + samples/config/S210A/img.params.equidistant | 51 ++ samples/config/S210A/img.params.pinhole | 62 ++ samples/config/S210A/imu.params | 33 + samples/device_writer.cc | 590 ++++++++++++++++++ samples/device_writer.h | 69 ++ samples/save_all_infos.cc | 43 ++ samples/write_device_info.cc | 41 ++ samples/write_img_params.cc | 41 ++ samples/write_imu_params.cc | 41 ++ 47 files changed, 1390 insertions(+), 110 deletions(-) delete mode 100644 docs/src/sdk/data/get_points.rst create mode 100644 samples/config/S1030/deprecated/img.params.old create mode 100644 samples/config/S1030/deprecated/img.params.old2 create mode 100644 samples/config/S1030/deprecated/img.params.old3 create mode 100644 samples/config/S1030/deprecated/imu.params.old create mode 100644 samples/config/S1030/device.info create mode 100644 samples/config/S1030/img.params.equidistant create mode 100644 samples/config/S1030/img.params.pinhole create mode 100644 samples/config/S1030/imu.params create mode 100644 samples/config/S210A/deprecated/img.params.old create mode 100644 samples/config/S210A/deprecated/imu.params.old create mode 100644 samples/config/S210A/device.info create mode 100644 samples/config/S210A/img.params.equidistant create mode 100644 samples/config/S210A/img.params.pinhole create mode 100644 samples/config/S210A/imu.params create mode 100644 samples/device_writer.cc create mode 100644 samples/device_writer.h create mode 100644 samples/save_all_infos.cc create mode 100644 samples/write_device_info.cc create mode 100644 samples/write_img_params.cc create mode 100644 samples/write_imu_params.cc diff --git a/docs/src/sdk/control/auto_exposure.rst b/docs/src/sdk/control/auto_exposure.rst index e117140..935699a 100644 --- a/docs/src/sdk/control/auto_exposure.rst +++ b/docs/src/sdk/control/auto_exposure.rst @@ -86,7 +86,7 @@ s1030: .. code-block:: bash - $ ./samples/_output/bin/tutorials/ctrl_auto_exposure + $ ./samples/_output/bin/ctrl_auto_exposure I0513 14:07:57.963943 31845 utils.cc:26] Detecting MYNT EYE devices I0513 14:07:58.457536 31845 utils.cc:33] MYNT EYE devices: I0513 14:07:58.457563 31845 utils.cc:37] index: 0, name: MYNT-EYE-S1000 @@ -101,7 +101,7 @@ s2100/s210a: .. code-block:: bash - $ ./samples/_output/bin/tutorials/ctrl_auto_exposure + $ ./samples/_output/bin/ctrl_auto_exposure I/utils.cc:30 Detecting MYNT EYE devices I/utils.cc:40 MYNT EYE devices: I/utils.cc:43 index: 0, name: MYNT-EYE-S210A, sn: 07C41A190009071F @@ -126,4 +126,4 @@ s2100/s210a: The sample program displays an image with a real exposure time in the upper left corner, in milliseconds. -Complete code examples, see `auto_exposure.cc `_ . +Complete code examples, see `ctrl_auto_exposure.cc `_ . diff --git a/docs/src/sdk/control/framerate.rst b/docs/src/sdk/control/framerate.rst index 37af436..a14e617 100644 --- a/docs/src/sdk/control/framerate.rst +++ b/docs/src/sdk/control/framerate.rst @@ -67,7 +67,7 @@ s1030: .. code-block:: bash - $ ./samples/_output/bin/tutorials/ctrl_framerate + $ ./samples/_output/bin/ctrl_framerate I0513 14:05:57.218222 31813 utils.cc:26] Detecting MYNT EYE devices I0513 14:05:57.899404 31813 utils.cc:33] MYNT EYE devices: I0513 14:05:57.899430 31813 utils.cc:37] index: 0, name: MYNT-EYE-S1000 @@ -82,7 +82,7 @@ s2100/s210a: .. code-block:: bash - $ ./samples/_output/bin/tutorials/ctrl_framerate + $ ./samples/_output/bin/ctrl_framerate I/utils.cc:30 Detecting MYNT EYE devices I/utils.cc:40 MYNT EYE devices: I/utils.cc:43 index: 0, name: MYNT-EYE-S210A, sn: 07C41A190009071F @@ -105,4 +105,4 @@ s2100/s210a: After the sample program finishes running with ``ESC/Q``, it will output the calculated value of the frame rate of image & IMU frequency. -Complete code samples,please see `framerate.cc `_ . +Complete code samples,please see `ctrl_framerate.cc `_ . diff --git a/docs/src/sdk/control/iic_address.rst b/docs/src/sdk/control/iic_address.rst index 25587f2..352e22c 100644 --- a/docs/src/sdk/control/iic_address.rst +++ b/docs/src/sdk/control/iic_address.rst @@ -37,7 +37,7 @@ s210a/s2100: .. code-block:: bash - $ ./samples/_output/bin/tutorials/ctrl_iic_adress + $ ./samples/_output/bin/ctrl_iic_adress I/utils.cc:30 Detecting MYNT EYE devices I/utils.cc:40 MYNT EYE devices: I/utils.cc:43 index: 0, name: MYNT-EYE-S210A, sn: 07C41A190009071F @@ -55,4 +55,4 @@ s210a/s2100: I/imu_range.cc:51 Set iic address to 0x31 After the sample program finishes running with ``ESC/Q``. -Complete code samples,please see `iic_address.cc `_ . +Complete code samples,please see `ctrl_iic_address.cc `_ . diff --git a/docs/src/sdk/control/imu_low_pass_filter.rst b/docs/src/sdk/control/imu_low_pass_filter.rst index 096f3df..4590e91 100644 --- a/docs/src/sdk/control/imu_low_pass_filter.rst +++ b/docs/src/sdk/control/imu_low_pass_filter.rst @@ -37,7 +37,7 @@ Reference running results on Linux: .. code-block:: bash - $ ./samples/_output/bin/tutorials/ctrl_imu_low_pass_filter + $ ./samples/_output/bin/ctrl_imu_low_pass_filter I/utils.cc:30 Detecting MYNT EYE devices I/utils.cc:40 MYNT EYE devices: I/utils.cc:43 index: 0, name: MYNT-EYE-S210A, sn: 07C41A190009071F @@ -60,4 +60,4 @@ Reference running results on Linux: After the sample program finishes running with ``ESC/Q``, the low-pass filter of imu setting is complete. The ranges will be kept inside the hardware and not affected by power off. -Complete code samples,please see `imu_low_pass_filter.cc `_ 。 +Complete code samples,please see `ctrl_imu_low_pass_filter.cc `_ 。 diff --git a/docs/src/sdk/control/imu_range.rst b/docs/src/sdk/control/imu_range.rst index 9e63271..4248fcf 100644 --- a/docs/src/sdk/control/imu_range.rst +++ b/docs/src/sdk/control/imu_range.rst @@ -67,7 +67,7 @@ s1030: .. code-block:: bash - $ ./samples/_output/bin/tutorials/ctrl_imu_range + $ ./samples/_output/bin/ctrl_imu_range I/utils.cc:28 Detecting MYNT EYE devices I/utils.cc:38 MYNT EYE devices: I/utils.cc:41 index: 0, name: MYNT-EYE-S1030, sn: 4B4C1F1100090712 @@ -82,7 +82,7 @@ s2100/s210a: .. code-block:: bash - $ ./samples/_output/bin/tutorials/ctrl_imu_range + $ ./samples/_output/bin/ctrl_imu_range I/utils.cc:30 Detecting MYNT EYE devices I/utils.cc:40 MYNT EYE devices: I/utils.cc:43 index: 0, name: MYNT-EYE-S210A, sn: 07C41A190009071F @@ -105,4 +105,4 @@ s2100/s210a: After the sample program finishes running with ``ESC/Q``, the ranges of imu setting is complete. The ranges will be kept inside the hardware and not affected by power off. -Complete code samples,please see `imu_range.cc `_. +Complete code samples,please see `ctrl_imu_range.cc `_. diff --git a/docs/src/sdk/control/infrared.rst b/docs/src/sdk/control/infrared.rst index 6d01e29..83bf925 100644 --- a/docs/src/sdk/control/infrared.rst +++ b/docs/src/sdk/control/infrared.rst @@ -33,7 +33,7 @@ Reference running results on Linux: .. code-block:: bash - $ ./samples/_output/bin/tutorials/ctrl_infrared + $ ./samples/_output/bin/ctrl_infrared I0504 16:16:28.016624 25848 utils.cc:13] Detecting MYNT EYE devices I0504 16:16:28.512462 25848 utils.cc:20] MYNT EYE devices: I0504 16:16:28.512473 25848 utils.cc:24] index: 0, name: MYNT-EYE-S1000 @@ -51,4 +51,4 @@ At this point, if the image is displayed, you can see IR speckle on the image, a The hardware will not record the IR value after being turned off. In order to keep IR enabled, you must set the IR value after turning on the device. -Complete code samples,see `infrared.cc `_ . +Complete code samples,see `ctrl_infrared.cc `_ . diff --git a/docs/src/sdk/control/manual_exposure.rst b/docs/src/sdk/control/manual_exposure.rst index c95f9ee..da944f0 100644 --- a/docs/src/sdk/control/manual_exposure.rst +++ b/docs/src/sdk/control/manual_exposure.rst @@ -71,7 +71,7 @@ s1030: .. code-block:: bash - $ ./samples/_output/bin/tutorials/ctrl_manual_exposure + $ ./samples/_output/bin/ctrl_manual_exposure I0513 14:09:17.104431 31908 utils.cc:26] Detecting MYNT EYE devices I0513 14:09:17.501519 31908 utils.cc:33] MYNT EYE devices: I0513 14:09:17.501551 31908 utils.cc:37] index: 0, name: MYNT-EYE-S1000 @@ -85,7 +85,7 @@ s2100/s210a: .. code-block:: bash - $ ./samples/_output/bin/tutorials/ctrl_manual_exposure + $ ./samples/_output/bin/ctrl_manual_exposure I/utils.cc:30 Detecting MYNT EYE devices I/utils.cc:40 MYNT EYE devices: I/utils.cc:43 index: 0, name: MYNT-EYE-S210A, sn: 07C41A190009071F @@ -107,4 +107,4 @@ s2100/s210a: The sample program displays an image with a real exposure time in the upper left corner, in milliseconds. -Complete code samples,see `manual_exposure.cc `_ . +Complete code samples,see `ctrl_manual_exposure.cc `_ . diff --git a/docs/src/sdk/data/contents.rst b/docs/src/sdk/data/contents.rst index 7f5de77..a381091 100644 --- a/docs/src/sdk/data/contents.rst +++ b/docs/src/sdk/data/contents.rst @@ -12,7 +12,6 @@ SDK Data Samples get_stereo_rectified get_disparity get_depth - get_points get_imu get_imu_correspondence get_from_callbacks diff --git a/docs/src/sdk/data/get_depth.rst b/docs/src/sdk/data/get_depth.rst index 0e178a2..13f41c2 100644 --- a/docs/src/sdk/data/get_depth.rst +++ b/docs/src/sdk/data/get_depth.rst @@ -47,8 +47,8 @@ Reference code snippet: The above code uses OpenCV to display the image. When the display window is selected, pressing ``ESC/Q`` will end the program. -Complete code examples, see `get_depth.cc `_ . +Complete code examples, see `get_depth.cc `_ . .. tip:: -Preview the value of a region of the depth image, see `get_depth_with_region.cc `_ . +Preview the value of a region of the depth image, see `get_depth_with_region.cc `_ . diff --git a/docs/src/sdk/data/get_device_info.rst b/docs/src/sdk/data/get_device_info.rst index 33ffdcf..afa5e95 100644 --- a/docs/src/sdk/data/get_device_info.rst +++ b/docs/src/sdk/data/get_device_info.rst @@ -24,7 +24,7 @@ Reference result on Linux: .. code-block:: bash - $ ./samples/_output/bin/tutorials/get_device_info + $ ./samples/_output/bin/get_device_info I0503 16:40:21.109391 32106 utils.cc:13] Detecting MYNT EYE devices I0503 16:40:21.604116 32106 utils.cc:20] MYNT EYE devices: I0503 16:40:21.604127 32106 utils.cc:24] index: 0, name: MYNT-EYE-S1000 @@ -38,4 +38,4 @@ Reference result on Linux: I0503 16:40:21.615164 32106 get_device_info.cc:16] IMU type: 0000 I0503 16:40:21.615171 32106 get_device_info.cc:17] Nominal baseline: 120 -Complete code examples, see `get_device_info.cc `_ . +Complete code examples, see `get_device_info.cc `_ . diff --git a/docs/src/sdk/data/get_disparity.rst b/docs/src/sdk/data/get_disparity.rst index f2acb0b..59799bf 100644 --- a/docs/src/sdk/data/get_disparity.rst +++ b/docs/src/sdk/data/get_disparity.rst @@ -59,4 +59,4 @@ Reference code snippet: The above code uses OpenCV to display the image. Select the display window, press ``ESC/Q`` to exit in the program. -Complete code examples, see `get_disparity.cc `_ . +Complete code examples, see `get_disparity.cc `_ . diff --git a/docs/src/sdk/data/get_from_callbacks.rst b/docs/src/sdk/data/get_from_callbacks.rst index d9ae0a6..b6df3c0 100644 --- a/docs/src/sdk/data/get_from_callbacks.rst +++ b/docs/src/sdk/data/get_from_callbacks.rst @@ -116,4 +116,4 @@ Reference code snippet: OpenCV is used to display images and data above. When the window is selected, pressing ``ESC/Q`` will exit program. -Complete code examples, see `get_from_callbacks.cc `_ . +Complete code examples, see `get_from_callbacks.cc `_ . diff --git a/docs/src/sdk/data/get_img_params.rst b/docs/src/sdk/data/get_img_params.rst index b2e05f1..bd68bfb 100644 --- a/docs/src/sdk/data/get_img_params.rst +++ b/docs/src/sdk/data/get_img_params.rst @@ -27,7 +27,7 @@ Reference result on Linux: .. code-block:: bash - $ ./samples/_output/bin/tutorials/get_img_params + $ ./samples/_output/bin/get_img_params I0510 15:00:22.643263 6980 utils.cc:26] Detecting MYNT EYE devices I0510 15:00:23.138811 6980 utils.cc:33] MYNT EYE devices: I0510 15:00:23.138849 6980 utils.cc:37] index: 0, name: MYNT-EYE-S1000 @@ -36,4 +36,4 @@ Reference result on Linux: I0510 15:00:23.210551 6980 get_img_params.cc:24] Intrinsics right: {width: 752, height: 480, fx: 736.38305001095545776, fy: 723.50066150722432212, cx: 456.68367112303980093, cy: 250.70083335536796199, model: 0, coeffs: [-0.51012886039889305, 0.38764476500996770, 0.00000000000000000, 0.00000000000000000, 0.00000000000000000]} I0510 15:00:23.210577 6980 get_img_params.cc:26] Extrinsics left to right: {rotation: [0.99701893306553813, -0.00095378124886237, -0.07715139279485062, 0.00144939967628305, 0.99997867219985104, 0.00636823256494144, 0.07714367342455503, -0.00646107164115277, 0.99699905125522237], translation: [-118.88991734400046596, -0.04560580387053091, -3.95313736911933855]} -Complete code examples, see `get_img_params.cc `_ . +Complete code examples, see `get_img_params.cc `_ . diff --git a/docs/src/sdk/data/get_imu.rst b/docs/src/sdk/data/get_imu.rst index 99b961f..5039a85 100644 --- a/docs/src/sdk/data/get_imu.rst +++ b/docs/src/sdk/data/get_imu.rst @@ -47,8 +47,13 @@ Sample code snippet: */ painter.DrawImgData(img, *left_data.img); - if (!motion_datas.empty()) { - painter.DrawImuData(img, *motion_datas[0].imu); + static std::vector motion_datas_s = motion_datas; + + if (!motion_datas.empty() && motion_datas.size() > 0) { + motion_datas_s = motion_datas; + } + if (!motion_datas_s.empty() && motion_datas_s.size() > 0) { + painter.DrawImuData(img, *motion_datas_s[0].imu); } cv::imshow("frame", img); @@ -63,4 +68,4 @@ Sample code snippet: OpenCV is used to display image and data. When window is selected, press ``ESC/Q`` to exit program. -Complete code examples, see `get_imu.cc `_ . +Complete code examples, see `get_imu.cc `_ . diff --git a/docs/src/sdk/data/get_imu_correspondence.rst b/docs/src/sdk/data/get_imu_correspondence.rst index 0266bb2..b496a50 100644 --- a/docs/src/sdk/data/get_imu_correspondence.rst +++ b/docs/src/sdk/data/get_imu_correspondence.rst @@ -58,7 +58,7 @@ Reference result on Linux: .. code-block:: bash - $ ./samples/_output/bin/tutorials/get_imu_correspondence + $ ./samples/_output/bin/get_imu_correspondence I/utils.cc:30 Detecting MYNT EYE devices I/utils.cc:40 MYNT EYE devices: I/utils.cc:43 index: 0, name: MYNT-EYE-S1030, sn: 0281351000090807 @@ -106,4 +106,4 @@ Reference result on Linux: I/get_imu_correspondence.cc:61 Imu timestamp: 171419650, diff_prev=2020, diff_img=16608 I/get_imu_correspondence.cc:61 Imu timestamp: 171421660, diff_prev=2010, diff_img=18624 -Complete code examples, see `get_imu_correspondence.cc `_ . +Complete code examples, see `get_imu_correspondence.cc `_ . diff --git a/docs/src/sdk/data/get_imu_params.rst b/docs/src/sdk/data/get_imu_params.rst index c7c5043..9bd44f7 100644 --- a/docs/src/sdk/data/get_imu_params.rst +++ b/docs/src/sdk/data/get_imu_params.rst @@ -15,4 +15,4 @@ Reference commands: LOG(INFO) << "Motion extrinsics left to imu: {" << api->GetMotionExtrinsics(Stream::LEFT) << "}"; -Complete code examples, see `get_imu_params.cc `_ . +Complete code examples, see `get_imu_params.cc `_ . diff --git a/docs/src/sdk/data/get_points.rst b/docs/src/sdk/data/get_points.rst deleted file mode 100644 index 767b4e6..0000000 --- a/docs/src/sdk/data/get_points.rst +++ /dev/null @@ -1,57 +0,0 @@ -.. _data_get_points: - -Get Point Image -================ - -Point images belongs to upper layer of synthetic data. To get this kind of data through ``GetStreamData()``, you need to start the ``EnableStreamData()`` beforehand. It should be check not empty before use. - -For detail process description, please see :ref:`get_stereo` :ref:`get_stereo_rectified` . - -It is recommended to use plugin to calculate depth: the depth map will be better with a higher frame rate. Please see :ref:`get_with_plugin` for detail. - -Sample code snippet: - -.. code-block:: c++ - - auto &&api = API::Create(argc, argv); - - api->EnableStreamData(Stream::POINTS); - - api->Start(Source::VIDEO_STREAMING); - - cv::namedWindow("frame"); - PCViewer pcviewer; - - while (true) { - api->WaitForStreams(); - - auto &&left_data = api->GetStreamData(Stream::LEFT); - auto &&right_data = api->GetStreamData(Stream::RIGHT); - - cv::Mat img; - cv::hconcat(left_data.frame, right_data.frame, img); - cv::imshow("frame", img); - - auto &&points_data = api->GetStreamData(Stream::POINTS); - if (!points_data.frame.empty()) { - pcviewer.Update(points_data.frame); - } - - char key = static_cast(cv::waitKey(1)); - if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q - break; - } - if (pcviewer.WasStopped()) { - break; - } - } - - api->Stop(Source::VIDEO_STREAMING); - -`PCL `_ is used to display point images above. Program will close when point image window is closed. - -Complete code examples, see `get_points.cc `_ . - -.. attention:: - - Sample code only compiles when `PCL `_ is ready. If your PCL was installed in a different directory, please set ``CMAKE_PREFIX_PATH`` in `tutorials/CMakeLists.txt `_ to the path of ``PCLConfig.cmake`` . You can find ``CMAKE_PREFIX_PATH`` near ``find_package(PCL)`` . diff --git a/docs/src/sdk/data/get_stereo.rst b/docs/src/sdk/data/get_stereo.rst index 8e1f8ab..f746d6b 100644 --- a/docs/src/sdk/data/get_stereo.rst +++ b/docs/src/sdk/data/get_stereo.rst @@ -37,4 +37,4 @@ Reference commands: The above code uses OpenCV to display the image. When the display window is selected, pressing ``ESC/Q`` will end the program. -Complete code examples, see `get_stereo.cc `_ . +Complete code examples, see `get_stereo.cc `_ . diff --git a/docs/src/sdk/data/get_stereo_rectified.rst b/docs/src/sdk/data/get_stereo_rectified.rst index 8875a55..28ebd61 100644 --- a/docs/src/sdk/data/get_stereo_rectified.rst +++ b/docs/src/sdk/data/get_stereo_rectified.rst @@ -48,4 +48,4 @@ Reference code snippet: OpenCV is used to display the image above. Select the display window, press ``ESC/Q`` to exit the program. -Complete code examples, see `get_stereo_rectified.cc `_ . +Complete code examples, see `get_stereo_rectified.cc `_ . diff --git a/docs/src/sdk/data/get_with_plugin.rst b/docs/src/sdk/data/get_with_plugin.rst index 1f7c91a..072461b 100644 --- a/docs/src/sdk/data/get_with_plugin.rst +++ b/docs/src/sdk/data/get_with_plugin.rst @@ -83,7 +83,7 @@ In addition, the following command can be executed to check whether the dependen If the plugin's dependent library is not found, it will report an error \"Open plugin failed\" when loading. -Complete code sample, see `get_with_plugin.cc `_ . +Complete code sample, see `get_with_plugin.cc `_ . .. tip:: diff --git a/docs/src/sdk/data/save_params.rst b/docs/src/sdk/data/save_params.rst index ec36086..45cd55e 100644 --- a/docs/src/sdk/data/save_params.rst +++ b/docs/src/sdk/data/save_params.rst @@ -3,22 +3,22 @@ Save Device Infomation And Parameters ===================================== -The SDK provides a tool ``save_all_infos`` for save information and parameters. For more information, please read `tools/README.md `_ . +The SDK provides a tool ``save_all_infos`` for save information and parameters. Reference commands: .. code-block:: bash - ./tools/_output/bin/writer/save_all_infos + ./samples/_output/bin/save_all_infos # Windows - .\tools\_output\bin\writer\save_all_infos.bat + .\samples\_output\bin\save_all_infos.bat Reference result on Linux: .. code-block:: bash - $ ./tools/_output/bin/writer/save_all_infos + $ ./samples/_output/bin/save_all_infos I0512 21:40:08.687088 4092 utils.cc:26] Detecting MYNT EYE devices I0512 21:40:09.366693 4092 utils.cc:33] MYNT EYE devices: I0512 21:40:09.366734 4092 utils.cc:37] index: 0, name: MYNT-EYE-S1000 diff --git a/docs/src/sdk/data/save_single_image.rst b/docs/src/sdk/data/save_single_image.rst index b8ab965..8cbe818 100644 --- a/docs/src/sdk/data/save_single_image.rst +++ b/docs/src/sdk/data/save_single_image.rst @@ -49,4 +49,4 @@ Reference commands: The above code uses OpenCV to display the image. When the display window is selected, pressing ``ESC/Q`` will end the program. -Complete code examples, see `save_single_image.cc `_ . +Complete code examples, see `save_single_image.cc `_ . diff --git a/docs/src/sdk/data/write_img_params.rst b/docs/src/sdk/data/write_img_params.rst index 06b3f57..9911b9c 100644 --- a/docs/src/sdk/data/write_img_params.rst +++ b/docs/src/sdk/data/write_img_params.rst @@ -3,7 +3,7 @@ Write Image Parameters ======================= -The SDK provides a tool ``img_params_writer`` for writing image parameters. For details, read `tools/README.md `_ . +The SDK provides a tool ``write_img_params`` for writing image parameters. For getting image parameters, please read :ref:`get_img_params`. This is used to calculate the deviation. @@ -11,21 +11,21 @@ Reference commands: .. code-block:: bash - ./tools/_output/bin/writer/img_params_writer tools/writer/config/img.params + ./samples/_output/bin/write_img_params samples/config/img.params # Windows - .\tools\_output\bin\writer\img_params_writer.bat tools\writer\config\img.params + .\samples\_output\bin\write_img_params.bat samples\config\img.params .. warning:: Please don't override parameters, you can use ``save_all_infos`` to backup parameters. -And, `tools/writer/config/S1030/img.params.pinhole `_ is the path of S1030 pihole parameters file. If you calibrated parameters yourself, you can edit it and run previous commands to write them into the devices. +And, `samples/config/S1030/img.params.pinhole `_ is the path of S1030 pihole parameters file. If you calibrated parameters yourself, you can edit it and run previous commands to write them into the devices. .. tip:: - The image calibration parameters of S2100/S210A are in ``tools/writer/config/S210A`` - The image calibration parameters of S1030 are in ``tools/writer/config/S1030`` + The image calibration parameters of S2100/S210A are in ``samples/config/S210A`` + The image calibration parameters of S1030 are in ``samples/config/S1030`` .. tip:: diff --git a/docs/src/sdk/data/write_imu_params.rst b/docs/src/sdk/data/write_imu_params.rst index b91f50a..88864cb 100644 --- a/docs/src/sdk/data/write_imu_params.rst +++ b/docs/src/sdk/data/write_imu_params.rst @@ -3,7 +3,7 @@ Write IMU Parameters ===================== -SDK provides the tool ``imu_params_writer`` to write IMU parameters. For deltail, please read `tools/README.md `_ . +SDK provides the tool ``write_imu_params`` to write IMU parameters. Information about how to get IMU parameters, please read :ref:`get_imu_params` . @@ -11,12 +11,12 @@ Reference commands: .. code-block:: bash - ./tools/_output/bin/writer/imu_params_writer tools/writer/config/imu.params + ./samples/_output/bin/write_imu_params samples/config/imu.params # Windows - .\tools\_output\bin\writer\imu_params_writer.bat tools\writer\config\imu.params + .\samples\_output\bin\write_imu_params.bat samples\config\imu.params -The path of parameters file can be found in `tools/writer/config/img.params `_ . If you calibrated the parameters yourself, you can edit the file and run above commands to write them into the device. +The path of parameters file can be found in `samples/config/img.params `_ . If you calibrated the parameters yourself, you can edit the file and run above commands to write them into the device. .. warning:: diff --git a/docs/src/sdk/project/cmake.rst b/docs/src/sdk/project/cmake.rst index a15c5de..1f96361 100644 --- a/docs/src/sdk/project/cmake.rst +++ b/docs/src/sdk/project/cmake.rst @@ -5,7 +5,7 @@ How to use SDK with CMake This tutorial will create a project with CMake to start using SDK. - You could find the project demo in ``/platforms/projects/cmake directory`` . + You could find the project demo in ``/samples/simple_demo/project_cmake directory`` . Preparation ----------- diff --git a/docs/src/sdk/project/vs2017.rst b/docs/src/sdk/project/vs2017.rst index 605a999..31f4aa6 100644 --- a/docs/src/sdk/project/vs2017.rst +++ b/docs/src/sdk/project/vs2017.rst @@ -5,7 +5,7 @@ How to use SDK with Visual Studio 2017 This tutorial will create a project with Visual Studio 2017 to start using SDK. - You could find the project demo in ``/platforms/projects/vs2017`` directory. + You could find the project demo in ``/samples/simple_demo/project_vs2017`` directory. Preparation ------------ diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 2e7b8db..74212b8 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -242,4 +242,40 @@ if(WITH_API) endif() endif() +## device_writer + +add_library(device_writer STATIC device_writer.cc) +target_link_libraries(device_writer mynteye ${OpenCV_LIBS}) + +## device_info_writer + +make_executable(write_device_info + SRCS write_device_info.cc + LINK_LIBS device_writer + DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH} +) + +## img_params_writer + +make_executable(write_img_params + SRCS write_img_params.cc + LINK_LIBS device_writer + DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH} +) + +## imu_params_writer + +make_executable(write_imu_params + SRCS write_imu_params.cc + LINK_LIBS device_writer + DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH} +) + +## save_all_infos + +make_executable(save_all_infos + SRCS save_all_infos.cc + LINK_LIBS device_writer + DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH} +) diff --git a/samples/config/S1030/deprecated/img.params.old b/samples/config/S1030/deprecated/img.params.old new file mode 100644 index 0000000..54f6f39 --- /dev/null +++ b/samples/config/S1030/deprecated/img.params.old @@ -0,0 +1,41 @@ +%YAML:1.0 +--- +M1: !!opencv-matrix + rows: 3 + cols: 3 + dt: d + data: [ 7.3638305001095546e+02, 0., 3.5691961817119693e+02, 0., + 7.2350066150722432e+02, 2.1727271340923883e+02, 0., 0., 1. ] +D1: !!opencv-matrix + rows: 1 + cols: 14 + dt: d + data: [ -5.4898645145016478e-01, 5.2837141203888638e-01, 0., 0., 0., + 0., 0., 4.3563985766435476e-01, 0., 0., 0., 0., 0., 0. ] +M2: !!opencv-matrix + rows: 3 + cols: 3 + dt: d + data: [ 7.3638305001095546e+02, 0., 4.5668367112303980e+02, 0., + 7.2350066150722432e+02, 2.5070083335536796e+02, 0., 0., 1. ] +D2: !!opencv-matrix + rows: 1 + cols: 14 + dt: d + data: [ -5.1012886039889305e-01, 3.8764476500996770e-01, 0., 0., 0., + 0., 0., 2.5629798245273044e-01, 0., 0., 0., 0., 0., 0. ] +R: !!opencv-matrix + rows: 3 + cols: 3 + dt: d + data: [ 9.9701893306553813e-01, -9.5378124886236681e-04, + -7.7151392794850615e-02, 1.4493996762830500e-03, + 9.9997867219985104e-01, 6.3682325649414354e-03, + 7.7143673424555026e-02, -6.4610716411527686e-03, + 9.9699905125522237e-01 ] +T: !!opencv-matrix + rows: 3 + cols: 1 + dt: d + data: [ -1.1888991734400047e+02, -4.5605803870530912e-02, + -3.9531373691193386e+00 ] diff --git a/samples/config/S1030/deprecated/img.params.old2 b/samples/config/S1030/deprecated/img.params.old2 new file mode 100644 index 0000000..350a171 --- /dev/null +++ b/samples/config/S1030/deprecated/img.params.old2 @@ -0,0 +1,30 @@ +%YAML:1.0 +--- +in_left: + width: 752 + height: 480 + fx: 3.6220059643202876e+02 + fy: 3.6350065250745848e+02 + cx: 4.0658699068023441e+02 + cy: 2.3435161110061483e+02 + model: 0 + coeffs: [ -2.5034765682756088e-01, 5.0579399202897619e-02, + -7.0536676161976066e-04, -8.5255451307033846e-03, 0. ] +in_right: + width: 752 + height: 480 + fx: 3.6514014888558478e+02 + fy: 3.6513385298966961e+02 + cx: 3.8932395100630907e+02 + cy: 2.3495160212312547e+02 + model: 0 + coeffs: [ -3.0377346762098512e-01, 7.9929693673999838e-02, + 5.1547517530716883e-05, -6.7345903740579250e-04, 0. ] +ex_right_to_left: + rotation: [ 9.9867908939669447e-01, -6.3445566137485428e-03, + 5.0988459509619687e-02, 5.9890316389333252e-03, + 9.9995670037792639e-01, 7.1224201868366971e-03, + -5.1031440326695092e-02, -6.8076406092671274e-03, + 9.9867384471984544e-01 ] + translation: [ -1.2002489764113250e+02, -1.1782637409050747e+00, + -5.2058205159996538e+00 ] diff --git a/samples/config/S1030/deprecated/img.params.old3 b/samples/config/S1030/deprecated/img.params.old3 new file mode 100644 index 0000000..28d2f6a --- /dev/null +++ b/samples/config/S1030/deprecated/img.params.old3 @@ -0,0 +1,33 @@ +%YAML:1.0 +--- +version: "1.0" +img_params_map: + - + in_left: + width: 752 + height: 480 + fx: 3.6220059643202876e+02 + fy: 3.6350065250745848e+02 + cx: 4.0658699068023441e+02 + cy: 2.3435161110061483e+02 + model: 0 + coeffs: [ -2.5034765682756088e-01, 5.0579399202897619e-02, + -7.0536676161976066e-04, -8.5255451307033846e-03, 0. ] + in_right: + width: 752 + height: 480 + fx: 3.6514014888558478e+02 + fy: 3.6513385298966961e+02 + cx: 3.8932395100630907e+02 + cy: 2.3495160212312547e+02 + model: 0 + coeffs: [ -3.0377346762098512e-01, 7.9929693673999838e-02, + 5.1547517530716883e-05, -6.7345903740579250e-04, 0. ] + ex_right_to_left: + rotation: [ 9.9867908939669447e-01, -6.3445566137485428e-03, + 5.0988459509619687e-02, 5.9890316389333252e-03, + 9.9995670037792639e-01, 7.1224201868366971e-03, + -5.1031440326695092e-02, -6.8076406092671274e-03, + 9.9867384471984544e-01 ] + translation: [ -1.2002489764113250e+02, -1.1782637409050747e+00, + -5.2058205159996538e+00 ] diff --git a/samples/config/S1030/deprecated/imu.params.old b/samples/config/S1030/deprecated/imu.params.old new file mode 100644 index 0000000..4500d4e --- /dev/null +++ b/samples/config/S1030/deprecated/imu.params.old @@ -0,0 +1,24 @@ +%YAML:1.0 +--- +in_accel: + scale: [ 1., 0., 0., 0., 1., 0., 0., 0., 1. ] + drift: [ 0., 0., 0. ] + noise: [ 1.6925432397973516e-02, 1.6735310195561025e-02, + 1.7452487504590969e-02 ] + bias: [ 1.9031356589714596e-04, 1.6996777864587261e-04, + 5.4490537096493644e-04 ] +in_gyro: + scale: [ 1., 0., 0., 0., 1., 0., 0., 0., 1. ] + drift: [ 0., 0., 0. ] + noise: [ 1.0848026158819934e-03, 1.2466367883501759e-03, + 1.1003229919806443e-03 ] + bias: [ 2.3404834136742844e-05, 2.3596771567764949e-05, + 1.4970418056326829e-05 ] +ex_left_to_imu: + rotation: [ -6.4662000000000001e-03, -9.9994994000000004e-01, + -7.6356499999999999e-03, 9.9997908999999996e-01, + -6.4656599999999998e-03, -9.5580000000000003e-05, + 4.6199999999999998e-05, -7.6361099999999998e-03, + 9.9997084000000003e-01 ] + translation: [ 5.3364600000000003e-03, -4.3029220000000000e-02, + 2.3031240000000001e-02 ] diff --git a/samples/config/S1030/device.info b/samples/config/S1030/device.info new file mode 100644 index 0000000..0c9e26b --- /dev/null +++ b/samples/config/S1030/device.info @@ -0,0 +1,10 @@ +%YAML:1.0 +--- +device_name: MYNT-EYE-S1030 +serial_number: "02811F3B00090807" +firmware_version: "2.2" +hardware_version: "2.0" +spec_version: "1.0" +lens_type: "0000" +imu_type: "0000" +nominal_baseline: 120 diff --git a/samples/config/S1030/img.params.equidistant b/samples/config/S1030/img.params.equidistant new file mode 100644 index 0000000..06600b5 --- /dev/null +++ b/samples/config/S1030/img.params.equidistant @@ -0,0 +1,28 @@ +%YAML:1.0 +--- +version: "1.2" +img_params: + - + model: 1 + width: 752 + height: 480 + in_left: + # coeffs: k2,k3,k4,k5,mu,mv,u0,v0 + coeffs: [ -1.3549950401924169e-02, -3.2306077263853893e-02, + 5.3814579203036512e-02, -3.6663721418756977e-02, + 3.6797709792391299e+02, 3.6808712539453859e+02, + 3.7414963027144353e+02, 2.3125000326472903e+02 ] + in_right: + # coeffs: k2,k3,k4,k5,mu,mv,u0,v0 + coeffs: [ -1.8964880945048872e-02, -2.6172447729615463e-02, + 4.0863326732708288e-02, -2.1522718578606163e-02, + 3.6807315003638877e+02, 3.6806204885853174e+02, + 3.8499216569965887e+02, 2.3183027347834383e+02 ] + ex_right_to_left: + rotation: [ 9.9867908939669447e-01, -6.3445566137485428e-03, + 5.0988459509619687e-02, 5.9890316389333252e-03, + 9.9995670037792639e-01, 7.1224201868366971e-03, + -5.1031440326695092e-02, -6.8076406092671274e-03, + 9.9867384471984544e-01 ] + translation: [ -1.2002489764113250e+02, -1.1782637409050747e+00, + -5.2058205159996538e+00 ] diff --git a/samples/config/S1030/img.params.pinhole b/samples/config/S1030/img.params.pinhole new file mode 100644 index 0000000..a375acc --- /dev/null +++ b/samples/config/S1030/img.params.pinhole @@ -0,0 +1,38 @@ +%YAML:1.0 +--- +version: "1.2" +img_params: + - + model: 0 + width: 752 + height: 480 + in_left: + # [fx 0 cx] + # [ 0 fy cy] + # [ 0 0 1] + fx: 3.6220059643202876e+02 + fy: 3.6350065250745848e+02 + cx: 4.0658699068023441e+02 + cy: 2.3435161110061483e+02 + # coeffs: k1,k2,p1,p2,k3 + coeffs: [ -2.5034765682756088e-01, 5.0579399202897619e-02, + -7.0536676161976066e-04, -8.5255451307033846e-03, 0. ] + in_right: + # [fx 0 cx] + # [ 0 fy cy] + # [ 0 0 1] + fx: 3.6514014888558478e+02 + fy: 3.6513385298966961e+02 + cx: 3.8932395100630907e+02 + cy: 2.3495160212312547e+02 + # coeffs: k1,k2,p1,p2,k3 + coeffs: [ -3.0377346762098512e-01, 7.9929693673999838e-02, + 5.1547517530716883e-05, -6.7345903740579250e-04, 0. ] + ex_right_to_left: + rotation: [ 9.9867908939669447e-01, -6.3445566137485428e-03, + 5.0988459509619687e-02, 5.9890316389333252e-03, + 9.9995670037792639e-01, 7.1224201868366971e-03, + -5.1031440326695092e-02, -6.8076406092671274e-03, + 9.9867384471984544e-01 ] + translation: [ -1.2002489764113250e+02, -1.1782637409050747e+00, + -5.2058205159996538e+00 ] diff --git a/samples/config/S1030/imu.params b/samples/config/S1030/imu.params new file mode 100644 index 0000000..93ad7e8 --- /dev/null +++ b/samples/config/S1030/imu.params @@ -0,0 +1,33 @@ +%YAML:1.0 +--- +version: "1.2" +in_accel: + scale: [ 1., 0., 0., 0., 1., 0., 0., 0., 1. ] + assembly: [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] + drift: [ 0., 0., 0. ] + noise: [ 1.6925432397973516e-02, 1.6735310195561025e-02, + 1.7452487504590969e-02 ] + bias: [ 1.9031356589714596e-04, 1.6996777864587261e-04, + 5.4490537096493644e-04 ] + x: [ 0.0, 0.0 ] + y: [ 0.0, 0.0 ] + z: [ 0.0, 0.0 ] +in_gyro: + scale: [ 1., 0., 0., 0., 1., 0., 0., 0., 1. ] + assembly: [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] + drift: [ 0., 0., 0. ] + noise: [ 1.0848026158819934e-03, 1.2466367883501759e-03, + 1.1003229919806443e-03 ] + bias: [ 2.3404834136742844e-05, 2.3596771567764949e-05, + 1.4970418056326829e-05 ] + x: [ 0.0, 0.0 ] + y: [ 0.0, 0.0 ] + z: [ 0.0, 0.0 ] +ex_left_to_imu: + rotation: [ -6.4662000000000001e-03, -9.9994994000000004e-01, + -7.6356499999999999e-03, 9.9997908999999996e-01, + -6.4656599999999998e-03, -9.5580000000000003e-05, + 4.6199999999999998e-05, -7.6361099999999998e-03, + 9.9997084000000003e-01 ] + translation: [ 5.3364600000000003e-03, -4.3029220000000000e-02, + 2.3031240000000001e-02 ] diff --git a/samples/config/S210A/deprecated/img.params.old b/samples/config/S210A/deprecated/img.params.old new file mode 100644 index 0000000..a368dbb --- /dev/null +++ b/samples/config/S210A/deprecated/img.params.old @@ -0,0 +1,62 @@ +%YAML:1.0 +--- +version: "1.1" +img_params_map: + - + in_left: + width: 640 + height: 400 + fx: 1.9739641213416058e+02 + fy: 1.9772337597617189e+02 + cx: 3.2611983633916327e+02 + cy: 1.9986969132833946e+02 + model: 0 + coeffs: [ 1.2135236310725651e-01, -8.5442776049177036e-02, + 2.4914898631983504e-03, -3.7752063658256863e-03, 0. ] + in_right: + width: 640 + height: 400 + fx: 2.0335498653655989e+02 + fy: 2.0453858622699008e+02 + cx: 3.1589962248180814e+02 + cy: 2.1871688038954812e+02 + model: 0 + coeffs: [ 2.2904330559241560e-02, -2.9561990079971841e-02, + 3.9725942760981507e-03, -3.9689073214945591e-03, 0. ] + ex_right_to_left: + rotation: [ 9.9998850083695123e-01, -1.9263678722299450e-03, + -4.3917309443490191e-03, 1.8166060642710027e-03, + 9.9968925981619028e-01, -2.4861290203142431e-02, + 4.4382582477776426e-03, 2.4853026274046636e-02, + 9.9968126367795229e-01 ] + translation: [ -8.2270200890555529e+01, -1.9535144360069059e+00, + 2.2588034344482368e+00 ] + - + in_left: + width: 1280 + height: 800 + fx: 1.9739641213416058e+02 + fy: 1.9772337597617189e+02 + cx: 3.2611983633916327e+02 + cy: 1.9986969132833946e+02 + model: 0 + coeffs: [ 1.2135236310725651e-01, -8.5442776049177036e-02, + 2.4914898631983504e-03, -3.7752063658256863e-03, 0. ] + in_right: + width: 1280 + height: 800 + fx: 2.0335498653655989e+02 + fy: 2.0453858622699008e+02 + cx: 3.1589962248180814e+02 + cy: 2.1871688038954812e+02 + model: 0 + coeffs: [ 2.2904330559241560e-02, -2.9561990079971841e-02, + 3.9725942760981507e-03, -3.9689073214945591e-03, 0. ] + ex_right_to_left: + rotation: [ 9.9998850083695123e-01, -1.9263678722299450e-03, + -4.3917309443490191e-03, 1.8166060642710027e-03, + 9.9968925981619028e-01, -2.4861290203142431e-02, + 4.4382582477776426e-03, 2.4853026274046636e-02, + 9.9968126367795229e-01 ] + translation: [ -8.2270200890555529e+01, -1.9535144360069059e+00, + 2.2588034344482368e+00 ] diff --git a/samples/config/S210A/deprecated/imu.params.old b/samples/config/S210A/deprecated/imu.params.old new file mode 100644 index 0000000..070f13a --- /dev/null +++ b/samples/config/S210A/deprecated/imu.params.old @@ -0,0 +1,15 @@ +%YAML:1.0 +--- +in_accel: + scale: [ 0., 0., 0., 0., 0., 0., 0., 0., 0. ] + drift: [ 0., 0., 0. ] + noise: [ 0., 0., 0. ] + bias: [ 0., 0., 0. ] +in_gyro: + scale: [ 0., 0., 0., 0., 0., 0., 0., 0., 0. ] + drift: [ 0., 0., 0. ] + noise: [ 0., 0., 0. ] + bias: [ 0., 0., 0. ] +ex_left_to_imu: + rotation: [ 0., 0., 0., 0., 0., 0., 0., 0., 0. ] + translation: [ 0., 0., 0. ] diff --git a/samples/config/S210A/device.info b/samples/config/S210A/device.info new file mode 100644 index 0000000..d7f4e16 --- /dev/null +++ b/samples/config/S210A/device.info @@ -0,0 +1,12 @@ +%YAML:1.0 +--- +device_name: MYNT-EYE-S210A +serial_number: "07C40D1C0009071F" +firmware_version: "1.1" +hardware_version: "1.0" +spec_version: "1.2" +lens_type: "0001" +imu_type: "0001" +nominal_baseline: 80 +auxiliary_chip_version: "1.0" +isp_version: "1.0" diff --git a/samples/config/S210A/img.params.equidistant b/samples/config/S210A/img.params.equidistant new file mode 100644 index 0000000..8949748 --- /dev/null +++ b/samples/config/S210A/img.params.equidistant @@ -0,0 +1,51 @@ +%YAML:1.0 +--- +version: "1.2" +img_params: + # There are two params of resolution [640x400], [1280x800]. + # If you only set one of them, write will keep another params if it exists. + - + model: 1 + width: 640 + height: 400 + in_left: + # coeffs: k2,k3,k4,k5,mu,mv,u0,v0 + coeffs: [ -1.3549950401924169e-02, -3.2306077263853893e-02, + 5.3814579203036512e-02, -3.6663721418756977e-02, + 3.6797709792391299e+02, 3.6808712539453859e+02, + 3.7414963027144353e+02, 2.3125000326472903e+02 ] + in_right: + coeffs: [ -1.8964880945048872e-02, -2.6172447729615463e-02, + 4.0863326732708288e-02, -2.1522718578606163e-02, + 3.6807315003638877e+02, 3.6806204885853174e+02, + 3.8499216569965887e+02, 2.3183027347834383e+02 ] + ex_right_to_left: + rotation: [ 9.9998850083695123e-01, -1.9263678722299450e-03, + -4.3917309443490191e-03, 1.8166060642710027e-03, + 9.9968925981619028e-01, -2.4861290203142431e-02, + 4.4382582477776426e-03, 2.4853026274046636e-02, + 9.9968126367795229e-01 ] + translation: [ -8.2270200890555529e+01, -1.9535144360069059e+00, + 2.2588034344482368e+00 ] + - + model: 1 + width: 1280 + height: 800 + in_left: + coeffs: [ -1.3549950401924169e-02, -3.2306077263853893e-02, + 5.3814579203036512e-02, -3.6663721418756977e-02, + 3.6797709792391299e+02, 3.6808712539453859e+02, + 3.7414963027144353e+02, 2.3125000326472903e+02 ] + in_right: + coeffs: [ -1.3549950401924169e-02, -3.2306077263853893e-02, + 5.3814579203036512e-02, -3.6663721418756977e-02, + 3.6797709792391299e+02, 3.6808712539453859e+02, + 3.7414963027144353e+02, 2.3125000326472903e+02 ] + ex_right_to_left: + rotation: [ 9.9998850083695123e-01, -1.9263678722299450e-03, + -4.3917309443490191e-03, 1.8166060642710027e-03, + 9.9968925981619028e-01, -2.4861290203142431e-02, + 4.4382582477776426e-03, 2.4853026274046636e-02, + 9.9968126367795229e-01 ] + translation: [ -8.2270200890555529e+01, -1.9535144360069059e+00, + 2.2588034344482368e+00 ] diff --git a/samples/config/S210A/img.params.pinhole b/samples/config/S210A/img.params.pinhole new file mode 100644 index 0000000..eb1b2a7 --- /dev/null +++ b/samples/config/S210A/img.params.pinhole @@ -0,0 +1,62 @@ +%YAML:1.0 +--- +version: "1.2" +img_params: + # There are two params of resolution [640x400], [1280x800]. + # If you only set one of them, write will keep another params if it exists. + - + model: 0 + width: 640 + height: 400 + in_left: + # [fx 0 cx] + # [ 0 fy cy] + # [ 0 0 1] + fx: 1.9739641213416058e+02 + fy: 1.9772337597617189e+02 + cx: 3.2611983633916327e+02 + cy: 1.9986969132833946e+02 + # coeffs: k1,k2,p1,p2,k3 + coeffs: [ 1.2135236310725651e-01, -8.5442776049177036e-02, + 2.4914898631983504e-03, -3.7752063658256863e-03, 0. ] + in_right: + fx: 2.0335498653655989e+02 + fy: 2.0453858622699008e+02 + cx: 3.1589962248180814e+02 + cy: 2.1871688038954812e+02 + coeffs: [ 2.2904330559241560e-02, -2.9561990079971841e-02, + 3.9725942760981507e-03, -3.9689073214945591e-03, 0. ] + ex_right_to_left: + rotation: [ 9.9998850083695123e-01, -1.9263678722299450e-03, + -4.3917309443490191e-03, 1.8166060642710027e-03, + 9.9968925981619028e-01, -2.4861290203142431e-02, + 4.4382582477776426e-03, 2.4853026274046636e-02, + 9.9968126367795229e-01 ] + translation: [ -8.2270200890555529e+01, -1.9535144360069059e+00, + 2.2588034344482368e+00 ] + - + model: 0 + width: 1280 + height: 800 + in_left: + fx: 1.9739641213416058e+02 + fy: 1.9772337597617189e+02 + cx: 3.2611983633916327e+02 + cy: 1.9986969132833946e+02 + coeffs: [ 1.2135236310725651e-01, -8.5442776049177036e-02, + 2.4914898631983504e-03, -3.7752063658256863e-03, 0. ] + in_right: + fx: 2.0335498653655989e+02 + fy: 2.0453858622699008e+02 + cx: 3.1589962248180814e+02 + cy: 2.1871688038954812e+02 + coeffs: [ 2.2904330559241560e-02, -2.9561990079971841e-02, + 3.9725942760981507e-03, -3.9689073214945591e-03, 0. ] + ex_right_to_left: + rotation: [ 9.9998850083695123e-01, -1.9263678722299450e-03, + -4.3917309443490191e-03, 1.8166060642710027e-03, + 9.9968925981619028e-01, -2.4861290203142431e-02, + 4.4382582477776426e-03, 2.4853026274046636e-02, + 9.9968126367795229e-01 ] + translation: [ -8.2270200890555529e+01, -1.9535144360069059e+00, + 2.2588034344482368e+00 ] diff --git a/samples/config/S210A/imu.params b/samples/config/S210A/imu.params new file mode 100644 index 0000000..93ad7e8 --- /dev/null +++ b/samples/config/S210A/imu.params @@ -0,0 +1,33 @@ +%YAML:1.0 +--- +version: "1.2" +in_accel: + scale: [ 1., 0., 0., 0., 1., 0., 0., 0., 1. ] + assembly: [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] + drift: [ 0., 0., 0. ] + noise: [ 1.6925432397973516e-02, 1.6735310195561025e-02, + 1.7452487504590969e-02 ] + bias: [ 1.9031356589714596e-04, 1.6996777864587261e-04, + 5.4490537096493644e-04 ] + x: [ 0.0, 0.0 ] + y: [ 0.0, 0.0 ] + z: [ 0.0, 0.0 ] +in_gyro: + scale: [ 1., 0., 0., 0., 1., 0., 0., 0., 1. ] + assembly: [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] + drift: [ 0., 0., 0. ] + noise: [ 1.0848026158819934e-03, 1.2466367883501759e-03, + 1.1003229919806443e-03 ] + bias: [ 2.3404834136742844e-05, 2.3596771567764949e-05, + 1.4970418056326829e-05 ] + x: [ 0.0, 0.0 ] + y: [ 0.0, 0.0 ] + z: [ 0.0, 0.0 ] +ex_left_to_imu: + rotation: [ -6.4662000000000001e-03, -9.9994994000000004e-01, + -7.6356499999999999e-03, 9.9997908999999996e-01, + -6.4656599999999998e-03, -9.5580000000000003e-05, + 4.6199999999999998e-05, -7.6361099999999998e-03, + 9.9997084000000003e-01 ] + translation: [ 5.3364600000000003e-03, -4.3029220000000000e-02, + 2.3031240000000001e-02 ] diff --git a/samples/device_writer.cc b/samples/device_writer.cc new file mode 100644 index 0000000..722a716 --- /dev/null +++ b/samples/device_writer.cc @@ -0,0 +1,590 @@ +// Copyright 2018 Slightech Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include "device_writer.h" + +#include + +#include + +#include "mynteye/logger.h" +#include "mynteye/util/files.h" + +#define SAVE_LATEST_VERSION Version(1, 2) + +MYNTEYE_BEGIN_NAMESPACE + +namespace tools { + +DeviceWriter::DeviceWriter(std::shared_ptr device) : device_(device) { + VLOG(2) << __func__; +} + +DeviceWriter::~DeviceWriter() { + VLOG(2) << __func__; +} + +bool DeviceWriter::WriteDeviceInfo(const dev_info_t &info) { + // Update device info + auto &&dev_info = device_->GetInfo(); + dev_info->lens_type = Type(info.lens_type); + dev_info->imu_type = Type(info.imu_type); + dev_info->nominal_baseline = info.nominal_baseline; + + if (device_->SetFiles(dev_info.get(), nullptr, nullptr)) { + LOG(INFO) << "Write device info success"; + LOG(INFO) << "Device info: {name: " << dev_info->name + << ", serial_number: " << dev_info->serial_number + << ", firmware_version: " + << dev_info->firmware_version.to_string() + << ", hardware_version: " + << dev_info->hardware_version.to_string() + << ", spec_version: " << dev_info->spec_version.to_string() + << ", lens_type: " << dev_info->lens_type.to_string() + << ", imu_type: " << dev_info->imu_type.to_string() + << ", nominal_baseline: " << dev_info->nominal_baseline + << ", auxiliary_chip_version: " + << dev_info->auxiliary_chip_version.to_string() + << ", isp_version: " + << dev_info->isp_version.to_string()<< "}"; + return true; + } else { + LOG(ERROR) << "Write device info failed"; + return false; + } +} + +bool DeviceWriter::WriteDeviceInfo(const std::string &filepath) { + return WriteDeviceInfo(LoadDeviceInfo(filepath)); +} + +bool DeviceWriter::WriteImgParams(const img_params_map_t &img_params_map) { + img_params_map_t *img_params_new = + const_cast(&img_params_map); + // Update image params with raw + auto &&img_params_raw = device_->GetImgParams(); + for (auto entry_raw : img_params_raw) { + // Add raw params if not load this resolution + if (img_params_new->find(entry_raw.first) == img_params_new->end()) { + (*img_params_new)[entry_raw.first] = entry_raw.second; + } + } + + if (device_->SetFiles(nullptr, img_params_new, nullptr)) { + LOG(INFO) << "Write img params success"; + for (auto it = img_params_new->begin(); it != img_params_new->end(); it++) { + LOG(INFO) << "Resolution: {width: " << (*it).first.width + << ", height: " << (*it).first.height << "}"; + LOG(INFO) << "Intrinsics left: {" << *(*it).second.in_left << "}"; + LOG(INFO) << "Intrinsics right: {" << *(*it).second.in_right << "}"; + LOG(INFO) << "Extrinsics right to left: {" + << (*it).second.ex_right_to_left << "}"; + } + return true; + } else { + LOG(ERROR) << "Write img params failed"; + return false; + } +} + +bool DeviceWriter::WriteImgParams(const std::string &filepath) { + return WriteImgParams(LoadImgParams(filepath)); +} + +bool DeviceWriter::WriteImuParams(const imu_params_t ¶ms) { + if (device_->SetFiles( + nullptr, nullptr, const_cast(¶ms))) { + LOG(INFO) << "Write imu params success"; + LOG(INFO) << "Imu intrinsics accel: {" << params.in_accel << "}"; + LOG(INFO) << "Imu intrinsics gyro: {" << params.in_gyro << "}"; + LOG(INFO) << "Imu extrinsics left to imu: {" << params.ex_left_to_imu + << "}"; + return true; + } else { + LOG(ERROR) << "Write imu params failed"; + return false; + } +} + +bool DeviceWriter::WriteImuParams(const std::string &filepath) { + return WriteImuParams(LoadImuParams(filepath)); +} + +namespace { + +cv::FileStorage &operator<<(cv::FileStorage &fs, const IntrinsicsPinhole &in) { + fs << "{" + << "fx" << in.fx << "fy" << in.fy + << "cx" << in.cx << "cy" << in.cy + << "coeffs" << std::vector(in.coeffs, in.coeffs + 5) << "}"; + return fs; +} + +cv::FileStorage &operator<<(cv::FileStorage &fs, + const IntrinsicsEquidistant &in) { + fs << "{" + << "coeffs" << std::vector(in.coeffs, in.coeffs + 8) << "}"; + return fs; +} + +cv::FileStorage &operator<<(cv::FileStorage &fs, + const std::shared_ptr &in) { + switch (in->calib_model()) { + case CalibrationModel::PINHOLE: + return fs << *std::dynamic_pointer_cast(in); + case CalibrationModel::KANNALA_BRANDT: + return fs << *std::dynamic_pointer_cast(in); + default: + LOG(FATAL) << "Unknown calib model: " << in->calib_model(); + return fs; + } +} + +cv::FileStorage &operator<<(cv::FileStorage &fs, const ImuIntrinsics &in) { + std::vector scales; + for (std::size_t i = 0; i < 3; i++) { + for (std::size_t j = 0; j < 3; j++) { + scales.push_back(in.scale[i][j]); + } + } + std::vector assembly; + for (std::size_t i = 0; i < 3; i++) { + for (std::size_t j = 0; j < 3; j++) { + assembly.push_back(in.assembly[i][j]); + } + } + fs << "{" + << "scale" << scales << "assembly" << assembly << "drift" + << std::vector(in.drift, in.drift + 3) << "noise" + << std::vector(in.noise, in.noise + 3) << "bias" + << std::vector(in.bias, in.bias + 3) << "x" + << std::vector(in.x, in.x + 2) << "y" + << std::vector(in.y, in.y + 2) << "z" + << std::vector(in.z, in.z + 2) << "}"; + return fs; +} + +cv::FileStorage &operator<<(cv::FileStorage &fs, const Extrinsics &ex) { + std::vector rotations; + for (std::size_t i = 0; i < 3; i++) { + for (std::size_t j = 0; j < 3; j++) { + rotations.push_back(ex.rotation[i][j]); + } + } + fs << "{" + << "rotation" << rotations << "translation" + << std::vector(ex.translation, ex.translation + 3) << "}"; + return fs; +} + +cv::FileStorage &operator<<( + cv::FileStorage &fs, const device::img_params_t ¶ms) { + fs << "{" + << "model" << static_cast(params.in_left->calib_model()) + << "width" << params.in_left->width + << "height" << params.in_left->height + << "in_left" << params.in_left + << "in_right" << params.in_right + << "ex_right_to_left" << params.ex_right_to_left << "}"; + return fs; +} + +cv::FileStorage &operator<<( + cv::FileStorage &fs, const DeviceWriter::img_params_map_t &img_params_map) { + fs << "["; + std::map::const_iterator it; + for (it = img_params_map.begin(); it != img_params_map.end(); it++) { + fs << (*it).second; + } + fs << "]"; + return fs; +} + +} // namespace + +bool DeviceWriter::SaveDeviceInfo( + const dev_info_t &info, const std::string &filepath) { + using FileStorage = cv::FileStorage; + FileStorage fs(filepath, FileStorage::WRITE); + if (!fs.isOpened()) { + LOG(ERROR) << "Failed to save file: " << filepath; + return false; + } + fs << "device_name" << info.name; + fs << "serial_number" << info.serial_number; + fs << "firmware_version" << info.firmware_version.to_string(); + fs << "hardware_version" << info.hardware_version.to_string(); + fs << "spec_version" << info.spec_version.to_string(); + fs << "lens_type" << info.lens_type.to_string(); + fs << "imu_type" << info.imu_type.to_string(); + fs << "nominal_baseline" << info.nominal_baseline; + fs << "auxiliary_chip_version" << info.auxiliary_chip_version.to_string(); + fs << "isp_version" << info.isp_version.to_string(); + // save other infos according to spec_version + fs.release(); + return true; +} + +bool DeviceWriter::SaveImgParams( + const img_params_map_t &img_params_map, + const std::string &filepath) { + if (img_params_map.empty()) { + return false; + } + std::string version = img_params_map.begin()->second.version; + if (Version(version) > SAVE_LATEST_VERSION) { + LOG(ERROR) << "Failed to save img params of version " << version + << ", please use latest SDK."; + return false; + } + + // always save img params with latest version format + using FileStorage = cv::FileStorage; + FileStorage fs(filepath, FileStorage::WRITE); + if (!fs.isOpened()) { + LOG(ERROR) << "Failed to save file: " << filepath; + return false; + } + fs << "version" << SAVE_LATEST_VERSION.to_string() + << "img_params" << img_params_map; + fs.release(); + return true; +} + +bool DeviceWriter::SaveImuParams( + const imu_params_t ¶ms, const std::string &filepath) { + if (!params.ok) return false; + std::string version = params.version; + if (Version(version) > SAVE_LATEST_VERSION) { + LOG(ERROR) << "Failed to save imu params of version " << version + << ", please use latest SDK."; + return false; + } + + // always save imu params with latest version format + using FileStorage = cv::FileStorage; + FileStorage fs(filepath, FileStorage::WRITE); + if (!fs.isOpened()) { + LOG(ERROR) << "Failed to save file: " << filepath; + return false; + } + fs << "version" << SAVE_LATEST_VERSION.to_string() + << "in_accel" << params.in_accel + << "in_gyro" << params.in_gyro + << "ex_left_to_imu" << params.ex_left_to_imu; + fs.release(); + return true; +} + +void DeviceWriter::SaveAllInfos(const std::string &dir) { + if (!files::mkdir(dir)) { + LOG(FATAL) << "Create directory failed: " << dir; + } + SaveDeviceInfo(*device_->GetInfo(), dir + MYNTEYE_OS_SEP "device.info"); + SaveImgParams(device_->GetImgParams(), dir + MYNTEYE_OS_SEP "img.params"); + SaveImuParams(device_->GetImuParams(), dir + MYNTEYE_OS_SEP "imu.params"); +} + +namespace { + +// old +void to_intrinsics( + const std::uint16_t &width, const std::uint16_t &height, + const std::uint8_t &model, const cv::Mat &M, const cv::Mat &D, + IntrinsicsPinhole *in) { + in->width = width; + in->height = height; + /* + fx, 0, cx, + 0, fy, cy, + 0, 0, 1 + */ + in->fx = M.at(0, 0); + in->fy = M.at(1, 1); + in->cx = M.at(0, 2); + in->cy = M.at(1, 2); + /* k1, k2, p1, p2, k3 */ + in->model = model; + LOG_IF(FATAL, D.cols < 5) << "Distortion coefficients must >= 5 columns"; + for (std::size_t i = 0; i < 5; i++) { + in->coeffs[i] = D.at(i); + } +} + +// old +void to_extrinsics(const cv::Mat &R, const cv::Mat &T, Extrinsics *ex) { + for (std::size_t i = 0; i < 3; i++) { + for (std::size_t j = 0; j < 3; j++) { + ex->rotation[i][j] = R.at(i, j); + } + } + for (std::size_t i = 0; i < 3; i++) { + ex->translation[i] = T.at(i); + } +} +// old +void operator>>(const cv::FileNode &n, IntrinsicsPinhole &in) { + n["width"] >> in.width; + n["height"] >> in.height; + n["fx"] >> in.fx; + n["fy"] >> in.fy; + n["cx"] >> in.cx; + n["cy"] >> in.cy; + n["model"] >> in.model; + for (std::size_t i = 0; i < 5; i++) { + in.coeffs[i] = n["coeffs"][i]; + } +} + +void operator>>(const cv::FileNode &n, ImuIntrinsics &in) { + for (std::size_t i = 0; i < 3; i++) { + for (std::size_t j = 0; j < 3; j++) { + in.scale[i][j] = n["scale"][3 * i + j]; + } + } + for (std::size_t i = 0; i < 3; i++) { + for (std::size_t j = 0; j < 3; j++) { + in.assembly[i][j] = n["assembly"][3 * i + j]; + } + } + for (std::size_t i = 0; i < 3; i++) { + in.drift[i] = n["drift"][i]; + } + for (std::size_t i = 0; i < 3; i++) { + in.noise[i] = n["noise"][i]; + } + for (std::size_t i = 0; i < 3; i++) { + in.bias[i] = n["bias"][i]; + } + for (std::size_t i = 0; i < 2; i++) { + in.x[i] = n["x"][i]; + } + for (std::size_t i = 0; i < 2; i++) { + in.y[i] = n["y"][i]; + } + for (std::size_t i = 0; i < 2; i++) { + in.z[i] = n["z"][i]; + } +} + +void operator>>(const cv::FileNode &n, Extrinsics &ex) { + for (std::size_t i = 0; i < 3; i++) { + for (std::size_t j = 0; j < 3; j++) { + ex.rotation[i][j] = n["rotation"][3 * i + j]; + } + } + for (std::size_t i = 0; i < 3; i++) { + ex.translation[i] = n["translation"][i]; + } +} + +// old +void operator>>(const cv::FileNode &n, DeviceWriter::img_params_t ¶ms) { + auto in_left = std::make_shared(); + auto in_right = std::make_shared(); + params.in_left = in_left; + params.in_right = in_right; + n["in_left"] >> *in_left; + n["in_right"] >> *in_right; + n["ex_right_to_left"] >> params.ex_right_to_left; +} + +std::shared_ptr to_intrinsics_pinhole( + const cv::FileNode &n, const std::uint8_t &model, + const std::uint16_t &width, const std::uint16_t &height) { + auto in = std::make_shared(); + in->width = width; + in->height = height; + in->model = model; + n["fx"] >> in->fx; + n["fy"] >> in->fy; + n["cx"] >> in->cx; + n["cy"] >> in->cy; + for (std::size_t i = 0; i < 5; i++) { + in->coeffs[i] = n["coeffs"][i]; + } + return in; +} + +std::shared_ptr to_intrinsics_equidistant( + const cv::FileNode &n, const std::uint8_t &model, + const std::uint16_t &width, const std::uint16_t &height) { + auto in = std::make_shared(); + in->width = width; + in->height = height; + for (std::size_t i = 0; i < 8; i++) { + in->coeffs[i] = n["coeffs"][i]; + } + MYNTEYE_UNUSED(model) + return in; +} + +DeviceWriter::img_params_t to_img_params( + const cv::FileNode &n, const std::uint8_t &model, + const std::uint16_t &width, const std::uint16_t &height) { + DeviceWriter::img_params_t params; + params.ok = false; + + CalibrationModel calib_model = static_cast(model); + switch (calib_model) { + case CalibrationModel::PINHOLE: { + params.ok = true; + params.in_left = to_intrinsics_pinhole( + n["in_left"], model, width, height); + params.in_right = to_intrinsics_pinhole( + n["in_right"], model, width, height); + n["ex_right_to_left"] >> params.ex_right_to_left; + } break; + case CalibrationModel::KANNALA_BRANDT: { + params.ok = true; + params.in_left = to_intrinsics_equidistant( + n["in_left"], model, width, height); + params.in_right = to_intrinsics_equidistant( + n["in_right"], model, width, height); + n["ex_right_to_left"] >> params.ex_right_to_left; + } break; + default: + LOG(FATAL) << "Could not load img params as unknown calib model" + ", please use latest SDK."; + } + return params; +} + +} // namespace + +DeviceWriter::dev_info_t DeviceWriter::LoadDeviceInfo( + const std::string &filepath) { + using FileStorage = cv::FileStorage; + FileStorage fs(filepath, FileStorage::READ); + if (!fs.isOpened()) { + LOG(FATAL) << "Failed to load file: " << filepath; + } + DeviceInfo info; + info.lens_type = Type(std::string(fs["lens_type"])); + info.imu_type = Type(std::string(fs["imu_type"])); + fs["nominal_baseline"] >> info.nominal_baseline; + fs.release(); + return info; +} + +DeviceWriter::img_params_map_t DeviceWriter::LoadImgParams( + const std::string &filepath) { + using FileStorage = cv::FileStorage; + FileStorage fs(filepath, FileStorage::READ); + if (!fs.isOpened()) { + LOG(FATAL) << "Failed to load file: " << filepath; + } + + img_params_map_t img_params_map; + if (!fs["version"].isNone()) { + std::string version = std::string(fs["version"]); + // load params according to verison + if (version == "1.0") { + fs["img_params_map"][0] >> img_params_map[{752, 480}]; + } else if (version == "1.1") { + fs["img_params_map"][0] >> img_params_map[{1280, 400}]; + fs["img_params_map"][1] >> img_params_map[{2560, 800}]; + } else if (version == "1.2") { + auto node = fs["img_params"]; + for (auto it = node.begin(); it < node.end(); it++) { + std::uint8_t model; + std::uint16_t width, height; + (*it)["model"] >> model; + (*it)["width"] >> width; + (*it)["height"] >> height; + auto params = to_img_params(*it, model, width, height); + if (params.ok) { + params.version = version; + img_params_map[{width, height}] = params; + } + } + } else { + LOG(ERROR) << "Failed to load img params of version " << version + << ", please use latest SDK."; + } + } else { + // load old params s1030 + auto in_left = std::make_shared(); + auto in_right = std::make_shared(); + Extrinsics ex_right_to_left; + if (fs["in_left"].isNone()) { + std::uint16_t w = 752; + std::uint16_t h = 480; + std::uint8_t m = 0; + if (!fs["width"].isNone()) + w = static_cast(fs["width"]); + if (!fs["height"].isNone()) + h = static_cast(fs["height"]); + if (!fs["model"].isNone()) + m = static_cast(fs["model"]); + + cv::Mat M1, D1, M2, D2, R, T; + fs["M1"] >> M1; + fs["D1"] >> D1; + fs["M2"] >> M2; + fs["D2"] >> D2; + fs["R"] >> R; + fs["T"] >> T; + + to_intrinsics(w, h, m, M1, D1, in_left.get()); + to_intrinsics(w, h, m, M2, D2, in_right.get()); + to_extrinsics(R, T, &ex_right_to_left); + } else { + fs["in_left"] >> *in_left; + fs["in_right"] >> *in_right; + fs["ex_right_to_left"] >> ex_right_to_left; + } + img_params_map[{752, 480}] = { + true, "1.0", in_left, in_right, ex_right_to_left + }; + } + + fs.release(); + return img_params_map; +} + +DeviceWriter::imu_params_t DeviceWriter::LoadImuParams( + const std::string &filepath) { + using FileStorage = cv::FileStorage; + FileStorage fs(filepath, FileStorage::READ); + if (!fs.isOpened()) { + LOG(FATAL) << "Failed to load file: " << filepath; + } + + imu_params_t params; + if (!fs["version"].isNone()) { + std::string version = std::string(fs["version"]); + // load params according to verison + if (version == "1.2") { + params.version = version; + fs["in_accel"] >> params.in_accel; + fs["in_gyro"] >> params.in_gyro; + fs["ex_left_to_imu"] >> params.ex_left_to_imu; + } else { + LOG(ERROR) << "Failed to load imu params of version " << version + << ", please use latest SDK."; + } + } else { + // load old params + fs["in_accel"] >> params.in_accel; + fs["in_gyro"] >> params.in_gyro; + fs["ex_left_to_imu"] >> params.ex_left_to_imu; + } + + fs.release(); + return params; +} + +} // namespace tools + +MYNTEYE_END_NAMESPACE diff --git a/samples/device_writer.h b/samples/device_writer.h new file mode 100644 index 0000000..1e36ed5 --- /dev/null +++ b/samples/device_writer.h @@ -0,0 +1,69 @@ +// Copyright 2018 Slightech Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef MYNTEYE_TOOLS_DEVICE_WRITER_H_ // NOLINT +#define MYNTEYE_TOOLS_DEVICE_WRITER_H_ +#pragma once + +#include +#include +#include + +#include "mynteye/device/device.h" + +MYNTEYE_BEGIN_NAMESPACE + +class Device; + +namespace tools { + +class DeviceWriter { + public: + using dev_info_t = DeviceInfo; + using imu_params_t = device::imu_params_t; + using img_params_t = device::img_params_t; + using img_params_map_t = std::map; + + explicit DeviceWriter(std::shared_ptr device); + ~DeviceWriter(); + + bool WriteDeviceInfo(const dev_info_t &info); + bool WriteDeviceInfo(const std::string &filepath); + + bool WriteImgParams(const img_params_map_t &img_params_map); + bool WriteImgParams(const std::string &filepath); + + bool WriteImuParams(const imu_params_t ¶ms); + bool WriteImuParams(const std::string &filepath); + + bool SaveDeviceInfo(const dev_info_t &info, const std::string &filepath); + bool SaveImgParams(const img_params_map_t &img_params_map, + const std::string &filepath); + bool SaveImuParams(const imu_params_t ¶ms, const std::string &filepath); + + /** Save all infos of this device */ + void SaveAllInfos(const std::string &dir); + + private: + dev_info_t LoadDeviceInfo(const std::string &filepath); + img_params_map_t LoadImgParams(const std::string &filepath); + imu_params_t LoadImuParams(const std::string &filepath); + + std::shared_ptr device_; +}; + +} // namespace tools + +MYNTEYE_END_NAMESPACE + +#endif // MYNTEYE_TOOLS_DEVICE_WRITER_H_ NOLINT diff --git a/samples/save_all_infos.cc b/samples/save_all_infos.cc new file mode 100644 index 0000000..0186107 --- /dev/null +++ b/samples/save_all_infos.cc @@ -0,0 +1,43 @@ +// Copyright 2018 Slightech Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include "mynteye/logger.h" +#include "mynteye/device/device.h" +#include "mynteye/device/utils.h" + +#include "device_writer.h" + +MYNTEYE_USE_NAMESPACE + +int main(int argc, char *argv[]) { + glog_init _(argc, argv); + + std::string dir{"config"}; + if (argc >= 2) { + dir = argv[1]; + } + + auto &&device = device::select(); + if (!device) + return 1; + + dir.append(MYNTEYE_OS_SEP).append(device->GetInfo()->name); + dir.append(MYNTEYE_OS_SEP "SN").append(device->GetInfo()->serial_number); + + tools::DeviceWriter writer(device); + writer.SaveAllInfos(dir); + + LOG(INFO) << "Save all infos to \"" << dir << "\""; + + return 0; +} diff --git a/samples/write_device_info.cc b/samples/write_device_info.cc new file mode 100644 index 0000000..428c8a1 --- /dev/null +++ b/samples/write_device_info.cc @@ -0,0 +1,41 @@ +// Copyright 2018 Slightech Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include "mynteye/logger.h" +#include "mynteye/device/device.h" +#include "mynteye/device/utils.h" + +#include "device_writer.h" + +MYNTEYE_USE_NAMESPACE + +int main(int argc, char *argv[]) { + glog_init _(argc, argv); + + const char *filepath; + if (argc >= 2) { + filepath = argv[1]; + } else { + LOG(ERROR) << "Usage: ./device_info_writer "; + return 2; + } + + auto &&device = device::select(); + if (!device) + return 1; + + tools::DeviceWriter writer(device); + writer.WriteDeviceInfo(filepath); + + return 0; +} diff --git a/samples/write_img_params.cc b/samples/write_img_params.cc new file mode 100644 index 0000000..5c7c1d7 --- /dev/null +++ b/samples/write_img_params.cc @@ -0,0 +1,41 @@ +// Copyright 2018 Slightech Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include "mynteye/logger.h" +#include "mynteye/device/device.h" +#include "mynteye/device/utils.h" + +#include "device_writer.h" + +MYNTEYE_USE_NAMESPACE + +int main(int argc, char *argv[]) { + glog_init _(argc, argv); + + const char *filepath; + if (argc >= 2) { + filepath = argv[1]; + } else { + LOG(ERROR) << "Usage: ./img_params_writer "; + return 2; + } + + auto &&device = device::select(); + if (!device) + return 1; + + tools::DeviceWriter writer(device); + writer.WriteImgParams(filepath); + + return 0; +} diff --git a/samples/write_imu_params.cc b/samples/write_imu_params.cc new file mode 100644 index 0000000..29ae057 --- /dev/null +++ b/samples/write_imu_params.cc @@ -0,0 +1,41 @@ +// Copyright 2018 Slightech Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include "mynteye/logger.h" +#include "mynteye/device/device.h" +#include "mynteye/device/utils.h" + +#include "device_writer.h" + +MYNTEYE_USE_NAMESPACE + +int main(int argc, char *argv[]) { + glog_init _(argc, argv); + + const char *filepath; + if (argc >= 2) { + filepath = argv[1]; + } else { + LOG(ERROR) << "Usage: ./imu_params_writer "; + return 2; + } + + auto &&device = device::select(); + if (!device) + return 1; + + tools::DeviceWriter writer(device); + writer.WriteImuParams(filepath); + + return 0; +}