From 23e28e20a606c087099902427b3f50b06cb6522e Mon Sep 17 00:00:00 2001 From: Osenberg-Y Date: Mon, 13 Aug 2018 18:42:53 +0800 Subject: [PATCH] Made some modification of code style and perfect function --- src/api/processor/disparity_processor.cc | 17 +++++++++++++++-- src/api/processor/disparity_processor.h | 4 +--- src/api/processor/points_processor.cc | 9 +++------ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/api/processor/disparity_processor.cc b/src/api/processor/disparity_processor.cc index 2f4ccda..cea855a 100644 --- a/src/api/processor/disparity_processor.cc +++ b/src/api/processor/disparity_processor.cc @@ -28,8 +28,16 @@ DisparityProcessor::DisparityProcessor(std::int32_t proc_period) VLOG(2) << __func__ << ": proc_period=" << proc_period; int blockSize_ = 15; // 15 - int minDisparity_ = 0; // 0 int numDisparities_ = 64; // 64 + +#ifdef USE_OPENCV2 + bm_ = cv::Ptr( + new cv::StereoBM( + cv::StereoBM::BASIC_PRESET, + numDisparities_, + blockSize_)); +#else + int minDisparity_ = 0; // 0 int preFilterSize_ = 9; // 9 int preFilterCap_ = 31; // 31 int uniquenessRatio_ = 15; // 15 @@ -37,7 +45,7 @@ DisparityProcessor::DisparityProcessor(std::int32_t proc_period) int speckleWindowSize_ = 100; // 100 int speckleRange_ = 4; // 4 - bm_ = cv::StereoBM::create(); + bm_ = cv::StereoBM::create(16, 9); bm_->setBlockSize(blockSize_); bm_->setMinDisparity(minDisparity_); bm_->setNumDisparities(numDisparities_); @@ -47,6 +55,7 @@ DisparityProcessor::DisparityProcessor(std::int32_t proc_period) bm_->setTextureThreshold(textureThreshold_); bm_->setSpeckleWindowSize(speckleWindowSize_); bm_->setSpeckleRange(speckleRange_); +#endif } DisparityProcessor::~DisparityProcessor() { @@ -68,7 +77,11 @@ bool DisparityProcessor::OnProcess( ObjMat *output = Object::Cast(out); cv::Mat disparity; +#ifdef USE_OPENCV2 + (*bm_)(input->first, input->second, disparity); +#else bm_->compute(input->first, input->second, disparity); +#endif disparity.convertTo(output->value, CV_32F, 1./16); return true; } diff --git a/src/api/processor/disparity_processor.h b/src/api/processor/disparity_processor.h index da4f78b..6a92ce6 100644 --- a/src/api/processor/disparity_processor.h +++ b/src/api/processor/disparity_processor.h @@ -21,13 +21,11 @@ #include "api/processor/processor.h" -#if 0 namespace cv { -class StereoSGBM; +class StereoBM; } // namespace cv -#endif MYNTEYE_BEGIN_NAMESPACE diff --git a/src/api/processor/points_processor.cc b/src/api/processor/points_processor.cc index 529c547..563beb8 100644 --- a/src/api/processor/points_processor.cc +++ b/src/api/processor/points_processor.cc @@ -45,8 +45,7 @@ bool PointsProcessor::OnProcess( UNUSED(parent) const ObjMat *input = Object::Cast(in); ObjMat *output = Object::Cast(out); - // cv::reprojectImageTo3D(input->value, output->value, Q_, true, -1); - bool handleMissingValues = true; + cv::Mat disparity = input->value; output->value.create(disparity.size(), CV_MAKETYPE(CV_32FC3, 3)); cv::Mat _3dImage = output->value; @@ -60,12 +59,9 @@ bool PointsProcessor::OnProcess( double minDisparity = FLT_MAX; - if (handleMissingValues) { - cv::minMaxIdx(disparity, &minDisparity, 0, 0, 0); - } + cv::minMaxIdx(disparity, &minDisparity, 0, 0, 0); for (int y = 0; y < disparity.rows; y++) { - float *sptr = disparity.ptr(y); cv::Vec3f *dptr = _3dImage.ptr(y); @@ -81,6 +77,7 @@ bool PointsProcessor::OnProcess( } } } + return true; }