立体匹配:关于用OpenCV彩色化middlebury网站给定的视差
2016-03-17 13:42
471 查看
#include "XYZ.h" void readPFM(Mat_<float> &disp, float &scale, string path) { //关于将Mat见我的另外一篇博客: ifstream in(path, ios_base::binary); int cols; int rows; char tmp[10]; in.get(tmp, 10, '\n'); in.get();//文件头 in.get(tmp, 10, ' '); in.get(); cols = atoi(tmp);//列数 in.get(tmp, 10, '\n'); in.get(); rows = atoi(tmp); //行数 in.get(tmp, 10, '\n'); in.get(); scale = atof(tmp);//缩放因子 disp.create(rows, cols); for (int i = disp.rows - 1; i >= 0; i--)//因为存储是从最后行开始存储的 for (int j = 0; 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); for (int i = 0; i < disp.rows; i++) for (int j = 0; 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)[2] = __max(0, __min(255, (int)(round(255 * (1.5 - 4 * fabs(x - .75)))))); (*xxx)[1] = __max(0, __min(255, (int)(round(255 * (1.5 - 4 * fabs(x - .5)))))); (*xxx)[0] = __max(0, __min(255, (int)(round(255 * (1.5 - 4 * fabs(x - .25)))))); } else (*xxx) = Vec3b(0, 0, 0); } } void dyeDisp_one(string dir) { string calibpath = dir + "/calib.txt"; string disppath = dir + "/disp0GT.pfm"; string colordisppath = dir + "/disp0GT.png"; //1.读取极值视差 float dmin = 0; float dmax = 0; char line[1000]; float f; FILE *fp = fopen(calibpath.c_str(), "r"); while (fgets(line, sizeof line, fp) != NULL) { if (sscanf(line, " vmin= %f", &f) == 1) dmin = f; if (sscanf(line, " vmax= %f", &f) == 1) 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"); for (int i = 0; i < dirs.size(); i++) dyeDisp_one(dirs[i]); } void main() { dyeDisp_dir(); }
View Code
相关文章推荐
- 可以免费自学编程的12个网站
- Html5_CSS_JS15个最佳教程网站和博客
- Kafka 架构原理、应用场景
- 关于大型网站技术演进的思考(一)--存储的瓶颈(1)
- KVM原理与架构系列之一 概念篇
- 分布式还是混合式? 谈CDN架构对服务质量的影响
- CC2640软件架构
- 免费的论文查重网站
- StackOverflow 这么大,它的架构是怎么样的?
- 标准web架构分层
- 大型分布式网站架构技术总结
- 理解RESTful架构
- 手机访问PC网站自动跳转到手机网站代码
- 【Java80小白建站系列】4.网站备案
- Spark1.0.0 运行架构基本概念
- 2月份处理钓鱼网站3799个:61.94%使用.com域名
- 大型网站常用优化技术
- 配置高可用的Hadoop平台
- HaProxy+Keepalived+Mycat高可用群集配置
- 网站更新对收录、排名的影响与解决方法