立体视觉算法--SAD+DP
[cpp]#include <cstdio>#include <cstring>#include <iostream>#include<cv.h>#include<highgui.h>#include <cmath>using namespace std;const int Width = 512;const int Height = 512;int Ddynamic[Width][Width];int main(){//打开文件FILE* pFile;if (pFile = fopen("data.txt","a")){//cout <<"File Open Success"<<endl;}else{//cout <<"File Open Failed"<<end;return 0;}// IplImage * leftImage = cvLoadImage("l1.png",0);// IplImage * rightImage = cvLoadImage("r1.png",0);//IplImage * leftImage = cvLoadImage("l2.jpg",0);//IplImage * rightImage = cvLoadImage("r2.jpg",0);IplImage * leftImage = cvLoadImage("left.bmp",0);IplImage * rightImage = cvLoadImage("right.bmp",0);int imageWidth = leftImage->width;int imageHeight =leftImage->height;IplImage * leftDepth = cvCreateImage(cvGetSize(leftImage),leftImage->depth,1);IplImage * rightDepth = cvCreateImage(cvGetSize(leftImage),leftImage->depth,1);IplImage * leftValid = cvCreateImage(cvGetSize(leftImage),leftImage->depth,1);IplImage * rightValid = cvCreateImage(cvGetSize(leftImage),leftImage->depth,1);IplImage * leftFilter = cvCreateImage(cvGetSize(leftImage),leftImage->depth,1);IplImage * rightFilter = cvCreateImage(cvGetSize(leftImage),leftImage->depth,1);IplImage * depth = cvCreateImage(cvGetSize(leftImage),leftImage->depth,1);IplImage * valid = cvCreateImage(cvGetSize(leftImage),leftImage->depth,1);unsigned char * pPixel = NULL;unsigned char pixel;unsigned char * pPixel2 = NULL;unsigned char pixel2;cvZero(leftDepth);cvZero(rightDepth);cvZero(leftValid);cvZero(rightValid);cvZero(leftFilter);cvZero(rightFilter);cvZero(depth);cvZero(valid);CvSize SADWindowSize = cvSize(5,5); //(widh,height)int SW2 = SADWindowSize.width/2;int SH2 = SADWindowSize.height/2;cout<<"SH2: "<<SH2<<endl;cout<<"SW2: "<<SW2<<endl;int minD = 0;int maxD = 15;//假设图像是经过矫正的,那么每次都只是需要搜搜同一行的内容int max12Diff = 8*SADWindowSize.width*SADWindowSize.height;for (int i = 0;i < imageWidth;i++){Ddynamic[0][i] = 0;Ddynamic[i][0] = 0;}unsigned char * pLeftPixel = NULL;unsigned char * pRightPixel = NULL;unsigned char leftPixel = 0;unsigned char rightPixel =0;int m,n,l;int difPixel = 0;int t1 = clock();for (int i = SH2 ; i < imageHeight -SH2;i++){for (int j = SW2; j<imageWidth - SW2;j++){for (int k = j + minD; k <= j + maxD;k++){difPixel = 0;for (m = -SH2;m <= SH2;m++){for (n = -SW2; n <= SW2;n++){pRightPixel= (unsigned char*)rightImage->imageData+(i+m)*rightImage->widthStep + j+n;rightPixel = *pRightPixel;if (k < SW2 || k >= imageWidth -SW2 ){difPixel += rightPixel;}else {pLeftPixel = (unsigned char*)leftImage->imageData +(i+m)*leftImage->widthStep + k+n;leftPixel = *pLeftPixel;difPixel += abs(leftPixel - rightPixel);}}}&n补充:软件开发 , C++ ,
上一个:idr机制(32叉树)
下一个:内核线程中获取接收到的信号
- 更多C/C++疑问解答:
- 关于c++的cout输出的问题。
- 在学校里学过C和C++,不过学的很一般,现在自学C#,会不会很难?
- 全国计算机二级C语言笔试题
- 已知某树有2个2度结点,3个3度结点,4个4度结点,问有几个叶子结点?
- c++数据结构内部排序问题,整数排序
- 2012九月计算机二级C语言全国题库,,急求急求
- 如果assert只有一个字符串作为参数,是什么意思呢?
- C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,谢谢了!
- 为什么用结构体编写的程序输入是,0输不出来啊~~~
- 将IEEE—754的十六进制转化为十进制浮点类型,用C或C++都行,多谢各位大侠啊,非常感谢!
- 为什么这个程序求不出公式?
- 这个链表倒置的算法请大家分析下
- c语言函数库调用
- C语言unsigned int纠错
- C语言快排求解啊