• 大小: 12KB
    文件类型: .cpp
    金币: 2
    下载: 2 次
    发布日期: 2021-06-06
  • 语言: C/C++
  • 标签: Stereo  Match  

资源简介

Stereo Match 立体匹配算法,包括SSD SAD SSD NCC NSSD Census 等基本算法,。用C/C++语言编写,适合初学者学习!

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include  

#include “cv.h“
#include “highgui.h“

// #define IMGHEIGHT 240
// #define IMGWIDTH  320

int IMGHEIGHT;
int IMGWIDTH;

#define DOMAIN    128
#define WndWidth  9
#define CODEWIDTH 80

typedef struct
{
int codebit[80];
}CodeStruct;

void SAD(unsigned char *LeftImg unsigned char *RightImg unsigned char *Disparity);
void SSD(unsigned char *LeftImg unsigned char *RightImg unsigned char *Disparity);
void NCC(unsigned char *LeftImg unsigned char *RightImg unsigned char *Disparity);
void NSSD(unsigned char *LeftImg unsigned char *RightImg unsigned char *Disparity);
void Census(unsigned char *LeftImg unsigned char *RightImg unsigned char *Disparity);
void Rank(unsigned char *LeftImg unsigned char *RightImg unsigned char *Disparity);
void CensusTransform(unsigned char *Image CodeStruct Code[]);
int HammingDist( CodeStruct Code1 CodeStruct Code2 );
void RankTransform(unsigned char *Image unsigned char *RankValue);


void SAD(unsigned char *LeftImg unsigned char *RightImg unsigned char *Disparity)
{
int ijd;
int absDiff;
int minSum;
int disp;
int *Col;
int *Wnd;

Col = new int[IMGWIDTH*DOMAIN];
Wnd = new int[IMGWIDTH*DOMAIN];

for( i=0; i {
Col[i]=0;
Wnd[i]=0;
}

for( j=0; j {
for( i=0; i {
minSum=100000;
disp=0;
for( d=0; d {
if( i>=DOMAIN )
absDiff=abs(LeftImg[j*IMGWIDTH+i]-RightImg[j*IMGWIDTH+i-d]);
else
absDiff=0;

Col[i*DOMAIN+d]=Col[i*DOMAIN+d]+absDiff;

if( j>WndWidth )
{
if( i>DOMAIN )
absDiff=abs(LeftImg[(j-WndWidth)*IMGWIDTH+i]-RightImg[(j-WndWidth)*IMGWIDTH+i-d]);
else
absDiff=0;
Col[i*DOMAIN+d]=Col[i*DOMAIN+d]-absDiff;
}

if( i Wnd[i*DOMAIN+d]=0;
else
Wnd[i*DOMAIN+d]=Wnd[(i-1)*DOMAIN+d]+Col[i*DOMAIN+d]
-Col[(i-WndWidth)*DOMAIN+d];

/*
if( i>WndWidth )
Wnd[i*DOMAIN+d]=Wnd[(i-1)*DOMAIN+d]+Col[i*DOMAIN+d]-Col[(i-WndWidth)*DOMAIN+d];
else 
{
if( i>d )
absDiff=abs(LeftImg[j*IMGWIDTH+i]-RightImg[j*IMGWIDTH+i-d]);
else
absDiff=0;

Wnd[i*DOMAIN+d]=Wnd[i*DOMAIN+d]+absDiff;
if( j>WndWidth )
{
if( i>d )
absDiff=abs(LeftImg[(j-WndWidth)*IMGWIDTH+i]-RightImg[(j-WndWidth)*IMGWIDTH+i-d]);
else
absDiff=0;
Wnd[i*DOMAIN+d]=Wnd[i*DOMAIN+d]-absDiff;
}
}
*/
if( Wnd[i*DOMAIN+d] {
minSum=Wnd[i*DOMAIN+d];
disp=d*15;
}

}

if( j>WndWidth && i>DOMAIN )
Disparity[ j * IMGWIDTH+ i]=disp;

}

}

delete []Col;
delete []Wnd;

}

void SSD(unsigned char *LeftImg unsigned char *RightImg unsigned char *Disparity)
{
int ijd;
int minSum;
int sqDiff;
int disp;
int *Col;
int *Wnd;

Col = new int[

评论

共有 条评论