Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
816adcfd
Commit
816adcfd
authored
Mar 05, 2013
by
Andrey Kamaev
Committed by
OpenCV Buildbot
Mar 05, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #605 from vpisarev:c2cpp_calib3d_stereo
parents
b9ab5939
df89f30b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
266 additions
and
39 deletions
+266
-39
calib3d.hpp
modules/calib3d/include/opencv2/calib3d/calib3d.hpp
+22
-12
compat_stereo.cpp
modules/calib3d/src/compat_stereo.cpp
+216
-0
stereobm.cpp
modules/calib3d/src/stereobm.cpp
+0
-0
stereosgbm.cpp
modules/calib3d/src/stereosgbm.cpp
+0
-0
stereo_match.cpp
samples/cpp/stereo_match.cpp
+28
-27
No files found.
modules/calib3d/include/opencv2/calib3d/calib3d.hpp
View file @
816adcfd
...
...
@@ -669,18 +669,32 @@ CV_EXPORTS_W void triangulatePoints( InputArray projMatr1, InputArray projMatr2,
CV_EXPORTS_W
void
correctMatches
(
InputArray
F
,
InputArray
points1
,
InputArray
points2
,
OutputArray
newPoints1
,
OutputArray
newPoints2
);
template
<>
CV_EXPORTS
void
Ptr
<
CvStereoBMState
>::
delete_obj
();
/*!
Block Matching Stereo Correspondence Algorithm
class
CV_EXPORTS_W
StereoMatcher
:
public
Algorithm
{
public
:
CV_WRAP
virtual
void
compute
(
InputArray
left
,
InputArray
right
,
OutputArray
disparity
)
=
0
;
};
The class implements BM stereo correspondence algorithm by K. Konolige.
*/
enum
{
STEREO_DISP_SCALE
=
16
,
STEREO_PREFILTER_NORMALIZED_RESPONSE
=
0
,
STEREO_PREFILTER_XSOBEL
=
1
};
CV_EXPORTS
Ptr
<
StereoMatcher
>
createStereoBM
(
int
numDisparities
=
0
,
int
SADWindowSize
=
21
);
CV_EXPORTS
Ptr
<
StereoMatcher
>
createStereoSGBM
(
int
minDisparity
,
int
numDisparities
,
int
SADWindowSize
,
int
P1
=
0
,
int
P2
=
0
,
int
disp12MaxDiff
=
0
,
int
preFilterCap
=
0
,
int
uniquenessRatio
=
0
,
int
speckleWindowSize
=
0
,
int
speckleRange
=
0
,
bool
fullDP
=
false
);
template
<>
CV_EXPORTS
void
Ptr
<
CvStereoBMState
>::
delete_obj
();
// to be moved to "compat" module
class
CV_EXPORTS_W
StereoBM
{
public
:
enum
{
PREFILTER_NORMALIZED_RESPONSE
=
0
,
PREFILTER_XSOBEL
=
1
,
BASIC_PRESET
=
0
,
FISH_EYE_PRESET
=
1
,
NARROW_PRESET
=
2
};
BASIC_PRESET
=
0
,
FISH_EYE_PRESET
=
1
,
NARROW_PRESET
=
2
};
//! the default constructor
CV_WRAP
StereoBM
();
...
...
@@ -697,11 +711,7 @@ public:
};
/*!
Semi-Global Block Matching Stereo Correspondence Algorithm
The class implements the original SGBM stereo correspondence algorithm by H. Hirschmuller and some its modification.
*/
// to be moved to "compat" module
class
CV_EXPORTS_W
StereoSGBM
{
public
:
...
...
@@ -736,7 +746,7 @@ public:
CV_PROP_RW
bool
fullDP
;
protected
:
Mat
buffer
;
Ptr
<
StereoMatcher
>
sm
;
};
//! filters off speckles (small regions of incorrectly computed disparity)
...
...
modules/calib3d/src/compat_stereo.cpp
0 → 100644
View file @
816adcfd
//M*//////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "precomp.hpp"
CvStereoBMState
*
cvCreateStereoBMState
(
int
/*preset*/
,
int
numberOfDisparities
)
{
CvStereoBMState
*
state
=
(
CvStereoBMState
*
)
cvAlloc
(
sizeof
(
*
state
)
);
if
(
!
state
)
return
0
;
state
->
preFilterType
=
CV_STEREO_BM_XSOBEL
;
//CV_STEREO_BM_NORMALIZED_RESPONSE;
state
->
preFilterSize
=
9
;
state
->
preFilterCap
=
31
;
state
->
SADWindowSize
=
15
;
state
->
minDisparity
=
0
;
state
->
numberOfDisparities
=
numberOfDisparities
>
0
?
numberOfDisparities
:
64
;
state
->
textureThreshold
=
10
;
state
->
uniquenessRatio
=
15
;
state
->
speckleRange
=
state
->
speckleWindowSize
=
0
;
state
->
trySmallerWindows
=
0
;
state
->
roi1
=
state
->
roi2
=
cvRect
(
0
,
0
,
0
,
0
);
state
->
disp12MaxDiff
=
-
1
;
state
->
preFilteredImg0
=
state
->
preFilteredImg1
=
state
->
slidingSumBuf
=
state
->
disp
=
state
->
cost
=
0
;
return
state
;
}
void
cvReleaseStereoBMState
(
CvStereoBMState
**
state
)
{
if
(
!
state
)
CV_Error
(
CV_StsNullPtr
,
""
);
if
(
!*
state
)
return
;
cvReleaseMat
(
&
(
*
state
)
->
preFilteredImg0
);
cvReleaseMat
(
&
(
*
state
)
->
preFilteredImg1
);
cvReleaseMat
(
&
(
*
state
)
->
slidingSumBuf
);
cvReleaseMat
(
&
(
*
state
)
->
disp
);
cvReleaseMat
(
&
(
*
state
)
->
cost
);
cvFree
(
state
);
}
template
<>
void
cv
::
Ptr
<
CvStereoBMState
>::
delete_obj
()
{
cvReleaseStereoBMState
(
&
obj
);
}
void
cvFindStereoCorrespondenceBM
(
const
CvArr
*
leftarr
,
const
CvArr
*
rightarr
,
CvArr
*
disparr
,
CvStereoBMState
*
state
)
{
cv
::
Mat
left
=
cv
::
cvarrToMat
(
leftarr
),
right
=
cv
::
cvarrToMat
(
rightarr
);
const
cv
::
Mat
disp
=
cv
::
cvarrToMat
(
disparr
);
CV_Assert
(
state
!=
0
);
cv
::
Ptr
<
cv
::
StereoMatcher
>
sm
=
cv
::
createStereoBM
(
state
->
numberOfDisparities
,
state
->
SADWindowSize
);
sm
->
set
(
"preFilterType"
,
state
->
preFilterType
);
sm
->
set
(
"preFilterSize"
,
state
->
preFilterSize
);
sm
->
set
(
"preFilterCap"
,
state
->
preFilterCap
);
sm
->
set
(
"SADWindowSize"
,
state
->
SADWindowSize
);
sm
->
set
(
"numDisparities"
,
state
->
numberOfDisparities
>
0
?
state
->
numberOfDisparities
:
64
);
sm
->
set
(
"textureThreshold"
,
state
->
textureThreshold
);
sm
->
set
(
"uniquenessRatio"
,
state
->
uniquenessRatio
);
sm
->
set
(
"speckleRange"
,
state
->
speckleRange
);
sm
->
set
(
"speckleWindowSize"
,
state
->
speckleWindowSize
);
sm
->
set
(
"disp12MaxDiff"
,
state
->
disp12MaxDiff
);
sm
->
compute
(
left
,
right
,
disp
);
}
CvRect
cvGetValidDisparityROI
(
CvRect
roi1
,
CvRect
roi2
,
int
minDisparity
,
int
numberOfDisparities
,
int
SADWindowSize
)
{
return
(
CvRect
)
cv
::
getValidDisparityROI
(
roi1
,
roi2
,
minDisparity
,
numberOfDisparities
,
SADWindowSize
);
}
void
cvValidateDisparity
(
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
);
}
namespace
cv
{
StereoBM
::
StereoBM
()
{
init
(
BASIC_PRESET
);
}
StereoBM
::
StereoBM
(
int
_preset
,
int
_ndisparities
,
int
_SADWindowSize
)
{
init
(
_preset
,
_ndisparities
,
_SADWindowSize
);
}
void
StereoBM
::
init
(
int
_preset
,
int
_ndisparities
,
int
_SADWindowSize
)
{
state
=
cvCreateStereoBMState
(
_preset
,
_ndisparities
);
state
->
SADWindowSize
=
_SADWindowSize
;
}
void
StereoBM
::
operator
()(
InputArray
_left
,
InputArray
_right
,
OutputArray
_disparity
,
int
disptype
)
{
Mat
left
=
_left
.
getMat
(),
right
=
_right
.
getMat
();
CV_Assert
(
disptype
==
CV_16S
||
disptype
==
CV_32F
);
_disparity
.
create
(
left
.
size
(),
disptype
);
Mat
disp
=
_disparity
.
getMat
();
CvMat
left_c
=
left
,
right_c
=
right
,
disp_c
=
disp
;
cvFindStereoCorrespondenceBM
(
&
left_c
,
&
right_c
,
&
disp_c
,
state
);
}
StereoSGBM
::
StereoSGBM
()
{
minDisparity
=
numberOfDisparities
=
0
;
SADWindowSize
=
0
;
P1
=
P2
=
0
;
disp12MaxDiff
=
0
;
preFilterCap
=
0
;
uniquenessRatio
=
0
;
speckleWindowSize
=
0
;
speckleRange
=
0
;
fullDP
=
false
;
sm
=
createStereoSGBM
(
0
,
0
,
0
);
}
StereoSGBM
::
StereoSGBM
(
int
_minDisparity
,
int
_numDisparities
,
int
_SADWindowSize
,
int
_P1
,
int
_P2
,
int
_disp12MaxDiff
,
int
_preFilterCap
,
int
_uniquenessRatio
,
int
_speckleWindowSize
,
int
_speckleRange
,
bool
_fullDP
)
{
minDisparity
=
_minDisparity
;
numberOfDisparities
=
_numDisparities
;
SADWindowSize
=
_SADWindowSize
;
P1
=
_P1
;
P2
=
_P2
;
disp12MaxDiff
=
_disp12MaxDiff
;
preFilterCap
=
_preFilterCap
;
uniquenessRatio
=
_uniquenessRatio
;
speckleWindowSize
=
_speckleWindowSize
;
speckleRange
=
_speckleRange
;
fullDP
=
_fullDP
;
sm
=
createStereoSGBM
(
0
,
0
,
0
);
}
StereoSGBM
::~
StereoSGBM
()
{
}
void
StereoSGBM
::
operator
()(
InputArray
_left
,
InputArray
_right
,
OutputArray
_disp
)
{
sm
->
set
(
"minDisparity"
,
minDisparity
);
sm
->
set
(
"numDisparities"
,
numberOfDisparities
);
sm
->
set
(
"SADWindowSize"
,
SADWindowSize
);
sm
->
set
(
"P1"
,
P1
);
sm
->
set
(
"P2"
,
P2
);
sm
->
set
(
"disp12MaxDiff"
,
disp12MaxDiff
);
sm
->
set
(
"preFilterCap"
,
preFilterCap
);
sm
->
set
(
"uniquenessRatio"
,
uniquenessRatio
);
sm
->
set
(
"speckleWindowSize"
,
speckleWindowSize
);
sm
->
set
(
"speckleRange"
,
speckleRange
);
sm
->
set
(
"fullDP"
,
fullDP
);
sm
->
compute
(
_left
,
_right
,
_disp
);
}
}
modules/calib3d/src/stereobm.cpp
View file @
816adcfd
This diff is collapsed.
Click to expand it.
modules/calib3d/src/stereosgbm.cpp
View file @
816adcfd
This diff is collapsed.
Click to expand it.
samples/cpp/stereo_match.cpp
View file @
816adcfd
...
...
@@ -66,8 +66,8 @@ int main(int argc, char** argv)
bool
no_display
=
false
;
float
scale
=
1.
f
;
StereoBM
bm
;
StereoSGBM
sgbm
;
Ptr
<
StereoMatcher
>
bm
=
createStereoBM
(
16
,
9
)
;
Ptr
<
StereoMatcher
>
sgbm
=
createStereoSGBM
(
0
,
16
,
3
)
;
StereoVar
var
;
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
...
...
@@ -220,32 +220,33 @@ int main(int argc, char** argv)
numberOfDisparities
=
numberOfDisparities
>
0
?
numberOfDisparities
:
((
img_size
.
width
/
8
)
+
15
)
&
-
16
;
bm
.
state
->
roi1
=
roi1
;
bm
.
state
->
roi2
=
roi2
;
bm
.
state
->
preFilterCap
=
31
;
bm
.
state
->
SADWindowSize
=
SADWindowSize
>
0
?
SADWindowSize
:
9
;
bm
.
state
->
minDisparity
=
0
;
bm
.
state
->
numberOfDisparities
=
numberOfDisparities
;
bm
.
state
->
textureThreshold
=
10
;
bm
.
state
->
uniquenessRatio
=
15
;
bm
.
state
->
speckleWindowSize
=
100
;
bm
.
state
->
speckleRange
=
32
;
bm
.
state
->
disp12MaxDiff
=
1
;
sgbm
.
preFilterCap
=
63
;
sgbm
.
SADWindowSize
=
SADWindowSize
>
0
?
SADWindowSize
:
3
;
//bm->set("roi1", roi1);
//bm->set("roi2", roi2);
bm
->
set
(
"preFilterCap"
,
31
);
bm
->
set
(
"SADWindowSize"
,
SADWindowSize
>
0
?
SADWindowSize
:
9
);
bm
->
set
(
"minDisparity"
,
0
);
bm
->
set
(
"numDisparities"
,
numberOfDisparities
);
bm
->
set
(
"textureThreshold"
,
10
);
bm
->
set
(
"uniquenessRatio"
,
15
);
bm
->
set
(
"speckleWindowSize"
,
100
);
bm
->
set
(
"speckleRange"
,
32
);
bm
->
set
(
"disp12MaxDiff"
,
1
);
sgbm
->
set
(
"preFilterCap"
,
63
);
int
sgbmWinSize
=
SADWindowSize
>
0
?
SADWindowSize
:
3
;
sgbm
->
set
(
"SADWindowSize"
,
sgbmWinSize
);
int
cn
=
img1
.
channels
();
sgbm
.
P1
=
8
*
cn
*
sgbm
.
SADWindowSize
*
sgbm
.
SADWindowSize
;
sgbm
.
P2
=
32
*
cn
*
sgbm
.
SADWindowSize
*
sgbm
.
SADWindowSize
;
sgbm
.
minDisparity
=
0
;
sgbm
.
numberOfDisparities
=
numberOfDisparities
;
sgbm
.
uniquenessRatio
=
10
;
sgbm
.
speckleWindowSize
=
bm
.
state
->
speckleWindowSize
;
sgbm
.
speckleRange
=
bm
.
state
->
speckleRange
;
sgbm
.
disp12MaxDiff
=
1
;
sgbm
.
fullDP
=
alg
==
STEREO_HH
;
sgbm
->
set
(
"P1"
,
8
*
cn
*
sgbmWinSize
*
sgbmWinSize
)
;
sgbm
->
set
(
"P2"
,
32
*
cn
*
sgbmWinSize
*
sgbmWinSize
)
;
sgbm
->
set
(
"minDisparity"
,
0
)
;
sgbm
->
set
(
"numDisparities"
,
numberOfDisparities
)
;
sgbm
->
set
(
"uniquenessRatio"
,
10
)
;
sgbm
->
set
(
"speckleWindowSize"
,
100
)
;
sgbm
->
set
(
"speckleRange"
,
32
)
;
sgbm
->
set
(
"disp12MaxDiff"
,
1
)
;
sgbm
->
set
(
"fullDP"
,
alg
==
STEREO_HH
)
;
var
.
levels
=
3
;
// ignored with USE_AUTO_PARAMS
var
.
pyrScale
=
0.5
;
// ignored with USE_AUTO_PARAMS
...
...
@@ -267,12 +268,12 @@ int main(int argc, char** argv)
int64
t
=
getTickCount
();
if
(
alg
==
STEREO_BM
)
bm
(
img1
,
img2
,
disp
);
bm
->
compute
(
img1
,
img2
,
disp
);
else
if
(
alg
==
STEREO_VAR
)
{
var
(
img1
,
img2
,
disp
);
}
else
if
(
alg
==
STEREO_SGBM
||
alg
==
STEREO_HH
)
sgbm
(
img1
,
img2
,
disp
);
sgbm
->
compute
(
img1
,
img2
,
disp
);
t
=
getTickCount
()
-
t
;
printf
(
"Time elapsed: %fms
\n
"
,
t
*
1000
/
getTickFrequency
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment