Select the img params by resolution

This commit is contained in:
Kalman
2018-09-14 20:00:28 +08:00
parent 3c670cedb3
commit 6feeb49d62
14 changed files with 221 additions and 75 deletions

View File

@@ -212,21 +212,7 @@ std::vector<std::string> get_plugin_paths() {
API::API(std::shared_ptr<Device> device) : device_(device) {
VLOG(2) << __func__;
if (std::dynamic_pointer_cast<StandardDevice>(device_) != nullptr) {
bool in_l_ok, in_r_ok, ex_l2r_ok;
device_->GetIntrinsics(Stream::LEFT, &in_l_ok);
device_->GetIntrinsics(Stream::RIGHT, &in_r_ok);
device_->GetExtrinsics(Stream::LEFT, Stream::RIGHT, &ex_l2r_ok);
if (!in_l_ok || !in_r_ok || !ex_l2r_ok) {
LOG(FATAL) << "Image params not found, but we need it to process the "
"images. Please `make tools` and use `img_params_writer` "
"to write the image params. If you update the SDK from "
"1.x, the `SN*.conf` is the file contains them. Besides, "
"you could also calibrate them by yourself. Read the guide "
"doc (https://github.com/slightech/MYNT-EYE-SDK-2-Guide) "
"to learn more.";
}
}
std::dynamic_pointer_cast<StandardDevice>(device_);
synthetic_.reset(new Synthetic(this));
}
@@ -283,6 +269,7 @@ bool API::Supports(const AddOns &addon) const {
void API::SetStreamRequest(
const Resolution &res, const Format &format, const FrameRate &rate) {
device_->SetStreamRequest(res, format, rate);
CheckImageParams();
}
const std::vector<StreamRequest> &API::GetStreamRequests(
@@ -452,4 +439,22 @@ std::shared_ptr<Device> API::device() {
return device_;
}
void API::CheckImageParams() {
if (device_ != nullptr) {
bool in_l_ok, in_r_ok, ex_l2r_ok;
device_->GetIntrinsics(Stream::LEFT, &in_l_ok);
device_->GetIntrinsics(Stream::RIGHT, &in_r_ok);
device_->GetExtrinsics(Stream::LEFT, Stream::RIGHT, &ex_l2r_ok);
if (!in_l_ok || !in_r_ok || !ex_l2r_ok) {
LOG(FATAL) << "Image params not found, but we need it to process the "
"images. Please `make tools` and use `img_params_writer` "
"to write the image params. If you update the SDK from "
"1.x, the `SN*.conf` is the file contains them. Besides, "
"you could also calibrate them by yourself. Read the guide "
"doc (https://github.com/slightech/MYNT-EYE-SDK-2-Guide) "
"to learn more.";
}
}
}
MYNTEYE_END_NAMESPACE

View File

@@ -280,6 +280,8 @@ class MYNTEYE_API API {
std::shared_ptr<Device> device_;
std::unique_ptr<Synthetic> synthetic_;
void CheckImageParams();
};
MYNTEYE_END_NAMESPACE

View File

@@ -435,6 +435,7 @@ std::vector<device::MotionData> Device::GetMotionDatas() {
void Device::SetStreamRequest(
const Resolution &res, const Format &format, const FrameRate &rate) {
StreamRequest request(res, format, rate);
ConfigIntrinsics(res);
request_ = request;
}
@@ -548,9 +549,8 @@ void Device::ReadAllInfos() {
device_info_ = std::make_shared<DeviceInfo>();
CHECK_NOTNULL(channels_);
Channels::img_params_t img_params;
Channels::imu_params_t imu_params;
if (!channels_->GetFiles(device_info_.get(), &img_params, &imu_params)) {
if (!channels_->GetFiles(device_info_.get(), &img_params_, &imu_params)) {
LOG(FATAL) << "Read device infos failed. Please upgrade your firmware to "
"the latest version.";
}
@@ -566,12 +566,8 @@ void Device::ReadAllInfos() {
<< ", nominal_baseline: " << device_info_->nominal_baseline << "}";
device_info_->name = uvc::get_name(*device_);
if (img_params.ok) {
SetIntrinsics(Stream::LEFT, img_params.in_left);
SetIntrinsics(Stream::RIGHT, img_params.in_right);
SetExtrinsics(Stream::LEFT, Stream::RIGHT, img_params.ex_left_to_right);
VLOG(2) << "Intrinsics left: {" << GetIntrinsics(Stream::LEFT) << "}";
VLOG(2) << "Intrinsics right: {" << GetIntrinsics(Stream::RIGHT) << "}";
if (img_params_.ok) {
SetExtrinsics(Stream::LEFT, Stream::RIGHT, img_params_.ex_left_to_right);
VLOG(2) << "Extrinsics left to right: {"
<< GetExtrinsics(Stream::LEFT, Stream::RIGHT) << "}";
} else {
@@ -588,6 +584,15 @@ void Device::ReadAllInfos() {
}
}
void Device::ConfigIntrinsics(const Resolution &res) {
if (img_params_.ok) {
SetIntrinsics(Stream::LEFT, img_params_.in_left_map[res]);
SetIntrinsics(Stream::RIGHT, img_params_.in_right_map[res]);
VLOG(2) << "Intrinsics left: {" << GetIntrinsics(Stream::LEFT) << "}";
VLOG(2) << "Intrinsics right: {" << GetIntrinsics(Stream::RIGHT) << "}";
}
}
void Device::CallbackPushedStreamData(const Stream &stream) {
if (HasStreamCallback(stream)) {
auto &&datas = streams_->stream_datas(stream);
@@ -611,4 +616,8 @@ void Device::CallbackMotionData(const device::MotionData &data) {
}
}
Channels::img_params_t Device::GetImgParams() {
return img_params_;
}
MYNTEYE_END_NAMESPACE

View File

@@ -22,6 +22,7 @@
#include <string>
#include <vector>
#include "internal/channels.h"
#include "mynteye/callbacks.h"
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
@@ -256,6 +257,10 @@ class MYNTEYE_API Device {
* Get the motion datas.
*/
std::vector<device::MotionData> GetMotionDatas();
/**
* Get the device img params
*/
Channels::img_params_t GetImgParams();
protected:
std::shared_ptr<uvc::device> device() const {
@@ -301,6 +306,7 @@ class MYNTEYE_API Device {
std::shared_ptr<MotionIntrinsics> motion_intrinsics_;
std::map<Stream, Extrinsics> motion_from_extrinsics_;
Channels::img_params_t img_params_;
stream_callbacks_t stream_callbacks_;
motion_callback_t motion_callback_;
@@ -319,6 +325,8 @@ class MYNTEYE_API Device {
void ReadAllInfos();
void ConfigIntrinsics(const Resolution &res);
void CallbackPushedStreamData(const Stream &stream);
void CallbackMotionData(const device::MotionData &data);

View File

@@ -104,7 +104,7 @@ void CheckSpecVersion(const Version *spec_version) {
std::vector<std::string> spec_versions{"1.0"};
for (auto &&spec_ver : spec_versions) {
if (*spec_version == Version(spec_ver)) {
if (*spec_version >= Version(spec_ver)) {
return; // supported
}
}
@@ -554,8 +554,33 @@ std::size_t from_data(
Channels::img_params_t *img_params, const std::uint8_t *data,
const Version *spec_version) {
std::size_t i = 0;
i += from_data(&img_params->in_left, data + i, spec_version);
i += from_data(&img_params->in_right, data + i, spec_version);
if (spec_version->major() == 1) {
if (spec_version->minor() == 0) {
i += from_data(
&img_params->in_left_map[Resolution::RES_752x480], data + i,
spec_version);
i += from_data(
&img_params->in_right_map[Resolution::RES_752x480], data + i,
spec_version);
}
if (spec_version->minor() == 1) {
i += from_data(
&img_params->in_left_map[Resolution::RES_1280x400], data + i,
spec_version);
i += from_data(
&img_params->in_right_map[Resolution::RES_1280x400], data + i,
spec_version);
i += from_data(
&img_params->in_left_map[Resolution::RES_2560x800], data + i,
spec_version);
i += from_data(
&img_params->in_right_map[Resolution::RES_2560x800], data + i,
spec_version);
}
}
i += from_data(&img_params->ex_left_to_right, data + i, spec_version);
return i;
}
@@ -826,8 +851,34 @@ std::size_t to_data(
const Channels::img_params_t *img_params, std::uint8_t *data,
const Version *spec_version) {
std::size_t i = 3; // skip id, size
i += to_data(&img_params->in_left, data + i, spec_version);
i += to_data(&img_params->in_right, data + i, spec_version);
if (spec_version->major() == 1) {
if (spec_version->minor() == 0) {
i += to_data(
&img_params->in_left_map.at(Resolution::RES_752x480), data + i,
spec_version);
i += to_data(
&img_params->in_right_map.at(Resolution::RES_752x480), data + i,
spec_version);
}
if (spec_version->minor() == 1) {
i += to_data(
&img_params->in_left_map.at(Resolution::RES_1280x400), data + i,
spec_version);
i += to_data(
&img_params->in_right_map.at(Resolution::RES_1280x400), data + i,
spec_version);
i += to_data(
&img_params->in_left_map.at(Resolution::RES_2560x800), data + i,
spec_version);
i += to_data(
&img_params->in_right_map.at(Resolution::RES_2560x800), data + i,
spec_version);
}
}
i += to_data(&img_params->ex_left_to_right, data + i, spec_version);
// others
std::size_t size = i - 3;

View File

@@ -70,8 +70,8 @@ class MYNTEYE_API Channels {
typedef struct ImgParams {
bool ok;
Intrinsics in_left;
Intrinsics in_right;
std::map<Resolution, Intrinsics> in_left_map;
std::map<Resolution, Intrinsics> in_right_map;
Extrinsics ex_left_to_right;
} img_params_t;

View File

@@ -23,10 +23,9 @@ const std::map<Model, CapabilitiesSupports> capabilities_supports_map = {
const std::map<Model, OptionSupports> option_supports_map = {
{Model::STANDARD,
{Option::GAIN, Option::BRIGHTNESS, Option::CONTRAST, Option::EXPOSURE_MODE,
Option::MAX_EXPOSURE_TIME, Option::ERASE_CHIP, Option::MIN_EXPOSURE_TIME,
Option::ACCELEROMETER_RANGE, Option::GYROSCOPE_RANGE,
Option::ACCELEROMETER_LOW_PASS_FILTER,
{Option::BRIGHTNESS, Option::EXPOSURE_MODE, Option::ERASE_CHIP,
Option::MIN_EXPOSURE_TIME, Option::ACCELEROMETER_RANGE,
Option::GYROSCOPE_RANGE, Option::ACCELEROMETER_LOW_PASS_FILTER,
Option::GYROSCOPE_LOW_PASS_FILTER}}};
const std::map<Model, std::map<Capabilities, StreamRequests>>

View File

@@ -114,6 +114,11 @@ const char *to_string(const Option &value) {
CASE(HDR_MODE)
CASE(ZERO_DRIFT_CALIBRATION)
CASE(ERASE_CHIP)
CASE(MIN_EXPOSURE_TIME)
CASE(ACCELEROMETER_RANGE)
CASE(GYROSCOPE_RANGE)
CASE(ACCELEROMETER_LOW_PASS_FILTER)
CASE(GYROSCOPE_LOW_PASS_FILTER)
default:
CHECK(is_valid(value));
return "Option::UNKNOWN";