Commit ee104c27 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

added gpu implementation of constant space belief propagation stereo matching.

some refactoring of StereoBeliefPropagation.
parent 53057afc
...@@ -375,34 +375,28 @@ namespace cv ...@@ -375,34 +375,28 @@ namespace cv
GpuMat minSSD, leBuf, riBuf; GpuMat minSSD, leBuf, riBuf;
}; };
//////////////////////// StereoBeliefPropagation_GPU ///////////////////////// ////////////////////////// StereoBeliefPropagation ///////////////////////////
class CV_EXPORTS StereoBeliefPropagation_GPU class CV_EXPORTS StereoBeliefPropagation
{ {
public: public:
enum { MSG_TYPE_AUTO,
MSG_TYPE_FLOAT,
MSG_TYPE_SHORT_SCALE_AUTO,
MSG_TYPE_SHORT_SCALE_MANUAL };
enum { DEFAULT_NDISP = 64 }; enum { DEFAULT_NDISP = 64 };
enum { DEFAULT_ITERS = 5 }; enum { DEFAULT_ITERS = 5 };
enum { DEFAULT_LEVELS = 5 }; enum { DEFAULT_LEVELS = 5 };
//! the default constructor //! the default constructor
explicit StereoBeliefPropagation_GPU(int ndisp = DEFAULT_NDISP, explicit StereoBeliefPropagation(int ndisp = DEFAULT_NDISP,
int iters = DEFAULT_ITERS, int iters = DEFAULT_ITERS,
int levels = DEFAULT_LEVELS, int levels = DEFAULT_LEVELS,
int msg_type = MSG_TYPE_AUTO, int msg_type = CV_32F);
float msg_scale = 1.0f);
//! the full constructor taking the number of disparities, number of BP iterations on each level, //! the full constructor taking the number of disparities, number of BP iterations on each level,
//! number of levels, truncation of data cost, data weight, //! number of levels, truncation of data cost, data weight,
//! truncation of discontinuity cost and discontinuity single jump //! truncation of discontinuity cost and discontinuity single jump
StereoBeliefPropagation_GPU(int ndisp, int iters, int levels, StereoBeliefPropagation(int ndisp, int iters, int levels,
float max_data_term, float data_weight, float max_data_term, float data_weight,
float max_disc_term, float disc_single_jump, float max_disc_term, float disc_single_jump,
int msg_type = MSG_TYPE_AUTO, int msg_type = CV_32F);
float msg_scale = 1.0f);
//! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair, //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair,
//! if disparity is empty output type will be CV_16S else output type will be disparity.type(). //! if disparity is empty output type will be CV_16S else output type will be disparity.type().
...@@ -410,11 +404,6 @@ namespace cv ...@@ -410,11 +404,6 @@ namespace cv
//! Acync version //! Acync version
void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, const Stream& stream); void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, const Stream& stream);
//! Some heuristics that tries to estmate
//! if current GPU will be faster then CPU in this algorithm.
//! It queries current active device.
static bool checkIfGpuCallReasonable();
int ndisp; int ndisp;
...@@ -427,12 +416,67 @@ namespace cv ...@@ -427,12 +416,67 @@ namespace cv
float disc_single_jump; float disc_single_jump;
int msg_type; int msg_type;
float msg_scale;
private: private:
GpuMat u, d, l, r, u2, d2, l2, r2; GpuMat u, d, l, r, u2, d2, l2, r2;
std::vector<GpuMat> datas; std::vector<GpuMat> datas;
GpuMat out; GpuMat out;
}; };
/////////////////////////// StereoConstantSpaceBP ///////////////////////////
class CV_EXPORTS StereoConstantSpaceBP
{
public:
enum { DEFAULT_NDISP = 64 };
enum { DEFAULT_ITERS = 5 };
enum { DEFAULT_LEVELS = 5 };
enum { DEFAULT_NR_PLANE = 2 };
//! the default constructor
explicit StereoConstantSpaceBP(int ndisp = DEFAULT_NDISP,
int iters = DEFAULT_ITERS,
int levels = DEFAULT_LEVELS,
int nr_plane = DEFAULT_NR_PLANE,
int msg_type = CV_32F);
//! the full constructor taking the number of disparities, number of BP iterations on each level,
//! number of levels, number of active disparity on the first level, truncation of data cost, data weight,
//! truncation of discontinuity cost and discontinuity single jump
StereoConstantSpaceBP(int ndisp, int iters, int levels, int nr_plane,
float max_data_term, float data_weight, float max_disc_term, float disc_single_jump,
int msg_type = CV_32F);
//! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair,
//! if disparity is empty output type will be CV_16S else output type will be disparity.type().
void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity);
//! Acync version
void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, const Stream& stream);
int ndisp;
int iters;
int levels;
int nr_plane;
float max_data_term;
float data_weight;
float max_disc_term;
float disc_single_jump;
int msg_type;
private:
GpuMat u[2], d[2], l[2], r[2];
GpuMat disp_selected_pyr[2];
GpuMat data_cost;
GpuMat data_cost_selected;
GpuMat temp1, temp2;
GpuMat out;
};
} }
//! Speckle filtering - filters small connected components on diparity image. //! Speckle filtering - filters small connected components on diparity image.
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment