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-10-27 16:24:04 +03:00
|
|
|
#include "mynteye/api/synthetic.h"
|
2018-08-05 18:30:06 +03:00
|
|
|
|
2018-04-27 10:47:54 +03:00
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
2018-04-27 04:58:53 +03:00
|
|
|
#include <stdexcept>
|
2018-08-05 18:18:51 +03:00
|
|
|
|
2018-11-27 08:50:12 +02:00
|
|
|
#include <opencv2/imgproc/imgproc.hpp>
|
|
|
|
|
2018-11-16 10:30:13 +02:00
|
|
|
#include "mynteye/logger.h"
|
2018-10-27 16:24:04 +03:00
|
|
|
#include "mynteye/api/object.h"
|
|
|
|
#include "mynteye/api/plugin.h"
|
|
|
|
#include "mynteye/api/processor.h"
|
|
|
|
#include "mynteye/api/processor/disparity_normalized_processor.h"
|
|
|
|
#include "mynteye/api/processor/disparity_processor.h"
|
2019-01-09 07:07:05 +02:00
|
|
|
#include "mynteye/api/processor/rectify_processor_ocv.h"
|
2019-01-09 04:53:05 +02:00
|
|
|
#include "mynteye/api/processor/depth_processor_ocv.h"
|
|
|
|
#include "mynteye/api/processor/points_processor_ocv.h"
|
2019-01-14 10:06:35 +02:00
|
|
|
#include "mynteye/api/config.h"
|
2019-01-09 07:07:05 +02:00
|
|
|
#ifdef WITH_CAM_MODELS
|
|
|
|
#include "mynteye/api/processor/depth_processor.h"
|
|
|
|
#include "mynteye/api/processor/points_processor.h"
|
|
|
|
#include "mynteye/api/processor/rectify_processor.h"
|
|
|
|
#endif
|
2018-10-27 16:24:04 +03:00
|
|
|
#include "mynteye/device/device.h"
|
2018-04-26 05:33:37 +03:00
|
|
|
|
2018-06-01 05:32:36 +03:00
|
|
|
#define RECTIFY_PROC_PERIOD 0
|
|
|
|
#define DISPARITY_PROC_PERIOD 0
|
|
|
|
#define DISPARITY_NORM_PROC_PERIOD 0
|
|
|
|
#define POINTS_PROC_PERIOD 0
|
|
|
|
#define DEPTH_PROC_PERIOD 0
|
|
|
|
|
2018-04-26 05:33:37 +03:00
|
|
|
MYNTEYE_BEGIN_NAMESPACE
|
|
|
|
|
2018-04-27 17:35:43 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
cv::Mat frame2mat(const std::shared_ptr<device::Frame> &frame) {
|
2018-08-05 18:18:51 +03:00
|
|
|
if (frame->format() == Format::YUYV) {
|
|
|
|
cv::Mat img(frame->height(), frame->width(), CV_8UC2, frame->data());
|
|
|
|
cv::cvtColor(img, img, cv::COLOR_YUV2BGR_YUY2);
|
|
|
|
return img;
|
2018-08-06 21:29:07 +03:00
|
|
|
} else if (frame->format() == Format::BGR888) {
|
|
|
|
cv::Mat img(frame->height(), frame->width(), CV_8UC3, frame->data());
|
|
|
|
return img;
|
2018-12-20 18:23:42 +02:00
|
|
|
} else { // Format::GRAY
|
2018-08-05 18:18:51 +03:00
|
|
|
return cv::Mat(frame->height(), frame->width(), CV_8UC1, frame->data());
|
|
|
|
}
|
2018-04-27 17:35:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
api::StreamData data2api(const device::StreamData &data) {
|
2018-10-26 10:39:34 +03:00
|
|
|
return {data.img, frame2mat(data.frame), data.frame, data.frame_id};
|
2018-04-27 17:35:43 +03:00
|
|
|
}
|
|
|
|
|
2018-06-12 17:05:47 +03:00
|
|
|
void process_childs(
|
|
|
|
const std::shared_ptr<Processor> &proc, const std::string &name,
|
|
|
|
const Object &obj) {
|
|
|
|
auto &&processor = find_processor<Processor>(proc, name);
|
|
|
|
for (auto child : processor->GetChilds()) {
|
|
|
|
child->Process(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 17:35:43 +03:00
|
|
|
} // namespace
|
|
|
|
|
2019-01-09 10:12:43 +02:00
|
|
|
void Synthetic::InitCalibInfo() {
|
2019-01-14 10:06:35 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
LOG(INFO) << "camera calib model: pinhole";
|
|
|
|
intr_left_ = api_->GetIntrinsicsBase(Stream::LEFT);
|
|
|
|
intr_right_ = api_->GetIntrinsicsBase(Stream::RIGHT);
|
|
|
|
extr_ = std::make_shared<Extrinsics>(
|
|
|
|
api_->GetExtrinsics(Stream::LEFT, Stream::RIGHT));
|
|
|
|
#ifdef WITH_CAM_MODELS
|
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
LOG(INFO) << "camera calib model: kannala_brandt";
|
2019-01-09 10:12:43 +02:00
|
|
|
intr_left_ = api_->GetIntrinsicsBase(Stream::LEFT);
|
|
|
|
intr_right_ = api_->GetIntrinsicsBase(Stream::RIGHT);
|
|
|
|
extr_ = std::make_shared<Extrinsics>(
|
|
|
|
api_->GetExtrinsics(Stream::LEFT, Stream::RIGHT));
|
2019-01-14 10:06:35 +02:00
|
|
|
#endif
|
|
|
|
} else {
|
2019-01-14 10:40:05 +02:00
|
|
|
calib_default_tag_ = true;
|
2019-01-14 10:06:35 +02:00
|
|
|
calib_model_ = CalibrationModel::PINHOLE;
|
|
|
|
LOG(INFO) << "camera calib model: unknow ,use default pinhole data";
|
|
|
|
intr_left_ = getDefaultIntrinsics();
|
|
|
|
intr_right_ = getDefaultIntrinsics();
|
|
|
|
extr_ = getDefaultExtrinsics();
|
2019-01-09 10:12:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 10:18:34 +02:00
|
|
|
Synthetic::Synthetic(API *api, CalibrationModel calib_model)
|
2019-01-09 10:12:43 +02:00
|
|
|
: api_(api),
|
|
|
|
plugin_(nullptr),
|
2019-01-14 10:40:05 +02:00
|
|
|
calib_model_(calib_model),
|
|
|
|
calib_default_tag_(false) {
|
2018-04-26 05:33:37 +03:00
|
|
|
VLOG(2) << __func__;
|
2018-04-27 04:58:53 +03:00
|
|
|
CHECK_NOTNULL(api_);
|
2019-01-09 10:12:43 +02:00
|
|
|
InitCalibInfo();
|
2018-04-27 04:58:53 +03:00
|
|
|
InitStreamSupports();
|
2018-04-27 10:47:54 +03:00
|
|
|
InitProcessors();
|
2018-04-26 05:33:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Synthetic::~Synthetic() {
|
|
|
|
VLOG(2) << __func__;
|
2018-04-27 10:47:54 +03:00
|
|
|
if (processor_) {
|
|
|
|
processor_->Deactivate(true);
|
|
|
|
processor_ = nullptr;
|
|
|
|
}
|
2018-04-26 05:33:37 +03:00
|
|
|
}
|
|
|
|
|
2019-01-14 10:40:05 +02:00
|
|
|
void Synthetic::NotifyImageParamsChanged() {
|
|
|
|
if (!calib_default_tag_) {
|
2019-01-12 12:53:14 +02:00
|
|
|
intr_left_ = api_->GetIntrinsicsBase(Stream::LEFT);
|
|
|
|
intr_right_ = api_->GetIntrinsicsBase(Stream::RIGHT);
|
|
|
|
extr_ = std::make_shared<Extrinsics>(
|
|
|
|
api_->GetExtrinsics(Stream::LEFT, Stream::RIGHT));
|
2019-01-14 10:40:05 +02:00
|
|
|
}
|
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
2019-01-09 07:07:05 +02:00
|
|
|
auto &&processor = find_processor<RectifyProcessorOCV>(processor_);
|
2019-01-12 12:53:14 +02:00
|
|
|
if (processor) processor->ReloadImageParams(intr_left_, intr_right_, extr_);
|
2019-01-09 07:07:05 +02:00
|
|
|
#ifdef WITH_CAM_MODELS
|
2019-01-14 10:40:05 +02:00
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
2019-01-09 07:07:05 +02:00
|
|
|
auto &&processor = find_processor<RectifyProcessor>(processor_);
|
2019-01-12 12:53:14 +02:00
|
|
|
if (processor) processor->ReloadImageParams(intr_left_, intr_right_, extr_);
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_ << ", use default pinhole model";
|
|
|
|
auto &&processor = find_processor<RectifyProcessorOCV>(processor_);
|
2019-01-12 12:53:14 +02:00
|
|
|
if (processor) processor->ReloadImageParams(intr_left_, intr_right_, extr_);
|
2019-01-09 07:07:05 +02:00
|
|
|
}
|
2018-12-20 16:08:29 +02:00
|
|
|
}
|
|
|
|
|
2018-04-27 17:35:43 +03:00
|
|
|
bool Synthetic::Supports(const Stream &stream) const {
|
|
|
|
return stream_supports_mode_.find(stream) != stream_supports_mode_.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
Synthetic::mode_t Synthetic::SupportsMode(const Stream &stream) const {
|
2018-04-27 04:58:53 +03:00
|
|
|
try {
|
|
|
|
return stream_supports_mode_.at(stream);
|
|
|
|
} catch (const std::out_of_range &e) {
|
|
|
|
return MODE_LAST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::EnableStreamData(const Stream &stream) {
|
2018-04-27 10:47:54 +03:00
|
|
|
EnableStreamData(stream, 0);
|
2018-04-27 04:58:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::DisableStreamData(const Stream &stream) {
|
2018-04-27 10:47:54 +03:00
|
|
|
DisableStreamData(stream, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::IsStreamDataEnabled(const Stream &stream) const {
|
2018-04-27 17:35:43 +03:00
|
|
|
return stream_enabled_mode_.find(stream) != stream_enabled_mode_.end();
|
2018-04-26 09:44:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::SetStreamCallback(
|
|
|
|
const Stream &stream, stream_callback_t callback) {
|
2018-04-27 10:47:54 +03:00
|
|
|
if (callback == nullptr) {
|
|
|
|
stream_callbacks_.erase(stream);
|
|
|
|
} else {
|
|
|
|
stream_callbacks_[stream] = callback;
|
|
|
|
}
|
2018-04-26 09:44:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::HasStreamCallback(const Stream &stream) const {
|
2018-04-27 10:47:54 +03:00
|
|
|
return stream_callbacks_.find(stream) != stream_callbacks_.end();
|
2018-04-26 09:44:47 +03:00
|
|
|
}
|
|
|
|
|
2018-04-27 17:35:43 +03:00
|
|
|
void Synthetic::StartVideoStreaming() {
|
|
|
|
auto &&device = api_->device();
|
|
|
|
for (auto &&it = stream_supports_mode_.begin();
|
|
|
|
it != stream_supports_mode_.end(); it++) {
|
|
|
|
if (it->second == MODE_NATIVE) {
|
|
|
|
auto &&stream = it->first;
|
|
|
|
device->SetStreamCallback(
|
2018-05-31 10:39:42 +03:00
|
|
|
stream,
|
|
|
|
[this, stream](const device::StreamData &data) {
|
2018-04-27 17:35:43 +03:00
|
|
|
auto &&stream_data = data2api(data);
|
2018-04-28 07:40:29 +03:00
|
|
|
ProcessNativeStream(stream, stream_data);
|
2018-04-27 17:35:43 +03:00
|
|
|
// Need mutex if set callback after start
|
|
|
|
if (HasStreamCallback(stream)) {
|
|
|
|
stream_callbacks_.at(stream)(stream_data);
|
|
|
|
}
|
2018-05-31 10:39:42 +03:00
|
|
|
},
|
|
|
|
true);
|
2018-04-27 17:35:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
device->Start(Source::VIDEO_STREAMING);
|
|
|
|
}
|
2018-04-26 09:44:47 +03:00
|
|
|
|
2018-04-27 17:35:43 +03:00
|
|
|
void Synthetic::StopVideoStreaming() {
|
|
|
|
auto &&device = api_->device();
|
|
|
|
for (auto &&it = stream_supports_mode_.begin();
|
|
|
|
it != stream_supports_mode_.end(); it++) {
|
|
|
|
if (it->second == MODE_NATIVE) {
|
|
|
|
device->SetStreamCallback(it->first, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
device->Stop(Source::VIDEO_STREAMING);
|
|
|
|
}
|
2018-04-26 09:44:47 +03:00
|
|
|
|
2018-04-27 17:35:43 +03:00
|
|
|
void Synthetic::WaitForStreams() {
|
|
|
|
api_->device()->WaitForStreams();
|
|
|
|
}
|
2018-04-26 09:44:47 +03:00
|
|
|
|
|
|
|
api::StreamData Synthetic::GetStreamData(const Stream &stream) {
|
2018-04-27 17:35:43 +03:00
|
|
|
auto &&mode = GetStreamEnabledMode(stream);
|
|
|
|
if (mode == MODE_NATIVE) {
|
|
|
|
auto &&device = api_->device();
|
2018-12-20 11:10:18 +02:00
|
|
|
return data2api(device->GetStreamData(stream));
|
2018-04-27 17:35:43 +03:00
|
|
|
} else if (mode == MODE_SYNTHETIC) {
|
2018-06-13 13:00:31 +03:00
|
|
|
if (stream == Stream::LEFT_RECTIFIED || stream == Stream::RIGHT_RECTIFIED) {
|
|
|
|
static std::shared_ptr<ObjMat2> output = nullptr;
|
2019-01-09 07:07:05 +02:00
|
|
|
std::shared_ptr<Processor> processor = nullptr;
|
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
processor = find_processor<RectifyProcessorOCV>(processor_);
|
|
|
|
#ifdef WITH_CAM_MODELS
|
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
processor = find_processor<RectifyProcessor>(processor_);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_ << ", use default pinhole model";
|
|
|
|
processor = find_processor<RectifyProcessorOCV>(processor_);
|
|
|
|
}
|
2018-06-13 13:00:31 +03:00
|
|
|
auto &&out = processor->GetOutput();
|
|
|
|
if (out != nullptr) {
|
|
|
|
// Obtain the output, out will be nullptr if get again immediately.
|
|
|
|
output = Object::Cast<ObjMat2>(out);
|
|
|
|
}
|
|
|
|
if (output != nullptr) {
|
|
|
|
if (stream == Stream::LEFT_RECTIFIED) {
|
2018-11-05 11:50:15 +02:00
|
|
|
return {output->first_data, output->first, nullptr, output->first_id};
|
2018-06-13 13:00:31 +03:00
|
|
|
} else {
|
2018-11-05 11:50:15 +02:00
|
|
|
return {output->second_data, output->second, nullptr,
|
|
|
|
output->second_id};
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
2018-06-13 13:00:31 +03:00
|
|
|
}
|
|
|
|
VLOG(2) << "Rectify not ready now";
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
switch (stream) {
|
2018-04-28 07:40:29 +03:00
|
|
|
case Stream::DISPARITY: {
|
|
|
|
auto &&processor = find_processor<DisparityProcessor>(processor_);
|
2018-06-13 13:00:31 +03:00
|
|
|
auto &&out = processor->GetOutput();
|
2018-04-28 07:40:29 +03:00
|
|
|
if (out != nullptr) {
|
2018-06-13 13:00:31 +03:00
|
|
|
auto &&output = Object::Cast<ObjMat>(out);
|
2018-11-05 11:50:15 +02:00
|
|
|
return {output->data, output->value, nullptr, output->id};
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
VLOG(2) << "Disparity not ready now";
|
|
|
|
} break;
|
|
|
|
case Stream::DISPARITY_NORMALIZED: {
|
|
|
|
auto &&processor =
|
|
|
|
find_processor<DisparityNormalizedProcessor>(processor_);
|
2018-06-13 13:00:31 +03:00
|
|
|
auto &&out = processor->GetOutput();
|
2018-04-28 07:40:29 +03:00
|
|
|
if (out != nullptr) {
|
2018-06-13 13:00:31 +03:00
|
|
|
auto &&output = Object::Cast<ObjMat>(out);
|
2018-11-05 11:50:15 +02:00
|
|
|
return {output->data, output->value, nullptr, output->id};
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
VLOG(2) << "Disparity normalized not ready now";
|
|
|
|
} break;
|
|
|
|
case Stream::POINTS: {
|
2019-01-09 04:53:05 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
auto &&processor = find_processor<PointsProcessorOCV>(processor_);
|
|
|
|
auto &&out = processor->GetOutput();
|
|
|
|
if (out != nullptr) {
|
|
|
|
auto &&output = Object::Cast<ObjMat>(out);
|
|
|
|
return {output->data, output->value, nullptr, output->id};
|
|
|
|
}
|
|
|
|
VLOG(2) << "Points not ready now";
|
2019-01-09 07:07:05 +02:00
|
|
|
#ifdef WITH_CAM_MODELS
|
2019-01-09 04:53:05 +02:00
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
auto &&processor = find_processor<PointsProcessor>(processor_);
|
|
|
|
auto &&out = processor->GetOutput();
|
|
|
|
if (out != nullptr) {
|
|
|
|
auto &&output = Object::Cast<ObjMat>(out);
|
|
|
|
return {output->data, output->value, nullptr, output->id};
|
|
|
|
}
|
|
|
|
VLOG(2) << "Points not ready now";
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
2019-01-09 04:53:05 +02:00
|
|
|
} else {
|
|
|
|
// UNKNOW
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_;
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case Stream::DEPTH: {
|
2019-01-09 04:53:05 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
auto &&processor = find_processor<DepthProcessorOCV>(processor_);
|
|
|
|
auto &&out = processor->GetOutput();
|
|
|
|
if (out != nullptr) {
|
|
|
|
auto &&output = Object::Cast<ObjMat>(out);
|
|
|
|
return {output->data, output->value, nullptr, output->id};
|
|
|
|
}
|
|
|
|
VLOG(2) << "Depth not ready now";
|
2019-01-09 07:07:05 +02:00
|
|
|
#ifdef WITH_CAM_MODELS
|
2019-01-09 04:53:05 +02:00
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
auto &&processor = find_processor<DepthProcessor>(processor_);
|
|
|
|
auto &&out = processor->GetOutput();
|
|
|
|
if (out != nullptr) {
|
|
|
|
auto &&output = Object::Cast<ObjMat>(out);
|
|
|
|
return {output->data, output->value, nullptr, output->id};
|
|
|
|
}
|
|
|
|
VLOG(2) << "Depth not ready now";
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
2019-01-09 04:53:05 +02:00
|
|
|
} else {
|
|
|
|
// UNKNOW
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_;
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return {}; // frame.empty() == true
|
2018-04-27 17:35:43 +03:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Failed to get stream data of " << stream
|
|
|
|
<< ", unsupported or disabled";
|
2018-04-28 07:40:29 +03:00
|
|
|
return {}; // frame.empty() == true
|
2018-04-27 17:35:43 +03:00
|
|
|
}
|
2018-04-26 09:44:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<api::StreamData> Synthetic::GetStreamDatas(const Stream &stream) {
|
2018-04-27 17:35:43 +03:00
|
|
|
auto &&mode = GetStreamEnabledMode(stream);
|
|
|
|
if (mode == MODE_NATIVE) {
|
|
|
|
auto &&device = api_->device();
|
|
|
|
std::vector<api::StreamData> datas;
|
|
|
|
for (auto &&data : device->GetStreamDatas(stream)) {
|
|
|
|
datas.push_back(data2api(data));
|
|
|
|
}
|
|
|
|
return datas;
|
|
|
|
} else if (mode == MODE_SYNTHETIC) {
|
2018-04-28 07:40:29 +03:00
|
|
|
return {GetStreamData(stream)};
|
2018-04-27 17:35:43 +03:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Failed to get stream data of " << stream
|
|
|
|
<< ", unsupported or disabled";
|
|
|
|
}
|
2018-04-26 09:44:47 +03:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2018-05-08 06:12:45 +03:00
|
|
|
void Synthetic::SetPlugin(std::shared_ptr<Plugin> plugin) {
|
|
|
|
plugin_ = plugin;
|
|
|
|
}
|
|
|
|
|
2018-06-04 17:09:20 +03:00
|
|
|
bool Synthetic::HasPlugin() const {
|
|
|
|
return plugin_ != nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-27 04:58:53 +03:00
|
|
|
void Synthetic::InitStreamSupports() {
|
|
|
|
auto &&device = api_->device();
|
2018-04-27 17:35:43 +03:00
|
|
|
if (device->Supports(Stream::LEFT) && device->Supports(Stream::RIGHT)) {
|
|
|
|
stream_supports_mode_[Stream::LEFT] = MODE_NATIVE;
|
|
|
|
stream_supports_mode_[Stream::RIGHT] = MODE_NATIVE;
|
|
|
|
|
|
|
|
std::vector<Stream> stream_chain{
|
|
|
|
Stream::LEFT_RECTIFIED, Stream::RIGHT_RECTIFIED,
|
|
|
|
Stream::DISPARITY, Stream::DISPARITY_NORMALIZED,
|
|
|
|
Stream::POINTS, Stream::DEPTH};
|
|
|
|
for (auto &&stream : stream_chain) {
|
|
|
|
if (device->Supports(stream)) {
|
|
|
|
stream_supports_mode_[stream] = MODE_NATIVE;
|
|
|
|
} else {
|
|
|
|
stream_supports_mode_[stream] = MODE_SYNTHETIC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enabled native streams by default
|
|
|
|
for (auto &&it = stream_supports_mode_.begin();
|
|
|
|
it != stream_supports_mode_.end(); it++) {
|
|
|
|
if (it->second == MODE_NATIVE) {
|
|
|
|
stream_enabled_mode_[it->first] = MODE_NATIVE;
|
2018-04-27 04:58:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 17:35:43 +03:00
|
|
|
Synthetic::mode_t Synthetic::GetStreamEnabledMode(const Stream &stream) const {
|
|
|
|
try {
|
|
|
|
return stream_enabled_mode_.at(stream);
|
|
|
|
} catch (const std::out_of_range &e) {
|
|
|
|
return MODE_LAST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::IsStreamEnabledNative(const Stream &stream) const {
|
|
|
|
return GetStreamEnabledMode(stream) == MODE_NATIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::IsStreamEnabledSynthetic(const Stream &stream) const {
|
|
|
|
return GetStreamEnabledMode(stream) == MODE_SYNTHETIC;
|
|
|
|
}
|
|
|
|
|
2018-04-27 10:47:54 +03:00
|
|
|
void Synthetic::EnableStreamData(const Stream &stream, std::uint32_t depth) {
|
2018-04-27 17:35:43 +03:00
|
|
|
if (IsStreamDataEnabled(stream))
|
2018-04-27 10:47:54 +03:00
|
|
|
return;
|
|
|
|
// Activate processors of synthetic stream
|
|
|
|
switch (stream) {
|
|
|
|
case Stream::LEFT_RECTIFIED: {
|
2018-04-27 17:35:43 +03:00
|
|
|
if (!IsStreamDataEnabled(Stream::LEFT))
|
2018-04-27 10:47:54 +03:00
|
|
|
break;
|
2018-04-27 17:35:43 +03:00
|
|
|
stream_enabled_mode_[stream] = MODE_SYNTHETIC;
|
2019-01-09 07:07:05 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
CHECK(ActivateProcessor<RectifyProcessorOCV>());
|
|
|
|
#ifdef WITH_CAM_MODELS
|
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
CHECK(ActivateProcessor<RectifyProcessor>());
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_ << ", use default pinhole model";
|
|
|
|
CHECK(ActivateProcessor<RectifyProcessorOCV>());
|
|
|
|
}
|
2018-12-20 16:08:29 +02:00
|
|
|
} return;
|
2018-04-27 10:47:54 +03:00
|
|
|
case Stream::RIGHT_RECTIFIED: {
|
2018-04-27 17:35:43 +03:00
|
|
|
if (!IsStreamDataEnabled(Stream::RIGHT))
|
2018-04-27 10:47:54 +03:00
|
|
|
break;
|
2018-04-27 17:35:43 +03:00
|
|
|
stream_enabled_mode_[stream] = MODE_SYNTHETIC;
|
2019-01-09 07:07:05 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
CHECK(ActivateProcessor<RectifyProcessorOCV>());
|
|
|
|
#ifdef WITH_CAM_MODELS
|
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
CHECK(ActivateProcessor<RectifyProcessor>());
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_ << ", use default pinhole model";
|
|
|
|
CHECK(ActivateProcessor<RectifyProcessorOCV>());
|
|
|
|
}
|
2018-12-20 16:08:29 +02:00
|
|
|
} return;
|
2018-04-27 10:47:54 +03:00
|
|
|
case Stream::DISPARITY: {
|
2018-04-27 17:35:43 +03:00
|
|
|
stream_enabled_mode_[stream] = MODE_SYNTHETIC;
|
2018-04-27 10:47:54 +03:00
|
|
|
EnableStreamData(Stream::LEFT_RECTIFIED, depth + 1);
|
|
|
|
EnableStreamData(Stream::RIGHT_RECTIFIED, depth + 1);
|
|
|
|
CHECK(ActivateProcessor<DisparityProcessor>());
|
2018-12-20 16:08:29 +02:00
|
|
|
} return;
|
2018-04-27 10:47:54 +03:00
|
|
|
case Stream::DISPARITY_NORMALIZED: {
|
2018-04-27 17:35:43 +03:00
|
|
|
stream_enabled_mode_[stream] = MODE_SYNTHETIC;
|
2018-04-27 10:47:54 +03:00
|
|
|
EnableStreamData(Stream::DISPARITY, depth + 1);
|
|
|
|
CHECK(ActivateProcessor<DisparityNormalizedProcessor>());
|
2018-12-20 16:08:29 +02:00
|
|
|
} return;
|
2018-04-27 10:47:54 +03:00
|
|
|
case Stream::POINTS: {
|
2018-04-27 17:35:43 +03:00
|
|
|
stream_enabled_mode_[stream] = MODE_SYNTHETIC;
|
2019-01-09 04:53:05 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
2019-01-09 12:09:01 +02:00
|
|
|
EnableStreamData(Stream::DISPARITY, depth + 1);
|
2019-01-09 04:53:05 +02:00
|
|
|
CHECK(ActivateProcessor<PointsProcessorOCV>());
|
2019-01-09 07:07:05 +02:00
|
|
|
#ifdef WITH_CAM_MODELS
|
2019-01-09 04:53:05 +02:00
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
2019-01-09 12:09:01 +02:00
|
|
|
EnableStreamData(Stream::DEPTH, depth + 1);
|
2019-01-09 04:53:05 +02:00
|
|
|
CHECK(ActivateProcessor<PointsProcessor>());
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
2019-01-09 04:53:05 +02:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_;
|
|
|
|
}
|
2018-12-20 16:08:29 +02:00
|
|
|
} return;
|
2018-04-27 10:47:54 +03:00
|
|
|
case Stream::DEPTH: {
|
2018-04-27 17:35:43 +03:00
|
|
|
stream_enabled_mode_[stream] = MODE_SYNTHETIC;
|
2019-01-09 04:53:05 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
2019-01-09 12:09:01 +02:00
|
|
|
EnableStreamData(Stream::POINTS, depth + 1);
|
2019-01-09 04:53:05 +02:00
|
|
|
CHECK(ActivateProcessor<DepthProcessorOCV>());
|
2019-01-09 07:07:05 +02:00
|
|
|
#ifdef WITH_CAM_MODELS
|
2019-01-09 04:53:05 +02:00
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
2019-01-09 12:09:01 +02:00
|
|
|
EnableStreamData(Stream::DISPARITY, depth + 1);
|
2019-01-09 04:53:05 +02:00
|
|
|
CHECK(ActivateProcessor<DepthProcessor>());
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
2019-01-09 04:53:05 +02:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_;
|
|
|
|
}
|
2018-12-20 16:08:29 +02:00
|
|
|
} return;
|
|
|
|
default: break;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
if (depth == 0) {
|
|
|
|
LOG(WARNING) << "Enable stream data of " << stream << " failed";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::DisableStreamData(const Stream &stream, std::uint32_t depth) {
|
|
|
|
if (!IsStreamDataEnabled(stream))
|
|
|
|
return;
|
|
|
|
// Deactivate processors of synthetic stream
|
2018-04-27 17:35:43 +03:00
|
|
|
if (stream_enabled_mode_[stream] != MODE_NATIVE) {
|
|
|
|
stream_enabled_mode_.erase(stream);
|
2018-04-27 10:47:54 +03:00
|
|
|
switch (stream) {
|
|
|
|
case Stream::LEFT_RECTIFIED: {
|
2018-04-27 17:35:43 +03:00
|
|
|
if (IsStreamEnabledSynthetic(Stream::RIGHT_RECTIFIED)) {
|
2018-04-27 10:47:54 +03:00
|
|
|
DisableStreamData(Stream::RIGHT_RECTIFIED, depth + 1);
|
|
|
|
}
|
2018-04-27 17:35:43 +03:00
|
|
|
if (IsStreamEnabledSynthetic(Stream::DISPARITY)) {
|
2018-04-27 10:47:54 +03:00
|
|
|
DisableStreamData(Stream::DISPARITY, depth + 1);
|
|
|
|
}
|
2019-01-09 07:07:05 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
DeactivateProcessor<RectifyProcessorOCV>();
|
|
|
|
#ifdef WITH_CAM_MODELS
|
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
DeactivateProcessor<RectifyProcessor>();
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_ << ", use default pinhole model";
|
|
|
|
DeactivateProcessor<RectifyProcessorOCV>();
|
|
|
|
}
|
2018-04-27 10:47:54 +03:00
|
|
|
} break;
|
|
|
|
case Stream::RIGHT_RECTIFIED: {
|
2018-04-27 17:35:43 +03:00
|
|
|
if (IsStreamEnabledSynthetic(Stream::LEFT_RECTIFIED)) {
|
2018-04-27 10:47:54 +03:00
|
|
|
DisableStreamData(Stream::LEFT_RECTIFIED, depth + 1);
|
|
|
|
}
|
2018-04-27 17:35:43 +03:00
|
|
|
if (IsStreamEnabledSynthetic(Stream::DISPARITY)) {
|
2018-04-27 10:47:54 +03:00
|
|
|
DisableStreamData(Stream::DISPARITY, depth + 1);
|
|
|
|
}
|
2019-01-09 07:07:05 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
DeactivateProcessor<RectifyProcessorOCV>();
|
|
|
|
#ifdef WITH_CAM_MODELS
|
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
DeactivateProcessor<RectifyProcessor>();
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_ << ", use default pinhole model";
|
|
|
|
DeactivateProcessor<RectifyProcessorOCV>();
|
|
|
|
}
|
2018-04-27 10:47:54 +03:00
|
|
|
} break;
|
|
|
|
case Stream::DISPARITY: {
|
2019-01-16 05:08:16 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
if (IsStreamEnabledSynthetic(Stream::DISPARITY_NORMALIZED)) {
|
|
|
|
DisableStreamData(Stream::DISPARITY_NORMALIZED, depth + 1);
|
|
|
|
}
|
|
|
|
if (IsStreamEnabledSynthetic(Stream::POINTS)) {
|
|
|
|
DisableStreamData(Stream::POINTS, depth + 1);
|
|
|
|
}
|
|
|
|
DeactivateProcessor<DisparityProcessor>();
|
|
|
|
#ifdef WITH_CAM_MODELS
|
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
if (IsStreamEnabledSynthetic(Stream::DISPARITY_NORMALIZED)) {
|
|
|
|
DisableStreamData(Stream::DISPARITY_NORMALIZED, depth + 1);
|
|
|
|
}
|
|
|
|
if (IsStreamEnabledSynthetic(Stream::DEPTH)) {
|
|
|
|
DisableStreamData(Stream::DEPTH, depth + 1);
|
|
|
|
}
|
|
|
|
DeactivateProcessor<DisparityProcessor>();
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case Stream::DISPARITY_NORMALIZED: {
|
|
|
|
DeactivateProcessor<DisparityNormalizedProcessor>();
|
|
|
|
} break;
|
|
|
|
case Stream::POINTS: {
|
2019-01-09 04:53:05 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
if (IsStreamEnabledSynthetic(Stream::DEPTH)) {
|
|
|
|
DisableStreamData(Stream::DEPTH, depth + 1);
|
|
|
|
}
|
|
|
|
DeactivateProcessor<PointsProcessorOCV>();
|
2019-01-09 07:07:05 +02:00
|
|
|
#ifdef WITH_CAM_MODELS
|
2019-01-09 04:53:05 +02:00
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
DeactivateProcessor<PointsProcessor>();
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
2019-01-09 04:53:05 +02:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case Stream::DEPTH: {
|
2019-01-09 04:53:05 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
DeactivateProcessor<DepthProcessorOCV>();
|
2019-01-09 07:07:05 +02:00
|
|
|
#ifdef WITH_CAM_MODELS
|
2019-01-09 04:53:05 +02:00
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
2019-01-16 05:08:16 +02:00
|
|
|
if (IsStreamEnabledSynthetic(Stream::POINTS)) {
|
2019-01-09 04:53:05 +02:00
|
|
|
DisableStreamData(Stream::POINTS, depth + 1);
|
|
|
|
}
|
|
|
|
DeactivateProcessor<DepthProcessor>();
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
2019-01-09 04:53:05 +02:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_;
|
|
|
|
}
|
2018-04-27 10:47:54 +03:00
|
|
|
} break;
|
2018-12-20 16:08:29 +02:00
|
|
|
default: return;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
if (depth > 0) {
|
|
|
|
LOG(WARNING) << "Disable synthetic stream data of " << stream << " too";
|
|
|
|
}
|
|
|
|
} else if (depth == 0) {
|
|
|
|
LOG(WARNING) << "Disable native stream data of " << stream << " failed";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::InitProcessors() {
|
2019-01-09 07:07:05 +02:00
|
|
|
std::shared_ptr<Processor> rectify_processor = nullptr;
|
2019-01-09 11:30:38 +02:00
|
|
|
#ifdef WITH_CAM_MODELS
|
|
|
|
std::shared_ptr<RectifyProcessor> rectify_processor_imp = nullptr;
|
|
|
|
#endif
|
2019-01-09 07:07:05 +02:00
|
|
|
cv::Mat Q;
|
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
auto &&rectify_processor_ocv =
|
2019-01-09 10:12:43 +02:00
|
|
|
std::make_shared<RectifyProcessorOCV>(intr_left_, intr_right_, extr_,
|
2019-01-09 07:07:05 +02:00
|
|
|
RECTIFY_PROC_PERIOD);
|
|
|
|
rectify_processor = rectify_processor_ocv;
|
|
|
|
Q = rectify_processor_ocv->Q;
|
|
|
|
#ifdef WITH_CAM_MODELS
|
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
2019-01-09 11:30:38 +02:00
|
|
|
rectify_processor_imp =
|
2019-01-09 10:12:43 +02:00
|
|
|
std::make_shared<RectifyProcessor>(intr_left_, intr_right_, extr_,
|
|
|
|
RECTIFY_PROC_PERIOD);
|
2019-01-09 11:30:38 +02:00
|
|
|
rectify_processor = rectify_processor_imp;
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_ << ", use default pinhole model";
|
|
|
|
auto &&rectify_processor_ocv =
|
2019-01-09 10:12:43 +02:00
|
|
|
std::make_shared<RectifyProcessorOCV>(intr_left_, intr_right_, extr_,
|
2019-01-09 07:07:05 +02:00
|
|
|
RECTIFY_PROC_PERIOD);
|
|
|
|
rectify_processor = rectify_processor_ocv;
|
|
|
|
}
|
2018-06-01 05:32:36 +03:00
|
|
|
auto &&disparity_processor =
|
2019-01-15 04:07:58 +02:00
|
|
|
std::make_shared<DisparityProcessor>(DisparityProcessorType::SGBM,
|
2019-01-14 14:08:14 +02:00
|
|
|
DISPARITY_PROC_PERIOD);
|
2018-04-27 10:47:54 +03:00
|
|
|
auto &&disparitynormalized_processor =
|
2018-06-01 05:32:36 +03:00
|
|
|
std::make_shared<DisparityNormalizedProcessor>(
|
|
|
|
DISPARITY_NORM_PROC_PERIOD);
|
2019-01-09 04:53:05 +02:00
|
|
|
std::shared_ptr<Processor> points_processor = nullptr;
|
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
2019-01-09 07:07:05 +02:00
|
|
|
points_processor = std::make_shared<PointsProcessorOCV>(
|
|
|
|
Q, POINTS_PROC_PERIOD);
|
|
|
|
#ifdef WITH_CAM_MODELS
|
2019-01-09 04:53:05 +02:00
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
2019-01-09 07:07:05 +02:00
|
|
|
points_processor = std::make_shared<PointsProcessor>(
|
2019-01-09 11:30:38 +02:00
|
|
|
rectify_processor_imp -> getCalibInfoPair(),
|
2019-01-09 05:03:13 +02:00
|
|
|
POINTS_PROC_PERIOD);
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
2019-01-09 04:53:05 +02:00
|
|
|
} else {
|
2019-01-09 07:07:05 +02:00
|
|
|
points_processor = std::make_shared<PointsProcessorOCV>(
|
|
|
|
Q, POINTS_PROC_PERIOD);
|
2019-01-09 04:53:05 +02:00
|
|
|
}
|
|
|
|
std::shared_ptr<Processor> depth_processor = nullptr;
|
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
2019-01-09 07:07:05 +02:00
|
|
|
depth_processor = std::make_shared<DepthProcessorOCV>(DEPTH_PROC_PERIOD);
|
|
|
|
#ifdef WITH_CAM_MODELS
|
2019-01-09 04:53:05 +02:00
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
2019-01-09 11:30:38 +02:00
|
|
|
depth_processor = std::make_shared<DepthProcessor>(
|
|
|
|
rectify_processor_imp -> getCalibInfoPair(),
|
|
|
|
DEPTH_PROC_PERIOD);
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
2019-01-09 04:53:05 +02:00
|
|
|
} else {
|
2019-01-09 07:07:05 +02:00
|
|
|
depth_processor = std::make_shared<DepthProcessorOCV>(DEPTH_PROC_PERIOD);
|
2019-01-09 04:53:05 +02:00
|
|
|
}
|
2018-04-27 10:47:54 +03:00
|
|
|
|
|
|
|
using namespace std::placeholders; // NOLINT
|
|
|
|
rectify_processor->SetProcessCallback(
|
|
|
|
std::bind(&Synthetic::OnRectifyProcess, this, _1, _2, _3));
|
|
|
|
disparity_processor->SetProcessCallback(
|
|
|
|
std::bind(&Synthetic::OnDisparityProcess, this, _1, _2, _3));
|
|
|
|
disparitynormalized_processor->SetProcessCallback(
|
|
|
|
std::bind(&Synthetic::OnDisparityNormalizedProcess, this, _1, _2, _3));
|
|
|
|
points_processor->SetProcessCallback(
|
|
|
|
std::bind(&Synthetic::OnPointsProcess, this, _1, _2, _3));
|
|
|
|
depth_processor->SetProcessCallback(
|
|
|
|
std::bind(&Synthetic::OnDepthProcess, this, _1, _2, _3));
|
|
|
|
|
2018-04-28 07:40:29 +03:00
|
|
|
rectify_processor->SetPostProcessCallback(
|
|
|
|
std::bind(&Synthetic::OnRectifyPostProcess, this, _1));
|
|
|
|
disparity_processor->SetPostProcessCallback(
|
|
|
|
std::bind(&Synthetic::OnDisparityPostProcess, this, _1));
|
|
|
|
disparitynormalized_processor->SetPostProcessCallback(
|
|
|
|
std::bind(&Synthetic::OnDisparityNormalizedPostProcess, this, _1));
|
|
|
|
points_processor->SetPostProcessCallback(
|
|
|
|
std::bind(&Synthetic::OnPointsPostProcess, this, _1));
|
|
|
|
depth_processor->SetPostProcessCallback(
|
|
|
|
std::bind(&Synthetic::OnDepthPostProcess, this, _1));
|
|
|
|
|
2019-01-08 10:18:34 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
// PINHOLE
|
|
|
|
rectify_processor->AddChild(disparity_processor);
|
|
|
|
disparity_processor->AddChild(disparitynormalized_processor);
|
|
|
|
disparity_processor->AddChild(points_processor);
|
|
|
|
points_processor->AddChild(depth_processor);
|
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
// KANNALA_BRANDT
|
|
|
|
rectify_processor->AddChild(disparity_processor);
|
|
|
|
disparity_processor->AddChild(disparitynormalized_processor);
|
2019-01-09 04:53:05 +02:00
|
|
|
disparity_processor->AddChild(depth_processor);
|
|
|
|
depth_processor->AddChild(points_processor);
|
2019-01-08 10:18:34 +02:00
|
|
|
} else {
|
|
|
|
// UNKNOW
|
2019-01-09 04:53:05 +02:00
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_;
|
2019-01-08 10:18:34 +02:00
|
|
|
}
|
2018-04-27 10:47:54 +03:00
|
|
|
|
|
|
|
processor_ = rectify_processor;
|
|
|
|
}
|
|
|
|
|
2018-04-28 07:40:29 +03:00
|
|
|
void Synthetic::ProcessNativeStream(
|
|
|
|
const Stream &stream, const api::StreamData &data) {
|
2018-06-12 17:05:47 +03:00
|
|
|
if (stream == Stream::LEFT || stream == Stream::RIGHT) {
|
|
|
|
static api::StreamData left_data, right_data;
|
|
|
|
if (stream == Stream::LEFT) {
|
|
|
|
left_data = data;
|
|
|
|
} else if (stream == Stream::RIGHT) {
|
|
|
|
right_data = data;
|
|
|
|
}
|
|
|
|
if (left_data.img && right_data.img &&
|
|
|
|
left_data.img->frame_id == right_data.img->frame_id) {
|
2019-01-09 07:07:05 +02:00
|
|
|
std::shared_ptr<Processor> processor = nullptr;
|
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
processor = find_processor<RectifyProcessorOCV>(processor_);
|
|
|
|
#ifdef WITH_CAM_MODELS
|
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
processor = find_processor<RectifyProcessor>(processor_);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_ << ", use default pinhole model";
|
|
|
|
processor = find_processor<RectifyProcessorOCV>(processor_);
|
|
|
|
}
|
2018-11-05 11:50:15 +02:00
|
|
|
processor->Process(ObjMat2{
|
|
|
|
left_data.frame, left_data.frame_id, left_data.img,
|
|
|
|
right_data.frame, right_data.frame_id, right_data.img});
|
2018-06-12 17:05:47 +03:00
|
|
|
}
|
2018-04-28 07:40:29 +03:00
|
|
|
return;
|
2018-06-12 17:05:47 +03:00
|
|
|
}
|
2018-04-28 07:40:29 +03:00
|
|
|
|
2018-06-12 17:05:47 +03:00
|
|
|
if (stream == Stream::LEFT_RECTIFIED || stream == Stream::RIGHT_RECTIFIED) {
|
|
|
|
static api::StreamData left_rect_data, right_rect_data;
|
|
|
|
if (stream == Stream::LEFT_RECTIFIED) {
|
|
|
|
left_rect_data = data;
|
|
|
|
} else if (stream == Stream::RIGHT_RECTIFIED) {
|
|
|
|
right_rect_data = data;
|
|
|
|
}
|
|
|
|
if (left_rect_data.img && right_rect_data.img &&
|
|
|
|
left_rect_data.img->frame_id == right_rect_data.img->frame_id) {
|
2019-01-09 07:07:05 +02:00
|
|
|
std::string name = RectifyProcessorOCV::NAME;
|
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
name = RectifyProcessorOCV::NAME;
|
|
|
|
#ifdef WITH_CAM_MODELS
|
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
name = RectifyProcessor::NAME;
|
|
|
|
#endif
|
|
|
|
}
|
2018-06-12 17:05:47 +03:00
|
|
|
process_childs(
|
2019-01-09 07:07:05 +02:00
|
|
|
processor_, name, ObjMat2{
|
2018-11-05 11:50:15 +02:00
|
|
|
left_rect_data.frame, left_rect_data.frame_id, left_rect_data.img,
|
|
|
|
right_rect_data.frame, right_rect_data.frame_id,
|
|
|
|
right_rect_data.img});
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
return;
|
2018-06-12 17:05:47 +03:00
|
|
|
}
|
2018-04-28 07:40:29 +03:00
|
|
|
|
|
|
|
switch (stream) {
|
|
|
|
case Stream::DISPARITY: {
|
2018-10-26 10:39:34 +03:00
|
|
|
process_childs(processor_, DisparityProcessor::NAME,
|
2018-11-05 11:50:15 +02:00
|
|
|
ObjMat{data.frame, data.frame_id, data.img});
|
2018-04-28 07:40:29 +03:00
|
|
|
} break;
|
|
|
|
case Stream::DISPARITY_NORMALIZED: {
|
2018-10-26 10:39:34 +03:00
|
|
|
process_childs(processor_, DisparityNormalizedProcessor::NAME,
|
2018-11-05 11:50:15 +02:00
|
|
|
ObjMat{data.frame, data.frame_id, data.img});
|
2018-04-28 07:40:29 +03:00
|
|
|
} break;
|
|
|
|
case Stream::POINTS: {
|
2019-01-09 04:53:05 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
// PINHOLE
|
|
|
|
process_childs(processor_, PointsProcessorOCV::NAME,
|
|
|
|
ObjMat{data.frame, data.frame_id, data.img});
|
2019-01-09 07:07:05 +02:00
|
|
|
#ifdef WITH_CAM_MODELS
|
2019-01-09 04:53:05 +02:00
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
// KANNALA_BRANDT
|
|
|
|
process_childs(processor_, PointsProcessor::NAME,
|
|
|
|
ObjMat{data.frame, data.frame_id, data.img});
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
2019-01-09 04:53:05 +02:00
|
|
|
} else {
|
|
|
|
// UNKNOW
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_;
|
|
|
|
}
|
2018-04-28 07:40:29 +03:00
|
|
|
} break;
|
|
|
|
case Stream::DEPTH: {
|
2019-01-09 04:53:05 +02:00
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
// PINHOLE
|
|
|
|
process_childs(processor_, DepthProcessorOCV::NAME,
|
|
|
|
ObjMat{data.frame, data.frame_id, data.img});
|
2019-01-09 07:07:05 +02:00
|
|
|
#ifdef WITH_CAM_MODELS
|
2019-01-09 04:53:05 +02:00
|
|
|
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
// KANNALA_BRANDT
|
|
|
|
process_childs(processor_, DepthProcessor::NAME,
|
|
|
|
ObjMat{data.frame, data.frame_id, data.img});
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
2019-01-09 04:53:05 +02:00
|
|
|
} else {
|
|
|
|
// UNKNOW
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_;
|
|
|
|
}
|
2018-04-28 07:40:29 +03:00
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
2018-04-27 17:35:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 10:47:54 +03:00
|
|
|
bool Synthetic::OnRectifyProcess(
|
|
|
|
Object *const in, Object *const out, Processor *const parent) {
|
2018-09-11 05:19:25 +03:00
|
|
|
MYNTEYE_UNUSED(parent)
|
2018-05-08 06:12:45 +03:00
|
|
|
if (plugin_ && plugin_->OnRectifyProcess(in, out)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-28 07:40:29 +03:00
|
|
|
return GetStreamEnabledMode(Stream::LEFT_RECTIFIED) != MODE_SYNTHETIC;
|
|
|
|
// && GetStreamEnabledMode(Stream::RIGHT_RECTIFIED) != MODE_SYNTHETIC
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::OnDisparityProcess(
|
|
|
|
Object *const in, Object *const out, Processor *const parent) {
|
2018-09-11 05:19:25 +03:00
|
|
|
MYNTEYE_UNUSED(parent)
|
2018-05-08 06:12:45 +03:00
|
|
|
if (plugin_ && plugin_->OnDisparityProcess(in, out)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-28 07:40:29 +03:00
|
|
|
return GetStreamEnabledMode(Stream::DISPARITY) != MODE_SYNTHETIC;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::OnDisparityNormalizedProcess(
|
|
|
|
Object *const in, Object *const out, Processor *const parent) {
|
2018-09-11 05:19:25 +03:00
|
|
|
MYNTEYE_UNUSED(parent)
|
2018-05-08 06:12:45 +03:00
|
|
|
if (plugin_ && plugin_->OnDisparityNormalizedProcess(in, out)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-28 07:40:29 +03:00
|
|
|
return GetStreamEnabledMode(Stream::DISPARITY_NORMALIZED) != MODE_SYNTHETIC;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::OnPointsProcess(
|
|
|
|
Object *const in, Object *const out, Processor *const parent) {
|
2018-09-11 05:19:25 +03:00
|
|
|
MYNTEYE_UNUSED(parent)
|
2018-05-08 06:12:45 +03:00
|
|
|
if (plugin_ && plugin_->OnPointsProcess(in, out)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-28 07:40:29 +03:00
|
|
|
return GetStreamEnabledMode(Stream::POINTS) != MODE_SYNTHETIC;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::OnDepthProcess(
|
|
|
|
Object *const in, Object *const out, Processor *const parent) {
|
2018-09-11 05:19:25 +03:00
|
|
|
MYNTEYE_UNUSED(parent)
|
2018-05-08 06:12:45 +03:00
|
|
|
if (plugin_ && plugin_->OnDepthProcess(in, out)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-28 07:40:29 +03:00
|
|
|
return GetStreamEnabledMode(Stream::DEPTH) != MODE_SYNTHETIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::OnRectifyPostProcess(Object *const out) {
|
|
|
|
const ObjMat2 *output = Object::Cast<ObjMat2>(out);
|
|
|
|
if (HasStreamCallback(Stream::LEFT_RECTIFIED)) {
|
2018-06-07 12:39:51 +03:00
|
|
|
stream_callbacks_.at(Stream::LEFT_RECTIFIED)(
|
2018-11-05 11:50:15 +02:00
|
|
|
{output->first_data, output->first, nullptr, output->first_id});
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
if (HasStreamCallback(Stream::RIGHT_RECTIFIED)) {
|
2018-06-07 12:39:51 +03:00
|
|
|
stream_callbacks_.at(Stream::RIGHT_RECTIFIED)(
|
2018-11-05 11:50:15 +02:00
|
|
|
{output->second_data, output->second, nullptr, output->second_id});
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::OnDisparityPostProcess(Object *const out) {
|
|
|
|
const ObjMat *output = Object::Cast<ObjMat>(out);
|
|
|
|
if (HasStreamCallback(Stream::DISPARITY)) {
|
2018-10-26 10:39:34 +03:00
|
|
|
stream_callbacks_.at(Stream::DISPARITY)(
|
2018-11-05 11:50:15 +02:00
|
|
|
{output->data, output->value, nullptr, output->id});
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::OnDisparityNormalizedPostProcess(Object *const out) {
|
|
|
|
const ObjMat *output = Object::Cast<ObjMat>(out);
|
|
|
|
if (HasStreamCallback(Stream::DISPARITY_NORMALIZED)) {
|
|
|
|
stream_callbacks_.at(Stream::DISPARITY_NORMALIZED)(
|
2018-11-05 11:50:15 +02:00
|
|
|
{output->data, output->value, nullptr, output->id});
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::OnPointsPostProcess(Object *const out) {
|
|
|
|
const ObjMat *output = Object::Cast<ObjMat>(out);
|
|
|
|
if (HasStreamCallback(Stream::POINTS)) {
|
2018-10-26 10:39:34 +03:00
|
|
|
stream_callbacks_.at(Stream::POINTS)(
|
2018-11-05 11:50:15 +02:00
|
|
|
{output->data, output->value, nullptr, output->id});
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::OnDepthPostProcess(Object *const out) {
|
|
|
|
const ObjMat *output = Object::Cast<ObjMat>(out);
|
|
|
|
if (HasStreamCallback(Stream::DEPTH)) {
|
2018-10-26 10:39:34 +03:00
|
|
|
stream_callbacks_.at(Stream::DEPTH)(
|
2018-11-05 11:50:15 +02:00
|
|
|
{output->data, output->value, nullptr, output->id});
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
2018-04-26 05:33:37 +03:00
|
|
|
MYNTEYE_END_NAMESPACE
|