Commit 9b55c04e authored by Muresan Mircea Paul's avatar Muresan Mircea Paul

I have put all the modules in the stereo namespace

changed the ptr<StereBinaryBM> to ptr<cv::stereo::StereoBinaryBM>

modified the documentation

modified documentation for the stereo_c

documentation

doc

fixed two issues

modfified the precomp.hpp header by explicitly adding the cvdef header from core

modified comments for documentation for stereo and removed some headers

added a header and modified some function definition

test

test 2

changed exports_w to exports

removed the correct matches module
parent 0d1fd8de
...@@ -47,43 +47,55 @@ ...@@ -47,43 +47,55 @@
#include "opencv2/core.hpp" #include "opencv2/core.hpp"
#include "opencv2/features2d.hpp" #include "opencv2/features2d.hpp"
#include "opencv2/core/affine.hpp" #include "opencv2/core/affine.hpp"
#include "opencv2/core/cvdef.h"
/**
@defgroup stereo Stereo Correspondance Algorithms
*/
namespace cv namespace cv
{ {
CV_EXPORTS_W void correctMatches( InputArray F, InputArray points1, InputArray points2, namespace stereo
OutputArray newPoints1, OutputArray newPoints2 ); {
/** @brief Filters off small noise blobs (speckles) in the disparity map //! @addtogroup stereo
//! @{
@param img The input 16-bit signed disparity image // void correctMatches( InputArray F, InputArray points1, InputArray points2,
@param newVal The disparity value used to paint-off the speckles // OutputArray newPoints1, OutputArray newPoints2 );
@param maxSpeckleSize The maximum speckle size to consider it a speckle. Larger blobs are not
affected by the algorithm /** @brief Filters off small noise blobs (speckles) in the disparity map
@param maxDiff Maximum difference between neighbor disparity pixels to put them into the same
blob. Note that since StereoBM, StereoSGBM and may be other algorithms return a fixed-point @param img The input 16-bit signed disparity image
disparity map, where disparity values are multiplied by 16, this scale factor should be taken into @param newVal The disparity value used to paint-off the speckles
account when specifying this parameter value. @param maxSpeckleSize The maximum speckle size to consider it a speckle. Larger blobs are not
@param buf The optional temporary buffer to avoid memory allocation within the function. affected by the algorithm
@param maxDiff Maximum difference between neighbor disparity pixels to put them into the same
blob. Note that since StereoBM, StereoSGBM and may be other algorithms return a fixed-point
disparity map, where disparity values are multiplied by 16, this scale factor should be taken into
account when specifying this parameter value.
@param buf The optional temporary buffer to avoid memory allocation within the function.
*/ */
CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal, void filterSpeckles( InputOutputArray img, double newVal,
int maxSpeckleSize, double maxDiff, int maxSpeckleSize, double maxDiff,
InputOutputArray buf = noArray() ); InputOutputArray buf = noArray() );
//! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify()) //! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify())
CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2, Rect getValidDisparityROI( Rect roi1, Rect roi2,
int minDisparity, int numberOfDisparities, int minDisparity, int numberOfDisparities,
int SADWindowSize ); int SADWindowSize );
//! validates disparity using the left-right check. The matrix "cost" should be computed by the stereo correspondence algorithm //! validates disparity using the left-right check. The matrix "cost" should be computed by the stereo correspondence algorithm
CV_EXPORTS_W void validateDisparity( InputOutputArray disparity, InputArray cost, void validateDisparity( InputOutputArray disparity, InputArray cost,
int minDisparity, int numberOfDisparities, int minDisparity, int numberOfDisparities,
int disp12MaxDisp = 1 ); int disp12MaxDisp = 1 );
/** @brief The base class for stereo correspondence algorithms. /** @brief The base class for stereo correspondence algorithms.
*/ */
class CV_EXPORTS_W StereoMatcher : public Algorithm class StereoMatcher : public Algorithm
{ {
public: public:
enum { DISP_SHIFT = 4, enum { DISP_SHIFT = 4,
DISP_SCALE = (1 << DISP_SHIFT) DISP_SCALE = (1 << DISP_SHIFT)
}; };
...@@ -96,62 +108,62 @@ public: ...@@ -96,62 +108,62 @@ public:
like StereoBM or StereoSGBM compute 16-bit fixed-point disparity map (where each disparity value like StereoBM or StereoSGBM compute 16-bit fixed-point disparity map (where each disparity value
has 4 fractional bits), whereas other algorithms output 32-bit floating-point disparity map. has 4 fractional bits), whereas other algorithms output 32-bit floating-point disparity map.
*/ */
CV_WRAP virtual void compute( InputArray left, InputArray right, virtual void compute( InputArray left, InputArray right,
OutputArray disparity ) = 0; OutputArray disparity ) = 0;
CV_WRAP virtual int getMinDisparity() const = 0; virtual int getMinDisparity() const = 0;
CV_WRAP virtual void setMinDisparity(int minDisparity) = 0; virtual void setMinDisparity(int minDisparity) = 0;
CV_WRAP virtual int getNumDisparities() const = 0; virtual int getNumDisparities() const = 0;
CV_WRAP virtual void setNumDisparities(int numDisparities) = 0; virtual void setNumDisparities(int numDisparities) = 0;
CV_WRAP virtual int getBlockSize() const = 0; virtual int getBlockSize() const = 0;
CV_WRAP virtual void setBlockSize(int blockSize) = 0; virtual void setBlockSize(int blockSize) = 0;
CV_WRAP virtual int getSpeckleWindowSize() const = 0; virtual int getSpeckleWindowSize() const = 0;
CV_WRAP virtual void setSpeckleWindowSize(int speckleWindowSize) = 0; virtual void setSpeckleWindowSize(int speckleWindowSize) = 0;
CV_WRAP virtual int getSpeckleRange() const = 0; virtual int getSpeckleRange() const = 0;
CV_WRAP virtual void setSpeckleRange(int speckleRange) = 0; virtual void setSpeckleRange(int speckleRange) = 0;
CV_WRAP virtual int getDisp12MaxDiff() const = 0; virtual int getDisp12MaxDiff() const = 0;
CV_WRAP virtual void setDisp12MaxDiff(int disp12MaxDiff) = 0; virtual void setDisp12MaxDiff(int disp12MaxDiff) = 0;
}; };
/** @brief Class for computing stereo correspondence using the block matching algorithm, introduced and /** @brief Class for computing stereo correspondence using the block matching algorithm, introduced and
contributed to OpenCV by K. Konolige. contributed to OpenCV by K. Konolige.
*/ */
class CV_EXPORTS_W StereoBinaryBM : public StereoMatcher class StereoBinaryBM : public StereoMatcher
{ {
public: public:
enum { PREFILTER_NORMALIZED_RESPONSE = 0, enum { PREFILTER_NORMALIZED_RESPONSE = 0,
PREFILTER_XSOBEL = 1 PREFILTER_XSOBEL = 1
}; };
CV_WRAP virtual int getPreFilterType() const = 0; virtual int getPreFilterType() const = 0;
CV_WRAP virtual void setPreFilterType(int preFilterType) = 0; virtual void setPreFilterType(int preFilterType) = 0;
CV_WRAP virtual int getPreFilterSize() const = 0; virtual int getPreFilterSize() const = 0;
CV_WRAP virtual void setPreFilterSize(int preFilterSize) = 0; virtual void setPreFilterSize(int preFilterSize) = 0;
CV_WRAP virtual int getPreFilterCap() const = 0; virtual int getPreFilterCap() const = 0;
CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0; virtual void setPreFilterCap(int preFilterCap) = 0;
CV_WRAP virtual int getTextureThreshold() const = 0; virtual int getTextureThreshold() const = 0;
CV_WRAP virtual void setTextureThreshold(int textureThreshold) = 0; virtual void setTextureThreshold(int textureThreshold) = 0;
CV_WRAP virtual int getUniquenessRatio() const = 0; virtual int getUniquenessRatio() const = 0;
CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0; virtual void setUniquenessRatio(int uniquenessRatio) = 0;
CV_WRAP virtual int getSmallerBlockSize() const = 0; virtual int getSmallerBlockSize() const = 0;
CV_WRAP virtual void setSmallerBlockSize(int blockSize) = 0; virtual void setSmallerBlockSize(int blockSize) = 0;
CV_WRAP virtual Rect getROI1() const = 0; virtual Rect getROI1() const = 0;
CV_WRAP virtual void setROI1(Rect roi1) = 0; virtual void setROI1(Rect roi1) = 0;
CV_WRAP virtual Rect getROI2() const = 0; virtual Rect getROI2() const = 0;
CV_WRAP virtual void setROI2(Rect roi2) = 0; virtual void setROI2(Rect roi2) = 0;
/** @brief Creates StereoBM object /** @brief Creates StereoBM object
...@@ -166,50 +178,50 @@ public: ...@@ -166,50 +178,50 @@ public:
The function create StereoBM object. You can then call StereoBM::compute() to compute disparity for The function create StereoBM object. You can then call StereoBM::compute() to compute disparity for
a specific stereo pair. a specific stereo pair.
*/ */
CV_WRAP static Ptr<StereoBinaryBM> create(int numDisparities = 0, int blockSize = 21); CV_EXPORTS static Ptr< cv::stereo::StereoBinaryBM > create(int numDisparities = 0, int blockSize = 21);
}; };
/** @brief The class implements the modified H. Hirschmuller algorithm @cite HH08 that differs from the original /** @brief The class implements the modified H. Hirschmuller algorithm @cite HH08 that differs from the original
one as follows: one as follows:
- By default, the algorithm is single-pass, which means that you consider only 5 directions - By default, the algorithm is single-pass, which means that you consider only 5 directions
instead of 8. Set mode=StereoSGBM::MODE_HH in createStereoSGBM to run the full variant of the instead of 8. Set mode=StereoSGBM::MODE_HH in createStereoSGBM to run the full variant of the
algorithm but beware that it may consume a lot of memory. algorithm but beware that it may consume a lot of memory.
- The algorithm matches blocks, not individual pixels. Though, setting blockSize=1 reduces the - The algorithm matches blocks, not individual pixels. Though, setting blockSize=1 reduces the
blocks to single pixels. blocks to single pixels.
- Mutual information cost function is not implemented. Instead, a simpler Birchfield-Tomasi - Mutual information cost function is not implemented. Instead, a simpler Birchfield-Tomasi
sub-pixel metric from @cite BT98 is used. Though, the color images are supported as well. sub-pixel metric from @cite BT98 is used. Though, the color images are supported as well.
- Some pre- and post- processing steps from K. Konolige algorithm StereoBM are included, for - Some pre- and post- processing steps from K. Konolige algorithm StereoBM are included, for
example: pre-filtering (StereoBM::PREFILTER_XSOBEL type) and post-filtering (uniqueness example: pre-filtering (StereoBM::PREFILTER_XSOBEL type) and post-filtering (uniqueness
check, quadratic interpolation and speckle filtering). check, quadratic interpolation and speckle filtering).
@note @note
- (Python) An example illustrating the use of the StereoSGBM matching algorithm can be found - (Python) An example illustrating the use of the StereoSGBM matching algorithm can be found
at opencv_source_code/samples/python2/stereo_match.py at opencv_source_code/samples/python2/stereo_match.py
*/ */
class CV_EXPORTS_W StereoBinarySGBM : public StereoMatcher class StereoBinarySGBM : public StereoMatcher
{ {
public: public:
enum enum
{ {
MODE_SGBM = 0, MODE_SGBM = 0,
MODE_HH = 1 MODE_HH = 1
}; };
CV_WRAP virtual int getPreFilterCap() const = 0; virtual int getPreFilterCap() const = 0;
CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0; virtual void setPreFilterCap(int preFilterCap) = 0;
CV_WRAP virtual int getUniquenessRatio() const = 0; virtual int getUniquenessRatio() const = 0;
CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0; virtual void setUniquenessRatio(int uniquenessRatio) = 0;
CV_WRAP virtual int getP1() const = 0; virtual int getP1() const = 0;
CV_WRAP virtual void setP1(int P1) = 0; virtual void setP1(int P1) = 0;
CV_WRAP virtual int getP2() const = 0; virtual int getP2() const = 0;
CV_WRAP virtual void setP2(int P2) = 0; virtual void setP2(int P2) = 0;
CV_WRAP virtual int getMode() const = 0; virtual int getMode() const = 0;
CV_WRAP virtual void setMode(int mode) = 0; virtual void setMode(int mode) = 0;
/** @brief Creates StereoSGBM object /** @brief Creates StereoSGBM object
...@@ -248,17 +260,19 @@ public: ...@@ -248,17 +260,19 @@ public:
set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
to a custom value. to a custom value.
*/ */
CV_WRAP static Ptr<StereoBinarySGBM> create(int minDisparity, int numDisparities, int blockSize, CV_EXPORTS static Ptr<cv::stereo::StereoBinarySGBM> create(int minDisparity, int numDisparities, int blockSize,
int P1 = 0, int P2 = 0, int disp12MaxDiff = 0, int P1 = 0, int P2 = 0, int disp12MaxDiff = 0,
int preFilterCap = 0, int uniquenessRatio = 0, int preFilterCap = 0, int uniquenessRatio = 0,
int speckleWindowSize = 0, int speckleRange = 0, int speckleWindowSize = 0, int speckleRange = 0,
int mode = StereoBinarySGBM::MODE_SGBM); int mode = StereoBinarySGBM::MODE_SGBM);
}; };
//! @}
}//sterep
} // cv } // cv
#ifndef DISABLE_OPENCV_24_COMPATIBILITY #ifndef DISABLE_OPENCV_24_COMPATIBILITY
#include "opencv2/calib3d/calib3d_c.h" #include "opencv2/stereo/stereo_c.h"
#endif #endif
#endif #endif
...@@ -46,3 +46,4 @@ ...@@ -46,3 +46,4 @@
#endif #endif
#include "opencv2/stereo.hpp" #include "opencv2/stereo.hpp"
...@@ -52,17 +52,14 @@ extern "C" { ...@@ -52,17 +52,14 @@ extern "C" {
/** @addtogroup stereo_c /** @addtogroup stereo_c
@{ @{
*/ **/
/****************************************************************************************\ //! stereo correspondence parameters and functions
* Stereo *
\****************************************************************************************/
/* stereo correspondence parameters and functions */
#define CV_STEREO_BM_NORMALIZED_RESPONSE 0 #define CV_STEREO_BM_NORMALIZED_RESPONSE 0
#define CV_STEREO_BM_XSOBEL 1 #define CV_STEREO_BM_XSOBEL 1
/* Block matching algorithm structure */ //! Block matching algorithm structure
typedef struct CvStereoBinaryBMState typedef struct CvStereoBinaryBMState
{ {
// pre-filtering (normalization of input images) // pre-filtering (normalization of input images)
...@@ -109,14 +106,15 @@ CVAPI(void) cvReleaseStereoBinaryBMState( CvStereoBinaryBMState** state ); ...@@ -109,14 +106,15 @@ CVAPI(void) cvReleaseStereoBinaryBMState( CvStereoBinaryBMState** state );
CVAPI(void) cvFindStereoCorrespondenceBinaryBM( const CvArr* left, const CvArr* right, CVAPI(void) cvFindStereoCorrespondenceBinaryBM( const CvArr* left, const CvArr* right,
CvArr* disparity, CvStereoBinaryBMState* state ); CvArr* disparity, CvStereoBinaryBMState* state );
CVAPI(CvRect) cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity, CVAPI(CvRect) cvStereoBinaryGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity,
int numberOfDisparities, int SADWindowSize ); int numberOfDisparities, int SADWindowSize );
CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost, CVAPI(void) cvStereoBinaryValidateDisparity( CvArr* disparity, const CvArr* cost,
int minDisparity, int numberOfDisparities, int minDisparity, int numberOfDisparities,
int disp12MaxDiff CV_DEFAULT(1) ); int disp12MaxDiff CV_DEFAULT(1) );
/** @} stereo_c */
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif
#endif /* __OPENCV_STEREO_C_H__ */ #endif /* __OPENCV_STEREO_C_H__ */
...@@ -92,7 +92,7 @@ void cvFindStereoCorrespondenceBinaryBM( const CvArr* leftarr, const CvArr* righ ...@@ -92,7 +92,7 @@ void cvFindStereoCorrespondenceBinaryBM( const CvArr* leftarr, const CvArr* righ
CV_Assert( state != 0 ); CV_Assert( state != 0 );
cv::Ptr<cv::StereoBinaryBM> sm = cv::StereoBinaryBM::create(state->numberOfDisparities, cv::Ptr<cv::stereo::StereoBinaryBM> sm = cv::stereo::StereoBinaryBM::create(state->numberOfDisparities,
state->SADWindowSize); state->SADWindowSize);
sm->setPreFilterType(state->preFilterType); sm->setPreFilterType(state->preFilterType);
sm->setPreFilterSize(state->preFilterSize); sm->setPreFilterSize(state->preFilterSize);
...@@ -108,17 +108,18 @@ void cvFindStereoCorrespondenceBinaryBM( const CvArr* leftarr, const CvArr* righ ...@@ -108,17 +108,18 @@ void cvFindStereoCorrespondenceBinaryBM( const CvArr* leftarr, const CvArr* righ
sm->compute(left, right, disp); sm->compute(left, right, disp);
} }
CvRect cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity, CvRect cvStereoBinaryGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity,
int numberOfDisparities, int SADWindowSize ) int numberOfDisparities, int SADWindowSize )
{ {
return (CvRect)cv::getValidDisparityROI( roi1, roi2, minDisparity, return (CvRect)cv::stereo::getValidDisparityROI( roi1, roi2, minDisparity,
numberOfDisparities, SADWindowSize ); numberOfDisparities, SADWindowSize );
} }
void cvValidateDisparity( CvArr* _disp, const CvArr* _cost, int minDisparity, void cvStereoBinaryValidateDisparity( CvArr* _disp, const CvArr* _cost, int minDisparity,
int numberOfDisparities, int disp12MaxDiff ) int numberOfDisparities, int disp12MaxDiff )
{ {
cv::Mat disp = cv::cvarrToMat(_disp), cost = cv::cvarrToMat(_cost); cv::Mat disp = cv::cvarrToMat(_disp), cost = cv::cvarrToMat(_cost);
cv::validateDisparity( disp, cost, minDisparity, numberOfDisparities, disp12MaxDiff ); cv::stereo::validateDisparity( disp, cost, minDisparity, numberOfDisparities, disp12MaxDiff );
} }
...@@ -45,9 +45,10 @@ ...@@ -45,9 +45,10 @@
#include "opencv2/stereo.hpp" #include "opencv2/stereo.hpp"
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include "opencv2/features2d.hpp" #include "opencv2/features2d.hpp"
#include "opencv2/core.hpp"
#include "opencv2/core/utility.hpp" #include "opencv2/core/utility.hpp"
#include "opencv2/core/private.hpp" #include "opencv2/core/private.hpp"
#include "opencv2/core.hpp" #include "opencv2/core/cvdef.h"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include <algorithm> #include <algorithm>
......
...@@ -51,7 +51,8 @@ ...@@ -51,7 +51,8 @@
namespace cv namespace cv
{ {
namespace stereo
{
struct StereoBinaryBMParams struct StereoBinaryBMParams
{ {
StereoBinaryBMParams(int _numDisparities = 64, int _SADWindowSize = 9) StereoBinaryBMParams(int _numDisparities = 64, int _SADWindowSize = 9)
...@@ -730,7 +731,7 @@ namespace cv ...@@ -730,7 +731,7 @@ namespace cv
{ {
return makePtr<StereoBinaryBMImpl>(_numDisparities, _SADWindowSize); return makePtr<StereoBinaryBMImpl>(_numDisparities, _SADWindowSize);
} }
}
} }
/* End of file. */ /* End of file. */
......
...@@ -42,29 +42,30 @@ ...@@ -42,29 +42,30 @@
//M*/ //M*/
/* /*
This is a variation of This is a variation of
"Stereo Processing by Semiglobal Matching and Mutual Information" "Stereo Processing by Semiglobal Matching and Mutual Information"
by Heiko Hirschmuller. by Heiko Hirschmuller.
We match blocks rather than individual pixels, thus the algorithm is called We match blocks rather than individual pixels, thus the algorithm is called
SGBM (Semi-global block matching) SGBM (Semi-global block matching)
*/ */
#include "precomp.hpp" #include "precomp.hpp"
#include <limits.h> #include <limits.h>
namespace cv namespace cv
{ {
namespace stereo
{
typedef uchar PixType;
typedef short CostType;
typedef short DispType;
typedef uchar PixType; enum { NR = 16, NR2 = NR/2 };
typedef short CostType;
typedef short DispType;
enum { NR = 16, NR2 = NR/2 };
struct StereoBinarySGBMParams struct StereoBinarySGBMParams
{ {
StereoBinarySGBMParams() StereoBinarySGBMParams()
{ {
minDisparity = numDisparities = 0; minDisparity = numDisparities = 0;
...@@ -107,9 +108,9 @@ struct StereoBinarySGBMParams ...@@ -107,9 +108,9 @@ struct StereoBinarySGBMParams
int speckleRange; int speckleRange;
int disp12MaxDiff; int disp12MaxDiff;
int mode; int mode;
}; };
/* /*
For each pixel row1[x], max(-maxD, 0) <= minX <= x < maxX <= width - max(0, -minD), For each pixel row1[x], max(-maxD, 0) <= minX <= x < maxX <= width - max(0, -minD),
and for each disparity minD<=d<maxD the function and for each disparity minD<=d<maxD the function
computes the cost (cost[(x-minX)*(maxD - minD) + (d - minD)]), depending on the difference between computes the cost (cost[(x-minX)*(maxD - minD) + (d - minD)]), depending on the difference between
...@@ -119,11 +120,11 @@ struct StereoBinarySGBMParams ...@@ -119,11 +120,11 @@ struct StereoBinarySGBMParams
the temporary buffer should contain width2*2 elements the temporary buffer should contain width2*2 elements
*/ */
static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y, static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y,
int minD, int maxD, CostType* cost, int minD, int maxD, CostType* cost,
PixType* buffer, const PixType* tab, PixType* buffer, const PixType* tab,
int tabOfs, int ) int tabOfs, int )
{ {
int x, c, width = img1.cols, cn = img1.channels(); int x, c, width = img1.cols, cn = img1.channels();
int minX1 = std::max(-maxD, 0), maxX1 = width + std::min(minD, 0); int minX1 = std::max(-maxD, 0), maxX1 = width + std::min(minD, 0);
int minX2 = std::max(minX1 - maxD, 0), maxX2 = std::min(maxX1 - minD, width); int minX2 = std::max(minX1 - maxD, 0), maxX2 = std::min(maxX1 - minD, width);
...@@ -211,7 +212,7 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y, ...@@ -211,7 +212,7 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y,
int u0 = std::min(ul, ur); u0 = std::min(u0, u); int u0 = std::min(ul, ur); u0 = std::min(u0, u);
int u1 = std::max(ul, ur); u1 = std::max(u1, u); int u1 = std::max(ul, ur); u1 = std::max(u1, u);
#if CV_SSE2 #if CV_SSE2
if( useSIMD ) if( useSIMD )
{ {
__m128i _u = _mm_set1_epi8((char)u), _u0 = _mm_set1_epi8((char)u0); __m128i _u = _mm_set1_epi8((char)u), _u0 = _mm_set1_epi8((char)u0);
...@@ -235,7 +236,7 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y, ...@@ -235,7 +236,7 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y,
} }
} }
else else
#endif #endif
{ {
for( int d = minD; d < maxD; d++ ) for( int d = minD; d < maxD; d++ )
{ {
...@@ -256,7 +257,7 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y, ...@@ -256,7 +257,7 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y,
for( x = minX1; x < maxX1; x++ ) for( x = minX1; x < maxX1; x++ )
{ {
int u = prow1[x]; int u = prow1[x];
#if CV_SSE2 #if CV_SSE2
if( useSIMD ) if( useSIMD )
{ {
__m128i _u = _mm_set1_epi8(u), z = _mm_setzero_si128(); __m128i _u = _mm_set1_epi8(u), z = _mm_setzero_si128();
...@@ -273,7 +274,7 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y, ...@@ -273,7 +274,7 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y,
} }
} }
else else
#endif #endif
{ {
for( int d = minD; d < maxD; d++ ) for( int d = minD; d < maxD; d++ )
{ {
...@@ -284,10 +285,10 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y, ...@@ -284,10 +285,10 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y,
} }
} }
#endif #endif
} }
/* /*
computes disparity for "roi" in img1 w.r.t. img2 and write it to disp1buf. computes disparity for "roi" in img1 w.r.t. img2 and write it to disp1buf.
that is, disp1buf(x, y)=d means that img1(x+roi.x, y+roi.y) ~ img2(x+roi.x-d, y+roi.y). that is, disp1buf(x, y)=d means that img1(x+roi.x, y+roi.y) ~ img2(x+roi.x-d, y+roi.y).
minD <= d < maxD. minD <= d < maxD.
...@@ -307,10 +308,10 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y, ...@@ -307,10 +308,10 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y,
disp2cost also has the same size as img1 (or img2). disp2cost also has the same size as img1 (or img2).
It contains the minimum current cost, used to find the best disparity, corresponding to the minimal cost. It contains the minimum current cost, used to find the best disparity, corresponding to the minimal cost.
*/ */
static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2, static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
Mat& disp1, const StereoBinarySGBMParams& params, Mat& disp1, const StereoBinarySGBMParams& params,
Mat& buffer ) Mat& buffer )
{ {
#if CV_SSE2 #if CV_SSE2
static const uchar LSBTab[] = static const uchar LSBTab[] =
{ {
...@@ -468,7 +469,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2, ...@@ -468,7 +469,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
const CostType* pixAdd = pixDiff + std::min(x + SW2*D, (width1-1)*D); const CostType* pixAdd = pixDiff + std::min(x + SW2*D, (width1-1)*D);
const CostType* pixSub = pixDiff + std::max(x - (SW2+1)*D, 0); const CostType* pixSub = pixDiff + std::max(x - (SW2+1)*D, 0);
#if CV_SSE2 #if CV_SSE2
if( useSIMD ) if( useSIMD )
{ {
for( d = 0; d < D; d += 8 ) for( d = 0; d < D; d += 8 )
...@@ -486,7 +487,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2, ...@@ -486,7 +487,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
} }
} }
else else
#endif #endif
{ {
for( d = 0; d < D; d++ ) for( d = 0; d < D; d++ )
{ {
...@@ -565,7 +566,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2, ...@@ -565,7 +566,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
const CostType* Cp = C + x*D; const CostType* Cp = C + x*D;
CostType* Sp = S + x*D; CostType* Sp = S + x*D;
#if CV_SSE2 #if CV_SSE2
if( useSIMD ) if( useSIMD )
{ {
__m128i _P1 = _mm_set1_epi16((short)P1); __m128i _P1 = _mm_set1_epi16((short)P1);
...@@ -634,7 +635,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2, ...@@ -634,7 +635,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
_mm_storel_epi64((__m128i*)&minLr[0][xm], _minL0); _mm_storel_epi64((__m128i*)&minLr[0][xm], _minL0);
} }
else else
#endif #endif
{ {
int minL0 = MAX_COST, minL1 = MAX_COST, minL2 = MAX_COST, minL3 = MAX_COST; int minL0 = MAX_COST, minL1 = MAX_COST, minL2 = MAX_COST, minL3 = MAX_COST;
...@@ -693,7 +694,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2, ...@@ -693,7 +694,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
const CostType* Cp = C + x*D; const CostType* Cp = C + x*D;
#if CV_SSE2 #if CV_SSE2
if( useSIMD ) if( useSIMD )
{ {
__m128i _P1 = _mm_set1_epi16((short)P1); __m128i _P1 = _mm_set1_epi16((short)P1);
...@@ -745,7 +746,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2, ...@@ -745,7 +746,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
bestDisp = bestDispBuf[LSBTab[idx]]; bestDisp = bestDispBuf[LSBTab[idx]];
} }
else else
#endif #endif
{ {
for( d = 0; d < D; d++ ) for( d = 0; d < D; d++ )
{ {
...@@ -827,11 +828,11 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2, ...@@ -827,11 +828,11 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
std::swap( minLr[0], minLr[1] ); std::swap( minLr[0], minLr[1] );
} }
} }
} }
class StereoBinarySGBMImpl : public StereoBinarySGBM class StereoBinarySGBMImpl : public StereoBinarySGBM
{ {
public: public:
StereoBinarySGBMImpl() StereoBinarySGBMImpl()
{ {
params = StereoBinarySGBMParams(); params = StereoBinarySGBMParams();
...@@ -934,30 +935,30 @@ public: ...@@ -934,30 +935,30 @@ public:
StereoBinarySGBMParams params; StereoBinarySGBMParams params;
Mat buffer; Mat buffer;
static const char* name_; static const char* name_;
}; };
const char* StereoBinarySGBMImpl::name_ = "StereoMatcher.SGBM"; const char* StereoBinarySGBMImpl::name_ = "StereoMatcher.SGBM";
Ptr<StereoBinarySGBM> StereoBinarySGBM::create(int minDisparity, int numDisparities, int SADWindowSize, Ptr<StereoBinarySGBM> StereoBinarySGBM::create(int minDisparity, int numDisparities, int SADWindowSize,
int P1, int P2, int disp12MaxDiff, int P1, int P2, int disp12MaxDiff,
int preFilterCap, int uniquenessRatio, int preFilterCap, int uniquenessRatio,
int speckleWindowSize, int speckleRange, int speckleWindowSize, int speckleRange,
int mode) int mode)
{ {
return Ptr<StereoBinarySGBM>( return Ptr<StereoBinarySGBM>(
new StereoBinarySGBMImpl(minDisparity, numDisparities, SADWindowSize, new StereoBinarySGBMImpl(minDisparity, numDisparities, SADWindowSize,
P1, P2, disp12MaxDiff, P1, P2, disp12MaxDiff,
preFilterCap, uniquenessRatio, preFilterCap, uniquenessRatio,
speckleWindowSize, speckleRange, speckleWindowSize, speckleRange,
mode)); mode));
} }
Rect getValidDisparityROI( Rect roi1, Rect roi2, Rect getValidDisparityROI( Rect roi1, Rect roi2,
int minDisparity, int minDisparity,
int numberOfDisparities, int numberOfDisparities,
int SADWindowSize ) int SADWindowSize )
{ {
int SW2 = SADWindowSize/2; int SW2 = SADWindowSize/2;
int minD = minDisparity, maxD = minDisparity + numberOfDisparities - 1; int minD = minDisparity, maxD = minDisparity + numberOfDisparities - 1;
...@@ -969,13 +970,13 @@ Rect getValidDisparityROI( Rect roi1, Rect roi2, ...@@ -969,13 +970,13 @@ Rect getValidDisparityROI( Rect roi1, Rect roi2,
Rect r(xmin, ymin, xmax - xmin, ymax - ymin); Rect r(xmin, ymin, xmax - xmin, ymax - ymin);
return r.width > 0 && r.height > 0 ? r : Rect(); return r.width > 0 && r.height > 0 ? r : Rect();
} }
typedef cv::Point_<short> Point2s; typedef cv::Point_<short> Point2s;
template <typename T> template <typename T>
void filterSpecklesImpl(cv::Mat& img, int newVal, int maxSpeckleSize, int maxDiff, cv::Mat& _buf) void filterSpecklesImpl(cv::Mat& img, int newVal, int maxSpeckleSize, int maxDiff, cv::Mat& _buf)
{ {
using namespace cv; using namespace cv;
int width = img.cols, height = img.rows, npixels = width*height; int width = img.cols, height = img.rows, npixels = width*height;
...@@ -1068,11 +1069,11 @@ void filterSpecklesImpl(cv::Mat& img, int newVal, int maxSpeckleSize, int maxDif ...@@ -1068,11 +1069,11 @@ void filterSpecklesImpl(cv::Mat& img, int newVal, int maxSpeckleSize, int maxDif
} }
} }
} }
}
}
} }
} void cv::stereo::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSize,
void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSize,
double _maxDiff, InputOutputArray __buf ) double _maxDiff, InputOutputArray __buf )
{ {
Mat img = _img.getMat(); Mat img = _img.getMat();
...@@ -1120,7 +1121,7 @@ void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSi ...@@ -1120,7 +1121,7 @@ void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSi
filterSpecklesImpl<short>(img, newVal, maxSpeckleSize, maxDiff, _buf); filterSpecklesImpl<short>(img, newVal, maxSpeckleSize, maxDiff, _buf);
} }
void cv::validateDisparity( InputOutputArray _disp, InputArray _cost, int minDisparity, void cv::stereo::validateDisparity( InputOutputArray _disp, InputArray _cost, int minDisparity,
int numberOfDisparities, int disp12MaxDiff ) int numberOfDisparities, int disp12MaxDiff )
{ {
Mat disp = _disp.getMat(), cost = _cost.getMat(); Mat disp = _disp.getMat(), cost = _cost.getMat();
......
...@@ -11,10 +11,21 @@ ...@@ -11,10 +11,21 @@
#include <iostream> #include <iostream>
#include "opencv2/ts.hpp" #include "opencv2/ts.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/stereo.hpp"
#include "opencv2/imgcodecs.hpp" #include "opencv2/imgcodecs.hpp"
#include "opencv2/stereo.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/core/private.hpp"
#include "opencv2/core/cvdef.h"
#include "opencv2/core.hpp" #include "opencv2/core.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include <algorithm>
#include <cmath>
#endif #endif
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