#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();
 }

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

  1. 光流算法:关于OpenCV读写middlebury网站给定的光流的代码

    Middlebury是每个研究光流算法的人不可能不使用的网站,Middlebury提供了许多标准的测试库,这极大地推进了光流算法的进展.Middlebury提供的标准库,其计算出的光流保存在后缀名为. ...

  2. 立体匹配:关于OpenCV读写middlebury网站的给定的视差并恢复三维场景的代码

    Middlebury是每个研究立体匹配算法的人不可能不使用的网站,Middlebury提供了许多标准的测试库,这极大地推进了立体匹配算法的进展.Middlebury提供的标准库,其计算出的视差保存在后 ...

  3. opencv 彩色图像分割(inrange)

    灰度图像大多通过算子寻找边缘和区域生长融合来分割图像. 彩色图像增加了色彩信息,可以通过不同的色彩值来分割图像,常用彩色空间HSV/HSI, RGB, LAB等都可以用于分割! 笔者主要介绍inran ...

  4. OpenCV定制化创建角点检测子

    定制化创建角点检测子 目标 在这个教程中我们将涉及: 使用 OpenCV 函数 cornerEigenValsAndVecs 来计算像素对应的本征值和本征向量来确定其是否是角点. 使用OpenCV 函 ...

  5. OpenCV阈值化处理

    图像的阈值化就是利用图像像素点分布规律,设定阈值进行像素点分割,进而得到图像的二值图像.图像阈值化操作有多种方法,常用方法有经典的OTSU.固定阈值.自适应阈值.双阈值及半阈值化操作.这里对各种阈值化 ...

  6. OpenCV灰度化图像

    OpenCV2版本号非常多函数发生了变化.比如二值化,其演示样例: void CmyMFC2Dlg::OnBnClickedButton1() { // TODO: Add your control ...

  7. opencv 彩色图像亮度、对比度调节 直方图均衡化

    直接上代码: #include <Windows.h> #include <iostream>// for stand I/O #include <string> ...

  8. Jenkins(9)- 汉化 Jenkins 网站

    如果想从头学起Jenkins的话,可以看看这一系列的文章哦 https://www.cnblogs.com/poloyy/category/1645399.html 下载插件 安装这两个插件,然后重启 ...

  9. OpenCV——阈值化

    上述五种结合CV_THRESH_OTSU(自适应阈值),写成:THRESH_BINARY | CV_THRESH_OTSU

随机推荐

  1. 二模 (16) day1&day2

    第一题:题目大意: 数列a[0]=a[1]=1, a[n]=a[n-2]*a[n-1]*n,求a[n]的因子个数 mod 1000000007.  n<=1000000 解题过程: 1.递推式还 ...

  2. mysql 中execute、executeQuery和executeUpdate之间的区别

    在用纯JSP做一个页面报警功能的时候习惯性的用executeQuery来执行SQL语句,结果执行update时就遇到问题,语句能执行,但返回结果出现问题,另外还忽略了executeUpdate的返回值 ...

  3. jq 操作radio,设置选中、获取选中值

    <label><input type="radio" name="sex" value="1">男</labe ...

  4. [蟒蛇菜谱]Python获取任意xml节点的值

    # -*- coding: utf-8 -*- import xml.dom.minidom ELEMENT_NODE = xml.dom.Node.ELEMENT_NODE class Simple ...

  5. bsp STEP

    Web开发不仅现在比较流行,将来也会.我来谈一下最近bsp  application项目的体会吧,属初学者,请各位多多指教. SAP 的web开发方法有很多种,bsp只是其中一种,而bsp开发有可以分 ...

  6. C语言实现双向循环链表

    #include <stdio.h> #include <stdlib.h> #include <string.h> struct list_head { stru ...

  7. javaweb-dbutils2

    package cn.itcast.demo; import java.sql.SQLException;import java.util.Arrays;import java.util.List;i ...

  8. Smart210学习记录----nand flash驱动

    [详解]如何编写Linux下Nand Flash驱动  :http://www.cnblogs.com/linux-rookie/articles/3016990.html 当读写文件请求到来的时候, ...

  9. 修改LR自带的示例程序端口号

    问题:LoadRunner的HP Web Tours 应用程序服务启动不了,提示1080端口被占用的问题 解决方法: 查看占用1080端口的进程 Cmd 窗口输入netstat –ano  找到占用该 ...

  10. [转]设置Android手机以使用ARM Streamline进行性能分析(二)

    原文因为arm社区改版访问不到了,原作者鲍方,原文地址,这篇是从google cache里挖出来的,希望能帮到要对cocos2dx优化的各位   Posted by Fang Bao, Leave C ...