#include "DisparityCostVolumeEstimator.hpp"

#include "DisparityCostVolume.hpp"

#include "stereo_matching/cost_functions.hpp"

#include "helpers/get_option_value.hpp"
#include "helpers/fill_multi_array.hpp" #include <boost/gil/image_view_factory.hpp> namespace doppia
{ using namespace boost;
using namespace boost::gil;
using namespace std; typedef DisparityCostVolume::range_t range_t;
typedef DisparityCostVolume::const_data_2d_view_t const_data_2d_view_t;
typedef DisparityCostVolume::const_data_1d_view_t const_data_1d_view_t;
typedef DisparityCostVolume::const_data_2d_subarray_t const_data_2d_subarray_t;
typedef DisparityCostVolume::const_data_1d_subarray_t const_data_1d_subarray_t;
typedef DisparityCostVolume::data_3d_view_t data_3d_view_t; program_options::options_description DisparityCostVolumeEstimator::get_args_options()
{
program_options::options_description desc("DisparityCostVolumeEstimator options"); const bool simple_block_matcher_options_are_included = true; if(not simple_block_matcher_options_are_included)
{
desc.add_options() ("pixels_matching",
program_options::value<string>()->default_value("sad"),
"pixels matching method: sad, ssd, census or gradient") ("threshold",
program_options::value<float>()->default_value(0.5),
"minimum percent of pixels required to declare a match value between [0,1]") ;
} return desc;
} DisparityCostVolumeEstimator::DisparityCostVolumeEstimator()
: AbstractDisparityCostVolumeEstimator()
{
// this constructor should only be used for unit testing
return;
} DisparityCostVolumeEstimator::DisparityCostVolumeEstimator(const program_options::variables_map &options)
: AbstractDisparityCostVolumeEstimator(options)
{ threshold_percent = get_option_value<float>(options,"threshold"); assert(threshold_percent > 0.0f);
assert(threshold_percent <= 1.0f); return;
} DisparityCostVolumeEstimator::~DisparityCostVolumeEstimator()
{
// nothing to do here
return;
} void DisparityCostVolumeEstimator::compute(gil::gray8c_view_t &left,
gil::gray8c_view_t &right,
DisparityCostVolume &cost_volume)
{
compute_impl(left, right, cost_volume);
return;
} void DisparityCostVolumeEstimator::compute(gil::rgb8c_view_t &left,
gil::rgb8c_view_t &right,
DisparityCostVolume &cost_volume)
{
compute_impl(left, right, cost_volume);
return;
} template <typename ImgView>
void DisparityCostVolumeEstimator::compute_impl( ImgView &left, ImgView &right, DisparityCostVolume &cost_volume)
{ if (pixels_matching_method == "sad")
{
if(first_computation)
{
printf("DisparityCostVolumeEstimator::compute_impl will use sad matching over %zi disparities\n\n",
max_disparity);
}
SadCostFunctionT<uint8_t> pixels_distance;
compute_costs_impl(left, right, pixels_distance, cost_volume);
}
else if (pixels_matching_method == "ssd")
{
if(first_computation)
{
printf("DisparityCostVolumeEstimator::compute_impl will use ssd matching over %zi disparities\n\n",
max_disparity);
}
SsdCostFunction pixels_distance;
compute_costs_impl(left, right, pixels_distance, cost_volume);
}
else
{
printf("DisparityCostVolumeEstimator::compute_impl received an unknow pixels_matching_method value == %s\n",
pixels_matching_method.c_str()); throw std::invalid_argument("DisparityCostVolumeEstimator::compute_impl received an unknow pixels_matching_method");
} first_computation = false; return;
} template <typename ImgView, typename PixelsCostType>
inline void compute_costs_for_disparity(const ImgView &left, const ImgView &right,
PixelsCostType &pixels_distance,
const int disparity,
DisparityCostVolume::data_2d_view_t &disparity_cost_view)
{
typedef typename ImgView::value_type pixel_t;
typedef DisparityCostVolume::data_1d_subarray_t data_1d_subarray_t; // a pixel (x,y) on the left image should be matched on the right image on the range ([0,x],y)
//const int first_right_x = first_left_x - disparity; for(int y=; y < left.height(); y+=)
{
typename ImgView::x_iterator left_row_it = left.x_at(disparity, y);
typename ImgView::x_iterator right_row_it = right.row_begin(y);
data_1d_subarray_t cost_row_subarray = disparity_cost_view[y];
data_1d_subarray_t::iterator cost_it = cost_row_subarray.begin() + disparity;
for(int left_x=disparity; left_x < left.width(); left_x+=, ++left_row_it, ++right_row_it, ++cost_it)
{
const DisparityCostVolume::cost_t pixel_cost = pixels_distance(*left_row_it, *right_row_it);
*cost_it = pixel_cost;
} // end of 'for each row'
} // end of 'for each column' return;
} template <typename ImgView, typename PixelsCostType>
void DisparityCostVolumeEstimator::compute_costs_impl(const ImgView &left, const ImgView &right,
PixelsCostType &pixels_distance,
DisparityCostVolume &cost_volume)
{ typedef typename ImgView::value_type pixel_t;
maximum_cost_per_pixel = pixels_distance.template get_maximum_cost_per_pixel<pixel_t>(); // lazy initialization
this->resize_cost_volume(left.dimensions(), cost_volume); const bool crop_borders = false; if(crop_borders)
{
// FIXME hardcoded values
const int top_bottom_margin = ; // 20 // 10 // pixels
const int left_right_margin = ; //left.width()*0.1; // *0.05 // pixels const int
sub_width = left.width() - *left_right_margin,
sub_height = left.height() - *top_bottom_margin;
const ImgView
left_subview = boost::gil::subimage_view(left,
left_right_margin, top_bottom_margin,
sub_width, sub_height),
right_subview = boost::gil::subimage_view(right,
left_right_margin,top_bottom_margin,
sub_width, sub_height); const int y_min = top_bottom_margin, y_max = left.height() - top_bottom_margin;
const int x_min = left_right_margin, x_max = left.width() - left_right_margin;
data_3d_view_t data = cost_volume.get_costs_views();
data_3d_view_t
data_subview = data[ boost::indices[range_t(y_min, y_max)][range_t(x_min, x_max)][range_t()] ]; // fill the original volumn with zero
fill(cost_volume.get_costs_views(), ); #pragma omp parallel for
for(size_t disparity=; disparity < max_disparity; disparity +=)
{
DisparityCostVolume::data_2d_view_t disparity_slice = data_subview[ boost::indices[range_t()][range_t()][disparity] ];
compute_costs_for_disparity(left_subview, right_subview, pixels_distance, disparity, disparity_slice);
} }
else
{ // for each pixel and each disparity value
#pragma omp parallel for
for(size_t disparity=; disparity < max_disparity; disparity +=)
{
data_3d_view_t data = cost_volume.get_costs_views();
DisparityCostVolume::data_2d_view_t disparity_slice = data[ boost::indices[range_t()][range_t()][disparity] ];
compute_costs_for_disparity(left, right, pixels_distance, disparity, disparity_slice);
} } // end of "if else crop_borders" return;
} } // end of namespace doppia

ImgView这个模版类没有找到

SsdCostFunction、SadCostFunctionT来自cost_functions.hpp,实际上就是具体值怎么计算

DisparityCostVolumeEstimator.cpp的更多相关文章

  1. 使用“Cocos引擎”创建的cpp工程如何在VS中调试Cocos2d-x源码

    前段时间Cocos2d-x更新了一个Cocos引擎,这是一个集合源码,IDE,Studio这一家老小的整合包,我们可以使用这个Cocos引擎来创建我们的项目. 在Cocos2d-x被整合到Cocos引 ...

  2. Json CPP 中文支持与入门示例

    在每一个Json Cpp自带*.cpp文件头加上: #include "stdafx.h" 将Json Cpp对自带的头文件的引用修改为单引号方式,例如json_reader.cp ...

  3. cpp 调用python

    在用cpp调用python时, 出现致命错误: no module named site  ,  原因解释器在搜索路径下没有找到python库.可以在调用Py_Initialize前,调用 Py_Se ...

  4. nginx+fastcgi+c/cpp

    参考:http://github.tiankonguse.com/blog/2015/01/19/cgi-nginx-three/ 跟着做了一遍,然后根据记忆写的,不清楚有没错漏步骤,希望多多评论多多 ...

  5. APM程序分析-ArduCopter.cpp

    该文件是APM的主文件. #define SCHED_TASK(func, rate_hz, max_time_micros) SCHED_TASK_CLASS(Copter, &copter ...

  6. APM程序分析-AC_WPNav.cpp

    APM程序分析 主程序在ArduCopter.cpp的loop()函数. /// advance_wp_target_along_track - move target location along ...

  7. Dev Cpp 输出中文字符问题

    最近 c++ 上机作业,vc++6.0 挂了没法用,只好用 Dev Cpp 先顶替一下,然而在遇到输出中文字符的时候出现了乱码的情况,但这种情况又非常诡异.于是简单了解了一下写成此博客. [写在前面] ...

  8. 【安卓】aidl.exe E 10744 10584 io_delegate.cpp:102] Error while creating directories: Invalid argument

    这几天在使用.aidl文件的时候eclipse的控制台总是爆出如下提示: aidl.exe E 10744 10584 io_delegate.cpp:102] Error while creatin ...

  9. Identify Memory Leaks in Visual CPP Applications —— VLD内存泄漏检测工具

    原文地址:http://www.codeproject.com/Articles/1045847/Identify-Memory-Leaks-in-Visual-CPP-Applications 基于 ...

随机推荐

  1. GreenPlum 大数据平台--介绍

    一,GreenPlum 01,介绍: Greenplum是一种基于PostgreSQL的分布式数据库,其采用shared-nothing架构,主机.操作系统.内存.存储都是自我控制的,不存在共享. 官 ...

  2. vue中promise的使用

    vue中promise的使用 promise是处理异步的利器,在之前的文章<ES6之promise>中,我详细介绍了promise的使用, 在文章<js动画实现&&回 ...

  3. LaTex 2

    LaTex 入门 此时是否安装成功 如果安装成功了LaTeX, 那么在计算机上会多出来LaTeX的编译器, LaTex Live 安装包在计算机上安装了多个不同的编译器, 有latex, xelate ...

  4. HDU 1800——Flying to the Mars——————【字符串哈希】

    Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  5. 从零开始写C# MVC框架之--- 项目结构

    框架总分2个项目:Web开发项目.帮助类项目 (ZyCommon.Zy.Utilities) 1.ZyCommon,是Web开发项目结构.新建一个空解决方案,再建Data.Service.ZyWeb解 ...

  6. springboot和mybatis集成,自动生成model、mapper,增加mybatis分页功能

    整体思路和http://www.cnblogs.com/mahuan2/p/5859921.html相同. 主要讲maven的pom.xml和一些配置变化,详细说明. 软件简介 Spring是一个流行 ...

  7. 【学习笔记】Java中生成对象的5中方法

    概述:本文介绍以下java五种创建对象的方式: 1.用new语句创建对象,这是最常用的创建对象的方式. 2.使用Class类的newInstance方法 3.运用反射手段,调用java.lang.re ...

  8. Java笔记之Scanner先读取一个数字,在读取一行字符串方法分析

    问题:大家在学习Java读取数据的时候一般都是使用Scanner方法读取数据,但是其中有一个小问题大家可能不知道, 就是我们在使用scanner的时候如果你先读取一个数字,在读取一行带有空格的字符串, ...

  9. 前端参数统一校验工具类ValidParamUtils

    1,前端参数不可信,对于后端开发人员来说应该是一条铁律,所以对于前端参数的校验,必不可少,而统一的前端参数校验工具,对我们进行参数校验起到事半功倍的效果 2,统一参数校验工具ValidParamUti ...

  10. Django组件——cookie与session

    一.会话跟踪技术 1.什么是会话跟踪技术 可以把会话理解为客户端与服务器之间的一次会晤,在一次会晤中可能会包含多次请求和响应. 在JavaWeb中,客户向某一服务器发出第一个请求开始,会话就开始了,直 ...