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
eff6dccb
Commit
eff6dccb
authored
Jun 21, 2013
by
Roman Donchenko
Committed by
OpenCV Buildbot
Jun 21, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1014 from jet47:gpustereo-refactoring
parents
b20c9ad2
4e29f0ee
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
290 additions
and
184 deletions
+290
-184
stereo.rst
modules/gpustereo/doc/stereo.rst
+0
-0
gpustereo.hpp
modules/gpustereo/include/opencv2/gpustereo.hpp
+0
-0
perf_stereo.cpp
modules/gpustereo/perf/perf_stereo.cpp
+8
-9
disparity_bilateral_filter.cpp
modules/gpustereo/src/disparity_bilateral_filter.cpp
+95
-43
precomp.hpp
modules/gpustereo/src/precomp.hpp
+1
-0
stereobm.cpp
modules/gpustereo/src/stereobm.cpp
+95
-50
stereobp.cpp
modules/gpustereo/src/stereobp.cpp
+0
-0
stereocsbp.cpp
modules/gpustereo/src/stereocsbp.cpp
+0
-0
util.cpp
modules/gpustereo/src/util.cpp
+21
-15
test_stereo.cpp
modules/gpustereo/test/test_stereo.cpp
+11
-6
driver_api_stereo_multi.cpp
samples/gpu/driver_api_stereo_multi.cpp
+6
-7
stereo_match.cpp
samples/gpu/stereo_match.cpp
+47
-47
stereo_multi.cpp
samples/gpu/stereo_multi.cpp
+6
-7
No files found.
modules/gpustereo/doc/stereo.rst
View file @
eff6dccb
This diff is collapsed.
Click to expand it.
modules/gpustereo/include/opencv2/gpustereo.hpp
View file @
eff6dccb
This diff is collapsed.
Click to expand it.
modules/gpustereo/perf/perf_stereo.cpp
View file @
eff6dccb
...
...
@@ -63,18 +63,17 @@ PERF_TEST_P(ImagePair, StereoBM,
const
cv
::
Mat
imgRight
=
readImage
(
GET_PARAM
(
1
),
cv
::
IMREAD_GRAYSCALE
);
ASSERT_FALSE
(
imgRight
.
empty
());
const
int
preset
=
0
;
const
int
ndisp
=
256
;
if
(
PERF_RUN_GPU
())
{
cv
::
gpu
::
StereoBM_GPU
d_bm
(
preset
,
ndisp
);
cv
::
Ptr
<
cv
::
StereoBM
>
d_bm
=
cv
::
gpu
::
createStereoBM
(
ndisp
);
const
cv
::
gpu
::
GpuMat
d_imgLeft
(
imgLeft
);
const
cv
::
gpu
::
GpuMat
d_imgRight
(
imgRight
);
cv
::
gpu
::
GpuMat
dst
;
TEST_CYCLE
()
d_bm
(
d_imgLeft
,
d_imgRight
,
dst
);
TEST_CYCLE
()
d_bm
->
compute
(
d_imgLeft
,
d_imgRight
,
dst
);
GPU_SANITY_CHECK
(
dst
);
}
...
...
@@ -108,13 +107,13 @@ PERF_TEST_P(ImagePair, StereoBeliefPropagation,
if
(
PERF_RUN_GPU
())
{
cv
::
gpu
::
StereoBeliefPropagation
d_bp
(
ndisp
);
cv
::
Ptr
<
cv
::
gpu
::
StereoBeliefPropagation
>
d_bp
=
cv
::
gpu
::
createStereoBeliefPropagation
(
ndisp
);
const
cv
::
gpu
::
GpuMat
d_imgLeft
(
imgLeft
);
const
cv
::
gpu
::
GpuMat
d_imgRight
(
imgRight
);
cv
::
gpu
::
GpuMat
dst
;
TEST_CYCLE
()
d_bp
(
d_imgLeft
,
d_imgRight
,
dst
);
TEST_CYCLE
()
d_bp
->
compute
(
d_imgLeft
,
d_imgRight
,
dst
);
GPU_SANITY_CHECK
(
dst
);
}
...
...
@@ -142,13 +141,13 @@ PERF_TEST_P(ImagePair, StereoConstantSpaceBP,
if
(
PERF_RUN_GPU
())
{
cv
::
gpu
::
StereoConstantSpaceBP
d_csbp
(
ndisp
);
cv
::
Ptr
<
cv
::
gpu
::
StereoConstantSpaceBP
>
d_csbp
=
cv
::
gpu
::
createStereoConstantSpaceBP
(
ndisp
);
const
cv
::
gpu
::
GpuMat
d_imgLeft
(
imgLeft
);
const
cv
::
gpu
::
GpuMat
d_imgRight
(
imgRight
);
cv
::
gpu
::
GpuMat
dst
;
TEST_CYCLE
()
d_csbp
(
d_imgLeft
,
d_imgRight
,
dst
);
TEST_CYCLE
()
d_csbp
->
compute
(
d_imgLeft
,
d_imgRight
,
dst
);
GPU_SANITY_CHECK
(
dst
);
}
...
...
@@ -174,13 +173,13 @@ PERF_TEST_P(ImagePair, DisparityBilateralFilter,
if
(
PERF_RUN_GPU
())
{
cv
::
gpu
::
DisparityBilateralFilter
d_f
ilter
(
ndisp
);
cv
::
Ptr
<
cv
::
gpu
::
DisparityBilateralFilter
>
d_filter
=
cv
::
gpu
::
createDisparityBilateralF
ilter
(
ndisp
);
const
cv
::
gpu
::
GpuMat
d_img
(
img
);
const
cv
::
gpu
::
GpuMat
d_disp
(
disp
);
cv
::
gpu
::
GpuMat
dst
;
TEST_CYCLE
()
d_filter
(
d_disp
,
d_img
,
dst
);
TEST_CYCLE
()
d_filter
->
apply
(
d_disp
,
d_img
,
dst
);
GPU_SANITY_CHECK
(
dst
);
}
...
...
modules/gpustereo/src/disparity_bilateral_filter.cpp
View file @
eff6dccb
...
...
@@ -47,10 +47,7 @@ using namespace cv::gpu;
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
cv
::
gpu
::
DisparityBilateralFilter
::
DisparityBilateralFilter
(
int
,
int
,
int
)
{
throw_no_cuda
();
}
cv
::
gpu
::
DisparityBilateralFilter
::
DisparityBilateralFilter
(
int
,
int
,
int
,
float
,
float
,
float
)
{
throw_no_cuda
();
}
void
cv
::
gpu
::
DisparityBilateralFilter
::
operator
()(
const
GpuMat
&
,
const
GpuMat
&
,
GpuMat
&
,
Stream
&
)
{
throw_no_cuda
();
}
Ptr
<
gpu
::
DisparityBilateralFilter
>
cv
::
gpu
::
createDisparityBilateralFilter
(
int
,
int
,
int
)
{
throw_no_cuda
();
return
Ptr
<
gpu
::
DisparityBilateralFilter
>
();
}
#else
/* !defined (HAVE_CUDA) */
...
...
@@ -65,15 +62,46 @@ namespace cv { namespace gpu { namespace cudev
}
}}}
using
namespace
::
cv
::
gpu
::
cudev
::
disp_bilateral_filter
;
namespace
{
const
float
DEFAULT_EDGE_THRESHOLD
=
0.1
f
;
const
float
DEFAULT_MAX_DISC_THRESHOLD
=
0.2
f
;
const
float
DEFAULT_SIGMA_RANGE
=
10.0
f
;
class
DispBilateralFilterImpl
:
public
gpu
::
DisparityBilateralFilter
{
public
:
DispBilateralFilterImpl
(
int
ndisp
,
int
radius
,
int
iters
);
void
apply
(
InputArray
disparity
,
InputArray
image
,
OutputArray
dst
,
Stream
&
stream
);
int
getNumDisparities
()
const
{
return
ndisp_
;
}
void
setNumDisparities
(
int
numDisparities
)
{
ndisp_
=
numDisparities
;
}
int
getRadius
()
const
{
return
radius_
;
}
void
setRadius
(
int
radius
);
int
getNumIters
()
const
{
return
iters_
;
}
void
setNumIters
(
int
iters
)
{
iters_
=
iters
;
}
inline
void
calc_color_weighted_table
(
GpuMat
&
table_color
,
float
sigma_range
,
int
len
)
double
getEdgeThreshold
()
const
{
return
edge_threshold_
;
}
void
setEdgeThreshold
(
double
edge_threshold
)
{
edge_threshold_
=
(
float
)
edge_threshold
;
}
double
getMaxDiscThreshold
()
const
{
return
max_disc_threshold_
;
}
void
setMaxDiscThreshold
(
double
max_disc_threshold
)
{
max_disc_threshold_
=
(
float
)
max_disc_threshold
;
}
double
getSigmaRange
()
const
{
return
sigma_range_
;
}
void
setSigmaRange
(
double
sigma_range
);
private
:
int
ndisp_
;
int
radius_
;
int
iters_
;
float
edge_threshold_
;
float
max_disc_threshold_
;
float
sigma_range_
;
GpuMat
table_color_
;
GpuMat
table_space_
;
};
void
calc_color_weighted_table
(
GpuMat
&
table_color
,
float
sigma_range
,
int
len
)
{
Mat
cpu_table_color
(
1
,
len
,
CV_32F
);
...
...
@@ -85,7 +113,7 @@ namespace
table_color
.
upload
(
cpu_table_color
);
}
inline
void
calc_space_weighted_filter
(
GpuMat
&
table_space
,
int
win_size
,
float
dist_space
)
void
calc_space_weighted_filter
(
GpuMat
&
table_space
,
int
win_size
,
float
dist_space
)
{
int
half
=
(
win_size
>>
1
);
...
...
@@ -101,54 +129,78 @@ namespace
table_space
.
upload
(
cpu_table_space
);
}
const
float
DEFAULT_EDGE_THRESHOLD
=
0.1
f
;
const
float
DEFAULT_MAX_DISC_THRESHOLD
=
0.2
f
;
const
float
DEFAULT_SIGMA_RANGE
=
10.0
f
;
DispBilateralFilterImpl
::
DispBilateralFilterImpl
(
int
ndisp
,
int
radius
,
int
iters
)
:
ndisp_
(
ndisp
),
radius_
(
radius
),
iters_
(
iters
),
edge_threshold_
(
DEFAULT_EDGE_THRESHOLD
),
max_disc_threshold_
(
DEFAULT_MAX_DISC_THRESHOLD
),
sigma_range_
(
DEFAULT_SIGMA_RANGE
)
{
calc_color_weighted_table
(
table_color_
,
sigma_range_
,
255
);
calc_space_weighted_filter
(
table_space_
,
radius_
*
2
+
1
,
radius_
+
1.0
f
);
}
void
DispBilateralFilterImpl
::
setRadius
(
int
radius
)
{
radius_
=
radius
;
calc_space_weighted_filter
(
table_space_
,
radius_
*
2
+
1
,
radius_
+
1.0
f
);
}
void
DispBilateralFilterImpl
::
setSigmaRange
(
double
sigma_range
)
{
sigma_range_
=
(
float
)
sigma_range
;
calc_color_weighted_table
(
table_color_
,
sigma_range_
,
255
);
}
template
<
typename
T
>
void
disp_bilateral_filter_operator
(
int
ndisp
,
int
radius
,
int
iters
,
float
edge_threshold
,
float
max_disc_threshold
,
GpuMat
&
table_color
,
GpuMat
&
table_space
,
const
GpuMat
&
disp
,
const
GpuMat
&
img
,
GpuMat
&
dst
,
Stream
&
stream
)
void
disp_bilateral_filter_operator
(
int
ndisp
,
int
radius
,
int
iters
,
float
edge_threshold
,
float
max_disc_threshold
,
GpuMat
&
table_color
,
GpuMat
&
table_space
,
const
GpuMat
&
disp
,
const
GpuMat
&
img
,
OutputArray
_dst
,
Stream
&
stream
)
{
short
edge_disc
=
std
::
max
<
short
>
(
short
(
1
),
short
(
ndisp
*
edge_threshold
+
0.5
));
short
max_disc
=
short
(
ndisp
*
max_disc_threshold
+
0.5
);
using
namespace
cv
::
gpu
::
cudev
::
disp_bilateral_filter
;
const
short
edge_disc
=
std
::
max
<
short
>
(
short
(
1
),
short
(
ndisp
*
edge_threshold
+
0.5
));
const
short
max_disc
=
short
(
ndisp
*
max_disc_threshold
+
0.5
);
disp_load_constants
(
table_color
.
ptr
<
float
>
(),
table_space
,
ndisp
,
radius
,
edge_disc
,
max_disc
);
if
(
&
dst
!=
&
disp
)
{
_dst
.
create
(
disp
.
size
(),
disp
.
type
());
GpuMat
dst
=
_dst
.
getGpuMat
();
if
(
dst
.
data
!=
disp
.
data
)
disp
.
copyTo
(
dst
,
stream
);
}
disp_bilateral_filter
<
T
>
(
dst
,
img
,
img
.
channels
(),
iters
,
StreamAccessor
::
getStream
(
stream
));
}
typedef
void
(
*
bilateral_filter_operator_t
)(
int
ndisp
,
int
radius
,
int
iters
,
float
edge_threshold
,
float
max_disc_threshold
,
GpuMat
&
table_color
,
GpuMat
&
table_space
,
const
GpuMat
&
disp
,
const
GpuMat
&
img
,
GpuMat
&
dst
,
Stream
&
stream
);
void
DispBilateralFilterImpl
::
apply
(
InputArray
_disp
,
InputArray
_image
,
OutputArray
dst
,
Stream
&
stream
)
{
typedef
void
(
*
bilateral_filter_operator_t
)(
int
ndisp
,
int
radius
,
int
iters
,
float
edge_threshold
,
float
max_disc_threshold
,
GpuMat
&
table_color
,
GpuMat
&
table_space
,
const
GpuMat
&
disp
,
const
GpuMat
&
img
,
OutputArray
dst
,
Stream
&
stream
);
const
bilateral_filter_operator_t
operators
[]
=
{
disp_bilateral_filter_operator
<
unsigned
char
>
,
0
,
0
,
disp_bilateral_filter_operator
<
short
>
,
0
,
0
,
0
,
0
};
const
bilateral_filter_operator_t
operators
[]
=
{
disp_bilateral_filter_operator
<
unsigned
char
>
,
0
,
0
,
disp_bilateral_filter_operator
<
short
>
,
0
,
0
,
0
,
0
};
}
CV_Assert
(
0
<
ndisp_
&&
0
<
radius_
&&
0
<
iters_
);
cv
::
gpu
::
DisparityBilateralFilter
::
DisparityBilateralFilter
(
int
ndisp_
,
int
radius_
,
int
iters_
)
:
ndisp
(
ndisp_
),
radius
(
radius_
),
iters
(
iters_
),
edge_threshold
(
DEFAULT_EDGE_THRESHOLD
),
max_disc_threshold
(
DEFAULT_MAX_DISC_THRESHOLD
),
sigma_range
(
DEFAULT_SIGMA_RANGE
)
{
calc_color_weighted_table
(
table_color
,
sigma_range
,
255
);
calc_space_weighted_filter
(
table_space
,
radius
*
2
+
1
,
radius
+
1.0
f
);
}
GpuMat
disp
=
_disp
.
getGpuMat
();
GpuMat
img
=
_image
.
getGpuMat
();
cv
::
gpu
::
DisparityBilateralFilter
::
DisparityBilateralFilter
(
int
ndisp_
,
int
radius_
,
int
iters_
,
float
edge_threshold_
,
float
max_disc_threshold_
,
float
sigma_range_
)
:
ndisp
(
ndisp_
),
radius
(
radius_
),
iters
(
iters_
),
edge_threshold
(
edge_threshold_
),
max_disc_threshold
(
max_disc_threshold_
),
sigma_range
(
sigma_range_
)
{
calc_color_weighted_table
(
table_color
,
sigma_range
,
255
);
calc_space_weighted_filter
(
table_space
,
radius
*
2
+
1
,
radius
+
1.0
f
);
CV_Assert
(
disp
.
type
()
==
CV_8U
||
disp
.
type
()
==
CV_16S
);
CV_Assert
(
img
.
type
()
==
CV_8UC1
||
img
.
type
()
==
CV_8UC3
);
CV_Assert
(
disp
.
size
()
==
img
.
size
()
);
operators
[
disp
.
type
()](
ndisp_
,
radius_
,
iters_
,
edge_threshold_
,
max_disc_threshold_
,
table_color_
,
table_space_
,
disp
,
img
,
dst
,
stream
);
}
}
void
cv
::
gpu
::
DisparityBilateralFilter
::
operator
()(
const
GpuMat
&
disp
,
const
GpuMat
&
img
,
GpuMat
&
dst
,
Stream
&
stream
)
Ptr
<
gpu
::
DisparityBilateralFilter
>
cv
::
gpu
::
createDisparityBilateralFilter
(
int
ndisp
,
int
radius
,
int
iters
)
{
CV_DbgAssert
(
0
<
ndisp
&&
0
<
radius
&&
0
<
iters
);
CV_Assert
(
disp
.
rows
==
img
.
rows
&&
disp
.
cols
==
img
.
cols
&&
(
disp
.
type
()
==
CV_8U
||
disp
.
type
()
==
CV_16S
)
&&
(
img
.
type
()
==
CV_8UC1
||
img
.
type
()
==
CV_8UC3
));
operators
[
disp
.
type
()](
ndisp
,
radius
,
iters
,
edge_threshold
,
max_disc_threshold
,
table_color
,
table_space
,
disp
,
img
,
dst
,
stream
);
return
new
DispBilateralFilterImpl
(
ndisp
,
radius
,
iters
);
}
#endif
/* !defined (HAVE_CUDA) */
modules/gpustereo/src/precomp.hpp
View file @
eff6dccb
...
...
@@ -48,5 +48,6 @@
#include "opencv2/gpustereo.hpp"
#include "opencv2/core/private.gpu.hpp"
#include "opencv2/core/utility.hpp"
#endif
/* __OPENCV_PRECOMP_H__ */
modules/gpustereo/src/stereobm.cpp
View file @
eff6dccb
...
...
@@ -47,11 +47,7 @@ using namespace cv::gpu;
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
cv
::
gpu
::
StereoBM_GPU
::
StereoBM_GPU
()
{
throw_no_cuda
();
}
cv
::
gpu
::
StereoBM_GPU
::
StereoBM_GPU
(
int
,
int
,
int
)
{
throw_no_cuda
();
}
bool
cv
::
gpu
::
StereoBM_GPU
::
checkIfGpuCallReasonable
()
{
throw_no_cuda
();
return
false
;
}
void
cv
::
gpu
::
StereoBM_GPU
::
operator
()
(
const
GpuMat
&
,
const
GpuMat
&
,
GpuMat
&
,
Stream
&
)
{
throw_no_cuda
();
}
Ptr
<
gpu
::
StereoBM
>
cv
::
gpu
::
createStereoBM
(
int
,
int
)
{
throw_no_cuda
();
return
Ptr
<
gpu
::
StereoBM
>
();
}
#else
/* !defined (HAVE_CUDA) */
...
...
@@ -67,74 +63,123 @@ namespace cv { namespace gpu { namespace cudev
namespace
{
const
float
defaultAvgTexThreshold
=
3
;
}
class
StereoBMImpl
:
public
gpu
::
StereoBM
{
public
:
StereoBMImpl
(
int
numDisparities
,
int
blockSize
);
cv
::
gpu
::
StereoBM_GPU
::
StereoBM_GPU
()
:
preset
(
BASIC_PRESET
),
ndisp
(
DEFAULT_NDISP
),
winSize
(
DEFAULT_WINSZ
),
avergeTexThreshold
(
defaultAvgTexThreshold
)
{
}
void
compute
(
InputArray
left
,
InputArray
right
,
OutputArray
disparity
);
void
compute
(
InputArray
left
,
InputArray
right
,
OutputArray
disparity
,
Stream
&
stream
);
cv
::
gpu
::
StereoBM_GPU
::
StereoBM_GPU
(
int
preset_
,
int
ndisparities_
,
int
winSize_
)
:
preset
(
preset_
),
ndisp
(
ndisparities_
),
winSize
(
winSize_
),
avergeTexThreshold
(
defaultAvgTexThreshold
)
{
const
int
max_supported_ndisp
=
1
<<
(
sizeof
(
unsigned
char
)
*
8
);
CV_Assert
(
0
<
ndisp
&&
ndisp
<=
max_supported_ndisp
);
CV_Assert
(
ndisp
%
8
==
0
);
CV_Assert
(
winSize
%
2
==
1
);
}
int
getMinDisparity
()
const
{
return
0
;
}
void
setMinDisparity
(
int
/*minDisparity*/
)
{}
bool
cv
::
gpu
::
StereoBM_GPU
::
checkIfGpuCallReasonable
()
{
if
(
0
==
getCudaEnabledDeviceCount
())
return
false
;
int
getNumDisparities
()
const
{
return
ndisp_
;
}
void
setNumDisparities
(
int
numDisparities
)
{
ndisp_
=
numDisparities
;
}
DeviceInfo
device_info
;
int
getBlockSize
()
const
{
return
winSize_
;
}
void
setBlockSize
(
int
blockSize
)
{
winSize_
=
blockSize
;
}
if
(
device_info
.
major
()
>
1
||
device_info
.
multiProcessorCount
()
>
16
)
return
true
;
int
getSpeckleWindowSize
()
const
{
return
0
;
}
void
setSpeckleWindowSize
(
int
/*speckleWindowSize*/
)
{}
return
false
;
}
int
getSpeckleRange
()
const
{
return
0
;
}
void
setSpeckleRange
(
int
/*speckleRange*/
)
{
}
namespace
{
void
stereo_bm_gpu_operator
(
GpuMat
&
minSSD
,
GpuMat
&
leBuf
,
GpuMat
&
riBuf
,
int
preset
,
int
ndisp
,
int
winSize
,
float
avergeTexThreshold
,
const
GpuMat
&
left
,
const
GpuMat
&
right
,
GpuMat
&
disparity
,
cudaStream_t
stream
)
int
getDisp12MaxDiff
()
const
{
return
0
;
}
void
setDisp12MaxDiff
(
int
/*disp12MaxDiff*/
)
{}
int
getPreFilterType
()
const
{
return
preset_
;
}
void
setPreFilterType
(
int
preFilterType
)
{
preset_
=
preFilterType
;
}
int
getPreFilterSize
()
const
{
return
0
;
}
void
setPreFilterSize
(
int
/*preFilterSize*/
)
{}
int
getPreFilterCap
()
const
{
return
preFilterCap_
;
}
void
setPreFilterCap
(
int
preFilterCap
)
{
preFilterCap_
=
preFilterCap
;
}
int
getTextureThreshold
()
const
{
return
avergeTexThreshold_
;
}
void
setTextureThreshold
(
int
textureThreshold
)
{
avergeTexThreshold_
=
textureThreshold
;
}
int
getUniquenessRatio
()
const
{
return
0
;
}
void
setUniquenessRatio
(
int
/*uniquenessRatio*/
)
{}
int
getSmallerBlockSize
()
const
{
return
0
;
}
void
setSmallerBlockSize
(
int
/*blockSize*/
){}
Rect
getROI1
()
const
{
return
Rect
();
}
void
setROI1
(
Rect
/*roi1*/
)
{}
Rect
getROI2
()
const
{
return
Rect
();
}
void
setROI2
(
Rect
/*roi2*/
)
{}
private
:
int
preset_
;
int
ndisp_
;
int
winSize_
;
int
preFilterCap_
;
float
avergeTexThreshold_
;
GpuMat
minSSD_
,
leBuf_
,
riBuf_
;
};
StereoBMImpl
::
StereoBMImpl
(
int
numDisparities
,
int
blockSize
)
:
preset_
(
0
),
ndisp_
(
numDisparities
),
winSize_
(
blockSize
),
preFilterCap_
(
31
),
avergeTexThreshold_
(
3
)
{
}
void
StereoBMImpl
::
compute
(
InputArray
left
,
InputArray
right
,
OutputArray
disparity
)
{
compute
(
left
,
right
,
disparity
,
Stream
::
Null
());
}
void
StereoBMImpl
::
compute
(
InputArray
_left
,
InputArray
_right
,
OutputArray
_disparity
,
Stream
&
_stream
)
{
using
namespace
::
cv
::
gpu
::
cudev
::
stereobm
;
CV_Assert
(
left
.
rows
==
right
.
rows
&&
left
.
cols
==
right
.
cols
);
CV_Assert
(
left
.
type
()
==
CV_8UC1
);
CV_Assert
(
right
.
type
()
==
CV_8UC1
);
const
int
max_supported_ndisp
=
1
<<
(
sizeof
(
unsigned
char
)
*
8
);
CV_Assert
(
0
<
ndisp_
&&
ndisp_
<=
max_supported_ndisp
);
CV_Assert
(
ndisp_
%
8
==
0
);
CV_Assert
(
winSize_
%
2
==
1
);
GpuMat
left
=
_left
.
getGpuMat
();
GpuMat
right
=
_right
.
getGpuMat
();
CV_Assert
(
left
.
type
()
==
CV_8UC1
);
CV_Assert
(
left
.
size
()
==
right
.
size
()
&&
left
.
type
()
==
right
.
type
()
);
_disparity
.
create
(
left
.
size
(),
CV_8UC1
);
GpuMat
disparity
=
_disparity
.
getGpuMat
();
cudaStream_t
stream
=
StreamAccessor
::
getStream
(
_stream
);
disparity
.
create
(
left
.
size
(),
CV_8U
);
minSSD
.
create
(
left
.
size
(),
CV_32S
);
gpu
::
ensureSizeIsEnough
(
left
.
size
(),
CV_32SC1
,
minSSD_
);
GpuMat
le_for_bm
=
left
;
GpuMat
ri_for_bm
=
right
;
PtrStepSzb
le_for_bm
=
left
;
PtrStepSzb
ri_for_bm
=
right
;
if
(
preset
==
StereoBM_GPU
::
PREFILTER_XSOBEL
)
if
(
preset
_
==
cv
::
StereoBM
::
PREFILTER_XSOBEL
)
{
leBuf
.
create
(
left
.
size
(),
left
.
type
()
);
riBuf
.
create
(
right
.
size
(),
right
.
type
()
);
gpu
::
ensureSizeIsEnough
(
left
.
size
(),
left
.
type
(),
leBuf_
);
gpu
::
ensureSizeIsEnough
(
right
.
size
(),
right
.
type
(),
riBuf_
);
prefilter_xsobel
(
left
,
leBuf
,
31
,
stream
);
prefilter_xsobel
(
right
,
riBuf
,
31
,
stream
);
prefilter_xsobel
(
left
,
leBuf
_
,
preFilterCap_
,
stream
);
prefilter_xsobel
(
right
,
riBuf
_
,
preFilterCap_
,
stream
);
le_for_bm
=
leBuf
;
ri_for_bm
=
riBuf
;
le_for_bm
=
leBuf
_
;
ri_for_bm
=
riBuf
_
;
}
stereoBM_GPU
(
le_for_bm
,
ri_for_bm
,
disparity
,
ndisp
,
winSize
,
minSSD
,
stream
);
stereoBM_GPU
(
le_for_bm
,
ri_for_bm
,
disparity
,
ndisp
_
,
winSize_
,
minSSD_
,
stream
);
if
(
avergeTexThreshold
)
postfilter_textureness
(
le_for_bm
,
winSize
,
avergeTexThreshold
,
disparity
,
stream
);
if
(
avergeTexThreshold
_
>
0
)
postfilter_textureness
(
le_for_bm
,
winSize
_
,
avergeTexThreshold_
,
disparity
,
stream
);
}
}
void
cv
::
gpu
::
StereoBM_GPU
::
operator
()
(
const
GpuMat
&
left
,
const
GpuMat
&
right
,
GpuMat
&
disparity
,
Stream
&
stream
)
Ptr
<
gpu
::
StereoBM
>
cv
::
gpu
::
createStereoBM
(
int
numDisparities
,
int
blockSize
)
{
stereo_bm_gpu_operator
(
minSSD
,
leBuf
,
riBuf
,
preset
,
ndisp
,
winSize
,
avergeTexThreshold
,
left
,
right
,
disparity
,
StreamAccessor
::
getStream
(
stream
)
);
return
new
StereoBMImpl
(
numDisparities
,
blockSize
);
}
#endif
/* !defined (HAVE_CUDA) */
modules/gpustereo/src/stereobp.cpp
View file @
eff6dccb
This diff is collapsed.
Click to expand it.
modules/gpustereo/src/stereocsbp.cpp
View file @
eff6dccb
This diff is collapsed.
Click to expand it.
modules/gpustereo/src/util.cpp
View file @
eff6dccb
...
...
@@ -47,8 +47,8 @@ using namespace cv::gpu;
#if !defined HAVE_CUDA || defined(CUDA_DISABLER)
void
cv
::
gpu
::
reprojectImageTo3D
(
const
GpuMat
&
,
GpuMat
&
,
const
Mat
&
,
int
,
Stream
&
)
{
throw_no_cuda
();
}
void
cv
::
gpu
::
drawColorDisp
(
const
GpuMat
&
,
GpuMat
&
,
int
,
Stream
&
)
{
throw_no_cuda
();
}
void
cv
::
gpu
::
reprojectImageTo3D
(
InputArray
,
OutputArray
,
InputArray
,
int
,
Stream
&
)
{
throw_no_cuda
();
}
void
cv
::
gpu
::
drawColorDisp
(
InputArray
,
OutputArray
,
int
,
Stream
&
)
{
throw_no_cuda
();
}
#else
...
...
@@ -61,7 +61,7 @@ namespace cv { namespace gpu { namespace cudev
void
reprojectImageTo3D_gpu
(
const
PtrStepSzb
disp
,
PtrStepSzb
xyz
,
const
float
*
q
,
cudaStream_t
stream
);
}}}
void
cv
::
gpu
::
reprojectImageTo3D
(
const
GpuMat
&
disp
,
GpuMat
&
xyz
,
const
Mat
&
Q
,
int
dst_cn
,
Stream
&
stream
)
void
cv
::
gpu
::
reprojectImageTo3D
(
InputArray
_disp
,
OutputArray
_xyz
,
InputArray
_
Q
,
int
dst_cn
,
Stream
&
stream
)
{
using
namespace
cv
::
gpu
::
cudev
;
...
...
@@ -72,11 +72,15 @@ void cv::gpu::reprojectImageTo3D(const GpuMat& disp, GpuMat& xyz, const Mat& Q,
{
reprojectImageTo3D_gpu
<
uchar
,
float4
>
,
0
,
0
,
reprojectImageTo3D_gpu
<
short
,
float4
>
}
};
CV_Assert
(
disp
.
type
()
==
CV_8U
||
disp
.
type
()
==
CV_16S
);
CV_Assert
(
Q
.
type
()
==
CV_32F
&&
Q
.
rows
==
4
&&
Q
.
cols
==
4
&&
Q
.
isContinuous
());
CV_Assert
(
dst_cn
==
3
||
dst_cn
==
4
);
GpuMat
disp
=
_disp
.
getGpuMat
();
Mat
Q
=
_Q
.
getMat
();
xyz
.
create
(
disp
.
size
(),
CV_MAKE_TYPE
(
CV_32F
,
dst_cn
));
CV_Assert
(
disp
.
type
()
==
CV_8U
||
disp
.
type
()
==
CV_16S
);
CV_Assert
(
Q
.
type
()
==
CV_32F
&&
Q
.
rows
==
4
&&
Q
.
cols
==
4
&&
Q
.
isContinuous
()
);
CV_Assert
(
dst_cn
==
3
||
dst_cn
==
4
);
_xyz
.
create
(
disp
.
size
(),
CV_MAKE_TYPE
(
CV_32F
,
dst_cn
));
GpuMat
xyz
=
_xyz
.
getGpuMat
();
funcs
[
dst_cn
==
4
][
disp
.
type
()](
disp
,
xyz
,
Q
.
ptr
<
float
>
(),
StreamAccessor
::
getStream
(
stream
));
}
...
...
@@ -93,23 +97,25 @@ namespace cv { namespace gpu { namespace cudev
namespace
{
template
<
typename
T
>
void
drawColorDisp_caller
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
int
ndisp
,
const
cudaStream_t
&
stream
)
void
drawColorDisp_caller
(
const
GpuMat
&
src
,
OutputArray
_
dst
,
int
ndisp
,
const
cudaStream_t
&
stream
)
{
using
namespace
::
cv
::
gpu
::
cudev
;
dst
.
create
(
src
.
size
(),
CV_8UC4
);
_dst
.
create
(
src
.
size
(),
CV_8UC4
);
GpuMat
dst
=
_dst
.
getGpuMat
();
drawColorDisp_gpu
((
PtrStepSz
<
T
>
)
src
,
dst
,
ndisp
,
stream
);
}
typedef
void
(
*
drawColorDisp_caller_t
)(
const
GpuMat
&
src
,
GpuMat
&
dst
,
int
ndisp
,
const
cudaStream_t
&
stream
);
const
drawColorDisp_caller_t
drawColorDisp_callers
[]
=
{
drawColorDisp_caller
<
unsigned
char
>
,
0
,
0
,
drawColorDisp_caller
<
short
>
,
0
,
0
,
0
,
0
};
}
void
cv
::
gpu
::
drawColorDisp
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
int
ndisp
,
Stream
&
stream
)
void
cv
::
gpu
::
drawColorDisp
(
InputArray
_src
,
OutputArray
dst
,
int
ndisp
,
Stream
&
stream
)
{
CV_Assert
(
src
.
type
()
==
CV_8U
||
src
.
type
()
==
CV_16S
);
typedef
void
(
*
drawColorDisp_caller_t
)(
const
GpuMat
&
src
,
OutputArray
dst
,
int
ndisp
,
const
cudaStream_t
&
stream
);
const
drawColorDisp_caller_t
drawColorDisp_callers
[]
=
{
drawColorDisp_caller
<
unsigned
char
>
,
0
,
0
,
drawColorDisp_caller
<
short
>
,
0
,
0
,
0
,
0
};
GpuMat
src
=
_src
.
getGpuMat
();
CV_Assert
(
src
.
type
()
==
CV_8U
||
src
.
type
()
==
CV_16S
);
drawColorDisp_callers
[
src
.
type
()](
src
,
dst
,
ndisp
,
StreamAccessor
::
getStream
(
stream
));
}
...
...
modules/gpustereo/test/test_stereo.cpp
View file @
eff6dccb
...
...
@@ -71,10 +71,10 @@ GPU_TEST_P(StereoBM, Regression)
ASSERT_FALSE
(
right_image
.
empty
());
ASSERT_FALSE
(
disp_gold
.
empty
());
cv
::
gpu
::
StereoBM_GPU
bm
(
0
,
128
,
19
);
cv
::
Ptr
<
cv
::
StereoBM
>
bm
=
cv
::
gpu
::
createStereoBM
(
128
,
19
);
cv
::
gpu
::
GpuMat
disp
;
bm
(
loadMat
(
left_image
),
loadMat
(
right_image
),
disp
);
bm
->
compute
(
loadMat
(
left_image
),
loadMat
(
right_image
),
disp
);
EXPECT_MAT_NEAR
(
disp_gold
,
disp
,
0.0
);
}
...
...
@@ -106,10 +106,15 @@ GPU_TEST_P(StereoBeliefPropagation, Regression)
ASSERT_FALSE
(
right_image
.
empty
());
ASSERT_FALSE
(
disp_gold
.
empty
());
cv
::
gpu
::
StereoBeliefPropagation
bp
(
64
,
8
,
2
,
25
,
0.1
f
,
15
,
1
,
CV_16S
);
cv
::
Ptr
<
cv
::
gpu
::
StereoBeliefPropagation
>
bp
=
cv
::
gpu
::
createStereoBeliefPropagation
(
64
,
8
,
2
,
CV_16S
);
bp
->
setMaxDataTerm
(
25.0
);
bp
->
setDataWeight
(
0.1
);
bp
->
setMaxDiscTerm
(
15.0
);
bp
->
setDiscSingleJump
(
1.0
);
cv
::
gpu
::
GpuMat
disp
;
bp
(
loadMat
(
left_image
),
loadMat
(
right_image
),
disp
);
bp
->
compute
(
loadMat
(
left_image
),
loadMat
(
right_image
),
disp
);
cv
::
Mat
h_disp
(
disp
);
h_disp
.
convertTo
(
h_disp
,
disp_gold
.
depth
());
...
...
@@ -150,10 +155,10 @@ GPU_TEST_P(StereoConstantSpaceBP, Regression)
ASSERT_FALSE
(
right_image
.
empty
());
ASSERT_FALSE
(
disp_gold
.
empty
());
cv
::
gpu
::
StereoConstantSpaceBP
csbp
(
128
,
16
,
4
,
4
);
cv
::
Ptr
<
cv
::
gpu
::
StereoConstantSpaceBP
>
csbp
=
cv
::
gpu
::
createStereoConstantSpaceBP
(
128
,
16
,
4
,
4
);
cv
::
gpu
::
GpuMat
disp
;
csbp
(
loadMat
(
left_image
),
loadMat
(
right_image
),
disp
);
csbp
->
compute
(
loadMat
(
left_image
),
loadMat
(
right_image
),
disp
);
cv
::
Mat
h_disp
(
disp
);
h_disp
.
convertTo
(
h_disp
,
disp_gold
.
depth
());
...
...
samples/gpu/driver_api_stereo_multi.cpp
View file @
eff6dccb
...
...
@@ -85,7 +85,7 @@ void inline contextOff()
// GPUs data
GpuMat
d_left
[
2
];
GpuMat
d_right
[
2
];
StereoBM_GPU
*
bm
[
2
];
Ptr
<
gpu
::
StereoBM
>
bm
[
2
];
GpuMat
d_result
[
2
];
static
void
printHelp
()
...
...
@@ -162,14 +162,14 @@ int main(int argc, char** argv)
contextOn
(
0
);
d_left
[
0
].
upload
(
left
.
rowRange
(
0
,
left
.
rows
/
2
));
d_right
[
0
].
upload
(
right
.
rowRange
(
0
,
right
.
rows
/
2
));
bm
[
0
]
=
new
StereoBM_GPU
();
bm
[
0
]
=
gpu
::
createStereoBM
();
contextOff
();
// Split source images for processing on the GPU #1
contextOn
(
1
);
d_left
[
1
].
upload
(
left
.
rowRange
(
left
.
rows
/
2
,
left
.
rows
));
d_right
[
1
].
upload
(
right
.
rowRange
(
right
.
rows
/
2
,
right
.
rows
));
bm
[
1
]
=
new
StereoBM_GPU
();
bm
[
1
]
=
gpu
::
createStereoBM
();
contextOff
();
// Execute calculation in two threads using two GPUs
...
...
@@ -182,7 +182,7 @@ int main(int argc, char** argv)
d_left
[
0
].
release
();
d_right
[
0
].
release
();
d_result
[
0
].
release
();
delete
bm
[
0
]
;
bm
[
0
].
release
()
;
contextOff
();
// Release the second GPU resources
...
...
@@ -191,7 +191,7 @@ int main(int argc, char** argv)
d_left
[
1
].
release
();
d_right
[
1
].
release
();
d_result
[
1
].
release
();
delete
bm
[
1
]
;
bm
[
1
].
release
()
;
contextOff
();
waitKey
();
...
...
@@ -204,8 +204,7 @@ void Worker::operator()(int device_id) const
{
contextOn
(
device_id
);
bm
[
device_id
]
->
operator
()(
d_left
[
device_id
],
d_right
[
device_id
],
d_result
[
device_id
]);
bm
[
device_id
]
->
compute
(
d_left
[
device_id
],
d_right
[
device_id
],
d_result
[
device_id
]);
std
::
cout
<<
"GPU #"
<<
device_id
<<
" ("
<<
DeviceInfo
().
name
()
<<
"): finished
\n
"
;
...
...
samples/gpu/stereo_match.cpp
View file @
eff6dccb
...
...
@@ -65,9 +65,9 @@ private:
Mat
left
,
right
;
gpu
::
GpuMat
d_left
,
d_right
;
gpu
::
StereoBM_GPU
bm
;
gpu
::
StereoBeliefPropagation
bp
;
gpu
::
StereoConstantSpaceBP
csbp
;
Ptr
<
gpu
::
StereoBM
>
bm
;
Ptr
<
gpu
::
StereoBeliefPropagation
>
bp
;
Ptr
<
gpu
::
StereoConstantSpaceBP
>
csbp
;
int64
work_begin
;
double
work_fps
;
...
...
@@ -172,9 +172,9 @@ void App::run()
imshow
(
"right"
,
right
);
// Set common parameters
bm
.
ndisp
=
p
.
ndisp
;
bp
.
ndisp
=
p
.
ndisp
;
csbp
.
ndisp
=
p
.
ndisp
;
bm
=
gpu
::
createStereoBM
(
p
.
ndisp
)
;
bp
=
gpu
::
createStereoBeliefPropagation
(
p
.
ndisp
)
;
csbp
=
cv
::
gpu
::
createStereoConstantSpaceBP
(
p
.
ndisp
)
;
// Prepare disparity map of specified type
Mat
disp
(
left
.
size
(),
CV_8U
);
...
...
@@ -201,10 +201,10 @@ void App::run()
imshow
(
"left"
,
left
);
imshow
(
"right"
,
right
);
}
bm
(
d_left
,
d_right
,
d_disp
);
bm
->
compute
(
d_left
,
d_right
,
d_disp
);
break
;
case
Params
:
:
BP
:
bp
(
d_left
,
d_right
,
d_disp
);
break
;
case
Params
:
:
CSBP
:
csbp
(
d_left
,
d_right
,
d_disp
);
break
;
case
Params
:
:
BP
:
bp
->
compute
(
d_left
,
d_right
,
d_disp
);
break
;
case
Params
:
:
CSBP
:
csbp
->
compute
(
d_left
,
d_right
,
d_disp
);
break
;
}
workEnd
();
...
...
@@ -228,16 +228,16 @@ void App::printParams() const
switch
(
p
.
method
)
{
case
Params
:
:
BM
:
cout
<<
"win_size: "
<<
bm
.
winSize
<<
endl
;
cout
<<
"prefilter_sobel: "
<<
bm
.
preset
<<
endl
;
cout
<<
"win_size: "
<<
bm
->
getBlockSize
()
<<
endl
;
cout
<<
"prefilter_sobel: "
<<
bm
->
getPreFilterType
()
<<
endl
;
break
;
case
Params
:
:
BP
:
cout
<<
"iter_count: "
<<
bp
.
iters
<<
endl
;
cout
<<
"level_count: "
<<
bp
.
levels
<<
endl
;
cout
<<
"iter_count: "
<<
bp
->
getNumIters
()
<<
endl
;
cout
<<
"level_count: "
<<
bp
->
getNumLevels
()
<<
endl
;
break
;
case
Params
:
:
CSBP
:
cout
<<
"iter_count: "
<<
csbp
.
iters
<<
endl
;
cout
<<
"level_count: "
<<
csbp
.
levels
<<
endl
;
cout
<<
"iter_count: "
<<
csbp
->
getNumIters
()
<<
endl
;
cout
<<
"level_count: "
<<
csbp
->
getNumLevels
()
<<
endl
;
break
;
}
cout
<<
endl
;
...
...
@@ -289,92 +289,92 @@ void App::handleKey(char key)
case
's'
:
case
'S'
:
if
(
p
.
method
==
Params
::
BM
)
{
switch
(
bm
.
preset
)
switch
(
bm
->
getPreFilterType
()
)
{
case
gpu
:
:
StereoBM_GPU
::
BASIC_PRESET
:
bm
.
preset
=
gpu
::
StereoBM_GPU
::
PREFILTER_XSOBEL
;
case
0
:
bm
->
setPreFilterType
(
cv
::
StereoBM
::
PREFILTER_XSOBEL
)
;
break
;
case
gpu
:
:
StereoBM_GPU
::
PREFILTER_XSOBEL
:
bm
.
preset
=
gpu
::
StereoBM_GPU
::
BASIC_PRESET
;
case
cv
:
:
StereoBM
::
PREFILTER_XSOBEL
:
bm
->
setPreFilterType
(
0
)
;
break
;
}
cout
<<
"prefilter_sobel: "
<<
bm
.
preset
<<
endl
;
cout
<<
"prefilter_sobel: "
<<
bm
->
getPreFilterType
()
<<
endl
;
}
break
;
case
'1'
:
p
.
ndisp
=
p
.
ndisp
==
1
?
8
:
p
.
ndisp
+
8
;
cout
<<
"ndisp: "
<<
p
.
ndisp
<<
endl
;
bm
.
ndisp
=
p
.
ndisp
;
bp
.
ndisp
=
p
.
ndisp
;
csbp
.
ndisp
=
p
.
ndisp
;
bm
->
setNumDisparities
(
p
.
ndisp
)
;
bp
->
setNumDisparities
(
p
.
ndisp
)
;
csbp
->
setNumDisparities
(
p
.
ndisp
)
;
break
;
case
'q'
:
case
'Q'
:
p
.
ndisp
=
max
(
p
.
ndisp
-
8
,
1
);
cout
<<
"ndisp: "
<<
p
.
ndisp
<<
endl
;
bm
.
ndisp
=
p
.
ndisp
;
bp
.
ndisp
=
p
.
ndisp
;
csbp
.
ndisp
=
p
.
ndisp
;
bm
->
setNumDisparities
(
p
.
ndisp
)
;
bp
->
setNumDisparities
(
p
.
ndisp
)
;
csbp
->
setNumDisparities
(
p
.
ndisp
)
;
break
;
case
'2'
:
if
(
p
.
method
==
Params
::
BM
)
{
bm
.
winSize
=
min
(
bm
.
winSize
+
1
,
51
);
cout
<<
"win_size: "
<<
bm
.
winSize
<<
endl
;
bm
->
setBlockSize
(
min
(
bm
->
getBlockSize
()
+
1
,
51
)
);
cout
<<
"win_size: "
<<
bm
->
getBlockSize
()
<<
endl
;
}
break
;
case
'w'
:
case
'W'
:
if
(
p
.
method
==
Params
::
BM
)
{
bm
.
winSize
=
max
(
bm
.
winSize
-
1
,
2
);
cout
<<
"win_size: "
<<
bm
.
winSize
<<
endl
;
bm
->
setBlockSize
(
max
(
bm
->
getBlockSize
()
-
1
,
2
)
);
cout
<<
"win_size: "
<<
bm
->
getBlockSize
()
<<
endl
;
}
break
;
case
'3'
:
if
(
p
.
method
==
Params
::
BP
)
{
bp
.
iters
+=
1
;
cout
<<
"iter_count: "
<<
bp
.
iters
<<
endl
;
bp
->
setNumIters
(
bp
->
getNumIters
()
+
1
)
;
cout
<<
"iter_count: "
<<
bp
->
getNumIters
()
<<
endl
;
}
else
if
(
p
.
method
==
Params
::
CSBP
)
{
csbp
.
iters
+=
1
;
cout
<<
"iter_count: "
<<
csbp
.
iters
<<
endl
;
csbp
->
setNumIters
(
csbp
->
getNumIters
()
+
1
)
;
cout
<<
"iter_count: "
<<
csbp
->
getNumIters
()
<<
endl
;
}
break
;
case
'e'
:
case
'E'
:
if
(
p
.
method
==
Params
::
BP
)
{
bp
.
iters
=
max
(
bp
.
iters
-
1
,
1
);
cout
<<
"iter_count: "
<<
bp
.
iters
<<
endl
;
bp
->
setNumIters
(
max
(
bp
->
getNumIters
()
-
1
,
1
)
);
cout
<<
"iter_count: "
<<
bp
->
getNumIters
()
<<
endl
;
}
else
if
(
p
.
method
==
Params
::
CSBP
)
{
csbp
.
iters
=
max
(
csbp
.
iters
-
1
,
1
);
cout
<<
"iter_count: "
<<
csbp
.
iters
<<
endl
;
csbp
->
setNumIters
(
max
(
csbp
->
getNumIters
()
-
1
,
1
)
);
cout
<<
"iter_count: "
<<
csbp
->
getNumIters
()
<<
endl
;
}
break
;
case
'4'
:
if
(
p
.
method
==
Params
::
BP
)
{
bp
.
levels
+=
1
;
cout
<<
"level_count: "
<<
bp
.
levels
<<
endl
;
bp
->
setNumLevels
(
bp
->
getNumLevels
()
+
1
)
;
cout
<<
"level_count: "
<<
bp
->
getNumLevels
()
<<
endl
;
}
else
if
(
p
.
method
==
Params
::
CSBP
)
{
csbp
.
levels
+=
1
;
cout
<<
"level_count: "
<<
csbp
.
levels
<<
endl
;
csbp
->
setNumLevels
(
csbp
->
getNumLevels
()
+
1
)
;
cout
<<
"level_count: "
<<
csbp
->
getNumLevels
()
<<
endl
;
}
break
;
case
'r'
:
case
'R'
:
if
(
p
.
method
==
Params
::
BP
)
{
bp
.
levels
=
max
(
bp
.
levels
-
1
,
1
);
cout
<<
"level_count: "
<<
bp
.
levels
<<
endl
;
bp
->
setNumLevels
(
max
(
bp
->
getNumLevels
()
-
1
,
1
)
);
cout
<<
"level_count: "
<<
bp
->
getNumLevels
()
<<
endl
;
}
else
if
(
p
.
method
==
Params
::
CSBP
)
{
csbp
.
levels
=
max
(
csbp
.
levels
-
1
,
1
);
cout
<<
"level_count: "
<<
csbp
.
levels
<<
endl
;
csbp
->
setNumLevels
(
max
(
csbp
->
getNumLevels
()
-
1
,
1
)
);
cout
<<
"level_count: "
<<
csbp
->
getNumLevels
()
<<
endl
;
}
break
;
}
...
...
samples/gpu/stereo_multi.cpp
View file @
eff6dccb
...
...
@@ -51,7 +51,7 @@ struct Worker { void operator()(int device_id) const; };
// GPUs data
GpuMat
d_left
[
2
];
GpuMat
d_right
[
2
];
StereoBM_GPU
*
bm
[
2
];
Ptr
<
gpu
::
StereoBM
>
bm
[
2
];
GpuMat
d_result
[
2
];
static
void
printHelp
()
...
...
@@ -112,13 +112,13 @@ int main(int argc, char** argv)
setDevice
(
0
);
d_left
[
0
].
upload
(
left
.
rowRange
(
0
,
left
.
rows
/
2
));
d_right
[
0
].
upload
(
right
.
rowRange
(
0
,
right
.
rows
/
2
));
bm
[
0
]
=
new
StereoBM_GPU
();
bm
[
0
]
=
gpu
::
createStereoBM
();
// Split source images for processing on the GPU #1
setDevice
(
1
);
d_left
[
1
].
upload
(
left
.
rowRange
(
left
.
rows
/
2
,
left
.
rows
));
d_right
[
1
].
upload
(
right
.
rowRange
(
right
.
rows
/
2
,
right
.
rows
));
bm
[
1
]
=
new
StereoBM_GPU
();
bm
[
1
]
=
gpu
::
createStereoBM
();
// Execute calculation in two threads using two GPUs
int
devices
[]
=
{
0
,
1
};
...
...
@@ -130,7 +130,7 @@ int main(int argc, char** argv)
d_left
[
0
].
release
();
d_right
[
0
].
release
();
d_result
[
0
].
release
();
delete
bm
[
0
]
;
bm
[
0
].
release
()
;
// Release the second GPU resources
setDevice
(
1
);
...
...
@@ -138,7 +138,7 @@ int main(int argc, char** argv)
d_left
[
1
].
release
();
d_right
[
1
].
release
();
d_result
[
1
].
release
();
delete
bm
[
1
]
;
bm
[
1
].
release
()
;
waitKey
();
return
0
;
...
...
@@ -149,8 +149,7 @@ void Worker::operator()(int device_id) const
{
setDevice
(
device_id
);
bm
[
device_id
]
->
operator
()(
d_left
[
device_id
],
d_right
[
device_id
],
d_result
[
device_id
]);
bm
[
device_id
]
->
compute
(
d_left
[
device_id
],
d_right
[
device_id
],
d_result
[
device_id
]);
std
::
cout
<<
"GPU #"
<<
device_id
<<
" ("
<<
DeviceInfo
().
name
()
<<
"): finished
\n
"
;
...
...
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