refactor(process): change process code sort.

This commit is contained in:
TinyO 2019-09-19 14:50:23 +08:00
parent f1b6ec9e04
commit 0b47b494ff
9 changed files with 19 additions and 215 deletions

View File

@ -213,8 +213,6 @@ if(WITH_API)
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/root_camera_processor.cc src/mynteye/api/processor/root_camera_processor.cc
src/mynteye/api/processor/points_processor_ocv.cc
src/mynteye/api/processor/depth_processor_ocv.cc
src/mynteye/api/processor/rectify_processor_ocv.cc src/mynteye/api/processor/rectify_processor_ocv.cc
src/mynteye/api/correspondence.cc src/mynteye/api/correspondence.cc
src/mynteye/api/version_checker.cc src/mynteye/api/version_checker.cc

View File

@ -45,6 +45,7 @@ class DepthProcessor : public Processor {
bool OnProcess( bool OnProcess(
Object *const in, Object *const out, Object *const in, Object *const out,
std::shared_ptr<Processor> const parent) override; std::shared_ptr<Processor> const parent) override;
private: private:
std::shared_ptr<struct CameraROSMsgInfoPair> calib_infos_; std::shared_ptr<struct CameraROSMsgInfoPair> calib_infos_;
std::shared_ptr<int> min_disp_; std::shared_ptr<int> min_disp_;

View File

@ -1,55 +0,0 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mynteye/api/processor/depth_processor_ocv.h"
#include <utility>
#include "mynteye/logger.h"
MYNTEYE_BEGIN_NAMESPACE
const char DepthProcessorOCV::NAME[] = "DepthProcessorOCV";
DepthProcessorOCV::DepthProcessorOCV(std::int32_t proc_period)
: Processor(std::move(proc_period)) {
VLOG(2) << __func__ << ": proc_period=" << proc_period;
}
DepthProcessorOCV::~DepthProcessorOCV() {
VLOG(2) << __func__;
}
std::string DepthProcessorOCV::Name() {
return NAME;
}
Object *DepthProcessorOCV::OnCreateOutput() {
return new ObjMat();
}
bool DepthProcessorOCV::OnProcess(
Object *const in, Object *const out,
std::shared_ptr<Processor> const parent) {
MYNTEYE_UNUSED(parent)
const ObjMat *input = Object::Cast<ObjMat>(in);
ObjMat *output = Object::Cast<ObjMat>(out);
cv::Mat channels[3 /*input->value.channels()*/];
cv::split(input->value, channels);
channels[2].convertTo(output->value, CV_16UC1);
output->id = input->id;
output->data = input->data;
return true;
}
MYNTEYE_END_NAMESPACE

View File

@ -1,42 +0,0 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MYNTEYE_API_PROCESSOR_DEPTH_PROCESSOR_OCV_H_
#define MYNTEYE_API_PROCESSOR_DEPTH_PROCESSOR_OCV_H_
#pragma once
#include <memory>
#include <string>
#include "mynteye/api/processor.h"
MYNTEYE_BEGIN_NAMESPACE
class DepthProcessorOCV : public Processor {
public:
static const char NAME[];
explicit DepthProcessorOCV(std::int32_t proc_period = 0);
virtual ~DepthProcessorOCV();
std::string Name() override;
protected:
Object *OnCreateOutput() override;
bool OnProcess(
Object *const in, Object *const out,
std::shared_ptr<Processor> const parent) override;
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_API_PROCESSOR_DEPTH_PROCESSOR_OCV_H_

View File

@ -1,55 +0,0 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mynteye/api/processor/points_processor_ocv.h"
#include <utility>
#include <opencv2/calib3d/calib3d.hpp>
#include "mynteye/logger.h"
MYNTEYE_BEGIN_NAMESPACE
const char PointsProcessorOCV::NAME[] = "PointsProcessorOCV";
PointsProcessorOCV::PointsProcessorOCV(cv::Mat Q, std::int32_t proc_period)
: Processor(std::move(proc_period)), Q_(std::move(Q)) {
VLOG(2) << __func__ << ": proc_period=" << proc_period;
}
PointsProcessorOCV::~PointsProcessorOCV() {
VLOG(2) << __func__;
}
std::string PointsProcessorOCV::Name() {
return NAME;
}
Object *PointsProcessorOCV::OnCreateOutput() {
return new ObjMat();
}
bool PointsProcessorOCV::OnProcess(
Object *const in, Object *const out,
std::shared_ptr<Processor> const parent) {
MYNTEYE_UNUSED(parent)
const ObjMat *input = Object::Cast<ObjMat>(in);
ObjMat *output = Object::Cast<ObjMat>(out);
cv::reprojectImageTo3D(input->value, output->value, Q_, true);
output->id = input->id;
output->data = input->data;
return true;
}
MYNTEYE_END_NAMESPACE

View File

@ -1,53 +0,0 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MYNTEYE_API_PROCESSOR_POINTS_PROCESSOR_OCV_H_
#define MYNTEYE_API_PROCESSOR_POINTS_PROCESSOR_OCV_H_
#pragma once
#include <string>
#include <memory>
#include <opencv2/core/core.hpp>
#include "mynteye/api/processor.h"
MYNTEYE_BEGIN_NAMESPACE
class PointsProcessorOCV : public Processor {
public:
static const char NAME[];
explicit PointsProcessorOCV(cv::Mat Q, std::int32_t proc_period = 0);
virtual ~PointsProcessorOCV();
std::string Name() override;
protected:
Object *OnCreateOutput() override;
bool OnProcess(
Object *const in, Object *const out,
std::shared_ptr<Processor> const parent) override;
// inline Processor::process_type ProcessOutputConnection() override {
// return Processor::WITHOUT_CLONE;
// }
// inline Processor::process_type ProcessInputConnection() override {
// return Processor::WITHOUT_CLONE;
// }
private:
cv::Mat Q_;
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_API_PROCESSOR_POINTS_PROCESSOR_OCV_H_

View File

@ -228,6 +228,8 @@ void RectifyProcessor::stereoRectify(models::CameraPtr leftOdo,
cvmSet(_P2, idx, 3, s*cvmGet(_P2, idx, 3)); cvmSet(_P2, idx, 3, s*cvmGet(_P2, idx, 3));
*cx1_min_cx2 = -(cx1 - cx2); *cx1_min_cx2 = -(cx1 - cx2);
// std::cout << "info_pair.T_mul_f :" << *T_mul_f << std::endl;
// std::cout << "info_pair.cx1_minus_cx2 :" << *cx1_min_cx2 << std::endl;
} }
} }

View File

@ -164,6 +164,10 @@ void RectifyProcessorOCV::InitParams(
info_pair.P[i] = info_pair.left.P[i]; info_pair.P[i] = info_pair.left.P[i];
} }
info_pair.T_mul_f = -1.f * in_left.fx * ex_right_to_left.translation[0];
info_pair.cx1_minus_cx2 = 0.-(in_left.cx - in_right.cx);
// std::cout << "info_pair.T_mul_f :" << info_pair.T_mul_f << std::endl;
// std::cout << "info_pair.cx1_minus_cx2 :" << info_pair.cx1_minus_cx2 << std::endl;
*calib_infos = info_pair; *calib_infos = info_pair;
cv::initUndistortRectifyMap(M1, D1, R1, P1, size, CV_16SC2, map11, map12); cv::initUndistortRectifyMap(M1, D1, R1, P1, size, CV_16SC2, map11, map12);

View File

@ -27,8 +27,6 @@
#include "mynteye/api/processor/disparity_processor.h" #include "mynteye/api/processor/disparity_processor.h"
#include "mynteye/api/processor/root_camera_processor.h" #include "mynteye/api/processor/root_camera_processor.h"
#include "mynteye/api/processor/rectify_processor_ocv.h" #include "mynteye/api/processor/rectify_processor_ocv.h"
#include "mynteye/api/processor/depth_processor_ocv.h"
#include "mynteye/api/processor/points_processor_ocv.h"
#ifdef WITH_CAM_MODELS #ifdef WITH_CAM_MODELS
#include "mynteye/api/processor/depth_processor.h" #include "mynteye/api/processor/depth_processor.h"
#include "mynteye/api/processor/points_processor.h" #include "mynteye/api/processor/points_processor.h"
@ -328,19 +326,25 @@ void Synthetic::InitProcessors() {
std::make_shared<RectifyProcessorOCV>(intr_left_, intr_right_, extr_, std::make_shared<RectifyProcessorOCV>(intr_left_, intr_right_, extr_,
RECTIFY_PROC_PERIOD); RECTIFY_PROC_PERIOD);
rectify_processor = rectify_processor_ocv; rectify_processor = rectify_processor_ocv;
points_processor = std::make_shared<PointsProcessorOCV>( points_processor = std::make_shared<PointsProcessor>(
rectify_processor_ocv->Q, POINTS_PROC_PERIOD); rectify_processor_ocv -> getCameraROSMsgInfoPair(),
disparity_processor = POINTS_PROC_PERIOD);
auto disparity_processor_imp =
std::make_shared<DisparityProcessor>(DisparityComputingMethod::BM, std::make_shared<DisparityProcessor>(DisparityComputingMethod::BM,
nullptr, nullptr,
DISPARITY_PROC_PERIOD); DISPARITY_PROC_PERIOD);
depth_processor = std::make_shared<DepthProcessorOCV>(DEPTH_PROC_PERIOD); depth_processor = std::make_shared<DepthProcessor>(
rectify_processor_ocv -> getCameraROSMsgInfoPair(),
disparity_processor_imp->GetMinDisparity(),
disparity_processor_imp->GetMaxDisparity(),
DEPTH_PROC_PERIOD);
disparity_processor = disparity_processor_imp;
root_processor->AddChild(rectify_processor); root_processor->AddChild(rectify_processor);
rectify_processor->AddChild(disparity_processor); rectify_processor->AddChild(disparity_processor);
disparity_processor->AddChild(disparitynormalized_processor); disparity_processor->AddChild(disparitynormalized_processor);
disparity_processor->AddChild(points_processor); disparity_processor->AddChild(depth_processor);
points_processor->AddChild(depth_processor); depth_processor->AddChild(points_processor);
#ifdef WITH_CAM_MODELS #ifdef WITH_CAM_MODELS
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
// KANNALA_BRANDT // KANNALA_BRANDT