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-27 17:35:43 +03:00
|
|
|
#include <opencv2/highgui/highgui.hpp>
|
|
|
|
|
2018-05-12 17:19:45 +03:00
|
|
|
#include <glog/logging.h>
|
2018-04-25 11:06:38 +03:00
|
|
|
|
|
|
|
#include "mynteye/api.h"
|
2018-04-27 17:35:43 +03:00
|
|
|
#include "mynteye/times.h"
|
2018-04-25 11:06:38 +03:00
|
|
|
|
|
|
|
MYNTEYE_USE_NAMESPACE
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2018-05-12 17:19:45 +03:00
|
|
|
auto &&api = API::Create(argc, argv);
|
2018-05-15 17:01:15 +03:00
|
|
|
if (!api)
|
|
|
|
return 1;
|
2018-08-05 18:18:51 +03:00
|
|
|
api->SetStreamRequest(
|
|
|
|
Resolution::RES_2560x800, Format::YUYV, FrameRate::RATE_20_FPS);
|
2018-04-28 09:27:43 +03:00
|
|
|
// api->SetOptionValue(Option::FRAME_RATE, 25);
|
|
|
|
// api->SetOptionValue(Option::IMU_FREQUENCY, 500);
|
|
|
|
api->SetOptionValue(Option::IR_CONTROL, 80);
|
2018-04-27 17:35:43 +03:00
|
|
|
api->LogOptionInfos();
|
|
|
|
|
|
|
|
std::size_t left_count = 0;
|
|
|
|
api->SetStreamCallback(
|
|
|
|
Stream::LEFT, [&left_count](const api::StreamData &data) {
|
|
|
|
CHECK_NOTNULL(data.img);
|
|
|
|
++left_count;
|
|
|
|
VLOG(2) << Stream::LEFT << ", count: " << left_count;
|
|
|
|
VLOG(2) << " frame_id: " << data.img->frame_id
|
|
|
|
<< ", timestamp: " << data.img->timestamp
|
|
|
|
<< ", exposure_time: " << data.img->exposure_time;
|
|
|
|
});
|
|
|
|
std::size_t right_count = 0;
|
|
|
|
api->SetStreamCallback(
|
|
|
|
Stream::RIGHT, [&right_count](const api::StreamData &data) {
|
|
|
|
CHECK_NOTNULL(data.img);
|
|
|
|
++right_count;
|
|
|
|
VLOG(2) << Stream::RIGHT << ", count: " << right_count;
|
|
|
|
VLOG(2) << " frame_id: " << data.img->frame_id
|
|
|
|
<< ", timestamp: " << data.img->timestamp
|
|
|
|
<< ", exposure_time: " << data.img->exposure_time;
|
|
|
|
});
|
|
|
|
|
|
|
|
std::size_t imu_count = 0;
|
|
|
|
api->SetMotionCallback([&imu_count](const api::MotionData &data) {
|
|
|
|
CHECK_NOTNULL(data.imu);
|
|
|
|
++imu_count;
|
|
|
|
VLOG(2) << "Imu count: " << imu_count;
|
2018-07-21 10:34:07 +03:00
|
|
|
VLOG(2) << ", timestamp: " << data.imu->timestamp
|
2018-04-27 17:35:43 +03:00
|
|
|
<< ", accel_x: " << data.imu->accel[0]
|
|
|
|
<< ", accel_y: " << data.imu->accel[1]
|
|
|
|
<< ", accel_z: " << data.imu->accel[2]
|
|
|
|
<< ", gyro_x: " << data.imu->gyro[0]
|
|
|
|
<< ", gyro_y: " << data.imu->gyro[1]
|
|
|
|
<< ", gyro_z: " << data.imu->gyro[2]
|
|
|
|
<< ", temperature: " << data.imu->temperature;
|
|
|
|
});
|
|
|
|
|
2018-04-28 09:27:43 +03:00
|
|
|
// api->EnableStreamData(Stream::LEFT_RECTIFIED);
|
|
|
|
// api->EnableStreamData(Stream::RIGHT_RECTIFIED);
|
2018-04-28 08:26:46 +03:00
|
|
|
api->EnableStreamData(Stream::DISPARITY_NORMALIZED);
|
2018-04-28 09:27:43 +03:00
|
|
|
api->EnableStreamData(Stream::DEPTH);
|
2018-04-27 17:35:43 +03:00
|
|
|
// Enable this will cache the motion datas until you get them.
|
|
|
|
api->EnableMotionDatas();
|
|
|
|
api->Start(Source::ALL);
|
|
|
|
|
|
|
|
cv::namedWindow("frame");
|
2018-04-28 08:26:46 +03:00
|
|
|
cv::namedWindow("disparity");
|
2018-04-28 09:27:43 +03:00
|
|
|
cv::namedWindow("depth");
|
2018-04-27 17:35:43 +03:00
|
|
|
|
|
|
|
std::size_t motion_count = 0;
|
|
|
|
auto &&time_beg = times::now();
|
|
|
|
while (true) {
|
|
|
|
api->WaitForStreams();
|
|
|
|
|
2018-04-28 07:44:15 +03:00
|
|
|
// auto &&left_data = api->GetStreamData(Stream::LEFT);
|
|
|
|
// auto &&right_data = api->GetStreamData(Stream::RIGHT);
|
|
|
|
auto &&left_data = api->GetStreamData(Stream::LEFT_RECTIFIED);
|
|
|
|
auto &&right_data = api->GetStreamData(Stream::RIGHT_RECTIFIED);
|
2018-04-28 08:26:46 +03:00
|
|
|
if (!left_data.frame.empty() && !right_data.frame.empty()) {
|
|
|
|
cv::Mat img;
|
|
|
|
cv::hconcat(left_data.frame, right_data.frame, img);
|
|
|
|
cv::imshow("frame", img);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &&disp_data = api->GetStreamData(Stream::DISPARITY_NORMALIZED);
|
|
|
|
if (!disp_data.frame.empty()) {
|
2018-04-28 09:27:43 +03:00
|
|
|
cv::imshow("disparity", disp_data.frame); // CV_8UC1
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &&depth_data = api->GetStreamData(Stream::DEPTH);
|
|
|
|
if (!depth_data.frame.empty()) {
|
|
|
|
cv::imshow("depth", depth_data.frame); // CV_16UC1
|
2018-04-28 07:44:15 +03:00
|
|
|
}
|
2018-04-27 17:35:43 +03:00
|
|
|
|
|
|
|
auto &&motion_datas = api->GetMotionDatas();
|
|
|
|
motion_count += motion_datas.size();
|
2018-08-05 18:18:51 +03:00
|
|
|
for (auto &&data : motion_datas) {
|
2018-07-21 10:34:07 +03:00
|
|
|
LOG(INFO) << ", timestamp: " << data.imu->timestamp
|
2018-04-27 17:35:43 +03:00
|
|
|
<< ", accel_x: " << data.imu->accel[0]
|
|
|
|
<< ", accel_y: " << data.imu->accel[1]
|
|
|
|
<< ", accel_z: " << data.imu->accel[2]
|
|
|
|
<< ", gyro_x: " << data.imu->gyro[0]
|
|
|
|
<< ", gyro_y: " << data.imu->gyro[1]
|
|
|
|
<< ", gyro_z: " << data.imu->gyro[2]
|
|
|
|
<< ", temperature: " << data.imu->temperature;
|
|
|
|
}
|
|
|
|
|
|
|
|
char key = static_cast<char>(cv::waitKey(1));
|
|
|
|
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto &&time_end = times::now();
|
|
|
|
|
|
|
|
api->Stop(Source::ALL);
|
2018-04-26 04:22:29 +03:00
|
|
|
|
2018-04-27 17:35:43 +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) << "Left count: " << left_count
|
|
|
|
<< ", fps: " << (1000.f * left_count / elapsed_ms);
|
|
|
|
LOG(INFO) << "Right count: " << right_count
|
|
|
|
<< ", fps: " << (1000.f * right_count / elapsed_ms);
|
|
|
|
LOG(INFO) << "Imu count: " << imu_count
|
|
|
|
<< ", hz: " << (1000.f * imu_count / elapsed_ms);
|
|
|
|
// LOG(INFO) << "Motion count: " << motion_count
|
|
|
|
// << ", hz: " << (1000.f * motion_count / elapsed_ms);
|
2018-04-25 11:06:38 +03:00
|
|
|
return 0;
|
|
|
|
}
|