fix(bm matcher): add complie switch
This commit is contained in:
parent
456613a030
commit
7b8ed81018
|
@ -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_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
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ MYNTEYE_END_NAMESPACE
|
|||
#cmakedefine WITH_API
|
||||
#cmakedefine WITH_DEVICE_INFO_REQUIRED
|
||||
#cmakedefine WITH_CAM_MODELS
|
||||
#cmakedefine WITH_BM_SOBEL_FILTER
|
||||
|
||||
#cmakedefine WITH_OPENCV
|
||||
#cmakedefine WITH_OPENCV2
|
||||
|
|
|
@ -51,7 +51,7 @@ bool DepthProcessor::OnProcess(
|
|||
ObjMat *output = Object::Cast<ObjMat>(out);
|
||||
int rows = input->value.rows;
|
||||
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
|
||||
cv::Mat depth_mat = cv::Mat::zeros(rows, cols, CV_16U);
|
||||
for (int i = 0; i < rows; i++) {
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
|
||||
#include <opencv2/calib3d/calib3d.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#ifdef WITH_BM_SOBEL_FILTER
|
||||
#include <opencv2/ximgproc/disparity_filter.hpp>
|
||||
#endif
|
||||
|
||||
#include "mynteye/logger.h"
|
||||
|
||||
|
@ -62,6 +65,7 @@ DisparityProcessor::DisparityProcessor(DisparityProcessorType type,
|
|||
sgbm_matcher->setSpeckleRange(32);
|
||||
sgbm_matcher->setDisp12MaxDiff(1);
|
||||
#endif
|
||||
#ifdef WITH_BM_SOBEL_FILTER
|
||||
} else if (type_ == DisparityProcessorType::BM) {
|
||||
#ifdef WITH_OPENCV2
|
||||
int bmWinSize = 3;
|
||||
|
@ -90,9 +94,42 @@ DisparityProcessor::DisparityProcessor(DisparityProcessorType type,
|
|||
bm_matcher->setSpeckleWindowSize(100);
|
||||
bm_matcher->setSpeckleRange(4);
|
||||
bm_matcher->setPreFilterType(cv::StereoBM::PREFILTER_XSOBEL);
|
||||
#endif
|
||||
#endif
|
||||
} 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.
|
||||
if (type_ == DisparityProcessorType::SGBM) {
|
||||
sgbm_matcher->compute(input->first, input->second, disparity);
|
||||
#ifdef WITH_BM_SOBEL_FILTER
|
||||
} else if (type_ == DisparityProcessorType::BM) {
|
||||
CvSize size = input->first.size();
|
||||
cv::Mat tmp1, tmp2;
|
||||
cv::cvtColor(input->first, tmp1, CV_RGB2GRAY);
|
||||
cv::cvtColor(input->second, tmp2, CV_RGB2GRAY);
|
||||
bm_matcher->compute(tmp1, tmp2, disparity);
|
||||
#endif
|
||||
} else {
|
||||
// default
|
||||
sgbm_matcher->compute(input->first, input->second, disparity);
|
||||
}
|
||||
#endif
|
||||
disparity.convertTo(output->value, CV_32F, 1./16, 1);
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <opencv2/ximgproc/disparity_filter.hpp>
|
||||
#include "mynteye/api/processor.h"
|
||||
|
||||
namespace cv {
|
||||
|
|
|
@ -613,7 +613,7 @@ void Synthetic::InitProcessors() {
|
|||
rectify_processor = rectify_processor_ocv;
|
||||
}
|
||||
auto &&disparity_processor =
|
||||
std::make_shared<DisparityProcessor>(DisparityProcessorType::BM,
|
||||
std::make_shared<DisparityProcessor>(DisparityProcessorType::SGBM,
|
||||
DISPARITY_PROC_PERIOD);
|
||||
auto &&disparitynormalized_processor =
|
||||
std::make_shared<DisparityNormalizedProcessor>(
|
||||
|
|
Loading…
Reference in New Issue
Block a user