refactor(calib models): add default calib model(pinhole)
This commit is contained in:
parent
eea273b0db
commit
6ee7539b8e
|
@ -231,14 +231,34 @@ std::shared_ptr<API> API::Create(
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<API> API::Create(const std::shared_ptr<Device> &device) {
|
std::shared_ptr<API> API::Create(const std::shared_ptr<Device> &device) {
|
||||||
auto left_intr = device -> GetIntrinsics(Stream::LEFT);
|
std::shared_ptr<API> api = nullptr;
|
||||||
auto right_intr = device -> GetIntrinsics(Stream::RIGHT);
|
if (device != nullptr) {
|
||||||
if (left_intr->calib_model() != right_intr->calib_model()) {
|
bool in_l_ok, in_r_ok;
|
||||||
VLOG(2) << __func__
|
auto left_intr = device->GetIntrinsics(Stream::LEFT, &in_l_ok);
|
||||||
<< "ERROR: "
|
auto right_intr = device->GetIntrinsics(Stream::RIGHT, &in_r_ok);
|
||||||
<<"left camera and right camera use different calib models!";
|
if (!in_l_ok || !in_r_ok) {
|
||||||
|
LOG(ERROR) << "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.";
|
||||||
|
LOG(WARNING) << "use pinhole as default";
|
||||||
|
api = std::make_shared<API>(device, CalibrationModel::UNKNOW);
|
||||||
|
} else {
|
||||||
|
if (left_intr->calib_model() != right_intr->calib_model()) {
|
||||||
|
LOG(ERROR) << "left camera and right camera use different calib models!";
|
||||||
|
LOG(WARNING) << "use pinhole as default";
|
||||||
|
api = std::make_shared<API>(device, CalibrationModel::UNKNOW);
|
||||||
|
} else {
|
||||||
|
api = std::make_shared<API>(device, left_intr->calib_model());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG(ERROR) <<"no device!";
|
||||||
|
api = std::make_shared<API>(device, CalibrationModel::UNKNOW);
|
||||||
}
|
}
|
||||||
auto api = std::make_shared<API>(device, left_intr->calib_model());
|
|
||||||
return api;
|
return api;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
61
src/mynteye/api/config.cc
Normal file
61
src/mynteye/api/config.cc
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
#include "mynteye/api/config.h"
|
||||||
|
|
||||||
|
MYNTEYE_BEGIN_NAMESPACE
|
||||||
|
/**
|
||||||
|
* default intrinsics
|
||||||
|
*/
|
||||||
|
|
||||||
|
std::shared_ptr<IntrinsicsBase> getDefaultIntrinsics() {
|
||||||
|
auto res = std::make_shared<IntrinsicsPinhole>();
|
||||||
|
res->fx = 3.6220059643202876e+02;
|
||||||
|
res->fy = 3.6350065250745848e+02;
|
||||||
|
res->cx = 4.0658699068023441e+02;
|
||||||
|
res->cy = 2.3435161110061483e+02;
|
||||||
|
double codffs[5] = {
|
||||||
|
-2.5034765682756088e-01,
|
||||||
|
5.0579399202897619e-02,
|
||||||
|
-7.0536676161976066e-04,
|
||||||
|
-8.5255451307033846e-03,
|
||||||
|
0.
|
||||||
|
};
|
||||||
|
for (unsigned int i = 0; i < 5; i++) {
|
||||||
|
res->coeffs[i] = codffs[i];
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Extrinsics> getDefaultExtrinsics() {
|
||||||
|
auto res = std::make_shared<Extrinsics>();
|
||||||
|
double rotation[9] = {
|
||||||
|
9.9867908939669447e-01, -6.3445566137485428e-03, 5.0988459509619687e-02,
|
||||||
|
5.9890316389333252e-03, 9.9995670037792639e-01, 7.1224201868366971e-03,
|
||||||
|
-5.1031440326695092e-02, -6.8076406092671274e-03, 9.9867384471984544e-01
|
||||||
|
};
|
||||||
|
double translation[3] = {-1.2002489764113250e+02, -1.1782637409050747e+00,
|
||||||
|
-5.2058205159996538e+00};
|
||||||
|
for (unsigned int i = 0; i < 3; i++) {
|
||||||
|
for (unsigned int j = 0; j < 3; j++) {
|
||||||
|
res->rotation[i][j] = rotation[i*3 + j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (unsigned int i = 0; i < 3; i++) {
|
||||||
|
res->translation[i] = translation[i];
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
MYNTEYE_END_NAMESPACE
|
28
src/mynteye/api/config.h
Normal file
28
src/mynteye/api/config.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// 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.
|
||||||
|
#ifndef MYNTEYE_API_CONFIG_H_
|
||||||
|
#define MYNTEYE_API_CONFIG_H_
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "mynteye/api/api.h"
|
||||||
|
|
||||||
|
MYNTEYE_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
std::shared_ptr<IntrinsicsBase> getDefaultIntrinsics();
|
||||||
|
|
||||||
|
std::shared_ptr<Extrinsics> getDefaultExtrinsics();
|
||||||
|
|
||||||
|
MYNTEYE_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // MYNTEYE_API_CONFIG_H_
|
|
@ -403,10 +403,16 @@ void RectifyProcessor::InitParams(
|
||||||
const char RectifyProcessor::NAME[] = "RectifyProcessor";
|
const char RectifyProcessor::NAME[] = "RectifyProcessor";
|
||||||
|
|
||||||
RectifyProcessor::RectifyProcessor(
|
RectifyProcessor::RectifyProcessor(
|
||||||
std::shared_ptr<Device> device, std::int32_t proc_period)
|
std::shared_ptr<IntrinsicsBase> intr_left,
|
||||||
: Processor(std::move(proc_period)), device_(device) {
|
std::shared_ptr<IntrinsicsBase> intr_right,
|
||||||
|
std::shared_ptr<Extrinsics> extr,
|
||||||
|
std::int32_t proc_period)
|
||||||
|
: Processor(std::move(proc_period)),
|
||||||
|
calib_model(CalibrationModel::UNKNOW) {
|
||||||
|
intr_left_ = intr_left;
|
||||||
|
intr_right_ = intr_right;
|
||||||
|
extr_ = extr;
|
||||||
VLOG(2) << __func__ << ": proc_period=" << proc_period;
|
VLOG(2) << __func__ << ": proc_period=" << proc_period;
|
||||||
calib_model = CalibrationModel::UNKNOW;
|
|
||||||
NotifyImageParamsChanged();
|
NotifyImageParamsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,12 +425,10 @@ std::string RectifyProcessor::Name() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RectifyProcessor::NotifyImageParamsChanged() {
|
void RectifyProcessor::NotifyImageParamsChanged() {
|
||||||
auto in_left = device_->GetIntrinsics(Stream::LEFT);
|
|
||||||
auto in_right = device_->GetIntrinsics(Stream::RIGHT);
|
|
||||||
InitParams(
|
InitParams(
|
||||||
*std::dynamic_pointer_cast<IntrinsicsEquidistant>(in_left),
|
*std::dynamic_pointer_cast<IntrinsicsEquidistant>(intr_left_),
|
||||||
*std::dynamic_pointer_cast<IntrinsicsEquidistant>(in_right),
|
*std::dynamic_pointer_cast<IntrinsicsEquidistant>(intr_right_),
|
||||||
device_->GetExtrinsics(Stream::RIGHT, Stream::LEFT));
|
*extr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *RectifyProcessor::OnCreateOutput() {
|
Object *RectifyProcessor::OnCreateOutput() {
|
||||||
|
|
|
@ -32,7 +32,10 @@ class RectifyProcessor : public Processor {
|
||||||
static const char NAME[];
|
static const char NAME[];
|
||||||
|
|
||||||
RectifyProcessor(
|
RectifyProcessor(
|
||||||
std::shared_ptr<Device> device, std::int32_t proc_period = 0);
|
std::shared_ptr<IntrinsicsBase> intr_left,
|
||||||
|
std::shared_ptr<IntrinsicsBase> intr_right,
|
||||||
|
std::shared_ptr<Extrinsics> extr,
|
||||||
|
std::int32_t proc_period = 0);
|
||||||
virtual ~RectifyProcessor();
|
virtual ~RectifyProcessor();
|
||||||
|
|
||||||
std::string Name() override;
|
std::string Name() override;
|
||||||
|
@ -51,7 +54,9 @@ class RectifyProcessor : public Processor {
|
||||||
void InitParams(IntrinsicsEquidistant in_left,
|
void InitParams(IntrinsicsEquidistant in_left,
|
||||||
IntrinsicsEquidistant in_right, Extrinsics ex_right_to_left);
|
IntrinsicsEquidistant in_right, Extrinsics ex_right_to_left);
|
||||||
|
|
||||||
std::shared_ptr<Device> device_;
|
std::shared_ptr<IntrinsicsBase> intr_left_;
|
||||||
|
std::shared_ptr<IntrinsicsBase> intr_right_;
|
||||||
|
std::shared_ptr<Extrinsics> extr_;
|
||||||
CalibrationModel calib_model;
|
CalibrationModel calib_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,16 @@ MYNTEYE_BEGIN_NAMESPACE
|
||||||
const char RectifyProcessorOCV::NAME[] = "RectifyProcessorOCV";
|
const char RectifyProcessorOCV::NAME[] = "RectifyProcessorOCV";
|
||||||
|
|
||||||
RectifyProcessorOCV::RectifyProcessorOCV(
|
RectifyProcessorOCV::RectifyProcessorOCV(
|
||||||
std::shared_ptr<Device> device, std::int32_t proc_period)
|
std::shared_ptr<IntrinsicsBase> intr_left,
|
||||||
: Processor(std::move(proc_period)), device_(device) {
|
std::shared_ptr<IntrinsicsBase> intr_right,
|
||||||
|
std::shared_ptr<Extrinsics> extr,
|
||||||
|
std::int32_t proc_period)
|
||||||
|
: Processor(std::move(proc_period)),
|
||||||
|
calib_model(CalibrationModel::UNKNOW) {
|
||||||
VLOG(2) << __func__ << ": proc_period=" << proc_period;
|
VLOG(2) << __func__ << ": proc_period=" << proc_period;
|
||||||
calib_model = CalibrationModel::UNKNOW;
|
intr_left_ = intr_left;
|
||||||
|
intr_right_ = intr_right;
|
||||||
|
extr_ = extr;
|
||||||
NotifyImageParamsChanged();
|
NotifyImageParamsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,12 +47,10 @@ std::string RectifyProcessorOCV::Name() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RectifyProcessorOCV::NotifyImageParamsChanged() {
|
void RectifyProcessorOCV::NotifyImageParamsChanged() {
|
||||||
auto in_left = device_->GetIntrinsics(Stream::LEFT);
|
|
||||||
auto in_right = device_->GetIntrinsics(Stream::RIGHT);
|
|
||||||
InitParams(
|
InitParams(
|
||||||
*std::dynamic_pointer_cast<IntrinsicsPinhole>(in_left),
|
*std::dynamic_pointer_cast<IntrinsicsPinhole>(intr_left_),
|
||||||
*std::dynamic_pointer_cast<IntrinsicsPinhole>(in_right),
|
*std::dynamic_pointer_cast<IntrinsicsPinhole>(intr_right_),
|
||||||
device_->GetExtrinsics(Stream::RIGHT, Stream::LEFT));
|
*extr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *RectifyProcessorOCV::OnCreateOutput() {
|
Object *RectifyProcessorOCV::OnCreateOutput() {
|
||||||
|
|
|
@ -32,7 +32,10 @@ class RectifyProcessorOCV : public Processor {
|
||||||
static const char NAME[];
|
static const char NAME[];
|
||||||
|
|
||||||
RectifyProcessorOCV(
|
RectifyProcessorOCV(
|
||||||
std::shared_ptr<Device> device, std::int32_t proc_period = 0);
|
std::shared_ptr<IntrinsicsBase> intr_left,
|
||||||
|
std::shared_ptr<IntrinsicsBase> intr_right,
|
||||||
|
std::shared_ptr<Extrinsics> extr,
|
||||||
|
std::int32_t proc_period = 0);
|
||||||
virtual ~RectifyProcessorOCV();
|
virtual ~RectifyProcessorOCV();
|
||||||
|
|
||||||
std::string Name() override;
|
std::string Name() override;
|
||||||
|
@ -51,7 +54,10 @@ class RectifyProcessorOCV : public Processor {
|
||||||
void InitParams(IntrinsicsPinhole in_left,
|
void InitParams(IntrinsicsPinhole in_left,
|
||||||
IntrinsicsPinhole in_right, Extrinsics ex_right_to_left);
|
IntrinsicsPinhole in_right, Extrinsics ex_right_to_left);
|
||||||
|
|
||||||
std::shared_ptr<Device> device_;
|
std::shared_ptr<IntrinsicsBase> intr_left_;
|
||||||
|
std::shared_ptr<IntrinsicsBase> intr_right_;
|
||||||
|
std::shared_ptr<Extrinsics> extr_;
|
||||||
|
|
||||||
CalibrationModel calib_model;
|
CalibrationModel calib_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -73,10 +73,31 @@ void process_childs(
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
void Synthetic::InitCalibInfo() {
|
||||||
|
if (calib_model_ == CalibrationModel::UNKNOW) {
|
||||||
|
calib_model_ = CalibrationModel::PINHOLE;
|
||||||
|
LOG(INFO) << "camera calib model: unknow";
|
||||||
|
// use default
|
||||||
|
} else {
|
||||||
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
||||||
|
LOG(INFO) << "camera calib model: pinhole";
|
||||||
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
||||||
|
LOG(INFO) << "camera calib model: kannala_brandt";
|
||||||
|
}
|
||||||
|
intr_left_ = api_->GetIntrinsicsBase(Stream::LEFT);
|
||||||
|
intr_right_ = api_->GetIntrinsicsBase(Stream::RIGHT);
|
||||||
|
extr_ = std::make_shared<Extrinsics>(
|
||||||
|
api_->GetExtrinsics(Stream::LEFT, Stream::RIGHT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Synthetic::Synthetic(API *api, CalibrationModel calib_model)
|
Synthetic::Synthetic(API *api, CalibrationModel calib_model)
|
||||||
: api_(api), plugin_(nullptr), calib_model_(calib_model) {
|
: api_(api),
|
||||||
|
plugin_(nullptr),
|
||||||
|
calib_model_(calib_model) {
|
||||||
VLOG(2) << __func__;
|
VLOG(2) << __func__;
|
||||||
CHECK_NOTNULL(api_);
|
CHECK_NOTNULL(api_);
|
||||||
|
InitCalibInfo();
|
||||||
InitStreamSupports();
|
InitStreamSupports();
|
||||||
InitProcessors();
|
InitProcessors();
|
||||||
}
|
}
|
||||||
|
@ -552,20 +573,21 @@ void Synthetic::InitProcessors() {
|
||||||
cv::Mat Q;
|
cv::Mat Q;
|
||||||
if (calib_model_ == CalibrationModel::PINHOLE) {
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
||||||
auto &&rectify_processor_ocv =
|
auto &&rectify_processor_ocv =
|
||||||
std::make_shared<RectifyProcessorOCV>(api_->device(),
|
std::make_shared<RectifyProcessorOCV>(intr_left_, intr_right_, extr_,
|
||||||
RECTIFY_PROC_PERIOD);
|
RECTIFY_PROC_PERIOD);
|
||||||
rectify_processor = rectify_processor_ocv;
|
rectify_processor = rectify_processor_ocv;
|
||||||
Q = rectify_processor_ocv->Q;
|
Q = rectify_processor_ocv->Q;
|
||||||
#ifdef WITH_CAM_MODELS
|
#ifdef WITH_CAM_MODELS
|
||||||
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
||||||
rectify_processor =
|
rectify_processor =
|
||||||
std::make_shared<RectifyProcessor>(api_->device(), RECTIFY_PROC_PERIOD);
|
std::make_shared<RectifyProcessor>(intr_left_, intr_right_, extr_,
|
||||||
|
RECTIFY_PROC_PERIOD);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << "Unknow calib model type in device: "
|
LOG(ERROR) << "Unknow calib model type in device: "
|
||||||
<< calib_model_ << ", use default pinhole model";
|
<< calib_model_ << ", use default pinhole model";
|
||||||
auto &&rectify_processor_ocv =
|
auto &&rectify_processor_ocv =
|
||||||
std::make_shared<RectifyProcessorOCV>(api_->device(),
|
std::make_shared<RectifyProcessorOCV>(intr_left_, intr_right_, extr_,
|
||||||
RECTIFY_PROC_PERIOD);
|
RECTIFY_PROC_PERIOD);
|
||||||
rectify_processor = rectify_processor_ocv;
|
rectify_processor = rectify_processor_ocv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "mynteye/api/api.h"
|
#include "mynteye/api/api.h"
|
||||||
// #include ""
|
#include "mynteye/api/config.h"
|
||||||
|
|
||||||
MYNTEYE_BEGIN_NAMESPACE
|
MYNTEYE_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ class Synthetic {
|
||||||
bool HasPlugin() const;
|
bool HasPlugin() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void InitCalibInfo();
|
||||||
void InitStreamSupports();
|
void InitStreamSupports();
|
||||||
|
|
||||||
mode_t GetStreamEnabledMode(const Stream &stream) const;
|
mode_t GetStreamEnabledMode(const Stream &stream) const;
|
||||||
|
@ -115,6 +116,10 @@ class Synthetic {
|
||||||
std::shared_ptr<Plugin> plugin_;
|
std::shared_ptr<Plugin> plugin_;
|
||||||
|
|
||||||
CalibrationModel calib_model_;
|
CalibrationModel calib_model_;
|
||||||
|
|
||||||
|
std::shared_ptr<IntrinsicsBase> intr_left_;
|
||||||
|
std::shared_ptr<IntrinsicsBase> intr_right_;
|
||||||
|
std::shared_ptr<Extrinsics> extr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T, class P>
|
template <class T, class P>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user