#pragma once

#include <opencv2/calib3d.hpp>

namespace dv::depth {
/**
 * Create a reasonable default stereo matcher, tailored for low texture images (that are generated by accumulating
 * events) and for faster execution.
 *
 * The method creates an instance of cv::StereoSGBM with following parameter values:
 * - minDisparity = 0
 * - numDisparities = 48
 * - blockSize = 11 : highest recommended block size, small block sizes generate noise in low texture)
 * - P1 = 8 * (blockSize ^ 2)
 * - P2 = 32 * (blockSize ^ 2) : P1 and P2 are calculated using recommended equations
 * - disp12MaxDiff = 0 : disparity is also calculated on right-left image pair, filter out any disparities that
 *   do not agree. This enables strong noise filtering (there can be a lot of noise due to low texture)
 * - preFilterCap = cv::StereoBM::PREFILTER_NORMALIZED_RESPONSE : disable Sobel filter preprocessing
 * - uniquenessRatio = 15 : this is also an aggressive value for a noise filter
 * - speckleWindowSize = 240 : this is also an aggressive value for a speckle noise filter
 * - speckleRange = 1 : this is also an aggressive value for a speckle noise filter
 * - mode = cv::StereoSGBM::MODE_SGBM_3WAY : Fastest disparity calculation mode
 *
 * @return Stereo semi global block matching algorithm with reasonable defaults for low texture images.
 */
[[nodiscard]] inline std::shared_ptr<cv::StereoMatcher> defaultStereoMatcher() {
	return cv::StereoSGBM::create(0, 48, 11, 8 * 11 * 11, 32 * 11 * 11, 0, cv::StereoBM::PREFILTER_NORMALIZED_RESPONSE,
		15, 240, 1, cv::StereoSGBM::MODE_SGBM_3WAY);
}

} // namespace dv::depth
