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-20 07:44:23 +03:00
|
|
|
#include "mynteye/utils.h"
|
|
|
|
|
|
|
|
#include <glog/logging.h>
|
|
|
|
|
|
|
|
#include "device/context.h"
|
|
|
|
#include "device/device.h"
|
|
|
|
|
|
|
|
MYNTEYE_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
namespace device {
|
|
|
|
|
|
|
|
std::shared_ptr<Device> select() {
|
|
|
|
LOG(INFO) << "Detecting MYNT EYE devices";
|
|
|
|
Context context;
|
|
|
|
auto &&devices = context.devices();
|
|
|
|
|
|
|
|
size_t n = devices.size();
|
2018-05-15 17:01:15 +03:00
|
|
|
if (n <= 0) {
|
|
|
|
LOG(ERROR) << "No MYNT EYE devices :(";
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-04-20 07:44:23 +03:00
|
|
|
|
|
|
|
LOG(INFO) << "MYNT EYE devices:";
|
|
|
|
for (size_t i = 0; i < n; i++) {
|
|
|
|
auto &&device = devices[i];
|
2018-06-14 04:38:38 +03:00
|
|
|
LOG(INFO) << " index: " << i
|
|
|
|
<< ", name: " << device->GetInfo(Info::DEVICE_NAME)
|
|
|
|
<< ", sn: " << device->GetInfo(Info::SERIAL_NUMBER);
|
2018-04-20 07:44:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Device> 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace device
|
|
|
|
|
2018-05-13 05:34:03 +03:00
|
|
|
namespace utils {
|
|
|
|
|
|
|
|
float get_real_exposure_time(
|
|
|
|
std::int32_t frame_rate, std::uint16_t exposure_time) {
|
|
|
|
float real_max = 0;
|
|
|
|
switch (frame_rate) {
|
|
|
|
case 10:
|
|
|
|
real_max = 18;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
real_max = 18;
|
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
real_max = 18;
|
|
|
|
break;
|
|
|
|
case 25:
|
|
|
|
real_max = 18;
|
|
|
|
break;
|
|
|
|
case 30:
|
|
|
|
real_max = 18;
|
|
|
|
break;
|
|
|
|
case 35:
|
|
|
|
real_max = 18;
|
|
|
|
break;
|
|
|
|
case 40:
|
|
|
|
real_max = 18;
|
|
|
|
break;
|
|
|
|
case 45:
|
|
|
|
real_max = 18;
|
|
|
|
break;
|
|
|
|
case 50:
|
|
|
|
real_max = 17;
|
|
|
|
break;
|
|
|
|
case 55:
|
|
|
|
real_max = 16.325;
|
|
|
|
break;
|
|
|
|
case 60:
|
|
|
|
real_max = 15;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG(ERROR) << "Invalid frame rate: " << frame_rate;
|
|
|
|
return exposure_time;
|
|
|
|
}
|
|
|
|
return exposure_time * real_max / 480.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace utils
|
|
|
|
|
2018-04-20 07:44:23 +03:00
|
|
|
MYNTEYE_END_NAMESPACE
|