立体匹配:关于用OpenCV彩色化middlebury网站给定的视差

 #include "XYZ.h"

 void readPFM(Mat_<float> &disp, float &scale, string path)
 {    //关于将Mat见我的另外一篇博客:
     ifstream in(path, ios_base::binary);

     int cols;
     int rows;
     ];
     , '\n'); in.get();//文件头
     , ' '); in.get(); cols = atoi(tmp);//列数
     , '\n'); in.get(); rows = atoi(tmp); //行数
     , '\n'); in.get(); scale = atof(tmp);//缩放因子

     disp.create(rows, cols);
     ; i >= ; i--)//因为存储是从最后行开始存储的
         ; j < disp.cols; j++)
             in.read((char*)(&disp(i, j)), sizeof(float));

     in.close();
 }

 void dyeDisp_core(Mat_<Vec3b> &colordisp, Mat_<float> &disp, float mindisp, float maxdisp)
 {
     float scale = 1.0 / (maxdisp - mindisp);
     ; i < disp.rows; i++)
         ; j < disp.cols; j++)
         {
             Vec3b *xxx = &colordisp(i, j);
             float x = disp(i, j);
             if ((x != INFINITY) && (x != -INFINITY))
             {
                 x = scale * (x - mindisp);
                 x = x / 1.15 + 0.1; // use slightly asymmetric range to avoid darkest shades of blue.
                 (*xxx)[] = __max(, __min(, ( * ( * fabs(x - .))))));
                 (*xxx)[] = __max(, __min(, ( * ( * fabs(x - .))))));
                 (*xxx)[] = __max(, __min(, ( * ( * fabs(x - .))))));
             }
             else
                 (*xxx) = Vec3b(, , );
         }
 }

 void dyeDisp_one(string dir)
 {
     string calibpath = dir + "/calib.txt";
     string disppath = dir + "/disp0GT.pfm";
     string colordisppath = dir + "/disp0GT.png";

     //1.读取极值视差
     ;
     ;
     ];
     float f;
     FILE *fp = fopen(calibpath.c_str(), "r");
     while (fgets(line, sizeof line, fp) != NULL)
     {
         ) dmin = f;
         ) dmax = f;
     }
     fclose(fp);

     //2.读取视差图像
     float scale;
     Mat_<float> disp;
     readPFM(disp, scale, disppath);
     //FileStorage fs(disppath, FileStorage::READ);
     //fs["mat"] >> disp;

     //3.计算彩色视差
     Mat_<Vec3b> colordisp(disp.rows, disp.cols);
     dyeDisp_core(colordisp, disp, dmin, dmax);

     //4.保存结果
     imwrite(colordisppath, colordisp);
 }

 void dyeDisp_dir()
 {
     vector<string> dirs = cv_GetListFolders("./../TestData");
     ; i < dirs.size(); i++)
         dyeDisp_one(dirs[i]);
 }

 void main()
 {
     dyeDisp_dir();
 }
上一篇:es6初始


下一篇:服务容错保护断路器Hystrix之八:Hystrix资源隔离策略