The class also performs pre- and post-filtering steps: Sobel pre-filtering (if ``PREFILTER_XSOBEL`` flag is set) and low textureness filtering (if ``averageTexThreshols > 0`` ). If ``avergeTexThreshold = 0`` , low textureness filtering is disabled. Otherwise, the disparity is set to 0 in each point ``(x, y)`` , where for the left image
..math::
\sum HorizontalGradiensInWindow(x, y, winSize) < (winSize \cdot winSize) \cdot avergeTexThreshold
This means that the input left image is low textured.
..ocv:function:: gpu::StereoBM_GPU::StereoBM_GPU(int preset, int ndisparities = DEFAULT_NDISP, int winSize = DEFAULT_WINSZ)
:param preset:Parameter presetting:
gpu::createStereoBM
-------------------
Creates StereoBM object.
* **BASIC_PRESET** Basic mode without pre-processing.
..ocv:function:: Ptr<gpu::StereoBM> gpu::createStereoBM(int numDisparities = 64, int blockSize = 19)
* **PREFILTER_XSOBEL** Sobel pre-filtering mode.
: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.
:param ndisparities:Number of disparities. It must be a multiple of 8 and less or equal to 256.
:param winSize:Block size.
gpu::StereoBM_GPU::operator ()
----------------------------------
Enables the stereo correspondence operator that finds the disparity for the specified rectified stereo pair.
: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.
gpu::StereoBeliefPropagation
----------------------------
..ocv:class:: gpu::StereoBeliefPropagation
..ocv:class:: gpu::StereoBeliefPropagation : public cv::StereoMatcher
Class computing stereo correspondence using the belief propagation algorithm. ::
class StereoBeliefPropagation
class CV_EXPORTS StereoBeliefPropagation : public cv::StereoMatcher
{
public:
enum { DEFAULT_NDISP = 64 };
enum { DEFAULT_ITERS = 5 };
enum { DEFAULT_LEVELS = 5 };
using cv::StereoMatcher::compute;
static void estimateRecommendedParams(int width, int height,
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.
..note::
@ -152,71 +92,57 @@ The class implements algorithm described in [Felzenszwalb2006]_ . It can compute
``width_step`` is the number of bytes in a line including padding.
``StereoBeliefPropagation`` uses a truncated linear model for the data cost and discontinuity terms:
Enables the :ocv:class:`gpu::StereoBeliefPropagation` constructors.
..ocv:function:: gpu::StereoBeliefPropagation::StereoBeliefPropagation(int ndisp = DEFAULT_NDISP, int iters = DEFAULT_ITERS, int levels = DEFAULT_LEVELS, int msg_type = CV_32F)
..ocv:function:: gpu::StereoBeliefPropagation::StereoBeliefPropagation(int ndisp, int iters, int levels, float max_data_term, float data_weight, float max_disc_term, float disc_single_jump, int msg_type = CV_32F)
:param ndisp:Number of disparities.
:param iters:Number of BP iterations on each level.
DataCost = data \_ weight \cdot \min ( \lvert Img_Left(x,y)-Img_Right(x-d,y) \rvert , max \_ data \_ term)
:param levels:Number of levels.
..math::
:param max_data_term:Threshold for data cost truncation.
DiscTerm = \min (disc \_ single \_ jump \cdot \lvert f_1-f_2 \rvert , max \_ disc \_ term)
:param data_weight:Data weight.
For more details, see [Felzenszwalb2006]_.
:param max_disc_term:Threshold for discontinuity truncation.
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:
:param disc_single_jump:Discontinuity single jump.
..math::
:param msg_type:Type for messages. ``CV_16SC1`` and ``CV_32FC1`` types are supported.
10 \cdot 2^{levels-1} \cdot max \_ data \_ term < SHRT \_ MAX
``StereoBeliefPropagation`` uses a truncated linear model for the data cost and discontinuity terms:
..seealso:::ocv:class:`StereoMatcher`
..math::
DataCost = data \_ weight \cdot \min ( \lvert Img_Left(x,y)-Img_Right(x-d,y) \rvert , max \_ data \_ term)
..math::
gpu::createStereoBeliefPropagation
----------------------------------
Creates StereoBeliefPropagation object.
DiscTerm = \min (disc \_ single \_ jump \cdot \lvert f_1-f_2 \rvert , max \_ disc \_ term)
..ocv:function:: Ptr<gpu::StereoBeliefPropagation> gpu::createStereoBeliefPropagation(int ndisp = 64, int iters = 5, int levels = 5, int msg_type = CV_32F)
For more details, see [Felzenszwalb2006]_.
:param ndisp:Number of disparities.
By default, :ocv:class:`gpu::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:
:param iters:Number of BP iterations on each level.
..math::
:param levels:Number of levels.
10 \cdot 2^{levels-1} \cdot max \_ data \_ term < SHRT \_ MAX
:param msg_type:Type for messages. ``CV_16SC1`` and ``CV_32FC1`` types are supported.
Uses a heuristic method to compute the recommended parameters ( ``ndisp``, ``iters`` and ``levels`` ) for the specified image size ( ``width`` and ``height`` ).
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`` .
Enables the :ocv:class:`gpu::StereoConstantSpaceBP` constructors.
..ocv:function:: gpu::StereoConstantSpaceBP::StereoConstantSpaceBP(int ndisp = DEFAULT_NDISP, int iters = DEFAULT_ITERS, int levels = DEFAULT_LEVELS, int nr_plane = DEFAULT_NR_PLANE, int msg_type = CV_32F)
..ocv:function:: gpu::StereoConstantSpaceBP::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 min_disp_th = 0, int msg_type = CV_32F)
:param ndisp:Number of disparities.
:param iters:Number of BP iterations on each level.
:param levels:Number of levels.
:param nr_plane:Number of disparity levels on the first level.
:param max_data_term:Truncation of data cost.
:param data_weight:Data weight.
:param max_disc_term:Truncation of discontinuity.
:param disc_single_jump:Discontinuity single jump.
:param min_disp_th:Minimal disparity threshold.
:param msg_type:Type for messages. ``CV_16SC1`` and ``CV_32FC1`` types are supported.
``StereoConstantSpaceBP`` uses a truncated linear model for the data cost and discontinuity terms:
..math::
@ -331,54 +194,65 @@ By default, ``StereoConstantSpaceBP`` uses floating-point arithmetics and the ``
:param msg_type:Type for messages. ``CV_16SC1`` and ``CV_32FC1`` types are supported.
:param left:Left image. ``CV_8UC1`` , ``CV_8UC3`` and ``CV_8UC4`` types are supported.
:param right:Right image with the same size and the same type as the left one.
:param disparity:Output disparity map. If ``disparity`` is empty, the output type is ``CV_16SC1`` . Otherwise, the output type is ``disparity.type()`` .
..ocv:function:: void gpu::reprojectImageTo3D(InputArray disp, OutputArray xyzw, InputArray Q, int dst_cn = 4, Stream& stream = Stream::Null())
:param src_disp:Source disparity image. ``CV_8UC1`` and ``CV_16SC1`` types are supported.
:param disp:Input disparity image. ``CV_8U`` and ``CV_16S`` types are supported.
:param dst_disp:Output disparity image. It has the same size as ``src_disp`` . The type is ``CV_8UC4`` in ``BGRA`` format (alpha = 255).
: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.
:param ndisp:Number of disparities.
:param Q::math:`4 \times 4` perspective transformation matrix that can be obtained via :ocv:func:`stereoRectify` .
:param stream:Stream for the asynchronous version.
:param dst_cn:The number of channels for output image. Can be 3 or 4.
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.
:param stream:Stream for the asynchronous version.
..seealso:::ocv:func:`reprojectImageTo3D`
gpu::reprojectImageTo3D
---------------------------
Reprojects a disparity image to 3D space.
..ocv:function:: void gpu::reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q, int dst_cn = 4, Stream& stream = Stream::Null())
gpu::drawColorDisp
------------------
Colors a disparity image.
:param disp:Input disparity image. ``CV_8U`` and ``CV_16S`` types are supported.
: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.
:param src_disp:Source disparity image. ``CV_8UC1`` and ``CV_16SC1`` types are supported.
:param Q::math:`4 \times 4` perspective transformation matrix that can be obtained via :ocv:func:`stereoRectify` .
:param dst_disp:Output disparity image. It has the same size as ``src_disp`` . The type is ``CV_8UC4`` in ``BGRA`` format (alpha = 255).
:param dst_cn:The number of channels for output image. Can be 3 or 4.
:param ndisp:Number of disparities.
:param stream:Stream for the asynchronous version.
..seealso:::ocv:func:`reprojectImageTo3D`
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.
..[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.