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
This diff is collapsed.
......@@ -46,3 +46,4 @@
#endif
#include "opencv2/stereo.hpp"
......@@ -52,17 +52,14 @@ extern "C" {
/** @addtogroup stereo_c
@{
*/
**/
/****************************************************************************************\
* Stereo *
\****************************************************************************************/
/* stereo correspondence parameters and functions */
//! stereo correspondence parameters and functions
#define CV_STEREO_BM_NORMALIZED_RESPONSE 0
#define CV_STEREO_BM_XSOBEL 1
/* Block matching algorithm structure */
//! Block matching algorithm structure
typedef struct CvStereoBinaryBMState
{
// pre-filtering (normalization of input images)
......@@ -109,14 +106,15 @@ CVAPI(void) cvReleaseStereoBinaryBMState( CvStereoBinaryBMState** state );
CVAPI(void) cvFindStereoCorrespondenceBinaryBM( const CvArr* left, const CvArr* right,
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 );
CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost,
CVAPI(void) cvStereoBinaryValidateDisparity( CvArr* disparity, const CvArr* cost,
int minDisparity, int numberOfDisparities,
int disp12MaxDiff CV_DEFAULT(1) );
/** @} stereo_c */
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* __OPENCV_STEREO_C_H__ */
......@@ -92,7 +92,7 @@ void cvFindStereoCorrespondenceBinaryBM( const CvArr* leftarr, const CvArr* righ
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);
sm->setPreFilterType(state->preFilterType);
sm->setPreFilterSize(state->preFilterSize);
......@@ -108,17 +108,18 @@ void cvFindStereoCorrespondenceBinaryBM( const CvArr* leftarr, const CvArr* righ
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 )
{
return (CvRect)cv::getValidDisparityROI( roi1, roi2, minDisparity,
return (CvRect)cv::stereo::getValidDisparityROI( roi1, roi2, minDisparity,
numberOfDisparities, SADWindowSize );
}
void cvValidateDisparity( CvArr* _disp, const CvArr* _cost, int minDisparity,
void cvStereoBinaryValidateDisparity( CvArr* _disp, const CvArr* _cost, int minDisparity,
int numberOfDisparities, int disp12MaxDiff )
{
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 @@
#include "opencv2/stereo.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/core.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/core/private.hpp"
#include "opencv2/core.hpp"
#include "opencv2/core/cvdef.h"
#include "opencv2/highgui.hpp"
#include <algorithm>
......
......@@ -51,7 +51,8 @@
namespace cv
{
namespace stereo
{
struct StereoBinaryBMParams
{
StereoBinaryBMParams(int _numDisparities = 64, int _SADWindowSize = 9)
......@@ -730,7 +731,7 @@ namespace cv
{
return makePtr<StereoBinaryBMImpl>(_numDisparities, _SADWindowSize);
}
}
}
/* End of file. */
......
......@@ -42,29 +42,30 @@
//M*/
/*
This is a variation of
"Stereo Processing by Semiglobal Matching and Mutual Information"
by Heiko Hirschmuller.
This is a variation of
"Stereo Processing by Semiglobal Matching and Mutual Information"
by Heiko Hirschmuller.
We match blocks rather than individual pixels, thus the algorithm is called
SGBM (Semi-global block matching)
*/
We match blocks rather than individual pixels, thus the algorithm is called
SGBM (Semi-global block matching)
*/
#include "precomp.hpp"
#include <limits.h>
namespace cv
{
namespace stereo
{
typedef uchar PixType;
typedef short CostType;
typedef short DispType;
typedef uchar PixType;
typedef short CostType;
typedef short DispType;
enum { NR = 16, NR2 = NR/2 };
enum { NR = 16, NR2 = NR/2 };
struct StereoBinarySGBMParams
{
struct StereoBinarySGBMParams
{
StereoBinarySGBMParams()
{
minDisparity = numDisparities = 0;
......@@ -107,9 +108,9 @@ struct StereoBinarySGBMParams
int speckleRange;
int disp12MaxDiff;
int mode;
};
};
/*
/*
For each pixel row1[x], max(-maxD, 0) <= minX <= x < maxX <= width - max(0, -minD),
and for each disparity minD<=d<maxD the function
computes the cost (cost[(x-minX)*(maxD - minD) + (d - minD)]), depending on the difference between
......@@ -119,11 +120,11 @@ struct StereoBinarySGBMParams
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,
PixType* buffer, const PixType* tab,
int tabOfs, int )
{
{
int x, c, width = img1.cols, cn = img1.channels();
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);
......@@ -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 u1 = std::max(ul, ur); u1 = std::max(u1, u);
#if CV_SSE2
#if CV_SSE2
if( useSIMD )
{
__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,
}
}
else
#endif
#endif
{
for( int d = minD; d < maxD; d++ )
{
......@@ -256,7 +257,7 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y,
for( x = minX1; x < maxX1; x++ )
{
int u = prow1[x];
#if CV_SSE2
#if CV_SSE2
if( useSIMD )
{
__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,
}
}
else
#endif
#endif
{
for( int d = minD; d < maxD; d++ )
{
......@@ -284,10 +285,10 @@ static void calcPixelCostBT( const Mat& img1, const Mat& img2, int y,
}
}
#endif
}
}
/*
/*
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).
minD <= d < maxD.
......@@ -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).
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& buffer )
{
{
#if CV_SSE2
static const uchar LSBTab[] =
{
......@@ -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* pixSub = pixDiff + std::max(x - (SW2+1)*D, 0);
#if CV_SSE2
#if CV_SSE2
if( useSIMD )
{
for( d = 0; d < D; d += 8 )
......@@ -486,7 +487,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
}
}
else
#endif
#endif
{
for( d = 0; d < D; d++ )
{
......@@ -565,7 +566,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
const CostType* Cp = C + x*D;
CostType* Sp = S + x*D;
#if CV_SSE2
#if CV_SSE2
if( useSIMD )
{
__m128i _P1 = _mm_set1_epi16((short)P1);
......@@ -634,7 +635,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
_mm_storel_epi64((__m128i*)&minLr[0][xm], _minL0);
}
else
#endif
#endif
{
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,
const CostType* Cp = C + x*D;
#if CV_SSE2
#if CV_SSE2
if( useSIMD )
{
__m128i _P1 = _mm_set1_epi16((short)P1);
......@@ -745,7 +746,7 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
bestDisp = bestDispBuf[LSBTab[idx]];
}
else
#endif
#endif
{
for( d = 0; d < D; d++ )
{
......@@ -827,11 +828,11 @@ static void computeDisparityBinarySGBM( const Mat& img1, const Mat& img2,
std::swap( minLr[0], minLr[1] );
}
}
}
}
class StereoBinarySGBMImpl : public StereoBinarySGBM
{
public:
class StereoBinarySGBMImpl : public StereoBinarySGBM
{
public:
StereoBinarySGBMImpl()
{
params = StereoBinarySGBMParams();
......@@ -934,30 +935,30 @@ public:
StereoBinarySGBMParams params;
Mat buffer;
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 preFilterCap, int uniquenessRatio,
int speckleWindowSize, int speckleRange,
int mode)
{
{
return Ptr<StereoBinarySGBM>(
new StereoBinarySGBMImpl(minDisparity, numDisparities, SADWindowSize,
P1, P2, disp12MaxDiff,
preFilterCap, uniquenessRatio,
speckleWindowSize, speckleRange,
mode));
}
}
Rect getValidDisparityROI( Rect roi1, Rect roi2,
Rect getValidDisparityROI( Rect roi1, Rect roi2,
int minDisparity,
int numberOfDisparities,
int SADWindowSize )
{
{
int SW2 = SADWindowSize/2;
int minD = minDisparity, maxD = minDisparity + numberOfDisparities - 1;
......@@ -969,13 +970,13 @@ Rect getValidDisparityROI( Rect roi1, Rect roi2,
Rect r(xmin, ymin, xmax - xmin, ymax - ymin);
return r.width > 0 && r.height > 0 ? r : Rect();
}
}
typedef cv::Point_<short> Point2s;
typedef cv::Point_<short> Point2s;
template <typename T>
void filterSpecklesImpl(cv::Mat& img, int newVal, int maxSpeckleSize, int maxDiff, cv::Mat& _buf)
{
template <typename T>
void filterSpecklesImpl(cv::Mat& img, int newVal, int maxSpeckleSize, int maxDiff, cv::Mat& _buf)
{
using namespace cv;
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
}
}
}
}
}
}
}
void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSize,
void cv::stereo::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSize,
double _maxDiff, InputOutputArray __buf )
{
Mat img = _img.getMat();
......@@ -1120,7 +1121,7 @@ void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSi
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 )
{
Mat disp = _disp.getMat(), cost = _cost.getMat();
......
......@@ -11,10 +11,21 @@
#include <iostream>
#include "opencv2/ts.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/stereo.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/highgui.hpp"
#include <algorithm>
#include <cmath>
#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