mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
337 lines
13 KiB
337 lines
13 KiB
12 years ago
|
Stereo Correspondence
|
||
|
=====================
|
||
14 years ago
|
|
||
|
.. highlight:: cpp
|
||
|
|
||
11 years ago
|
.. note::
|
||
13 years ago
|
|
||
11 years ago
|
* A basic stereo matching example can be found at opencv_source_code/samples/gpu/stereo_match.cpp
|
||
|
* A stereo matching example using several GPU's can be found at opencv_source_code/samples/gpu/stereo_multi.cpp
|
||
|
* A stereo matching example using several GPU's and driver API can be found at opencv_source_code/samples/gpu/driver_api_stereo_multi.cpp
|
||
13 years ago
|
|
||
12 years ago
|
gpu::StereoBM
|
||
|
-------------
|
||
|
.. ocv:class:: gpu::StereoBM : public cv::StereoBM
|
||
14 years ago
|
|
||
13 years ago
|
Class computing stereo correspondence (disparity map) using the block matching algorithm. ::
|
||
14 years ago
|
|
||
12 years ago
|
.. seealso:: :ocv:class:`StereoBM`
|
||
13 years ago
|
|
||
14 years ago
|
|
||
|
|
||
12 years ago
|
gpu::createStereoBM
|
||
|
-------------------
|
||
|
Creates StereoBM object.
|
||
14 years ago
|
|
||
12 years ago
|
.. ocv:function:: Ptr<gpu::StereoBM> gpu::createStereoBM(int numDisparities = 64, int blockSize = 19)
|
||
14 years ago
|
|
||
12 years ago
|
:param numDisparities: the disparity search range. For each pixel algorithm will find the best disparity from 0 (default minimum disparity) to ``numDisparities``. The search range can then be shifted by changing the minimum disparity.
|
||
14 years ago
|
|
||
12 years ago
|
:param blockSize: the linear size of the blocks compared by the algorithm. The size should be odd (as the block is centered at the current pixel). Larger block size implies smoother, though less accurate disparity map. Smaller block size gives more detailed disparity map, but there is higher chance for algorithm to find a wrong correspondence.
|
||
14 years ago
|
|
||
13 years ago
|
|
||
14 years ago
|
|
||
|
gpu::StereoBeliefPropagation
|
||
|
----------------------------
|
||
12 years ago
|
.. ocv:class:: gpu::StereoBeliefPropagation : public cv::StereoMatcher
|
||
14 years ago
|
|
||
14 years ago
|
Class computing stereo correspondence using the belief propagation algorithm. ::
|
||
14 years ago
|
|
||
12 years ago
|
class CV_EXPORTS StereoBeliefPropagation : public cv::StereoMatcher
|
||
14 years ago
|
{
|
||
|
public:
|
||
12 years ago
|
using cv::StereoMatcher::compute;
|
||
14 years ago
|
|
||
12 years ago
|
virtual void compute(InputArray left, InputArray right, OutputArray disparity, Stream& stream) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
//! version for user specified data term
|
||
|
virtual void compute(InputArray data, OutputArray disparity, Stream& stream = Stream::Null()) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
//! number of BP iterations on each level
|
||
|
virtual int getNumIters() const = 0;
|
||
|
virtual void setNumIters(int iters) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
//! number of levels
|
||
|
virtual int getNumLevels() const = 0;
|
||
|
virtual void setNumLevels(int levels) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
//! truncation of data cost
|
||
|
virtual double getMaxDataTerm() const = 0;
|
||
|
virtual void setMaxDataTerm(double max_data_term) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
//! data weight
|
||
|
virtual double getDataWeight() const = 0;
|
||
|
virtual void setDataWeight(double data_weight) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
//! truncation of discontinuity cost
|
||
|
virtual double getMaxDiscTerm() const = 0;
|
||
|
virtual void setMaxDiscTerm(double max_disc_term) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
//! discontinuity single jump
|
||
|
virtual double getDiscSingleJump() const = 0;
|
||
|
virtual void setDiscSingleJump(double disc_single_jump) = 0;
|
||
|
|
||
|
virtual int getMsgType() const = 0;
|
||
|
virtual void setMsgType(int msg_type) = 0;
|
||
|
|
||
|
static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels);
|
||
14 years ago
|
};
|
||
14 years ago
|
|
||
12 years ago
|
|
||
14 years ago
|
The class implements algorithm described in [Felzenszwalb2006]_ . It can compute own data cost (using a truncated linear model) or use a user-provided data cost.
|
||
14 years ago
|
|
||
14 years ago
|
.. note::
|
||
14 years ago
|
|
||
14 years ago
|
``StereoBeliefPropagation`` requires a lot of memory for message storage:
|
||
14 years ago
|
|
||
14 years ago
|
.. math::
|
||
14 years ago
|
|
||
14 years ago
|
width \_ step \cdot height \cdot ndisp \cdot 4 \cdot (1 + 0.25)
|
||
14 years ago
|
|
||
14 years ago
|
and for data cost storage:
|
||
14 years ago
|
|
||
14 years ago
|
.. math::
|
||
14 years ago
|
|
||
14 years ago
|
width\_step \cdot height \cdot ndisp \cdot (1 + 0.25 + 0.0625 + \dotsm + \frac{1}{4^{levels}})
|
||
|
|
||
|
``width_step`` is the number of bytes in a line including padding.
|
||
14 years ago
|
|
||
12 years ago
|
``StereoBeliefPropagation`` uses a truncated linear model for the data cost and discontinuity terms:
|
||
14 years ago
|
|
||
12 years ago
|
.. math::
|
||
13 years ago
|
|
||
12 years ago
|
DataCost = data \_ weight \cdot \min ( \lvert Img_Left(x,y)-Img_Right(x-d,y) \rvert , max \_ data \_ term)
|
||
14 years ago
|
|
||
12 years ago
|
.. math::
|
||
14 years ago
|
|
||
12 years ago
|
DiscTerm = \min (disc \_ single \_ jump \cdot \lvert f_1-f_2 \rvert , max \_ disc \_ term)
|
||
14 years ago
|
|
||
12 years ago
|
For more details, see [Felzenszwalb2006]_.
|
||
14 years ago
|
|
||
12 years ago
|
By default, ``StereoBeliefPropagation`` uses floating-point arithmetics and the ``CV_32FC1`` type for messages. But it can also use fixed-point arithmetics and the ``CV_16SC1`` message type for better performance. To avoid an overflow in this case, the parameters must satisfy the following requirement:
|
||
14 years ago
|
|
||
12 years ago
|
.. math::
|
||
14 years ago
|
|
||
12 years ago
|
10 \cdot 2^{levels-1} \cdot max \_ data \_ term < SHRT \_ MAX
|
||
13 years ago
|
|
||
12 years ago
|
.. seealso:: :ocv:class:`StereoMatcher`
|
||
14 years ago
|
|
||
|
|
||
|
|
||
12 years ago
|
gpu::createStereoBeliefPropagation
|
||
|
----------------------------------
|
||
|
Creates StereoBeliefPropagation object.
|
||
14 years ago
|
|
||
12 years ago
|
.. ocv:function:: Ptr<gpu::StereoBeliefPropagation> gpu::createStereoBeliefPropagation(int ndisp = 64, int iters = 5, int levels = 5, int msg_type = CV_32F)
|
||
14 years ago
|
|
||
12 years ago
|
:param ndisp: Number of disparities.
|
||
14 years ago
|
|
||
12 years ago
|
:param iters: Number of BP iterations on each level.
|
||
14 years ago
|
|
||
12 years ago
|
:param levels: Number of levels.
|
||
14 years ago
|
|
||
12 years ago
|
:param msg_type: Type for messages. ``CV_16SC1`` and ``CV_32FC1`` types are supported.
|
||
14 years ago
|
|
||
13 years ago
|
|
||
|
|
||
14 years ago
|
gpu::StereoBeliefPropagation::estimateRecommendedParams
|
||
12 years ago
|
-------------------------------------------------------
|
||
13 years ago
|
Uses a heuristic method to compute the recommended parameters ( ``ndisp``, ``iters`` and ``levels`` ) for the specified image size ( ``width`` and ``height`` ).
|
||
|
|
||
|
.. ocv:function:: void gpu::StereoBeliefPropagation::estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels)
|
||
14 years ago
|
|
||
14 years ago
|
|
||
|
|
||
12 years ago
|
gpu::StereoBeliefPropagation::compute
|
||
|
-------------------------------------
|
||
|
Enables the stereo correspondence operator that finds the disparity for the specified data cost.
|
||
14 years ago
|
|
||
12 years ago
|
.. ocv:function:: void gpu::StereoBeliefPropagation::compute(InputArray data, OutputArray disparity, Stream& stream = Stream::Null())
|
||
14 years ago
|
|
||
14 years ago
|
:param data: User-specified data cost, a matrix of ``msg_type`` type and ``Size(<image columns>*ndisp, <image rows>)`` size.
|
||
14 years ago
|
|
||
14 years ago
|
:param disparity: Output disparity map. If ``disparity`` is empty, the output type is ``CV_16SC1`` . Otherwise, the type is retained.
|
||
14 years ago
|
|
||
14 years ago
|
:param stream: Stream for the asynchronous version.
|
||
14 years ago
|
|
||
13 years ago
|
|
||
|
|
||
14 years ago
|
gpu::StereoConstantSpaceBP
|
||
|
--------------------------
|
||
12 years ago
|
.. ocv:class:: gpu::StereoConstantSpaceBP : public gpu::StereoBeliefPropagation
|
||
14 years ago
|
|
||
14 years ago
|
Class computing stereo correspondence using the constant space belief propagation algorithm. ::
|
||
14 years ago
|
|
||
12 years ago
|
class CV_EXPORTS StereoConstantSpaceBP : public gpu::StereoBeliefPropagation
|
||
14 years ago
|
{
|
||
|
public:
|
||
12 years ago
|
//! number of active disparity on the first level
|
||
|
virtual int getNrPlane() const = 0;
|
||
|
virtual void setNrPlane(int nr_plane) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
virtual bool getUseLocalInitDataCost() const = 0;
|
||
|
virtual void setUseLocalInitDataCost(bool use_local_init_data_cost) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels, int& nr_plane);
|
||
14 years ago
|
};
|
||
14 years ago
|
|
||
14 years ago
|
|
||
13 years ago
|
The class implements algorithm described in [Yang2010]_. ``StereoConstantSpaceBP`` supports both local minimum and global minimum data cost initialization algorithms. For more details, see the paper mentioned above. By default, a local algorithm is used. To enable a global algorithm, set ``use_local_init_data_cost`` to ``false`` .
|
||
13 years ago
|
|
||
14 years ago
|
``StereoConstantSpaceBP`` uses a truncated linear model for the data cost and discontinuity terms:
|
||
14 years ago
|
|
||
|
.. math::
|
||
|
|
||
14 years ago
|
DataCost = data \_ weight \cdot \min ( \lvert I_2-I_1 \rvert , max \_ data \_ term)
|
||
14 years ago
|
|
||
14 years ago
|
.. math::
|
||
14 years ago
|
|
||
14 years ago
|
DiscTerm = \min (disc \_ single \_ jump \cdot \lvert f_1-f_2 \rvert , max \_ disc \_ term)
|
||
14 years ago
|
|
||
14 years ago
|
For more details, see [Yang2010]_.
|
||
14 years ago
|
|
||
13 years ago
|
By default, ``StereoConstantSpaceBP`` uses floating-point arithmetics and the ``CV_32FC1`` type for messages. But it can also use fixed-point arithmetics and the ``CV_16SC1`` message type for better performance. To avoid an overflow in this case, the parameters must satisfy the following requirement:
|
||
14 years ago
|
|
||
|
.. math::
|
||
|
|
||
14 years ago
|
10 \cdot 2^{levels-1} \cdot max \_ data \_ term < SHRT \_ MAX
|
||
14 years ago
|
|
||
13 years ago
|
|
||
|
|
||
12 years ago
|
gpu::createStereoConstantSpaceBP
|
||
|
--------------------------------
|
||
|
Creates StereoConstantSpaceBP object.
|
||
13 years ago
|
|
||
12 years ago
|
.. ocv:function:: Ptr<gpu::StereoConstantSpaceBP> gpu::createStereoConstantSpaceBP(int ndisp = 128, int iters = 8, int levels = 4, int nr_plane = 4, int msg_type = CV_32F)
|
||
|
|
||
|
:param ndisp: Number of disparities.
|
||
14 years ago
|
|
||
12 years ago
|
:param iters: Number of BP iterations on each level.
|
||
14 years ago
|
|
||
12 years ago
|
:param levels: Number of levels.
|
||
14 years ago
|
|
||
12 years ago
|
:param nr_plane: Number of disparity levels on the first level.
|
||
14 years ago
|
|
||
12 years ago
|
:param msg_type: Type for messages. ``CV_16SC1`` and ``CV_32FC1`` types are supported.
|
||
14 years ago
|
|
||
|
|
||
|
|
||
12 years ago
|
gpu::StereoConstantSpaceBP::estimateRecommendedParams
|
||
|
-----------------------------------------------------
|
||
|
Uses a heuristic method to compute parameters (ndisp, iters, levelsand nrplane) for the specified image size (widthand height).
|
||
14 years ago
|
|
||
12 years ago
|
.. ocv:function:: void gpu::StereoConstantSpaceBP::estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels, int& nr_plane)
|
||
14 years ago
|
|
||
13 years ago
|
|
||
|
|
||
14 years ago
|
gpu::DisparityBilateralFilter
|
||
|
-----------------------------
|
||
12 years ago
|
.. ocv:class:: gpu::DisparityBilateralFilter : public cv::Algorithm
|
||
14 years ago
|
|
||
13 years ago
|
Class refining a disparity map using joint bilateral filtering. ::
|
||
14 years ago
|
|
||
12 years ago
|
class CV_EXPORTS DisparityBilateralFilter : public cv::Algorithm
|
||
14 years ago
|
{
|
||
|
public:
|
||
12 years ago
|
//! the disparity map refinement operator. Refine disparity map using joint bilateral filtering given a single color image.
|
||
|
//! disparity must have CV_8U or CV_16S type, image must have CV_8UC1 or CV_8UC3 type.
|
||
|
virtual void apply(InputArray disparity, InputArray image, OutputArray dst, Stream& stream = Stream::Null()) = 0;
|
||
|
|
||
|
virtual int getNumDisparities() const = 0;
|
||
|
virtual void setNumDisparities(int numDisparities) = 0;
|
||
|
|
||
|
virtual int getRadius() const = 0;
|
||
|
virtual void setRadius(int radius) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
virtual int getNumIters() const = 0;
|
||
|
virtual void setNumIters(int iters) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
//! truncation of data continuity
|
||
|
virtual double getEdgeThreshold() const = 0;
|
||
|
virtual void setEdgeThreshold(double edge_threshold) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
//! truncation of disparity continuity
|
||
|
virtual double getMaxDiscThreshold() const = 0;
|
||
|
virtual void setMaxDiscThreshold(double max_disc_threshold) = 0;
|
||
14 years ago
|
|
||
12 years ago
|
//! filter range sigma
|
||
|
virtual double getSigmaRange() const = 0;
|
||
|
virtual void setSigmaRange(double sigma_range) = 0;
|
||
14 years ago
|
};
|
||
14 years ago
|
|
||
14 years ago
|
|
||
14 years ago
|
The class implements [Yang2010]_ algorithm.
|
||
14 years ago
|
|
||
13 years ago
|
|
||
|
|
||
12 years ago
|
gpu::createDisparityBilateralFilter
|
||
|
-----------------------------------
|
||
|
Creates DisparityBilateralFilter object.
|
||
14 years ago
|
|
||
12 years ago
|
.. ocv:function:: Ptr<gpu::DisparityBilateralFilter> gpu::createDisparityBilateralFilter(int ndisp = 64, int radius = 3, int iters = 1)
|
||
14 years ago
|
|
||
14 years ago
|
:param ndisp: Number of disparities.
|
||
14 years ago
|
|
||
14 years ago
|
:param radius: Filter radius.
|
||
14 years ago
|
|
||
14 years ago
|
:param iters: Number of iterations.
|
||
14 years ago
|
|
||
|
|
||
|
|
||
12 years ago
|
gpu::DisparityBilateralFilter::apply
|
||
|
------------------------------------
|
||
13 years ago
|
Refines a disparity map using joint bilateral filtering.
|
||
14 years ago
|
|
||
12 years ago
|
.. ocv:function:: void gpu::DisparityBilateralFilter::apply(InputArray disparity, InputArray image, OutputArray dst, Stream& stream = Stream::Null())
|
||
14 years ago
|
|
||
14 years ago
|
:param disparity: Input disparity map. ``CV_8UC1`` and ``CV_16SC1`` types are supported.
|
||
14 years ago
|
|
||
14 years ago
|
:param image: Input image. ``CV_8UC1`` and ``CV_8UC3`` types are supported.
|
||
14 years ago
|
|
||
14 years ago
|
:param dst: Destination disparity map. It has the same size and type as ``disparity`` .
|
||
14 years ago
|
|
||
14 years ago
|
:param stream: Stream for the asynchronous version.
|
||
14 years ago
|
|
||
13 years ago
|
|
||
|
|
||
12 years ago
|
gpu::reprojectImageTo3D
|
||
|
-----------------------
|
||
|
Reprojects a disparity image to 3D space.
|
||
14 years ago
|
|
||
12 years ago
|
.. ocv:function:: void gpu::reprojectImageTo3D(InputArray disp, OutputArray xyzw, InputArray Q, int dst_cn = 4, Stream& stream = Stream::Null())
|
||
14 years ago
|
|
||
12 years ago
|
:param disp: Input disparity image. ``CV_8U`` and ``CV_16S`` types are supported.
|
||
14 years ago
|
|
||
12 years ago
|
:param xyzw: Output 3- or 4-channel floating-point image of the same size as ``disp`` . Each element of ``xyzw(x,y)`` contains 3D coordinates ``(x,y,z)`` or ``(x,y,z,1)`` of the point ``(x,y)`` , computed from the disparity map.
|
||
14 years ago
|
|
||
12 years ago
|
:param Q: :math:`4 \times 4` perspective transformation matrix that can be obtained via :ocv:func:`stereoRectify` .
|
||
14 years ago
|
|
||
12 years ago
|
:param dst_cn: The number of channels for output image. Can be 3 or 4.
|
||
14 years ago
|
|
||
12 years ago
|
:param stream: Stream for the asynchronous version.
|
||
14 years ago
|
|
||
12 years ago
|
.. seealso:: :ocv:func:`reprojectImageTo3D`
|
||
13 years ago
|
|
||
|
|
||
14 years ago
|
|
||
12 years ago
|
gpu::drawColorDisp
|
||
|
------------------
|
||
|
Colors a disparity image.
|
||
14 years ago
|
|
||
12 years ago
|
.. ocv:function:: void gpu::drawColorDisp(InputArray src_disp, OutputArray dst_disp, int ndisp, Stream& stream = Stream::Null())
|
||
14 years ago
|
|
||
12 years ago
|
:param src_disp: Source disparity image. ``CV_8UC1`` and ``CV_16SC1`` types are supported.
|
||
14 years ago
|
|
||
12 years ago
|
:param dst_disp: Output disparity image. It has the same size as ``src_disp`` . The type is ``CV_8UC4`` in ``BGRA`` format (alpha = 255).
|
||
14 years ago
|
|
||
12 years ago
|
:param ndisp: Number of disparities.
|
||
13 years ago
|
|
||
14 years ago
|
:param stream: Stream for the asynchronous version.
|
||
14 years ago
|
|
||
12 years ago
|
This function draws a colored disparity map by converting disparity values from ``[0..ndisp)`` interval first to ``HSV`` color space (where different disparity values correspond to different hues) and then converting the pixels to ``RGB`` for visualization.
|
||
13 years ago
|
|
||
|
|
||
|
|
||
14 years ago
|
.. [Felzenszwalb2006] Pedro F. Felzenszwalb algorithm [Pedro F. Felzenszwalb and Daniel P. Huttenlocher. *Efficient belief propagation for early vision*. International Journal of Computer Vision, 70(1), October 2006
|
||
|
.. [Yang2010] Q. Yang, L. Wang, and N. Ahuja. *A constant-space belief propagation algorithm for stereo matching*. In CVPR, 2010.
|