feat(synthetic): add DisparityComputingMethod
This commit is contained in:
parent
4011880148
commit
0b71d05813
|
@ -24,7 +24,6 @@ option(WITH_API "Build with API layer, need OpenCV" ON)
|
||||||
option(WITH_DEVICE_INFO_REQUIRED "Build with device info required" ON)
|
option(WITH_DEVICE_INFO_REQUIRED "Build with device info required" ON)
|
||||||
|
|
||||||
option(WITH_CAM_MODELS "Build with more camera models, WITH_API must be ON" OFF)
|
option(WITH_CAM_MODELS "Build with more camera models, WITH_API must be ON" OFF)
|
||||||
option(WITH_BM_SOBEL_FILTER "Build with bm and sobel filter, need OpenCV contronb" OFF)
|
|
||||||
|
|
||||||
# 3rdparty components
|
# 3rdparty components
|
||||||
|
|
||||||
|
|
|
@ -224,6 +224,13 @@ class MYNTEYE_API API {
|
||||||
* Get the option value.
|
* Get the option value.
|
||||||
*/
|
*/
|
||||||
std::int32_t GetOptionValue(const Option &option) const;
|
std::int32_t GetOptionValue(const Option &option) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the disparity computing method.
|
||||||
|
*/
|
||||||
|
void SetDisparityComputingMethodType(
|
||||||
|
const DisparityComputingMethod &MethodType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the option value.
|
* Set the option value.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -542,6 +542,20 @@ struct MYNTEYE_API Extrinsics {
|
||||||
MYNTEYE_API
|
MYNTEYE_API
|
||||||
std::ostream &operator<<(std::ostream &os, const Extrinsics &ex);
|
std::ostream &operator<<(std::ostream &os, const Extrinsics &ex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup disparity
|
||||||
|
* Camera disparity computing method type.
|
||||||
|
*/
|
||||||
|
enum class DisparityComputingMethod : std::uint8_t {
|
||||||
|
/** bm */
|
||||||
|
SGBM = 0,
|
||||||
|
/** sgbm */
|
||||||
|
BM = 1,
|
||||||
|
/** unknow */
|
||||||
|
UNKNOW
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup datatypes Datatypes
|
* @defgroup datatypes Datatypes
|
||||||
* @brief Public data types.
|
* @brief Public data types.
|
||||||
|
|
|
@ -29,6 +29,8 @@ int main(int argc, char *argv[]) {
|
||||||
// api->EnableStreamData(Stream::DISPARITY);
|
// api->EnableStreamData(Stream::DISPARITY);
|
||||||
api->EnableStreamData(Stream::DISPARITY_NORMALIZED);
|
api->EnableStreamData(Stream::DISPARITY_NORMALIZED);
|
||||||
|
|
||||||
|
api->SetDisparityComputingMethodType(DisparityComputingMethod::BM);
|
||||||
|
|
||||||
api->Start(Source::VIDEO_STREAMING);
|
api->Start(Source::VIDEO_STREAMING);
|
||||||
|
|
||||||
cv::namedWindow("frame");
|
cv::namedWindow("frame");
|
||||||
|
|
|
@ -485,6 +485,11 @@ void API::EnablePlugin(const std::string &path) {
|
||||||
synthetic_->SetPlugin(plugin);
|
synthetic_->SetPlugin(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void API::SetDisparityComputingMethodType(
|
||||||
|
const DisparityComputingMethod &MethodType) {
|
||||||
|
synthetic_->SetDisparityComputingMethodType(MethodType);
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<Device> API::device() {
|
std::shared_ptr<Device> API::device() {
|
||||||
return device_;
|
return device_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,18 +133,36 @@ void iterate_processors_PtoC_before(
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void iterate_processors_CtoP_before(
|
void iterate_processor_PtoC_after(
|
||||||
T processor, std::function<void(std::shared_ptr<Processor>)> fn) {
|
T processor, std::function<void(std::shared_ptr<Processor>)> fn) {
|
||||||
if (processor->GetParent() != nullptr)
|
fn(processor);
|
||||||
iterate_processors_CtoP_before(processor->GetParent(), fn);
|
auto chids = processor->GetChilds();
|
||||||
|
for (auto it : chids) {
|
||||||
|
iterate_processor_PtoC_after(it, fn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
void iterate_processor_PtoC_before(
|
||||||
|
T processor, std::function<void(std::shared_ptr<Processor>)> fn) {
|
||||||
|
auto chids = processor->GetChilds();
|
||||||
|
for (auto it : chids) {
|
||||||
|
iterate_processor_PtoC_before(it, fn);
|
||||||
|
}
|
||||||
fn(processor);
|
fn(processor);
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void iterate_processors_CtoP_after(
|
void iterate_processor_CtoP_before(
|
||||||
|
T processor, std::function<void(std::shared_ptr<Processor>)> fn) {
|
||||||
|
if (processor->GetParent() != nullptr)
|
||||||
|
iterate_processor_CtoP_before(processor->GetParent(), fn);
|
||||||
|
fn(processor);
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
void iterate_processor_CtoP_after(
|
||||||
T processor, std::function<void(std::shared_ptr<Processor>)> fn) {
|
T processor, std::function<void(std::shared_ptr<Processor>)> fn) {
|
||||||
fn(processor);
|
fn(processor);
|
||||||
if (processor->GetParent() != nullptr)
|
if (processor->GetParent() != nullptr)
|
||||||
iterate_processors_CtoP_after(processor->GetParent(), fn);
|
iterate_processor_CtoP_after(processor->GetParent(), fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
MYNTEYE_END_NAMESPACE
|
MYNTEYE_END_NAMESPACE
|
||||||
|
|
|
@ -20,21 +20,16 @@
|
||||||
|
|
||||||
#include "mynteye/logger.h"
|
#include "mynteye/logger.h"
|
||||||
|
|
||||||
#define WITH_BM_SOBEL_FILTER
|
|
||||||
|
|
||||||
MYNTEYE_BEGIN_NAMESPACE
|
MYNTEYE_BEGIN_NAMESPACE
|
||||||
|
|
||||||
const char DisparityProcessor::NAME[] = "DisparityProcessor";
|
const char DisparityProcessor::NAME[] = "DisparityProcessor";
|
||||||
|
|
||||||
DisparityProcessor::DisparityProcessor(DisparityProcessorType type,
|
DisparityProcessor::DisparityProcessor(DisparityComputingMethod type,
|
||||||
std::int32_t proc_period)
|
std::int32_t proc_period)
|
||||||
: Processor(std::move(proc_period)), type_(type) {
|
: Processor(std::move(proc_period)), type_(type) {
|
||||||
VLOG(2) << __func__ << ": proc_period=" << proc_period;
|
VLOG(2) << __func__ << ": proc_period=" << proc_period;
|
||||||
|
|
||||||
if (type_ == DisparityProcessorType::SGBM) {
|
|
||||||
int sgbmWinSize = 3;
|
int sgbmWinSize = 3;
|
||||||
int numberOfDisparities = 64;
|
int numberOfDisparities = 64;
|
||||||
|
|
||||||
#ifdef WITH_OPENCV2
|
#ifdef WITH_OPENCV2
|
||||||
// StereoSGBM
|
// StereoSGBM
|
||||||
// http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html?#stereosgbm
|
// http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html?#stereosgbm
|
||||||
|
@ -51,22 +46,6 @@ DisparityProcessor::DisparityProcessor(DisparityProcessorType type,
|
||||||
100, // speckleWindowSize
|
100, // speckleWindowSize
|
||||||
32, // speckleRange
|
32, // speckleRange
|
||||||
false)); // fullDP
|
false)); // fullDP
|
||||||
#else
|
|
||||||
sgbm_matcher = cv::StereoSGBM::create(0, 16, 3);
|
|
||||||
sgbm_matcher->setPreFilterCap(63);
|
|
||||||
sgbm_matcher->setBlockSize(sgbmWinSize);
|
|
||||||
sgbm_matcher->setP1(8 * sgbmWinSize * sgbmWinSize);
|
|
||||||
sgbm_matcher->setP2(32 * sgbmWinSize * sgbmWinSize);
|
|
||||||
sgbm_matcher->setMinDisparity(0);
|
|
||||||
sgbm_matcher->setNumDisparities(numberOfDisparities);
|
|
||||||
sgbm_matcher->setUniquenessRatio(10);
|
|
||||||
sgbm_matcher->setSpeckleWindowSize(100);
|
|
||||||
sgbm_matcher->setSpeckleRange(32);
|
|
||||||
sgbm_matcher->setDisp12MaxDiff(1);
|
|
||||||
#endif
|
|
||||||
#ifdef WITH_BM_SOBEL_FILTER
|
|
||||||
} else if (type_ == DisparityProcessorType::BM) {
|
|
||||||
#ifdef WITH_OPENCV2
|
|
||||||
LOG(ERROR) << "not supported in opencv 2.x";
|
LOG(ERROR) << "not supported in opencv 2.x";
|
||||||
// int bmWinSize = 3;
|
// int bmWinSize = 3;
|
||||||
// // StereoBM
|
// // StereoBM
|
||||||
|
@ -83,6 +62,18 @@ DisparityProcessor::DisparityProcessor(DisparityProcessorType type,
|
||||||
// 100,
|
// 100,
|
||||||
// 4));
|
// 4));
|
||||||
#else
|
#else
|
||||||
|
sgbm_matcher = cv::StereoSGBM::create(0, 16, 3);
|
||||||
|
sgbm_matcher->setPreFilterCap(63);
|
||||||
|
sgbm_matcher->setBlockSize(sgbmWinSize);
|
||||||
|
sgbm_matcher->setP1(8 * sgbmWinSize * sgbmWinSize);
|
||||||
|
sgbm_matcher->setP2(32 * sgbmWinSize * sgbmWinSize);
|
||||||
|
sgbm_matcher->setMinDisparity(0);
|
||||||
|
sgbm_matcher->setNumDisparities(numberOfDisparities);
|
||||||
|
sgbm_matcher->setUniquenessRatio(10);
|
||||||
|
sgbm_matcher->setSpeckleWindowSize(100);
|
||||||
|
sgbm_matcher->setSpeckleRange(32);
|
||||||
|
sgbm_matcher->setDisp12MaxDiff(1);
|
||||||
|
|
||||||
bm_matcher = cv::StereoBM::create(0, 3);
|
bm_matcher = cv::StereoBM::create(0, 3);
|
||||||
bm_matcher->setPreFilterSize(9);
|
bm_matcher->setPreFilterSize(9);
|
||||||
bm_matcher->setPreFilterCap(31);
|
bm_matcher->setPreFilterCap(31);
|
||||||
|
@ -95,48 +86,23 @@ DisparityProcessor::DisparityProcessor(DisparityProcessorType type,
|
||||||
bm_matcher->setSpeckleRange(4);
|
bm_matcher->setSpeckleRange(4);
|
||||||
bm_matcher->setPreFilterType(cv::StereoBM::PREFILTER_XSOBEL);
|
bm_matcher->setPreFilterType(cv::StereoBM::PREFILTER_XSOBEL);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
NotifyComputingTypeChanged(type_);
|
||||||
} else {
|
}
|
||||||
LOG(ERROR) << "no enum DisparityProcessorType,use default sgbm";
|
|
||||||
int sgbmWinSize = 3;
|
|
||||||
int numberOfDisparities = 64;
|
|
||||||
|
|
||||||
#ifdef WITH_OPENCV2
|
void DisparityProcessor::NotifyComputingTypeChanged(
|
||||||
// StereoSGBM
|
const DisparityComputingMethod &MethodType) {
|
||||||
// http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html?#stereosgbm
|
type_ = MethodType;
|
||||||
sgbm_matcher = cv::Ptr<cv::StereoSGBM>(
|
|
||||||
new cv::StereoSGBM(
|
|
||||||
0, // minDisparity
|
|
||||||
numberOfDisparities, // numDisparities
|
|
||||||
sgbmWinSize, // SADWindowSize
|
|
||||||
8 * sgbmWinSize * sgbmWinSize, // P1
|
|
||||||
32 * sgbmWinSize * sgbmWinSize, // P2
|
|
||||||
1, // disp12MaxDiff
|
|
||||||
63, // preFilterCap
|
|
||||||
10, // uniquenessRatio
|
|
||||||
100, // speckleWindowSize
|
|
||||||
32, // speckleRange
|
|
||||||
false)); // fullDP
|
|
||||||
#else
|
|
||||||
sgbm_matcher = cv::StereoSGBM::create(0, 16, 3);
|
|
||||||
sgbm_matcher->setPreFilterCap(63);
|
|
||||||
sgbm_matcher->setBlockSize(sgbmWinSize);
|
|
||||||
sgbm_matcher->setP1(8 * sgbmWinSize * sgbmWinSize);
|
|
||||||
sgbm_matcher->setP2(32 * sgbmWinSize * sgbmWinSize);
|
|
||||||
sgbm_matcher->setMinDisparity(0);
|
|
||||||
sgbm_matcher->setNumDisparities(numberOfDisparities);
|
|
||||||
sgbm_matcher->setUniquenessRatio(10);
|
|
||||||
sgbm_matcher->setSpeckleWindowSize(100);
|
|
||||||
sgbm_matcher->setSpeckleRange(32);
|
|
||||||
sgbm_matcher->setDisp12MaxDiff(1);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DisparityProcessor::~DisparityProcessor() {
|
DisparityProcessor::~DisparityProcessor() {
|
||||||
VLOG(2) << __func__;
|
VLOG(2) << __func__;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DisparityProcessor::SetDisparityComputingMethodType(
|
||||||
|
const DisparityComputingMethod &MethodType) {
|
||||||
|
NotifyComputingTypeChanged(MethodType);
|
||||||
|
}
|
||||||
|
|
||||||
std::string DisparityProcessor::Name() {
|
std::string DisparityProcessor::Name() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
@ -161,16 +127,14 @@ bool DisparityProcessor::OnProcess(
|
||||||
// It contains disparity values scaled by 16. So, to get the floating-point
|
// It contains disparity values scaled by 16. So, to get the floating-point
|
||||||
// disparity map,
|
// disparity map,
|
||||||
// you need to divide each disp element by 16.
|
// you need to divide each disp element by 16.
|
||||||
if (type_ == DisparityProcessorType::SGBM) {
|
if (type_ == DisparityComputingMethod::SGBM) {
|
||||||
(*sgbm_matcher)(input->first, input->second, disparity);
|
(*sgbm_matcher)(input->first, input->second, disparity);
|
||||||
#ifdef WITH_BM_SOBEL_FILTER
|
} else if (type_ == DisparityComputingMethod::BM) {
|
||||||
} else if (type_ == DisparityProcessorType::BM) {
|
|
||||||
LOG(ERROR) << "not supported in opencv 2.x";
|
LOG(ERROR) << "not supported in opencv 2.x";
|
||||||
// cv::Mat tmp1, tmp2;
|
// cv::Mat tmp1, tmp2;
|
||||||
// cv::cvtColor(input->first, tmp1, CV_RGB2GRAY);
|
// cv::cvtColor(input->first, tmp1, CV_RGB2GRAY);
|
||||||
// cv::cvtColor(input->second, tmp2, CV_RGB2GRAY);
|
// cv::cvtColor(input->second, tmp2, CV_RGB2GRAY);
|
||||||
// (*bm_matcher)(tmp1, tmp2, disparity);
|
// (*bm_matcher)(tmp1, tmp2, disparity);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// compute()
|
// compute()
|
||||||
|
@ -180,10 +144,9 @@ bool DisparityProcessor::OnProcess(
|
||||||
// disparity map
|
// disparity map
|
||||||
// (where each disparity value has 4 fractional bits),
|
// (where each disparity value has 4 fractional bits),
|
||||||
// whereas other algorithms output 32-bit floating-point disparity map.
|
// whereas other algorithms output 32-bit floating-point disparity map.
|
||||||
if (type_ == DisparityProcessorType::SGBM) {
|
if (type_ == DisparityComputingMethod::SGBM) {
|
||||||
sgbm_matcher->compute(input->first, input->second, disparity);
|
sgbm_matcher->compute(input->first, input->second, disparity);
|
||||||
#ifdef WITH_BM_SOBEL_FILTER
|
} else if (type_ == DisparityComputingMethod::BM) {
|
||||||
} else if (type_ == DisparityProcessorType::BM) {
|
|
||||||
cv::Mat tmp1, tmp2;
|
cv::Mat tmp1, tmp2;
|
||||||
if (input->first.channels() == 1) {
|
if (input->first.channels() == 1) {
|
||||||
// s1030
|
// s1030
|
||||||
|
@ -195,7 +158,6 @@ bool DisparityProcessor::OnProcess(
|
||||||
cv::cvtColor(input->second, tmp2, CV_RGB2GRAY);
|
cv::cvtColor(input->second, tmp2, CV_RGB2GRAY);
|
||||||
}
|
}
|
||||||
bm_matcher->compute(tmp1, tmp2, disparity);
|
bm_matcher->compute(tmp1, tmp2, disparity);
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
// default
|
// default
|
||||||
sgbm_matcher->compute(input->first, input->second, disparity);
|
sgbm_matcher->compute(input->first, input->second, disparity);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "mynteye/api/processor.h"
|
#include "mynteye/api/processor.h"
|
||||||
|
#include "mynteye/types.h"
|
||||||
|
|
||||||
namespace cv {
|
namespace cv {
|
||||||
|
|
||||||
|
@ -24,27 +25,20 @@ class StereoSGBM;
|
||||||
class StereoBM;
|
class StereoBM;
|
||||||
} // namespace cv
|
} // namespace cv
|
||||||
|
|
||||||
enum class DisparityProcessorType : std::uint8_t {
|
|
||||||
/** bm */
|
|
||||||
SGBM = 0,
|
|
||||||
/** sgbm */
|
|
||||||
BM = 1,
|
|
||||||
/** unknow */
|
|
||||||
UNKNOW
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
MYNTEYE_BEGIN_NAMESPACE
|
MYNTEYE_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class DisparityProcessor : public Processor {
|
class DisparityProcessor : public Processor {
|
||||||
public:
|
public:
|
||||||
static const char NAME[];
|
static const char NAME[];
|
||||||
|
|
||||||
explicit DisparityProcessor(DisparityProcessorType type,
|
explicit DisparityProcessor(DisparityComputingMethod type,
|
||||||
std::int32_t proc_period = 0);
|
std::int32_t proc_period = 0);
|
||||||
virtual ~DisparityProcessor();
|
virtual ~DisparityProcessor();
|
||||||
|
|
||||||
std::string Name() override;
|
std::string Name() override;
|
||||||
|
void SetDisparityComputingMethodType(
|
||||||
|
const DisparityComputingMethod &MethodType);
|
||||||
|
void NotifyComputingTypeChanged(const DisparityComputingMethod &MethodType);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Object *OnCreateOutput() override;
|
Object *OnCreateOutput() override;
|
||||||
|
@ -55,7 +49,7 @@ class DisparityProcessor : public Processor {
|
||||||
private:
|
private:
|
||||||
cv::Ptr<cv::StereoSGBM> sgbm_matcher;
|
cv::Ptr<cv::StereoSGBM> sgbm_matcher;
|
||||||
cv::Ptr<cv::StereoBM> bm_matcher;
|
cv::Ptr<cv::StereoBM> bm_matcher;
|
||||||
DisparityProcessorType type_;
|
DisparityComputingMethod type_;
|
||||||
};
|
};
|
||||||
|
|
||||||
MYNTEYE_END_NAMESPACE
|
MYNTEYE_END_NAMESPACE
|
||||||
|
|
|
@ -22,9 +22,7 @@ MYNTEYE_BEGIN_NAMESPACE
|
||||||
const char RootProcessor::NAME[] = "RootProcessor";
|
const char RootProcessor::NAME[] = "RootProcessor";
|
||||||
|
|
||||||
RootProcessor::RootProcessor(std::int32_t proc_period)
|
RootProcessor::RootProcessor(std::int32_t proc_period)
|
||||||
: Processor(std::move(proc_period)) {
|
: Processor(std::move(proc_period)) {}
|
||||||
// todo
|
|
||||||
}
|
|
||||||
RootProcessor::~RootProcessor() {
|
RootProcessor::~RootProcessor() {
|
||||||
VLOG(2) << __func__;
|
VLOG(2) << __func__;
|
||||||
}
|
}
|
||||||
|
@ -40,14 +38,6 @@ bool RootProcessor::OnProcess(
|
||||||
Object *const in, Object *const out,
|
Object *const in, Object *const out,
|
||||||
std::shared_ptr<Processor> const parent) {
|
std::shared_ptr<Processor> const parent) {
|
||||||
MYNTEYE_UNUSED(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;
|
return true;
|
||||||
}
|
}
|
||||||
MYNTEYE_END_NAMESPACE
|
MYNTEYE_END_NAMESPACE
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#define DISPARITY_NORM_PROC_PERIOD 0
|
#define DISPARITY_NORM_PROC_PERIOD 0
|
||||||
#define POINTS_PROC_PERIOD 0
|
#define POINTS_PROC_PERIOD 0
|
||||||
#define DEPTH_PROC_PERIOD 0
|
#define DEPTH_PROC_PERIOD 0
|
||||||
|
#define ROOT_PROC_PERIOD 0
|
||||||
|
|
||||||
MYNTEYE_BEGIN_NAMESPACE
|
MYNTEYE_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
@ -183,21 +184,6 @@ void Synthetic::setControlDateCallbackWithStream(
|
||||||
LOG(ERROR) << "ERROR: no suited processor for stream "<< ctr_data.stream;
|
LOG(ERROR) << "ERROR: no suited processor for stream "<< ctr_data.stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void Synthetic::setControlDateModeWithStream(
|
|
||||||
// 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].mode = ctr_data.mode;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// i++;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// LOG(ERROR) << "ERROR: no suited processor for stream "<< ctr_data.stream;
|
|
||||||
// }
|
|
||||||
|
|
||||||
bool Synthetic::checkControlDateWithStream(const Stream& stream) const {
|
bool Synthetic::checkControlDateWithStream(const Stream& stream) const {
|
||||||
for (auto &&it : processors_) {
|
for (auto &&it : processors_) {
|
||||||
for (auto it_s : it->getTargetStreams()) {
|
for (auto it_s : it->getTargetStreams()) {
|
||||||
|
@ -209,40 +195,25 @@ bool Synthetic::checkControlDateWithStream(const Stream& stream) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool Synthetic::Supports(const Stream &stream) const {
|
void Synthetic::EnableStreamData(const Stream &stream) {
|
||||||
// return checkControlDateWithStream(stream);
|
// Activate processors of synthetic stream
|
||||||
// }
|
auto processor = getProcessorWithStream(stream);
|
||||||
|
iterate_processor_CtoP_before(processor,
|
||||||
// Synthetic::status_mode_t Synthetic::GetStreamStatusMode(
|
[](std::shared_ptr<Processor> proce){
|
||||||
// const Stream &stream) const {
|
auto streams = proce->getTargetStreams();
|
||||||
// if (checkControlDateWithStream(stream)) {
|
int act_tag = 0;
|
||||||
// auto ctrData = getControlDateWithStream(stream);
|
for (unsigned int i = 0; i < proce->getStreamsSum() ; i++) {
|
||||||
// return ctrData.mode;
|
if (proce->target_streams_[i].enabled_mode_ == MODE_LAST) {
|
||||||
// } else {
|
act_tag++;
|
||||||
// return MODE_STATUS_LAST;
|
proce->target_streams_[i].enabled_mode_ = MODE_SYNTHETIC;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
if (act_tag > 0 && !proce->IsActivated()) {
|
||||||
// void Synthetic::EnableStreamData(const Stream &stream) {
|
// std::cout << proce->Name() << " Active now" << std::endl;
|
||||||
// // Activate processors of synthetic stream
|
proce->Activate();
|
||||||
// auto processor = getProcessorWithStream(stream);
|
}
|
||||||
// iterate_processors_CtoP_before(processor,
|
});
|
||||||
// [](std::shared_ptr<Processor> proce){
|
}
|
||||||
// auto streams = proce->getTargetStreams();
|
|
||||||
// int act_tag = 0;
|
|
||||||
// for (unsigned int i = 0; i < proce->getStreamsSum() ; i++) {
|
|
||||||
// if (proce->target_streams_[i].mode == MODE_STATUS_DISABLE) {
|
|
||||||
// act_tag++;
|
|
||||||
// proce->target_streams_[i].mode = MODE_STATUS_ENABLE;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (act_tag > 0) {
|
|
||||||
// std::cout << proce->Name() << "active" << std::endl;
|
|
||||||
// proce->Activate();
|
|
||||||
// }
|
|
||||||
// // std::cout <<std::endl;
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
bool Synthetic::Supports(const Stream &stream) const {
|
bool Synthetic::Supports(const Stream &stream) const {
|
||||||
|
@ -257,12 +228,23 @@ Synthetic::mode_t Synthetic::SupportsMode(const Stream &stream) const {
|
||||||
return MODE_LAST;
|
return MODE_LAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Synthetic::EnableStreamData(const Stream &stream) {
|
|
||||||
EnableStreamData(stream, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Synthetic::DisableStreamData(const Stream &stream) {
|
void Synthetic::DisableStreamData(const Stream &stream) {
|
||||||
DisableStreamData(stream, 0);
|
auto processor = getProcessorWithStream(stream);
|
||||||
|
iterate_processor_PtoC_before(processor,
|
||||||
|
[](std::shared_ptr<Processor> proce){
|
||||||
|
auto streams = proce->getTargetStreams();
|
||||||
|
int act_tag = 0;
|
||||||
|
for (unsigned int i = 0; i < proce->getStreamsSum() ; i++) {
|
||||||
|
if (proce->target_streams_[i].enabled_mode_ == MODE_SYNTHETIC) {
|
||||||
|
act_tag++;
|
||||||
|
proce->target_streams_[i].enabled_mode_ = MODE_LAST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (act_tag > 0 && proce->IsActivated()) {
|
||||||
|
// std::cout << proce->Name() << "Deactive now" << std::endl;
|
||||||
|
proce->Deactivate();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Synthetic::IsStreamDataEnabled(const Stream &stream) const {
|
bool Synthetic::IsStreamDataEnabled(const Stream &stream) const {
|
||||||
|
@ -349,7 +331,6 @@ api::StreamData Synthetic::GetStreamData(const Stream &stream) {
|
||||||
auto sum = processor->getStreamsSum();
|
auto sum = processor->getStreamsSum();
|
||||||
auto &&out = processor->GetOutput();
|
auto &&out = processor->GetOutput();
|
||||||
static std::shared_ptr<ObjMat2> output = nullptr;
|
static std::shared_ptr<ObjMat2> output = nullptr;
|
||||||
std::cout << processor->Name() << stream <<std::endl;
|
|
||||||
if (sum == 1) {
|
if (sum == 1) {
|
||||||
if (out != nullptr) {
|
if (out != nullptr) {
|
||||||
auto &&output = Object::Cast<ObjMat>(out);
|
auto &&output = Object::Cast<ObjMat>(out);
|
||||||
|
@ -469,205 +450,6 @@ bool Synthetic::IsStreamEnabledSynthetic(const Stream &stream) const {
|
||||||
return GetStreamEnabledMode(stream) == MODE_SYNTHETIC;
|
return GetStreamEnabledMode(stream) == MODE_SYNTHETIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Synthetic::EnableStreamData(const Stream &stream, std::uint32_t depth) {
|
|
||||||
if (IsStreamDataEnabled(stream))
|
|
||||||
return;
|
|
||||||
// Activate processors of synthetic stream
|
|
||||||
|
|
||||||
auto processor = getProcessorWithStream(stream);
|
|
||||||
for (unsigned int i = 0; i< processor->target_streams_.size(); i++) {
|
|
||||||
if (processor->target_streams_[i].stream == stream) {
|
|
||||||
processor->target_streams_[i].enabled_mode_ = MODE_SYNTHETIC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch (stream) {
|
|
||||||
case Stream::LEFT_RECTIFIED: {
|
|
||||||
if (!IsStreamDataEnabled(Stream::LEFT))
|
|
||||||
break;
|
|
||||||
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>());
|
|
||||||
}
|
|
||||||
} return;
|
|
||||||
case Stream::RIGHT_RECTIFIED: {
|
|
||||||
if (!IsStreamDataEnabled(Stream::RIGHT))
|
|
||||||
break;
|
|
||||||
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>());
|
|
||||||
}
|
|
||||||
} return;
|
|
||||||
case Stream::DISPARITY: {
|
|
||||||
EnableStreamData(Stream::LEFT_RECTIFIED, depth + 1);
|
|
||||||
EnableStreamData(Stream::RIGHT_RECTIFIED, depth + 1);
|
|
||||||
CHECK(ActivateProcessor<DisparityProcessor>());
|
|
||||||
} return;
|
|
||||||
case Stream::DISPARITY_NORMALIZED: {
|
|
||||||
EnableStreamData(Stream::DISPARITY, depth + 1);
|
|
||||||
CHECK(ActivateProcessor<DisparityNormalizedProcessor>());
|
|
||||||
} return;
|
|
||||||
case Stream::POINTS: {
|
|
||||||
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
||||||
EnableStreamData(Stream::DISPARITY, depth + 1);
|
|
||||||
CHECK(ActivateProcessor<PointsProcessorOCV>());
|
|
||||||
#ifdef WITH_CAM_MODELS
|
|
||||||
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
||||||
EnableStreamData(Stream::DEPTH, depth + 1);
|
|
||||||
CHECK(ActivateProcessor<PointsProcessor>());
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
LOG(ERROR) << "Unknow calib model type in device: "
|
|
||||||
<< calib_model_;
|
|
||||||
}
|
|
||||||
} return;
|
|
||||||
case Stream::DEPTH: {
|
|
||||||
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
||||||
EnableStreamData(Stream::POINTS, depth + 1);
|
|
||||||
CHECK(ActivateProcessor<DepthProcessorOCV>());
|
|
||||||
#ifdef WITH_CAM_MODELS
|
|
||||||
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
||||||
EnableStreamData(Stream::DISPARITY, depth + 1);
|
|
||||||
CHECK(ActivateProcessor<DepthProcessor>());
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
LOG(ERROR) << "Unknow calib model type in device: "
|
|
||||||
<< calib_model_;
|
|
||||||
}
|
|
||||||
} return;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
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
|
|
||||||
auto data = getControlDateWithStream(stream);
|
|
||||||
if (data.enabled_mode_ != MODE_NATIVE) {
|
|
||||||
data.enabled_mode_ = MODE_LAST;
|
|
||||||
switch (stream) {
|
|
||||||
case Stream::LEFT_RECTIFIED: {
|
|
||||||
if (IsStreamEnabledSynthetic(Stream::DISPARITY)) {
|
|
||||||
DisableStreamData(Stream::DISPARITY, depth + 1);
|
|
||||||
}
|
|
||||||
if (IsStreamEnabledSynthetic(Stream::RIGHT_RECTIFIED)) {
|
|
||||||
DisableStreamData(Stream::RIGHT_RECTIFIED, depth + 1);
|
|
||||||
}
|
|
||||||
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>();
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case Stream::RIGHT_RECTIFIED: {
|
|
||||||
if (IsStreamEnabledSynthetic(Stream::DISPARITY)) {
|
|
||||||
DisableStreamData(Stream::DISPARITY, depth + 1);
|
|
||||||
}
|
|
||||||
if (IsStreamEnabledSynthetic(Stream::LEFT_RECTIFIED)) {
|
|
||||||
DisableStreamData(Stream::LEFT_RECTIFIED, depth + 1);
|
|
||||||
}
|
|
||||||
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>();
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case Stream::DISPARITY: {
|
|
||||||
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_;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case Stream::DISPARITY_NORMALIZED: {
|
|
||||||
DeactivateProcessor<DisparityNormalizedProcessor>();
|
|
||||||
} break;
|
|
||||||
case Stream::POINTS: {
|
|
||||||
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
||||||
if (IsStreamEnabledSynthetic(Stream::DEPTH)) {
|
|
||||||
DisableStreamData(Stream::DEPTH, depth + 1);
|
|
||||||
}
|
|
||||||
DeactivateProcessor<PointsProcessorOCV>();
|
|
||||||
#ifdef WITH_CAM_MODELS
|
|
||||||
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
||||||
DeactivateProcessor<PointsProcessor>();
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
LOG(ERROR) << "Unknow calib model type in device: "
|
|
||||||
<< calib_model_;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case Stream::DEPTH: {
|
|
||||||
if (calib_model_ == CalibrationModel::PINHOLE) {
|
|
||||||
DeactivateProcessor<DepthProcessorOCV>();
|
|
||||||
#ifdef WITH_CAM_MODELS
|
|
||||||
} else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) {
|
|
||||||
if (IsStreamEnabledSynthetic(Stream::POINTS)) {
|
|
||||||
DisableStreamData(Stream::POINTS, depth + 1);
|
|
||||||
}
|
|
||||||
DeactivateProcessor<DepthProcessor>();
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
LOG(ERROR) << "Unknow calib model type in device: "
|
|
||||||
<< calib_model_;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
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() {
|
void Synthetic::InitProcessors() {
|
||||||
std::shared_ptr<Processor> rectify_processor = nullptr;
|
std::shared_ptr<Processor> rectify_processor = nullptr;
|
||||||
#ifdef WITH_CAM_MODELS
|
#ifdef WITH_CAM_MODELS
|
||||||
|
@ -696,7 +478,7 @@ void Synthetic::InitProcessors() {
|
||||||
rectify_processor = rectify_processor_ocv;
|
rectify_processor = rectify_processor_ocv;
|
||||||
}
|
}
|
||||||
auto &&disparity_processor =
|
auto &&disparity_processor =
|
||||||
std::make_shared<DisparityProcessor>(DisparityProcessorType::SGBM,
|
std::make_shared<DisparityProcessor>(DisparityComputingMethod::SGBM,
|
||||||
DISPARITY_PROC_PERIOD);
|
DISPARITY_PROC_PERIOD);
|
||||||
auto &&disparitynormalized_processor =
|
auto &&disparitynormalized_processor =
|
||||||
std::make_shared<DisparityNormalizedProcessor>(
|
std::make_shared<DisparityNormalizedProcessor>(
|
||||||
|
@ -1003,4 +785,15 @@ void Synthetic::OnDepthPostProcess(Object *const out) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.";
|
||||||
|
}
|
||||||
|
|
||||||
MYNTEYE_END_NAMESPACE
|
MYNTEYE_END_NAMESPACE
|
||||||
|
|
|
@ -80,6 +80,8 @@ class Synthetic {
|
||||||
const struct stream_control_t& ctr_data);
|
const struct stream_control_t& ctr_data);
|
||||||
bool checkControlDateWithStream(const Stream& stream) const;
|
bool checkControlDateWithStream(const Stream& stream) const;
|
||||||
std::shared_ptr<Processor> getProcessorWithStream(const Stream& stream);
|
std::shared_ptr<Processor> getProcessorWithStream(const Stream& stream);
|
||||||
|
void SetDisparityComputingMethodType(
|
||||||
|
const DisparityComputingMethod &MethoType);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitCalibInfo();
|
void InitCalibInfo();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user