2018-05-10 09:46:34 +03:00
|
|
|
// 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.
|
2018-04-15 09:59:51 +03:00
|
|
|
#include <opencv2/highgui/highgui.hpp>
|
|
|
|
#include <opencv2/imgproc/imgproc.hpp>
|
|
|
|
|
2018-09-04 10:12:04 +03:00
|
|
|
#include "mynteye/logger.h"
|
2018-10-30 09:56:09 +02:00
|
|
|
#include "mynteye/api/api.h"
|
2018-10-27 16:51:44 +03:00
|
|
|
#include "mynteye/util/times.h"
|
2018-04-15 09:59:51 +03:00
|
|
|
|
2018-04-15 14:18:21 +03:00
|
|
|
#include "dataset/dataset.h"
|
|
|
|
|
2018-04-15 09:59:51 +03:00
|
|
|
MYNTEYE_USE_NAMESPACE
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2018-10-30 09:56:09 +02:00
|
|
|
auto &&api = API::Create(argc, argv);
|
|
|
|
if (!api)
|
2018-05-15 17:01:15 +03:00
|
|
|
return 1;
|
2018-04-15 09:59:51 +03:00
|
|
|
/*
|
|
|
|
{ // auto-exposure
|
2018-10-30 09:56:09 +02:00
|
|
|
api->SetOptionValue(Option::EXPOSURE_MODE, 0);
|
|
|
|
api->SetOptionValue(Option::MAX_GAIN, 40); // [0.48]
|
|
|
|
api->SetOptionValue(Option::MAX_EXPOSURE_TIME, 120); // [0,240]
|
|
|
|
api->SetOptionValue(Option::DESIRED_BRIGHTNESS, 200); // [0,255]
|
2018-04-15 09:59:51 +03:00
|
|
|
}
|
|
|
|
{ // manual-exposure
|
2018-10-30 09:56:09 +02:00
|
|
|
api->SetOptionValue(Option::EXPOSURE_MODE, 1);
|
|
|
|
api->SetOptionValue(Option::GAIN, 20); // [0.48]
|
|
|
|
api->SetOptionValue(Option::BRIGHTNESS, 20); // [0,240]
|
|
|
|
api->SetOptionValue(Option::CONTRAST, 20); // [0,255]
|
2018-04-15 09:59:51 +03:00
|
|
|
}
|
2018-10-30 09:56:09 +02:00
|
|
|
api->SetOptionValue(Option::IR_CONTROL, 80);
|
|
|
|
api->SetOptionValue(Option::FRAME_RATE, 25);
|
|
|
|
api->SetOptionValue(Option::IMU_FREQUENCY, 500);
|
2018-04-15 09:59:51 +03:00
|
|
|
*/
|
2018-10-30 09:56:09 +02:00
|
|
|
api->LogOptionInfos();
|
2018-04-15 09:59:51 +03:00
|
|
|
|
|
|
|
// Enable this will cache the motion datas until you get them.
|
2018-10-30 09:56:09 +02:00
|
|
|
api->EnableMotionDatas();
|
|
|
|
api->Start(Source::ALL);
|
2018-04-15 09:59:51 +03:00
|
|
|
|
2018-04-15 14:18:21 +03:00
|
|
|
const char *outdir;
|
|
|
|
if (argc >= 2) {
|
|
|
|
outdir = argv[1];
|
|
|
|
} else {
|
|
|
|
outdir = "./dataset";
|
|
|
|
}
|
|
|
|
tools::Dataset dataset(outdir);
|
|
|
|
|
2018-04-15 09:59:51 +03:00
|
|
|
cv::namedWindow("frame");
|
|
|
|
|
|
|
|
std::size_t img_count = 0;
|
|
|
|
std::size_t imu_count = 0;
|
|
|
|
auto &&time_beg = times::now();
|
|
|
|
while (true) {
|
2018-10-30 09:56:09 +02:00
|
|
|
api->WaitForStreams();
|
2018-04-15 09:59:51 +03:00
|
|
|
|
2018-10-30 09:56:09 +02:00
|
|
|
auto &&left_datas = api->GetStreamDatas(Stream::LEFT);
|
|
|
|
auto &&right_datas = api->GetStreamDatas(Stream::RIGHT);
|
2018-04-15 09:59:51 +03:00
|
|
|
img_count += left_datas.size();
|
|
|
|
|
2018-10-30 09:56:09 +02:00
|
|
|
auto &&motion_datas = api->GetMotionDatas();
|
2018-04-15 09:59:51 +03:00
|
|
|
imu_count += motion_datas.size();
|
|
|
|
|
2018-10-30 09:56:09 +02:00
|
|
|
auto &&left_img = left_datas.back().frame;
|
|
|
|
auto &&right_img = right_datas.back().frame;
|
2018-04-15 09:59:51 +03:00
|
|
|
|
|
|
|
cv::Mat img;
|
|
|
|
cv::hconcat(left_img, right_img, img);
|
|
|
|
cv::imshow("frame", img);
|
|
|
|
|
2018-04-15 14:18:21 +03:00
|
|
|
{ // save
|
|
|
|
for (auto &&left : left_datas) {
|
|
|
|
dataset.SaveStreamData(Stream::LEFT, left);
|
|
|
|
}
|
|
|
|
for (auto &&right : right_datas) {
|
|
|
|
dataset.SaveStreamData(Stream::RIGHT, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &&motion : motion_datas) {
|
|
|
|
dataset.SaveMotionData(motion);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "\rSaved " << img_count << " imgs"
|
|
|
|
<< ", " << imu_count << " imus" << std::flush;
|
|
|
|
}
|
|
|
|
|
2018-04-15 09:59:51 +03:00
|
|
|
char key = static_cast<char>(cv::waitKey(1));
|
|
|
|
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-04-15 14:18:21 +03:00
|
|
|
std::cout << " to " << outdir << std::endl;
|
2018-04-15 09:59:51 +03:00
|
|
|
auto &&time_end = times::now();
|
|
|
|
|
2018-10-30 09:56:09 +02:00
|
|
|
api->Stop(Source::ALL);
|
2018-04-15 09:59:51 +03:00
|
|
|
|
|
|
|
float elapsed_ms =
|
|
|
|
times::count<times::microseconds>(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;
|
|
|
|
}
|