From fdd02dbd78d6358c6b7370a9c57149bcaae672d6 Mon Sep 17 00:00:00 2001 From: John Zhao Date: Sun, 15 Apr 2018 14:59:51 +0800 Subject: [PATCH] Add dataset record tool --- Makefile | 11 ++++ README.md | 1 + tools/CMakeLists.txt | 45 ++++++++++++++ tools/dataset/CMakeLists.txt | 22 +++++++ tools/dataset/record.cc | 117 +++++++++++++++++++++++++++++++++++ 5 files changed, 196 insertions(+) create mode 100644 tools/CMakeLists.txt create mode 100644 tools/dataset/CMakeLists.txt create mode 100644 tools/dataset/record.cc diff --git a/Makefile b/Makefile index 17cb965..a91110e 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ help: @echo " make test build test and run" @echo " make install install project" @echo " make samples build samples" + @echo " make tools build tools" @echo " make ros build ros wrapper" @echo " make clean|cleanall clean generated or useless things" @@ -90,6 +91,14 @@ samples: install .PHONY: samples +# tools + +tools: install + @$(call echo,Make $@) + @$(call cmake_build,./tools/_build) + +.PHONY: tools + # ros ros: install @@ -121,6 +130,8 @@ clean: @$(call rm,./_install/) @$(call rm,./samples/_build/) @$(call rm,./samples/_output/) + @$(call rm,./tools/_build/) + @$(call rm,./tools/_output/) @$(call rm,./test/_build/) @$(call rm,./test/_output/) @$(MAKE) cleanlog diff --git a/README.md b/README.md index c93d25d..714fee6 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Usage: make test build test and run make install install project make samples build samples + make tools build tools make ros build ros wrapper make clean|cleanall clean generated or useless things ``` diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 0000000..920c59c --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.0) + +project(mynteye_tools VERSION 2.0.0 LANGUAGES C CXX) + +get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY) + +# flags + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") + +include(${PRO_DIR}/cmake/DetectCXX11.cmake) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") + +string(STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS) +string(STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS) +message(STATUS "C_FLAGS: ${CMAKE_C_FLAGS}") +message(STATUS "CXX_FLAGS: ${CMAKE_CXX_FLAGS}") + +# packages + +LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/third_party/glog/_build) +find_package(glog REQUIRED) +message(STATUS "Found glog: ${glog_VERSION}") + +LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake) +find_package(mynteye REQUIRED) +message(STATUS "Found mynteye: ${mynteye_VERSION}") + +LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) + +find_package(OpenCV REQUIRED) +message(STATUS "Found OpenCV: ${OpenCV_VERSION}") + +# targets + +include(${PRO_DIR}/cmake/Common.cmake) + +set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/_output") + +# dataset + +add_subdirectory(dataset) diff --git a/tools/dataset/CMakeLists.txt b/tools/dataset/CMakeLists.txt new file mode 100644 index 0000000..a73cb47 --- /dev/null +++ b/tools/dataset/CMakeLists.txt @@ -0,0 +1,22 @@ +get_filename_component(DIR_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) + +set_outdir( + "${OUT_DIR}/lib/${DIR_NAME}" + "${OUT_DIR}/lib/${DIR_NAME}" + "${OUT_DIR}/bin/${DIR_NAME}" +) + +include_directories( + ${PRO_DIR}/src +) + +## record + +add_executable(record record.cc) +target_link_libraries(record mynteye ${OpenCV_LIBS}) + +if(OS_WIN) + target_compile_definitions(record + PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES + ) +endif() diff --git a/tools/dataset/record.cc b/tools/dataset/record.cc new file mode 100644 index 0000000..22aa9a7 --- /dev/null +++ b/tools/dataset/record.cc @@ -0,0 +1,117 @@ +#include +#include + +#include "mynteye/glog_init.h" + +#include "device/context.h" +#include "device/device.h" + +#include "internal/times.h" + +MYNTEYE_USE_NAMESPACE + +int main(int argc, char *argv[]) { + glog_init _(argc, argv); + + LOG(INFO) << "Detecting MYNT EYE devices"; + Context context; + auto &&devices = context.devices(); + + size_t n = devices.size(); + LOG_IF(FATAL, n <= 0) << "No MYNT EYE devices :("; + + LOG(INFO) << "MYNT EYE devices:"; + for (size_t i = 0; i < n; i++) { + auto &&device = devices[i]; + auto &&name = device->GetInfo(Info::DEVICE_NAME); + LOG(INFO) << " index: " << i << ", name: " << name; + } + + std::shared_ptr device = nullptr; + if (n <= 1) { + device = devices[0]; + LOG(INFO) << "Only one MYNT EYE device, select index: 0"; + } else { + while (true) { + size_t i; + LOG(INFO) << "There are " << n << " MYNT EYE devices, select index: "; + std::cin >> i; + if (i >= n) { + LOG(WARNING) << "Index out of range :("; + continue; + } + device = devices[i]; + break; + } + } + + /* + { // auto-exposure + device->SetOptionValue(Option::EXPOSURE_MODE, 0); + device->SetOptionValue(Option::MAX_GAIN, 40); // [0.48] + device->SetOptionValue(Option::MAX_EXPOSURE_TIME, 120); // [0,240] + device->SetOptionValue(Option::DESIRED_BRIGHTNESS, 200); // [0,255] + } + { // manual-exposure + device->SetOptionValue(Option::EXPOSURE_MODE, 1); + device->SetOptionValue(Option::GAIN, 20); // [0.48] + device->SetOptionValue(Option::BRIGHTNESS, 20); // [0,240] + device->SetOptionValue(Option::CONTRAST, 20); // [0,255] + } + device->SetOptionValue(Option::IR_CONTROL, 80); + device->SetOptionValue(Option::FRAME_RATE, 25); + device->SetOptionValue(Option::IMU_FREQUENCY, 500); + */ + device->LogOptionInfos(); + + // Enable this will cache the motion datas until you get them. + device->EnableMotionDatas(); + device->Start(Source::ALL); + + cv::namedWindow("frame"); + + std::size_t img_count = 0; + std::size_t imu_count = 0; + auto &&time_beg = times::now(); + while (true) { + device->WaitForStreams(); + + auto &&left_datas = device->GetStreamDatas(Stream::LEFT); + auto &&right_datas = device->GetStreamDatas(Stream::RIGHT); + img_count += left_datas.size(); + + auto &&motion_datas = device->GetMotionDatas(); + imu_count += motion_datas.size(); + + auto &&left_frame = left_datas.back().frame; + auto &&right_frame = right_datas.back().frame; + cv::Mat left_img( + left_frame->height(), left_frame->width(), CV_8UC1, left_frame->data()); + cv::Mat right_img( + right_frame->height(), right_frame->width(), CV_8UC1, + right_frame->data()); + + cv::Mat img; + cv::hconcat(left_img, right_img, img); + cv::imshow("frame", img); + + char key = static_cast(cv::waitKey(1)); + if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q + break; + } + } + auto &&time_end = times::now(); + + device->Stop(Source::ALL); + + float elapsed_ms = + times::count(time_end - time_beg) * 0.001f; + LOG(INFO) << "Time beg: " << times::to_local_string(time_beg) + << ", end: " << times::to_local_string(time_end) + << ", cost: " << elapsed_ms << "ms"; + LOG(INFO) << "Img count: " << img_count + << ", fps: " << (1000.f * img_count / elapsed_ms); + LOG(INFO) << "Imu count: " << imu_count + << ", hz: " << (1000.f * imu_count / elapsed_ms); + return 0; +}