2021-10-18
作者:互联网
opencv中SGBM算法的实现
原作者:立体视觉算法-SGBM(一)_机器视觉-CSDN博客
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, const char** argv)
{
Mat left = imread("E:/image/left.png", 0);
Mat right = imread("E:/image/right.png", 0);
if (left.empty() || right.empty())
{
printf("error:inputs are empty!please check the image path!");
return -1;
}
//assert(left.size == right.size);
cv::StereoSGBM sgbm;
int SADWindowSize = 9;
sgbm.preFilterCap = 63;
sgbm.SADWindowSize = SADWindowSize > 0 ? SADWindowSize : 3;
int cn = left.channels();
int numberOfDisparities = 64;
sgbm.P1 = 8 * cn*sgbm.SADWindowSize*sgbm.SADWindowSize;
sgbm.P2 = 32 * cn*sgbm.SADWindowSize*sgbm.SADWindowSize;
sgbm.minDisparity = 0;
sgbm.numberOfDisparities = numberOfDisparities;
sgbm.uniquenessRatio = 10;
sgbm.speckleWindowSize = 100;
sgbm.speckleRange = 32;
sgbm.disp12MaxDiff = 1;
Mat left_disp_,disp;
sgbm(left, right, disp);
disp.convertTo(left_disp_, CV_8U, 255 / (numberOfDisparities*16.));
imshow("disp", left_disp_);
waitKey(0);
return 0;
}
标签:disp,10,right,sgbm,int,18,SADWindowSize,2021,left 来源: https://blog.csdn.net/qq_42744388/article/details/120828939