fix(bm matcher): add complie switch

This commit is contained in:
TinyOh 2019-01-15 10:07:58 +08:00
parent 456613a030
commit 7b8ed81018
6 changed files with 47 additions and 5 deletions

View File

@ -24,6 +24,7 @@ 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

View File

@ -71,6 +71,7 @@ MYNTEYE_END_NAMESPACE
#cmakedefine WITH_API #cmakedefine WITH_API
#cmakedefine WITH_DEVICE_INFO_REQUIRED #cmakedefine WITH_DEVICE_INFO_REQUIRED
#cmakedefine WITH_CAM_MODELS #cmakedefine WITH_CAM_MODELS
#cmakedefine WITH_BM_SOBEL_FILTER
#cmakedefine WITH_OPENCV #cmakedefine WITH_OPENCV
#cmakedefine WITH_OPENCV2 #cmakedefine WITH_OPENCV2

View File

@ -51,7 +51,7 @@ bool DepthProcessor::OnProcess(
ObjMat *output = Object::Cast<ObjMat>(out); ObjMat *output = Object::Cast<ObjMat>(out);
int rows = input->value.rows; int rows = input->value.rows;
int cols = input->value.cols; int cols = input->value.cols;
std::cout << calib_infos_->T_mul_f << std::endl; // std::cout << calib_infos_->T_mul_f << std::endl;
// 0.0793434 // 0.0793434
cv::Mat depth_mat = cv::Mat::zeros(rows, cols, CV_16U); cv::Mat depth_mat = cv::Mat::zeros(rows, cols, CV_16U);
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {

View File

@ -17,6 +17,9 @@
#include <opencv2/calib3d/calib3d.hpp> #include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/imgproc/imgproc.hpp> #include <opencv2/imgproc/imgproc.hpp>
#ifdef WITH_BM_SOBEL_FILTER
#include <opencv2/ximgproc/disparity_filter.hpp>
#endif
#include "mynteye/logger.h" #include "mynteye/logger.h"
@ -62,6 +65,7 @@ DisparityProcessor::DisparityProcessor(DisparityProcessorType type,
sgbm_matcher->setSpeckleRange(32); sgbm_matcher->setSpeckleRange(32);
sgbm_matcher->setDisp12MaxDiff(1); sgbm_matcher->setDisp12MaxDiff(1);
#endif #endif
#ifdef WITH_BM_SOBEL_FILTER
} else if (type_ == DisparityProcessorType::BM) { } else if (type_ == DisparityProcessorType::BM) {
#ifdef WITH_OPENCV2 #ifdef WITH_OPENCV2
int bmWinSize = 3; int bmWinSize = 3;
@ -90,9 +94,42 @@ DisparityProcessor::DisparityProcessor(DisparityProcessorType type,
bm_matcher->setSpeckleWindowSize(100); bm_matcher->setSpeckleWindowSize(100);
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
} else { } else {
LOG(ERROR) << "no enum DisparityProcessorType" << static_cast<int>(type); LOG(ERROR) << "no enum DisparityProcessorType,use default sgbm";
int sgbmWinSize = 3;
int numberOfDisparities = 64;
#ifdef WITH_OPENCV2
// StereoSGBM
// http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html?#stereosgbm
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
} }
} }
@ -138,12 +175,16 @@ bool DisparityProcessor::OnProcess(
// 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_ == DisparityProcessorType::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_ == DisparityProcessorType::BM) { } else if (type_ == DisparityProcessorType::BM) {
CvSize size = input->first.size();
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->compute(tmp1, tmp2, disparity); bm_matcher->compute(tmp1, tmp2, disparity);
#endif
} else {
// default
sgbm_matcher->compute(input->first, input->second, disparity);
} }
#endif #endif
disparity.convertTo(output->value, CV_32F, 1./16, 1); disparity.convertTo(output->value, CV_32F, 1./16, 1);

View File

@ -16,7 +16,6 @@
#pragma once #pragma once
#include <string> #include <string>
#include <opencv2/ximgproc/disparity_filter.hpp>
#include "mynteye/api/processor.h" #include "mynteye/api/processor.h"
namespace cv { namespace cv {

View File

@ -613,7 +613,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::BM, std::make_shared<DisparityProcessor>(DisparityProcessorType::SGBM,
DISPARITY_PROC_PERIOD); DISPARITY_PROC_PERIOD);
auto &&disparitynormalized_processor = auto &&disparitynormalized_processor =
std::make_shared<DisparityNormalizedProcessor>( std::make_shared<DisparityNormalizedProcessor>(