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-22 05:30:34 +02:00
|
|
|
#include "mynteye/api/processor/root_camera_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"
|
2019-03-01 10:08:15 +02:00
|
|
|
#include "mynteye/api/data_tools.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
|
2019-01-23 11:17:08 +02:00
|
|
|
#define ROOT_PROC_PERIOD 0
|
2018-06-01 05:32:36 +03:00
|
|
|
|
2018-04-26 05:33:37 +03:00
|
|
|
MYNTEYE_BEGIN_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),
|
2019-02-21 16:21:17 +02:00
|
|
|
calib_default_tag_(false),
|
|
|
|
stream_data_listener_(nullptr) {
|
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 10:47:54 +03:00
|
|
|
InitProcessors();
|
2018-04-26 05:33:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Synthetic::~Synthetic() {
|
|
|
|
VLOG(2) << __func__;
|
2019-03-02 04:31:15 +02:00
|
|
|
processors_.clear();
|
2018-04-27 10:47:54 +03:00
|
|
|
if (processor_) {
|
|
|
|
processor_->Deactivate(true);
|
|
|
|
processor_ = nullptr;
|
|
|
|
}
|
2018-04-26 05:33:37 +03:00
|
|
|
}
|
|
|
|
|
2019-02-21 16:21:17 +02:00
|
|
|
void Synthetic::SetStreamDataListener(stream_data_listener_t listener) {
|
|
|
|
stream_data_listener_ = listener;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2019-03-01 10:08:15 +02:00
|
|
|
auto processor = getProcessorWithStream(Stream::LEFT_RECTIFIED);
|
|
|
|
|
|
|
|
if (processor && calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
auto proc = static_cast<RectifyProcessorOCV*>(&(*processor));
|
|
|
|
proc->ReloadImageParams(intr_left_, intr_right_, extr_);
|
2019-01-09 07:07:05 +02:00
|
|
|
#ifdef WITH_CAM_MODELS
|
2019-03-01 10:08:15 +02:00
|
|
|
} else if (processor && calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
|
|
auto proc = static_cast<RectifyProcessor*>(&(*processor));
|
|
|
|
proc->ReloadImageParams(intr_left_, intr_right_, extr_);
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
|
|
|
} else {
|
2019-03-01 10:08:15 +02:00
|
|
|
LOG(ERROR) << "Unknow calib model type in device" << std::endl;
|
2019-01-09 07:07:05 +02:00
|
|
|
}
|
2018-12-20 16:08:29 +02:00
|
|
|
}
|
|
|
|
|
2019-01-22 05:30:34 +02:00
|
|
|
const struct Synthetic::stream_control_t Synthetic::getControlDateWithStream(
|
|
|
|
const Stream& stream) const {
|
|
|
|
for (auto &&it : processors_) {
|
|
|
|
for (auto it_s : it->getTargetStreams()) {
|
|
|
|
if (it_s.stream == stream) {
|
|
|
|
return it_s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG(ERROR) << "ERROR: no suited processor for stream "<< stream;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:46:11 +02:00
|
|
|
std::shared_ptr<Processor> Synthetic::getProcessorWithStream(
|
|
|
|
const Stream& stream) {
|
|
|
|
for (auto &&it : processors_) {
|
|
|
|
for (auto it_s : it->getTargetStreams()) {
|
|
|
|
if (it_s.stream == stream) {
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG(ERROR) << "ERROR: no suited processor for stream "<< stream;
|
|
|
|
}
|
|
|
|
|
2019-01-22 05:30:34 +02:00
|
|
|
void Synthetic::setControlDateCallbackWithStream(
|
|
|
|
const struct stream_control_t& ctr_data) {
|
|
|
|
for (auto &&it : processors_) {
|
|
|
|
int i = 0;
|
|
|
|
for (auto it_s : it->getTargetStreams()) {
|
|
|
|
if (it_s.stream == ctr_data.stream) {
|
|
|
|
it->target_streams_[i].stream_callback = ctr_data.stream_callback;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG(ERROR) << "ERROR: no suited processor for stream "<< ctr_data.stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::checkControlDateWithStream(const Stream& stream) const {
|
|
|
|
for (auto &&it : processors_) {
|
|
|
|
for (auto it_s : it->getTargetStreams()) {
|
|
|
|
if (it_s.stream == stream) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-22 09:46:11 +02:00
|
|
|
return false;
|
2019-01-22 05:30:34 +02:00
|
|
|
}
|
|
|
|
|
2019-02-22 12:20:47 +02:00
|
|
|
bool Synthetic::Supports(const Stream &stream) const {
|
|
|
|
return checkControlDateWithStream(stream);
|
|
|
|
}
|
|
|
|
|
2019-03-14 03:51:42 +02:00
|
|
|
void Synthetic::setDuplicate(bool isEnable) {
|
|
|
|
for (auto it : processors_) {
|
|
|
|
it->setDupEnable(isEnable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:20:47 +02:00
|
|
|
void Synthetic::EnableStreamData(
|
|
|
|
const Stream &stream, stream_switch_callback_t callback,
|
|
|
|
bool try_tag) {
|
2019-01-23 11:17:08 +02:00
|
|
|
// Activate processors of synthetic stream
|
|
|
|
auto processor = getProcessorWithStream(stream);
|
|
|
|
iterate_processor_CtoP_before(processor,
|
2019-02-22 12:20:47 +02:00
|
|
|
[callback, try_tag](std::shared_ptr<Processor> proce){
|
2019-03-02 06:46:17 +02:00
|
|
|
if (proce->Name() == "RootProcessor") {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-23 11:17:08 +02:00
|
|
|
auto streams = proce->getTargetStreams();
|
|
|
|
int act_tag = 0;
|
|
|
|
for (unsigned int i = 0; i < proce->getStreamsSum() ; i++) {
|
2019-03-02 03:58:48 +02:00
|
|
|
if (proce->target_streams_[i].enabled_mode_ == MODE_OFF) {
|
2019-02-22 12:20:47 +02:00
|
|
|
callback(proce->target_streams_[i].stream);
|
|
|
|
if (!try_tag) {
|
|
|
|
act_tag++;
|
2019-03-02 03:58:48 +02:00
|
|
|
proce->target_streams_[i].enabled_mode_ = MODE_ON;
|
2019-02-22 12:20:47 +02:00
|
|
|
}
|
2019-01-23 11:17:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (act_tag > 0 && !proce->IsActivated()) {
|
|
|
|
// std::cout << proce->Name() << " Active now" << std::endl;
|
|
|
|
proce->Activate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-02-22 12:20:47 +02:00
|
|
|
void Synthetic::DisableStreamData(
|
|
|
|
const Stream &stream, stream_switch_callback_t callback,
|
|
|
|
bool try_tag) {
|
2019-01-23 11:17:08 +02:00
|
|
|
auto processor = getProcessorWithStream(stream);
|
|
|
|
iterate_processor_PtoC_before(processor,
|
2019-02-22 12:20:47 +02:00
|
|
|
[callback, try_tag](std::shared_ptr<Processor> proce){
|
2019-03-02 06:46:17 +02:00
|
|
|
if (proce->Name() == "RootProcessor") {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-23 11:17:08 +02:00
|
|
|
auto streams = proce->getTargetStreams();
|
|
|
|
int act_tag = 0;
|
|
|
|
for (unsigned int i = 0; i < proce->getStreamsSum() ; i++) {
|
2019-03-02 03:58:48 +02:00
|
|
|
if (proce->target_streams_[i].enabled_mode_ == MODE_ON) {
|
2019-02-22 12:20:47 +02:00
|
|
|
callback(proce->target_streams_[i].stream);
|
|
|
|
if (!try_tag) {
|
|
|
|
act_tag++;
|
2019-03-02 03:58:48 +02:00
|
|
|
proce->target_streams_[i].enabled_mode_ = MODE_OFF;
|
2019-02-22 12:20:47 +02:00
|
|
|
}
|
2019-01-23 11:17:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (act_tag > 0 && proce->IsActivated()) {
|
|
|
|
// std::cout << proce->Name() << "Deactive now" << std::endl;
|
|
|
|
proce->Deactivate();
|
|
|
|
}
|
|
|
|
});
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
2019-02-22 12:20:47 +02:00
|
|
|
void Synthetic::EnableStreamData(const Stream &stream) {
|
|
|
|
EnableStreamData(stream, [](const Stream &stream){
|
|
|
|
// std::cout << stream << "enabled in callback" << std::endl;
|
|
|
|
MYNTEYE_UNUSED(stream);
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::DisableStreamData(const Stream &stream) {
|
|
|
|
DisableStreamData(stream, [](const Stream &stream){
|
|
|
|
// std::cout << stream << "disabled in callback" << std::endl;
|
|
|
|
MYNTEYE_UNUSED(stream);
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
2018-04-27 10:47:54 +03:00
|
|
|
bool Synthetic::IsStreamDataEnabled(const Stream &stream) const {
|
2019-01-22 09:46:11 +02:00
|
|
|
if (checkControlDateWithStream(stream)) {
|
|
|
|
auto data = getControlDateWithStream(stream);
|
2019-03-02 03:58:48 +02:00
|
|
|
return data.enabled_mode_ == MODE_ON;
|
2019-01-22 09:46:11 +02:00
|
|
|
}
|
|
|
|
return false;
|
2018-04-26 09:44:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::SetStreamCallback(
|
|
|
|
const Stream &stream, stream_callback_t callback) {
|
2019-01-22 10:21:04 +02:00
|
|
|
stream_control_t data;
|
|
|
|
data.stream = stream;
|
2018-04-27 10:47:54 +03:00
|
|
|
if (callback == nullptr) {
|
2019-01-22 10:21:04 +02:00
|
|
|
data.stream_callback = nullptr;
|
2018-04-27 10:47:54 +03:00
|
|
|
} else {
|
2019-01-22 10:21:04 +02:00
|
|
|
data.stream_callback = callback;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
2019-01-22 10:21:04 +02:00
|
|
|
setControlDateCallbackWithStream(data);
|
2018-04-26 09:44:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::HasStreamCallback(const Stream &stream) const {
|
2019-01-22 10:21:04 +02:00
|
|
|
if (checkControlDateWithStream(stream)) {
|
|
|
|
auto data = getControlDateWithStream(stream);
|
|
|
|
if (data.stream_callback != nullptr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2018-04-26 09:44:47 +03:00
|
|
|
}
|
|
|
|
|
2018-04-27 17:35:43 +03:00
|
|
|
void Synthetic::StartVideoStreaming() {
|
2019-03-02 04:08:45 +02:00
|
|
|
processor_->StartVideoStreaming();
|
2018-04-27 17:35:43 +03:00
|
|
|
}
|
2018-04-26 09:44:47 +03:00
|
|
|
|
2018-04-27 17:35:43 +03:00
|
|
|
void Synthetic::StopVideoStreaming() {
|
2019-03-02 04:08:45 +02:00
|
|
|
processor_->StopVideoStreaming();
|
2018-04-27 17:35:43 +03:00
|
|
|
}
|
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) {
|
2019-03-01 10:08:15 +02:00
|
|
|
return getProcessorWithStream(stream)->GetStreamData(stream);
|
2018-04-26 09:44:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<api::StreamData> Synthetic::GetStreamDatas(const Stream &stream) {
|
2019-03-01 10:08:15 +02:00
|
|
|
return getProcessorWithStream(stream)->GetStreamDatas(stream);
|
2018-04-26 09:44:47 +03:00
|
|
|
}
|
|
|
|
|
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 17:35:43 +03:00
|
|
|
Synthetic::mode_t Synthetic::GetStreamEnabledMode(const Stream &stream) const {
|
2019-01-22 09:46:11 +02:00
|
|
|
if (checkControlDateWithStream(stream)) {
|
|
|
|
auto data = getControlDateWithStream(stream);
|
|
|
|
return data.enabled_mode_;
|
2018-04-27 17:35:43 +03:00
|
|
|
}
|
2019-03-02 03:58:48 +02:00
|
|
|
return MODE_OFF;
|
2018-04-27 17:35:43 +03:00
|
|
|
}
|
|
|
|
|
2018-04-27 10:47:54 +03:00
|
|
|
void Synthetic::InitProcessors() {
|
2019-01-09 07:07:05 +02:00
|
|
|
std::shared_ptr<Processor> rectify_processor = nullptr;
|
2019-02-28 10:44:55 +02:00
|
|
|
std::shared_ptr<Processor> points_processor = nullptr;
|
|
|
|
std::shared_ptr<Processor> depth_processor = nullptr;
|
|
|
|
|
2018-06-01 05:32:36 +03:00
|
|
|
auto &&disparity_processor =
|
2019-01-23 11:17:08 +02:00
|
|
|
std::make_shared<DisparityProcessor>(DisparityComputingMethod::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-02-28 10:44:55 +02:00
|
|
|
|
|
|
|
auto root_processor =
|
2019-03-01 10:08:15 +02:00
|
|
|
std::make_shared<s1s2Processor>(api_->device(), ROOT_PROC_PERIOD);
|
2019-02-28 10:44:55 +02:00
|
|
|
|
|
|
|
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
|
|
// PINHOLE
|
|
|
|
auto &&rectify_processor_ocv =
|
|
|
|
std::make_shared<RectifyProcessorOCV>(intr_left_, intr_right_, extr_,
|
|
|
|
RECTIFY_PROC_PERIOD);
|
|
|
|
rectify_processor = rectify_processor_ocv;
|
2019-01-09 07:07:05 +02:00
|
|
|
points_processor = std::make_shared<PointsProcessorOCV>(
|
2019-02-28 10:44:55 +02:00
|
|
|
rectify_processor_ocv->Q, POINTS_PROC_PERIOD);
|
|
|
|
depth_processor = std::make_shared<DepthProcessorOCV>(DEPTH_PROC_PERIOD);
|
|
|
|
|
|
|
|
root_processor->AddChild(rectify_processor);
|
|
|
|
rectify_processor->AddChild(disparity_processor);
|
|
|
|
disparity_processor->AddChild(disparitynormalized_processor);
|
|
|
|
disparity_processor->AddChild(points_processor);
|
|
|
|
points_processor->AddChild(depth_processor);
|
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-02-28 10:44:55 +02:00
|
|
|
// KANNALA_BRANDT
|
|
|
|
auto rectify_processor_imp =
|
|
|
|
std::make_shared<RectifyProcessor>(intr_left_, intr_right_, extr_,
|
|
|
|
RECTIFY_PROC_PERIOD);
|
|
|
|
rectify_processor = rectify_processor_imp;
|
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 11:30:38 +02:00
|
|
|
depth_processor = std::make_shared<DepthProcessor>(
|
|
|
|
rectify_processor_imp -> getCalibInfoPair(),
|
|
|
|
DEPTH_PROC_PERIOD);
|
2019-02-28 10:44:55 +02:00
|
|
|
|
|
|
|
root_processor->AddChild(rectify_processor);
|
|
|
|
rectify_processor->AddChild(disparity_processor);
|
|
|
|
disparity_processor->AddChild(disparitynormalized_processor);
|
|
|
|
disparity_processor->AddChild(depth_processor);
|
|
|
|
depth_processor->AddChild(points_processor);
|
2019-01-09 07:07:05 +02:00
|
|
|
#endif
|
2019-01-09 04:53:05 +02:00
|
|
|
} else {
|
2019-02-28 10:44:55 +02:00
|
|
|
// UNKNOW
|
|
|
|
LOG(ERROR) << "Unknow calib model type in device: "
|
|
|
|
<< calib_model_;
|
|
|
|
return;
|
2019-01-09 04:53:05 +02:00
|
|
|
}
|
2019-01-22 09:46:11 +02:00
|
|
|
|
2019-03-02 10:13:00 +02:00
|
|
|
root_processor->addTargetStreams(
|
|
|
|
{Stream::LEFT, Mode::MODE_OFF, nullptr});
|
|
|
|
root_processor->addTargetStreams(
|
|
|
|
{Stream::RIGHT, Mode::MODE_OFF, nullptr});
|
2019-01-22 10:21:04 +02:00
|
|
|
rectify_processor->addTargetStreams(
|
2019-03-02 03:58:48 +02:00
|
|
|
{Stream::LEFT_RECTIFIED, Mode::MODE_OFF, nullptr});
|
2019-01-22 10:21:04 +02:00
|
|
|
rectify_processor->addTargetStreams(
|
2019-03-02 03:58:48 +02:00
|
|
|
{Stream::RIGHT_RECTIFIED, Mode::MODE_OFF, nullptr});
|
2019-01-22 10:21:04 +02:00
|
|
|
disparity_processor->addTargetStreams(
|
2019-03-02 03:58:48 +02:00
|
|
|
{Stream::DISPARITY, Mode::MODE_OFF, nullptr});
|
2019-01-22 10:21:04 +02:00
|
|
|
disparitynormalized_processor->addTargetStreams(
|
2019-03-02 03:58:48 +02:00
|
|
|
{Stream::DISPARITY_NORMALIZED, Mode::MODE_OFF, nullptr});
|
2019-01-22 10:21:04 +02:00
|
|
|
points_processor->addTargetStreams(
|
2019-03-02 03:58:48 +02:00
|
|
|
{Stream::POINTS, Mode::MODE_OFF, nullptr});
|
2019-01-22 10:21:04 +02:00
|
|
|
depth_processor->addTargetStreams(
|
2019-03-02 03:58:48 +02:00
|
|
|
{Stream::DEPTH, Mode::MODE_OFF, nullptr});
|
2019-01-22 05:30:34 +02:00
|
|
|
|
|
|
|
processors_.push_back(root_processor);
|
|
|
|
processors_.push_back(rectify_processor);
|
|
|
|
processors_.push_back(disparity_processor);
|
|
|
|
processors_.push_back(disparitynormalized_processor);
|
|
|
|
processors_.push_back(points_processor);
|
|
|
|
processors_.push_back(depth_processor);
|
2018-04-27 10:47:54 +03:00
|
|
|
using namespace std::placeholders; // NOLINT
|
2019-03-02 02:35:33 +02:00
|
|
|
root_processor->SetProcessCallback(
|
|
|
|
std::bind(&Synthetic::OnDeviceProcess, this, _1, _2, _3));
|
2018-04-27 10:47:54 +03:00
|
|
|
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));
|
|
|
|
|
2019-03-02 02:35:33 +02:00
|
|
|
root_processor->SetPostProcessCallback(
|
|
|
|
std::bind(&Synthetic::OnDevicePostProcess, this, _1));
|
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-02-28 10:44:55 +02:00
|
|
|
processor_ = root_processor;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
2019-03-01 10:08:15 +02:00
|
|
|
bool Synthetic::OnDeviceProcess(
|
|
|
|
Object *const in, Object *const out,
|
|
|
|
std::shared_ptr<Processor> const parent) {
|
|
|
|
MYNTEYE_UNUSED(parent)
|
2019-03-02 10:13:00 +02:00
|
|
|
return GetStreamEnabledMode(Stream::LEFT) != MODE_ON
|
|
|
|
|| GetStreamEnabledMode(Stream::RIGHT) != MODE_ON;
|
2018-04-27 17:35:43 +03:00
|
|
|
}
|
|
|
|
|
2018-04-27 10:47:54 +03:00
|
|
|
bool Synthetic::OnRectifyProcess(
|
2019-01-22 05:23:54 +02:00
|
|
|
Object *const in, Object *const out,
|
|
|
|
std::shared_ptr<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;
|
|
|
|
}
|
2019-03-02 10:13:00 +02:00
|
|
|
return GetStreamEnabledMode(Stream::LEFT_RECTIFIED) != MODE_ON
|
|
|
|
&& GetStreamEnabledMode(Stream::RIGHT_RECTIFIED) != MODE_ON;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::OnDisparityProcess(
|
2019-01-22 05:23:54 +02:00
|
|
|
Object *const in, Object *const out,
|
|
|
|
std::shared_ptr<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;
|
|
|
|
}
|
2019-03-02 03:58:48 +02:00
|
|
|
return GetStreamEnabledMode(Stream::DISPARITY) != MODE_ON;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::OnDisparityNormalizedProcess(
|
2019-01-22 05:23:54 +02:00
|
|
|
Object *const in, Object *const out,
|
|
|
|
std::shared_ptr<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;
|
|
|
|
}
|
2019-03-02 03:58:48 +02:00
|
|
|
return GetStreamEnabledMode(Stream::DISPARITY_NORMALIZED) != MODE_ON;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::OnPointsProcess(
|
2019-01-22 05:23:54 +02:00
|
|
|
Object *const in, Object *const out,
|
|
|
|
std::shared_ptr<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;
|
|
|
|
}
|
2019-03-02 03:58:48 +02:00
|
|
|
return GetStreamEnabledMode(Stream::POINTS) != MODE_ON;
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Synthetic::OnDepthProcess(
|
2019-01-22 05:23:54 +02:00
|
|
|
Object *const in, Object *const out,
|
|
|
|
std::shared_ptr<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;
|
|
|
|
}
|
2019-03-02 03:58:48 +02:00
|
|
|
return GetStreamEnabledMode(Stream::DEPTH) != MODE_ON;
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
|
2019-03-01 10:08:15 +02:00
|
|
|
void Synthetic::OnDevicePostProcess(Object *const out) {
|
|
|
|
const ObjMat2 *output = Object::Cast<ObjMat2>(out);
|
|
|
|
NotifyStreamData(Stream::LEFT, obj_data_first(output));
|
|
|
|
NotifyStreamData(Stream::RIGHT, obj_data_second(output));
|
|
|
|
if (HasStreamCallback(Stream::LEFT)) {
|
|
|
|
auto data = getControlDateWithStream(Stream::LEFT);
|
|
|
|
data.stream_callback(obj_data_first(output));
|
|
|
|
}
|
|
|
|
if (HasStreamCallback(Stream::RIGHT)) {
|
|
|
|
auto data = getControlDateWithStream(Stream::RIGHT);
|
2019-03-02 03:58:48 +02:00
|
|
|
if (data.stream_callback)
|
|
|
|
data.stream_callback(obj_data_second(output));
|
2019-03-01 10:08:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-28 07:40:29 +03:00
|
|
|
void Synthetic::OnRectifyPostProcess(Object *const out) {
|
|
|
|
const ObjMat2 *output = Object::Cast<ObjMat2>(out);
|
2019-02-21 16:21:17 +02:00
|
|
|
NotifyStreamData(Stream::LEFT_RECTIFIED, obj_data_first(output));
|
|
|
|
NotifyStreamData(Stream::RIGHT_RECTIFIED, obj_data_second(output));
|
2018-04-28 07:40:29 +03:00
|
|
|
if (HasStreamCallback(Stream::LEFT_RECTIFIED)) {
|
2019-01-22 10:21:04 +02:00
|
|
|
auto data = getControlDateWithStream(Stream::LEFT_RECTIFIED);
|
2019-02-21 16:21:17 +02:00
|
|
|
data.stream_callback(obj_data_first(output));
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
if (HasStreamCallback(Stream::RIGHT_RECTIFIED)) {
|
2019-01-22 10:21:04 +02:00
|
|
|
auto data = getControlDateWithStream(Stream::RIGHT_RECTIFIED);
|
2019-02-21 16:21:17 +02:00
|
|
|
data.stream_callback(obj_data_second(output));
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::OnDisparityPostProcess(Object *const out) {
|
|
|
|
const ObjMat *output = Object::Cast<ObjMat>(out);
|
2019-02-21 16:21:17 +02:00
|
|
|
NotifyStreamData(Stream::DISPARITY, obj_data(output));
|
2018-04-28 07:40:29 +03:00
|
|
|
if (HasStreamCallback(Stream::DISPARITY)) {
|
2019-01-22 10:21:04 +02:00
|
|
|
auto data = getControlDateWithStream(Stream::DISPARITY);
|
2019-02-21 16:21:17 +02:00
|
|
|
data.stream_callback(obj_data(output));
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::OnDisparityNormalizedPostProcess(Object *const out) {
|
|
|
|
const ObjMat *output = Object::Cast<ObjMat>(out);
|
2019-02-21 16:21:17 +02:00
|
|
|
NotifyStreamData(Stream::DISPARITY_NORMALIZED, obj_data(output));
|
2018-04-28 07:40:29 +03:00
|
|
|
if (HasStreamCallback(Stream::DISPARITY_NORMALIZED)) {
|
2019-01-22 10:21:04 +02:00
|
|
|
auto data = getControlDateWithStream(Stream::DISPARITY_NORMALIZED);
|
2019-02-21 16:21:17 +02:00
|
|
|
data.stream_callback(obj_data(output));
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::OnPointsPostProcess(Object *const out) {
|
|
|
|
const ObjMat *output = Object::Cast<ObjMat>(out);
|
2019-02-21 16:21:17 +02:00
|
|
|
NotifyStreamData(Stream::POINTS, obj_data(output));
|
2018-04-28 07:40:29 +03:00
|
|
|
if (HasStreamCallback(Stream::POINTS)) {
|
2019-01-22 10:21:04 +02:00
|
|
|
auto data = getControlDateWithStream(Stream::POINTS);
|
2019-02-21 16:21:17 +02:00
|
|
|
data.stream_callback(obj_data(output));
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synthetic::OnDepthPostProcess(Object *const out) {
|
|
|
|
const ObjMat *output = Object::Cast<ObjMat>(out);
|
2019-02-21 16:21:17 +02:00
|
|
|
NotifyStreamData(Stream::DEPTH, obj_data(output));
|
2018-04-28 07:40:29 +03:00
|
|
|
if (HasStreamCallback(Stream::DEPTH)) {
|
2019-01-22 10:21:04 +02:00
|
|
|
auto data = getControlDateWithStream(Stream::DEPTH);
|
2019-02-21 16:21:17 +02:00
|
|
|
data.stream_callback(obj_data(output));
|
2018-04-28 07:40:29 +03:00
|
|
|
}
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
2019-01-23 11:17:08 +02:00
|
|
|
void Synthetic::SetDisparityComputingMethodType(
|
|
|
|
const DisparityComputingMethod &MethodType) {
|
|
|
|
if (checkControlDateWithStream(Stream::LEFT_RECTIFIED)) {
|
|
|
|
auto processor = find_processor<DisparityProcessor>(processor_);
|
|
|
|
if (processor)
|
|
|
|
processor->SetDisparityComputingMethodType(MethodType);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOG(ERROR) << "ERROR: no suited processor for disparity computing.";
|
|
|
|
}
|
|
|
|
|
2019-02-21 16:21:17 +02:00
|
|
|
void Synthetic::NotifyStreamData(
|
|
|
|
const Stream &stream, const api::StreamData &data) {
|
|
|
|
if (stream_data_listener_) {
|
|
|
|
stream_data_listener_(stream, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-26 05:33:37 +03:00
|
|
|
MYNTEYE_END_NAMESPACE
|