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-08 17:35:49 +03:00
|
|
|
#include <opencv2/highgui/highgui.hpp>
|
|
|
|
#include <opencv2/imgproc/imgproc.hpp>
|
|
|
|
|
2018-11-16 10:30:13 +02:00
|
|
|
#include "mynteye/logger.h"
|
2018-10-27 16:51:44 +03:00
|
|
|
#include "mynteye/device/device.h"
|
|
|
|
#include "mynteye/device/utils.h"
|
|
|
|
#include "mynteye/util/times.h"
|
2018-04-12 06:48:09 +03:00
|
|
|
|
2018-04-04 05:50:27 +03:00
|
|
|
MYNTEYE_USE_NAMESPACE
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
glog_init _(argc, argv);
|
|
|
|
|
2018-04-20 07:44:23 +03:00
|
|
|
auto &&device = device::select();
|
2018-12-20 11:10:18 +02:00
|
|
|
if (!device) return 1;
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
auto &&request = device::select_request(device, &ok);
|
|
|
|
if (!ok) return 1;
|
|
|
|
device->ConfigStreamRequest(request);
|
2018-04-10 11:00:38 +03:00
|
|
|
|
2018-04-08 17:35:49 +03:00
|
|
|
std::size_t left_count = 0;
|
|
|
|
device->SetStreamCallback(
|
|
|
|
Stream::LEFT, [&left_count](const device::StreamData &data) {
|
2018-04-10 15:20:42 +03:00
|
|
|
CHECK_NOTNULL(data.img);
|
2018-04-08 17:35:49 +03:00
|
|
|
++left_count;
|
2018-08-08 06:39:03 +03:00
|
|
|
VLOG(2) << Stream::LEFT << "count: " << left_count;
|
2018-04-10 15:20:42 +03:00
|
|
|
VLOG(2) << " frame_id: " << data.img->frame_id
|
|
|
|
<< ", timestamp: " << data.img->timestamp
|
|
|
|
<< ", exposure_time: " << data.img->exposure_time;
|
2018-04-08 17:35:49 +03:00
|
|
|
});
|
|
|
|
std::size_t right_count = 0;
|
|
|
|
device->SetStreamCallback(
|
|
|
|
Stream::RIGHT, [&right_count](const device::StreamData &data) {
|
2018-04-10 15:20:42 +03:00
|
|
|
CHECK_NOTNULL(data.img);
|
2018-04-08 17:35:49 +03:00
|
|
|
++right_count;
|
2018-08-08 06:39:03 +03:00
|
|
|
VLOG(2) << Stream::RIGHT << "count: " << right_count;
|
2018-04-10 15:20:42 +03:00
|
|
|
VLOG(2) << " frame_id: " << data.img->frame_id
|
|
|
|
<< ", timestamp: " << data.img->timestamp
|
|
|
|
<< ", exposure_time: " << data.img->exposure_time;
|
2018-04-08 17:35:49 +03:00
|
|
|
});
|
|
|
|
|
2018-04-10 15:20:42 +03:00
|
|
|
std::size_t imu_count = 0;
|
2018-07-21 10:34:07 +03:00
|
|
|
|
2018-04-10 15:20:42 +03:00
|
|
|
device->SetMotionCallback([&imu_count](const device::MotionData &data) {
|
|
|
|
CHECK_NOTNULL(data.imu);
|
|
|
|
++imu_count;
|
2018-08-05 18:18:51 +03:00
|
|
|
VLOG(2) << "Imu count: " << imu_count;
|
2018-07-21 10:34:07 +03:00
|
|
|
VLOG(2) << ", timestamp: " << data.imu->timestamp
|
2018-04-12 06:48:09 +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-10 15:20:42 +03:00
|
|
|
});
|
2018-07-21 10:34:07 +03:00
|
|
|
|
2018-04-12 07:22:55 +03:00
|
|
|
// Enable this will cache the motion datas until you get them.
|
2018-07-21 10:43:02 +03:00
|
|
|
device->EnableMotionDatas();
|
|
|
|
device->Start(Source::ALL);
|
2018-04-08 17:35:49 +03:00
|
|
|
cv::namedWindow("frame");
|
|
|
|
|
2018-04-12 07:22:55 +03:00
|
|
|
std::size_t motion_count = 0;
|
2018-04-12 06:48:09 +03:00
|
|
|
auto &&time_beg = times::now();
|
2018-04-08 17:35:49 +03:00
|
|
|
while (true) {
|
|
|
|
device->WaitForStreams();
|
|
|
|
|
2018-12-20 11:10:18 +02:00
|
|
|
device::StreamData left_data = device->GetStreamData(Stream::LEFT);
|
|
|
|
device::StreamData right_data = device->GetStreamData(Stream::RIGHT);
|
2018-07-21 10:34:07 +03:00
|
|
|
|
2018-04-12 07:22:55 +03:00
|
|
|
auto &&motion_datas = device->GetMotionDatas();
|
|
|
|
motion_count += motion_datas.size();
|
2018-08-05 18:18:51 +03:00
|
|
|
for (auto &&data : motion_datas) {
|
2018-08-08 06:39:03 +03:00
|
|
|
LOG(INFO) << "timestamp: " << data.imu->timestamp
|
2018-04-12 07:22:55 +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-07-21 10:34:07 +03:00
|
|
|
|
2018-04-08 17:35:49 +03:00
|
|
|
cv::Mat img;
|
2018-08-05 21:23:27 +03:00
|
|
|
|
2018-09-30 09:51:24 +03:00
|
|
|
// TODO(Kalman): Extract into public or internal method
|
2018-08-05 21:23:27 +03:00
|
|
|
if (left_data.frame->format() == Format::GREY) {
|
|
|
|
cv::Mat left_img(
|
|
|
|
left_data.frame->height(), left_data.frame->width(), CV_8UC1,
|
|
|
|
left_data.frame->data());
|
|
|
|
cv::Mat right_img(
|
|
|
|
right_data.frame->height(), right_data.frame->width(), CV_8UC1,
|
|
|
|
right_data.frame->data());
|
|
|
|
cv::hconcat(left_img, right_img, img);
|
|
|
|
} else if (left_data.frame->format() == Format::YUYV) {
|
|
|
|
cv::Mat left_img(
|
|
|
|
left_data.frame->height(), left_data.frame->width(), CV_8UC2,
|
|
|
|
left_data.frame->data());
|
|
|
|
cv::Mat right_img(
|
|
|
|
right_data.frame->height(), right_data.frame->width(), CV_8UC2,
|
|
|
|
right_data.frame->data());
|
|
|
|
cv::cvtColor(left_img, left_img, cv::COLOR_YUV2BGR_YUY2);
|
|
|
|
cv::cvtColor(right_img, right_img, cv::COLOR_YUV2BGR_YUY2);
|
|
|
|
cv::hconcat(left_img, right_img, img);
|
2018-08-06 21:29:07 +03:00
|
|
|
} else if (left_data.frame->format() == Format::BGR888) {
|
2018-08-05 21:23:27 +03:00
|
|
|
cv::Mat left_img(
|
|
|
|
left_data.frame->height(), left_data.frame->width(), CV_8UC3,
|
|
|
|
left_data.frame->data());
|
|
|
|
cv::Mat right_img(
|
|
|
|
right_data.frame->height(), right_data.frame->width(), CV_8UC3,
|
|
|
|
right_data.frame->data());
|
|
|
|
cv::hconcat(left_img, right_img, img);
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-04-08 17:35:49 +03:00
|
|
|
cv::imshow("frame", img);
|
|
|
|
|
|
|
|
char key = static_cast<char>(cv::waitKey(1));
|
|
|
|
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-04-12 06:48:09 +03:00
|
|
|
auto &&time_end = times::now();
|
2018-04-04 05:50:27 +03:00
|
|
|
|
2018-04-08 17:35:49 +03:00
|
|
|
device->Stop(Source::ALL);
|
2018-04-12 06:48:09 +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);
|
2018-07-21 10:34:07 +03:00
|
|
|
LOG(INFO) << "Motion count: " << motion_count
|
|
|
|
<< ", hz: " << (1000.f * motion_count / elapsed_ms);
|
2018-04-04 05:50:27 +03:00
|
|
|
return 0;
|
|
|
|
}
|