sgbm算法 C++
时间: 2024-01-11 12:18:33 浏览: 140
sgbm算法是一种立体匹配算法,用于计算两幅图像之间的视差图。在C++中,可以使用OpenCV库中的StereoSGBM类来实现该算法。下面是一个简单的示例代码:
```c++
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat img1 = imread("left.png", IMREAD_GRAYSCALE);
Mat img2 = imread("right.png", IMREAD_GRAYSCALE);
StereoSGBM sgbm;
sgbm.minDisparity = 0;
sgbm.numDisparities = 64;
sgbm.blockSize = 11;
sgbm.P1 = 8 * img1.channels() * sgbm.blockSize * sgbm.blockSize;
sgbm.P2 = 32 * img1.channels() * sgbm.blockSize * sgbm.blockSize;
sgbm.uniquenessRatio = 10;
sgbm.speckleWindowSize = 100;
sgbm.speckleRange = 32;
sgbm.disp12MaxDiff = 1;
Mat disp;
sgbm(img1, img2, disp);
imshow("disparity", disp);
waitKey(0);
return 0;
}
```
阅读全文