# 经典假设

1、左右视图成功匹配的窗口，具有相同的像素

2、像素P的视差只与其领域有关

3、相近颜色的点具有相近的视差

4、视差非连续区，应具有颜色差或亮度差

# 结尾

SGM部分可参考 SGM源码分析

``````
{
int Height = left->height;
int Width = left->width;
int winH2 = 0;//卷积核的半径
int winW2 = 1;
int winHSize = winH2 * 2 + 1;
int winWSize = winW2 * 2 + 1;

int DSR = 20;     //视差搜索范围
CVIMAGE disp = YMCV_Creat_Img_Creat(left->width, left->height, CVGrayType);
uint8* doutp = disp->data;
uint16 imgw = left->width;
//周围填充0，避免产生边框
YMCV_Gray_Image_Boundary_Padding_Val(doutp, winW2, winH2, disp->width, disp->height, 0.0f);

for (int i = 0 ,imax = Height - (2 * winH2); i < imax; i++)
{
uint8* doline = &doutp[(i + winH2) * imgw + winW2];
//左从DSR开始遍历
for (int j = DSR,jmax = Width - (2 * winW2); j < jmax; j++)
{
int minx = 0, minv = winHSize * winWSize * 255;
for (int k = 0; k < DSR; k++)
{
int xstart = j - k;
for (int y = i,ymax = i + winHSize; y < ymax; y++)
{
uint8* gLline = &left->data[y * imgw + j];
uint8* gRline = &right->data[y * imgw + xstart];
for (int x = 0; x < winWSize; x++)
{
}
}
//记录最小值
{
minx = k;
}
}
//匹配成功
if (minv < 125)//25*5 = 125
doline[j] = minx;
else
{
doline[j] = 0;
}
}
}
return disp;
}
``````

THE END