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;
}

上一篇:分布式ID,分布式锁,限流算法,微服务原则,CAP,BASE,双写一致性


下一篇:字节跳动算法工程师总结:中高级java开发面试题