refactor(calib models): remove depedence WITH_CAM_MODELS when complie process

This commit is contained in:
TinyOh 2019-01-09 13:07:05 +08:00
parent 9474528972
commit 210d35ffc3
4 changed files with 202 additions and 168 deletions

View File

@ -218,13 +218,19 @@ if(WITH_API)
src/mynteye/api/dl.cc src/mynteye/api/dl.cc
src/mynteye/api/processor.cc src/mynteye/api/processor.cc
src/mynteye/api/synthetic.cc src/mynteye/api/synthetic.cc
src/mynteye/api/processor/rectify_processor.cc
src/mynteye/api/processor/disparity_processor.cc src/mynteye/api/processor/disparity_processor.cc
src/mynteye/api/processor/disparity_normalized_processor.cc src/mynteye/api/processor/disparity_normalized_processor.cc
src/mynteye/api/processor/depth_processor.cc
src/mynteye/api/processor/points_processor.cc
src/mynteye/api/processor/points_processor_ocv.cc src/mynteye/api/processor/points_processor_ocv.cc
src/mynteye/api/processor/depth_processor_ocv.cc src/mynteye/api/processor/depth_processor_ocv.cc
src/mynteye/api/processor/rectify_processor_ocv.cc
)
endif()
if(WITH_CAM_MODELS)
list(APPEND MYNTEYE_SRCS
src/mynteye/api/processor/depth_processor.cc
src/mynteye/api/processor/points_processor.cc
src/mynteye/api/processor/rectify_processor.cc
) )
endif() endif()
if(NOT WITH_GLOG) if(NOT WITH_GLOG)

View File

@ -19,11 +19,6 @@
#include <opencv2/imgproc/imgproc.hpp> #include <opencv2/imgproc/imgproc.hpp>
#include "mynteye/logger.h" #include "mynteye/logger.h"
#include "mynteye/device/device.h" #include "mynteye/device/device.h"
// #define WITH_CAM_MODELS
#ifdef WITH_CAM_MODELS
#include <camodocal/camera_models/Camera.h> #include <camodocal/camera_models/Camera.h>
#include <camodocal/camera_models/CameraFactory.h> #include <camodocal/camera_models/CameraFactory.h>
#include <camodocal/camera_models/CataCamera.h> #include <camodocal/camera_models/CataCamera.h>
@ -344,130 +339,6 @@ struct camera_mat_info_pair stereoRectify(
return res; return res;
} }
#endif
MYNTEYE_BEGIN_NAMESPACE
const char RectifyProcessor::NAME[] = "RectifyProcessor";
RectifyProcessor::RectifyProcessor(
std::shared_ptr<Device> device, std::int32_t proc_period)
: Processor(std::move(proc_period)), device_(device) {
VLOG(2) << __func__ << ": proc_period=" << proc_period;
calib_model = CalibrationModel::UNKNOW;
NotifyImageParamsChanged();
}
RectifyProcessor::~RectifyProcessor() {
VLOG(2) << __func__;
}
std::string RectifyProcessor::Name() {
return NAME;
}
void RectifyProcessor::NotifyImageParamsChanged() {
auto in_left = device_->GetIntrinsics(Stream::LEFT);
auto in_right = device_->GetIntrinsics(Stream::RIGHT);
if (in_left->calib_model() == CalibrationModel::PINHOLE) {
InitParams(
*std::dynamic_pointer_cast<IntrinsicsPinhole>(in_left),
*std::dynamic_pointer_cast<IntrinsicsPinhole>(in_right),
device_->GetExtrinsics(Stream::RIGHT, Stream::LEFT));
} else if (in_left->calib_model() ==
CalibrationModel::KANNALA_BRANDT) {
#ifdef WITH_CAM_MODELS
InitParams(
*std::dynamic_pointer_cast<IntrinsicsEquidistant>(in_left),
*std::dynamic_pointer_cast<IntrinsicsEquidistant>(in_right),
device_->GetExtrinsics(Stream::RIGHT, Stream::LEFT));
#else
VLOG(2) << "calib model type KANNALA_BRANDT"
<< " is not been enabled.";
#endif
} else {
VLOG(2) << "calib model type "
<< in_left->calib_model()
<<" is not been enabled.";
}
}
Object *RectifyProcessor::OnCreateOutput() {
return new ObjMat2();
}
bool RectifyProcessor::OnProcess(
Object *const in, Object *const out, Processor *const parent) {
MYNTEYE_UNUSED(parent)
if (calib_model == CalibrationModel::PINHOLE) {
const ObjMat2 *input = Object::Cast<ObjMat2>(in);
ObjMat2 *output = Object::Cast<ObjMat2>(out);
cv::remap(input->first, output->first, map11, map12, cv::INTER_LINEAR);
cv::remap(input->second, output->second, map21, map22, cv::INTER_LINEAR);
output->first_id = input->first_id;
output->first_data = input->first_data;
output->second_id = input->second_id;
output->second_data = input->second_data;
return true;
} else if (calib_model == CalibrationModel::KANNALA_BRANDT) {
#ifdef WITH_CAM_MODELS
const ObjMat2 *input = Object::Cast<ObjMat2>(in);
ObjMat2 *output = Object::Cast<ObjMat2>(out);
cv::remap(input->first, output->first, map11, map12, cv::INTER_LINEAR);
cv::remap(input->second, output->second, map21, map22, cv::INTER_LINEAR);
output->first_id = input->first_id;
output->first_data = input->first_data;
output->second_id = input->second_id;
output->second_data = input->second_data;
return true;
#else
return false;
#endif
}
}
void RectifyProcessor::InitParams(
IntrinsicsPinhole in_left,
IntrinsicsPinhole in_right,
Extrinsics ex_right_to_left) {
calib_model = CalibrationModel::PINHOLE;
cv::Size size{in_left.width, in_left.height};
cv::Mat M1 =
(cv::Mat_<double>(3, 3) << in_left.fx, 0, in_left.cx, 0, in_left.fy,
in_left.cy, 0, 0, 1);
cv::Mat M2 =
(cv::Mat_<double>(3, 3) << in_right.fx, 0, in_right.cx, 0, in_right.fy,
in_right.cy, 0, 0, 1);
cv::Mat D1(1, 5, CV_64F, in_left.coeffs);
cv::Mat D2(1, 5, CV_64F, in_right.coeffs);
cv::Mat R =
(cv::Mat_<double>(3, 3) << ex_right_to_left.rotation[0][0],
ex_right_to_left.rotation[0][1], ex_right_to_left.rotation[0][2],
ex_right_to_left.rotation[1][0], ex_right_to_left.rotation[1][1],
ex_right_to_left.rotation[1][2], ex_right_to_left.rotation[2][0],
ex_right_to_left.rotation[2][1], ex_right_to_left.rotation[2][2]);
cv::Mat T(3, 1, CV_64F, ex_right_to_left.translation);
VLOG(2) << "InitParams size: " << size;
VLOG(2) << "M1: " << M1;
VLOG(2) << "M2: " << M2;
VLOG(2) << "D1: " << D1;
VLOG(2) << "D2: " << D2;
VLOG(2) << "R: " << R;
VLOG(2) << "T: " << T;
cv::Rect left_roi, right_roi;
cv::stereoRectify(
M1, D1, M2, D2, size, R, T, R1, R2, P1, P2, Q, cv::CALIB_ZERO_DISPARITY,
0, size, &left_roi, &right_roi);
cv::initUndistortRectifyMap(M1, D1, R1, P1, size, CV_16SC2, map11, map12);
cv::initUndistortRectifyMap(M2, D2, R2, P2, size, CV_16SC2, map21, map22);
}
#ifdef WITH_CAM_MODELS
camodocal::CameraPtr generateCameraFromIntrinsicsEquidistant( camodocal::CameraPtr generateCameraFromIntrinsicsEquidistant(
const mynteye::IntrinsicsEquidistant & in) { const mynteye::IntrinsicsEquidistant & in) {
camodocal::EquidistantCameraPtr camera( camodocal::EquidistantCameraPtr camera(
@ -485,6 +356,8 @@ camodocal::CameraPtr generateCameraFromIntrinsicsEquidistant(
return camera; return camera;
} }
MYNTEYE_BEGIN_NAMESPACE
void RectifyProcessor::InitParams( void RectifyProcessor::InitParams(
IntrinsicsEquidistant in_left, IntrinsicsEquidistant in_left,
IntrinsicsEquidistant in_right, IntrinsicsEquidistant in_right,
@ -526,6 +399,50 @@ void RectifyProcessor::InitParams(
cv::Size(0, 0), right_center[0], cv::Size(0, 0), right_center[0],
right_center[1], rect_R_r); right_center[1], rect_R_r);
} }
#endif
const char RectifyProcessor::NAME[] = "RectifyProcessor";
RectifyProcessor::RectifyProcessor(
std::shared_ptr<Device> device, std::int32_t proc_period)
: Processor(std::move(proc_period)), device_(device) {
VLOG(2) << __func__ << ": proc_period=" << proc_period;
calib_model = CalibrationModel::UNKNOW;
NotifyImageParamsChanged();
}
RectifyProcessor::~RectifyProcessor() {
VLOG(2) << __func__;
}
std::string RectifyProcessor::Name() {
return NAME;
}
void RectifyProcessor::NotifyImageParamsChanged() {
auto in_left = device_->GetIntrinsics(Stream::LEFT);
auto in_right = device_->GetIntrinsics(Stream::RIGHT);
InitParams(
*std::dynamic_pointer_cast<IntrinsicsEquidistant>(in_left),
*std::dynamic_pointer_cast<IntrinsicsEquidistant>(in_right),
device_->GetExtrinsics(Stream::RIGHT, Stream::LEFT));
}
Object *RectifyProcessor::OnCreateOutput() {
return new ObjMat2();
}
bool RectifyProcessor::OnProcess(
Object *const in, Object *const out, Processor *const parent) {
MYNTEYE_UNUSED(parent)
const ObjMat2 *input = Object::Cast<ObjMat2>(in);
ObjMat2 *output = Object::Cast<ObjMat2>(out);
cv::remap(input->first, output->first, map11, map12, cv::INTER_LINEAR);
cv::remap(input->second, output->second, map21, map22, cv::INTER_LINEAR);
output->first_id = input->first_id;
output->first_data = input->first_data;
output->second_id = input->second_id;
output->second_data = input->second_data;
return true;
}
MYNTEYE_END_NAMESPACE MYNTEYE_END_NAMESPACE

View File

@ -48,8 +48,6 @@ class RectifyProcessor : public Processor {
Object *const in, Object *const out, Processor *const parent) override; Object *const in, Object *const out, Processor *const parent) override;
private: private:
void InitParams(IntrinsicsPinhole in_left,
IntrinsicsPinhole in_right, Extrinsics ex_right_to_left);
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);

View File

@ -23,13 +23,16 @@
#include "mynteye/api/object.h" #include "mynteye/api/object.h"
#include "mynteye/api/plugin.h" #include "mynteye/api/plugin.h"
#include "mynteye/api/processor.h" #include "mynteye/api/processor.h"
#include "mynteye/api/processor/depth_processor.h"
#include "mynteye/api/processor/disparity_normalized_processor.h" #include "mynteye/api/processor/disparity_normalized_processor.h"
#include "mynteye/api/processor/disparity_processor.h" #include "mynteye/api/processor/disparity_processor.h"
#include "mynteye/api/processor/points_processor.h" #include "mynteye/api/processor/rectify_processor_ocv.h"
#include "mynteye/api/processor/rectify_processor.h"
#include "mynteye/api/processor/depth_processor_ocv.h" #include "mynteye/api/processor/depth_processor_ocv.h"
#include "mynteye/api/processor/points_processor_ocv.h" #include "mynteye/api/processor/points_processor_ocv.h"
#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
#include "mynteye/device/device.h" #include "mynteye/device/device.h"
#define RECTIFY_PROC_PERIOD 0 #define RECTIFY_PROC_PERIOD 0
@ -87,8 +90,20 @@ Synthetic::~Synthetic() {
} }
void Synthetic::NotifyImageParamsChanged() { void Synthetic::NotifyImageParamsChanged() {
if (calib_model_ == CalibrationModel::PINHOLE) {
auto &&processor = find_processor<RectifyProcessorOCV>(processor_);
if (processor) processor->NotifyImageParamsChanged();
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
auto &&processor = find_processor<RectifyProcessor>(processor_); auto &&processor = find_processor<RectifyProcessor>(processor_);
if (processor) processor->NotifyImageParamsChanged(); if (processor) processor->NotifyImageParamsChanged();
#endif
} else {
LOG(ERROR) << "Unknow calib model type in device: "
<< calib_model_ << ", use default pinhole model";
auto &&processor = find_processor<RectifyProcessorOCV>(processor_);
if (processor) processor->NotifyImageParamsChanged();
}
} }
bool Synthetic::Supports(const Stream &stream) const { bool Synthetic::Supports(const Stream &stream) const {
@ -173,7 +188,18 @@ api::StreamData Synthetic::GetStreamData(const Stream &stream) {
} else if (mode == MODE_SYNTHETIC) { } else if (mode == MODE_SYNTHETIC) {
if (stream == Stream::LEFT_RECTIFIED || stream == Stream::RIGHT_RECTIFIED) { if (stream == Stream::LEFT_RECTIFIED || stream == Stream::RIGHT_RECTIFIED) {
static std::shared_ptr<ObjMat2> output = nullptr; static std::shared_ptr<ObjMat2> output = nullptr;
auto &&processor = find_processor<RectifyProcessor>(processor_); 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_);
}
auto &&out = processor->GetOutput(); auto &&out = processor->GetOutput();
if (out != nullptr) { if (out != nullptr) {
// Obtain the output, out will be nullptr if get again immediately. // Obtain the output, out will be nullptr if get again immediately.
@ -219,6 +245,7 @@ api::StreamData Synthetic::GetStreamData(const Stream &stream) {
return {output->data, output->value, nullptr, output->id}; return {output->data, output->value, nullptr, output->id};
} }
VLOG(2) << "Points not ready now"; VLOG(2) << "Points not ready now";
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
auto &&processor = find_processor<PointsProcessor>(processor_); auto &&processor = find_processor<PointsProcessor>(processor_);
auto &&out = processor->GetOutput(); auto &&out = processor->GetOutput();
@ -227,6 +254,7 @@ api::StreamData Synthetic::GetStreamData(const Stream &stream) {
return {output->data, output->value, nullptr, output->id}; return {output->data, output->value, nullptr, output->id};
} }
VLOG(2) << "Points not ready now"; VLOG(2) << "Points not ready now";
#endif
} else { } else {
// UNKNOW // UNKNOW
LOG(ERROR) << "Unknow calib model type in device: " LOG(ERROR) << "Unknow calib model type in device: "
@ -242,6 +270,7 @@ api::StreamData Synthetic::GetStreamData(const Stream &stream) {
return {output->data, output->value, nullptr, output->id}; return {output->data, output->value, nullptr, output->id};
} }
VLOG(2) << "Depth not ready now"; VLOG(2) << "Depth not ready now";
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
auto &&processor = find_processor<DepthProcessor>(processor_); auto &&processor = find_processor<DepthProcessor>(processor_);
auto &&out = processor->GetOutput(); auto &&out = processor->GetOutput();
@ -250,6 +279,7 @@ api::StreamData Synthetic::GetStreamData(const Stream &stream) {
return {output->data, output->value, nullptr, output->id}; return {output->data, output->value, nullptr, output->id};
} }
VLOG(2) << "Depth not ready now"; VLOG(2) << "Depth not ready now";
#endif
} else { } else {
// UNKNOW // UNKNOW
LOG(ERROR) << "Unknow calib model type in device: " LOG(ERROR) << "Unknow calib model type in device: "
@ -346,13 +376,33 @@ void Synthetic::EnableStreamData(const Stream &stream, std::uint32_t depth) {
if (!IsStreamDataEnabled(Stream::LEFT)) if (!IsStreamDataEnabled(Stream::LEFT))
break; break;
stream_enabled_mode_[stream] = MODE_SYNTHETIC; stream_enabled_mode_[stream] = MODE_SYNTHETIC;
if (calib_model_ == CalibrationModel::PINHOLE) {
CHECK(ActivateProcessor<RectifyProcessorOCV>());
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
CHECK(ActivateProcessor<RectifyProcessor>()); CHECK(ActivateProcessor<RectifyProcessor>());
#endif
} else {
LOG(ERROR) << "Unknow calib model type in device: "
<< calib_model_ << ", use default pinhole model";
CHECK(ActivateProcessor<RectifyProcessorOCV>());
}
} return; } return;
case Stream::RIGHT_RECTIFIED: { case Stream::RIGHT_RECTIFIED: {
if (!IsStreamDataEnabled(Stream::RIGHT)) if (!IsStreamDataEnabled(Stream::RIGHT))
break; break;
stream_enabled_mode_[stream] = MODE_SYNTHETIC; stream_enabled_mode_[stream] = MODE_SYNTHETIC;
if (calib_model_ == CalibrationModel::PINHOLE) {
CHECK(ActivateProcessor<RectifyProcessorOCV>());
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
CHECK(ActivateProcessor<RectifyProcessor>()); CHECK(ActivateProcessor<RectifyProcessor>());
#endif
} else {
LOG(ERROR) << "Unknow calib model type in device: "
<< calib_model_ << ", use default pinhole model";
CHECK(ActivateProcessor<RectifyProcessorOCV>());
}
} return; } return;
case Stream::DISPARITY: { case Stream::DISPARITY: {
stream_enabled_mode_[stream] = MODE_SYNTHETIC; stream_enabled_mode_[stream] = MODE_SYNTHETIC;
@ -370,8 +420,10 @@ void Synthetic::EnableStreamData(const Stream &stream, std::uint32_t depth) {
EnableStreamData(Stream::DISPARITY, depth + 1); EnableStreamData(Stream::DISPARITY, depth + 1);
if (calib_model_ == CalibrationModel::PINHOLE) { if (calib_model_ == CalibrationModel::PINHOLE) {
CHECK(ActivateProcessor<PointsProcessorOCV>()); CHECK(ActivateProcessor<PointsProcessorOCV>());
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
CHECK(ActivateProcessor<PointsProcessor>()); CHECK(ActivateProcessor<PointsProcessor>());
#endif
} else { } else {
LOG(ERROR) << "Unknow calib model type in device: " LOG(ERROR) << "Unknow calib model type in device: "
<< calib_model_; << calib_model_;
@ -382,8 +434,10 @@ void Synthetic::EnableStreamData(const Stream &stream, std::uint32_t depth) {
EnableStreamData(Stream::POINTS, depth + 1); EnableStreamData(Stream::POINTS, depth + 1);
if (calib_model_ == CalibrationModel::PINHOLE) { if (calib_model_ == CalibrationModel::PINHOLE) {
CHECK(ActivateProcessor<DepthProcessorOCV>()); CHECK(ActivateProcessor<DepthProcessorOCV>());
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
CHECK(ActivateProcessor<DepthProcessor>()); CHECK(ActivateProcessor<DepthProcessor>());
#endif
} else { } else {
LOG(ERROR) << "Unknow calib model type in device: " LOG(ERROR) << "Unknow calib model type in device: "
<< calib_model_; << calib_model_;
@ -410,7 +464,17 @@ void Synthetic::DisableStreamData(const Stream &stream, std::uint32_t depth) {
if (IsStreamEnabledSynthetic(Stream::DISPARITY)) { if (IsStreamEnabledSynthetic(Stream::DISPARITY)) {
DisableStreamData(Stream::DISPARITY, depth + 1); DisableStreamData(Stream::DISPARITY, depth + 1);
} }
if (calib_model_ == CalibrationModel::PINHOLE) {
DeactivateProcessor<RectifyProcessorOCV>();
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
DeactivateProcessor<RectifyProcessor>(); DeactivateProcessor<RectifyProcessor>();
#endif
} else {
LOG(ERROR) << "Unknow calib model type in device: "
<< calib_model_ << ", use default pinhole model";
DeactivateProcessor<RectifyProcessorOCV>();
}
} break; } break;
case Stream::RIGHT_RECTIFIED: { case Stream::RIGHT_RECTIFIED: {
if (IsStreamEnabledSynthetic(Stream::LEFT_RECTIFIED)) { if (IsStreamEnabledSynthetic(Stream::LEFT_RECTIFIED)) {
@ -419,7 +483,17 @@ void Synthetic::DisableStreamData(const Stream &stream, std::uint32_t depth) {
if (IsStreamEnabledSynthetic(Stream::DISPARITY)) { if (IsStreamEnabledSynthetic(Stream::DISPARITY)) {
DisableStreamData(Stream::DISPARITY, depth + 1); DisableStreamData(Stream::DISPARITY, depth + 1);
} }
if (calib_model_ == CalibrationModel::PINHOLE) {
DeactivateProcessor<RectifyProcessorOCV>();
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
DeactivateProcessor<RectifyProcessor>(); DeactivateProcessor<RectifyProcessor>();
#endif
} else {
LOG(ERROR) << "Unknow calib model type in device: "
<< calib_model_ << ", use default pinhole model";
DeactivateProcessor<RectifyProcessorOCV>();
}
} break; } break;
case Stream::DISPARITY: { case Stream::DISPARITY: {
if (IsStreamEnabledSynthetic(Stream::DISPARITY_NORMALIZED)) { if (IsStreamEnabledSynthetic(Stream::DISPARITY_NORMALIZED)) {
@ -439,8 +513,10 @@ void Synthetic::DisableStreamData(const Stream &stream, std::uint32_t depth) {
DisableStreamData(Stream::DEPTH, depth + 1); DisableStreamData(Stream::DEPTH, depth + 1);
} }
DeactivateProcessor<PointsProcessorOCV>(); DeactivateProcessor<PointsProcessorOCV>();
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
DeactivateProcessor<PointsProcessor>(); DeactivateProcessor<PointsProcessor>();
#endif
} else { } else {
LOG(ERROR) << "Unknow calib model type in device: " LOG(ERROR) << "Unknow calib model type in device: "
<< calib_model_; << calib_model_;
@ -449,11 +525,13 @@ void Synthetic::DisableStreamData(const Stream &stream, std::uint32_t depth) {
case Stream::DEPTH: { case Stream::DEPTH: {
if (calib_model_ == CalibrationModel::PINHOLE) { if (calib_model_ == CalibrationModel::PINHOLE) {
DeactivateProcessor<DepthProcessorOCV>(); DeactivateProcessor<DepthProcessorOCV>();
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
if (IsStreamEnabledSynthetic(Stream::DEPTH)) { if (IsStreamEnabledSynthetic(Stream::DEPTH)) {
DisableStreamData(Stream::POINTS, depth + 1); DisableStreamData(Stream::POINTS, depth + 1);
} }
DeactivateProcessor<DepthProcessor>(); DeactivateProcessor<DepthProcessor>();
#endif
} else { } else {
LOG(ERROR) << "Unknow calib model type in device: " LOG(ERROR) << "Unknow calib model type in device: "
<< calib_model_; << calib_model_;
@ -470,8 +548,27 @@ void Synthetic::DisableStreamData(const Stream &stream, std::uint32_t depth) {
} }
void Synthetic::InitProcessors() { void Synthetic::InitProcessors() {
auto &&rectify_processor = std::shared_ptr<Processor> rectify_processor = nullptr;
cv::Mat Q;
if (calib_model_ == CalibrationModel::PINHOLE) {
auto &&rectify_processor_ocv =
std::make_shared<RectifyProcessorOCV>(api_->device(),
RECTIFY_PROC_PERIOD);
rectify_processor = rectify_processor_ocv;
Q = rectify_processor_ocv->Q;
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
rectify_processor =
std::make_shared<RectifyProcessor>(api_->device(), RECTIFY_PROC_PERIOD); std::make_shared<RectifyProcessor>(api_->device(), RECTIFY_PROC_PERIOD);
#endif
} else {
LOG(ERROR) << "Unknow calib model type in device: "
<< calib_model_ << ", use default pinhole model";
auto &&rectify_processor_ocv =
std::make_shared<RectifyProcessorOCV>(api_->device(),
RECTIFY_PROC_PERIOD);
rectify_processor = rectify_processor_ocv;
}
auto &&disparity_processor = auto &&disparity_processor =
std::make_shared<DisparityProcessor>(DISPARITY_PROC_PERIOD); std::make_shared<DisparityProcessor>(DISPARITY_PROC_PERIOD);
auto &&disparitynormalized_processor = auto &&disparitynormalized_processor =
@ -479,33 +576,26 @@ void Synthetic::InitProcessors() {
DISPARITY_NORM_PROC_PERIOD); DISPARITY_NORM_PROC_PERIOD);
std::shared_ptr<Processor> points_processor = nullptr; std::shared_ptr<Processor> points_processor = nullptr;
if (calib_model_ == CalibrationModel::PINHOLE) { if (calib_model_ == CalibrationModel::PINHOLE) {
auto &&points_processor_pin = std::make_shared<PointsProcessorOCV>( points_processor = std::make_shared<PointsProcessorOCV>(
rectify_processor->Q, POINTS_PROC_PERIOD); Q, POINTS_PROC_PERIOD);
points_processor = points_processor_pin; #ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
auto &&points_processor_kan = std::make_shared<PointsProcessor>( points_processor = std::make_shared<PointsProcessor>(
POINTS_PROC_PERIOD); POINTS_PROC_PERIOD);
points_processor = points_processor_kan; #endif
} else { } else {
LOG(ERROR) << "Unknow calib model type in device: " points_processor = std::make_shared<PointsProcessorOCV>(
<< calib_model_ << ", use default pinhole model"; Q, POINTS_PROC_PERIOD);
auto &&points_processor_pin = std::make_shared<PointsProcessorOCV>(
rectify_processor->Q, POINTS_PROC_PERIOD);
points_processor = points_processor_pin;
} }
std::shared_ptr<Processor> depth_processor = nullptr; std::shared_ptr<Processor> depth_processor = nullptr;
if (calib_model_ == CalibrationModel::PINHOLE) { if (calib_model_ == CalibrationModel::PINHOLE) {
auto &&depth_processor_pin = depth_processor = std::make_shared<DepthProcessorOCV>(DEPTH_PROC_PERIOD);
std::make_shared<DepthProcessorOCV>(DEPTH_PROC_PERIOD); #ifdef WITH_CAM_MODELS
depth_processor = depth_processor_pin;
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
auto &&depth_processor_kan = depth_processor = std::make_shared<DepthProcessor>(DEPTH_PROC_PERIOD);
std::make_shared<DepthProcessor>(DEPTH_PROC_PERIOD); #endif
depth_processor = depth_processor_kan;
} else { } else {
auto &&depth_processor_pin = depth_processor = std::make_shared<DepthProcessorOCV>(DEPTH_PROC_PERIOD);
std::make_shared<DepthProcessorOCV>(DEPTH_PROC_PERIOD);
depth_processor = depth_processor_pin;
} }
using namespace std::placeholders; // NOLINT using namespace std::placeholders; // NOLINT
@ -563,7 +653,18 @@ void Synthetic::ProcessNativeStream(
} }
if (left_data.img && right_data.img && if (left_data.img && right_data.img &&
left_data.img->frame_id == right_data.img->frame_id) { left_data.img->frame_id == right_data.img->frame_id) {
auto &&processor = find_processor<RectifyProcessor>(processor_); 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_);
}
processor->Process(ObjMat2{ processor->Process(ObjMat2{
left_data.frame, left_data.frame_id, left_data.img, left_data.frame, left_data.frame_id, left_data.img,
right_data.frame, right_data.frame_id, right_data.img}); right_data.frame, right_data.frame_id, right_data.img});
@ -580,8 +681,16 @@ void Synthetic::ProcessNativeStream(
} }
if (left_rect_data.img && right_rect_data.img && if (left_rect_data.img && right_rect_data.img &&
left_rect_data.img->frame_id == right_rect_data.img->frame_id) { left_rect_data.img->frame_id == right_rect_data.img->frame_id) {
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
}
process_childs( process_childs(
processor_, RectifyProcessor::NAME, ObjMat2{ processor_, name, ObjMat2{
left_rect_data.frame, left_rect_data.frame_id, left_rect_data.img, 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.frame, right_rect_data.frame_id,
right_rect_data.img}); right_rect_data.img});
@ -603,10 +712,12 @@ void Synthetic::ProcessNativeStream(
// PINHOLE // PINHOLE
process_childs(processor_, PointsProcessorOCV::NAME, process_childs(processor_, PointsProcessorOCV::NAME,
ObjMat{data.frame, data.frame_id, data.img}); ObjMat{data.frame, data.frame_id, data.img});
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
// KANNALA_BRANDT // KANNALA_BRANDT
process_childs(processor_, PointsProcessor::NAME, process_childs(processor_, PointsProcessor::NAME,
ObjMat{data.frame, data.frame_id, data.img}); ObjMat{data.frame, data.frame_id, data.img});
#endif
} else { } else {
// UNKNOW // UNKNOW
LOG(ERROR) << "Unknow calib model type in device: " LOG(ERROR) << "Unknow calib model type in device: "
@ -618,10 +729,12 @@ void Synthetic::ProcessNativeStream(
// PINHOLE // PINHOLE
process_childs(processor_, DepthProcessorOCV::NAME, process_childs(processor_, DepthProcessorOCV::NAME,
ObjMat{data.frame, data.frame_id, data.img}); ObjMat{data.frame, data.frame_id, data.img});
#ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
// KANNALA_BRANDT // KANNALA_BRANDT
process_childs(processor_, DepthProcessor::NAME, process_childs(processor_, DepthProcessor::NAME,
ObjMat{data.frame, data.frame_id, data.img}); ObjMat{data.frame, data.frame_id, data.img});
#endif
} else { } else {
// UNKNOW // UNKNOW
LOG(ERROR) << "Unknow calib model type in device: " LOG(ERROR) << "Unknow calib model type in device: "