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
ddc23517
Commit
ddc23517
authored
Mar 06, 2014
by
Konstantin Matskevich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new approach
parent
a5d989f3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
17 deletions
+32
-17
perf_stereobm.cpp
modules/calib3d/perf/opencl/perf_stereobm.cpp
+1
-1
stereobm.cl
modules/calib3d/src/opencl/stereobm.cl
+0
-0
stereobm.cpp
modules/calib3d/src/stereobm.cpp
+27
-12
test_stereobm.cpp
modules/calib3d/test/opencl/test_stereobm.cpp
+4
-4
No files found.
modules/calib3d/perf/opencl/perf_stereobm.cpp
View file @
ddc23517
...
...
@@ -68,7 +68,7 @@ OCL_PERF_TEST_P(StereoBMFixture, StereoBM, ::testing::Combine(OCL_PERF_ENUM(32,
OCL_TEST_CYCLE
()
bm
->
compute
(
left
,
right
,
disp
);
SANITY_CHECK
(
disp
,
1e-3
,
ERROR_RELATIVE
);
SANITY_CHECK
_NOTHING
();
//
(disp, 1e-3, ERROR_RELATIVE);
}
}
//ocl
...
...
modules/calib3d/src/opencl/stereobm.cl
View file @
ddc23517
This diff is collapsed.
Click to expand it.
modules/calib3d/src/stereobm.cpp
View file @
ddc23517
...
...
@@ -681,7 +681,7 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right,
sad
[
ndisp
]
=
sad
[
ndisp
-
2
];
int
p
=
sad
[
mind
+
1
],
n
=
sad
[
mind
-
1
];
d
=
p
+
n
-
2
*
sad
[
mind
]
+
std
::
abs
(
p
-
n
);
dptr
[
y
*
dstep
]
=
(
short
)
mind
;
//
(((ndisp - mind - 1 + mindisp)*256 + (d != 0 ? (p-n)*256/d : 0) + 15) >> 4);
dptr
[
y
*
dstep
]
=
(
short
)(((
ndisp
-
mind
-
1
+
mindisp
)
*
256
+
(
d
!=
0
?
(
p
-
n
)
*
256
/
d
:
0
)
+
15
)
>>
4
);
costptr
[
y
*
coststep
]
=
sad
[
mind
];
}
}
...
...
@@ -739,27 +739,43 @@ static bool ocl_stereobm_opt( InputArray _left, InputArray _right,
OutputArray
_disp
,
StereoBMParams
*
state
)
{
//printf("opt\n");
int
ndisp
=
state
->
numDisparities
;
int
mindisp
=
state
->
minDisparity
;
int
wsz
=
state
->
SADWindowSize
;
ocl
::
Kernel
k
(
"stereoBM_opt"
,
ocl
::
calib3d
::
stereobm_oclsrc
,
cv
::
format
(
"-D csize=%d -D tsize=%d -D wsz=%d"
,
wsz
*
ndisp
,
ndisp
,
wsz
)
);
int
wsz2
=
wsz
/
2
;
int
sizeX
=
9
,
sizeY
=
sizeX
-
1
,
N
=
ndisp
*
2
;
ocl
::
Kernel
k
(
"stereoBM_opt"
,
ocl
::
calib3d
::
stereobm_oclsrc
,
cv
::
format
(
"-D csize=%d -D tsize=%d -D wsz=%d"
,
(
2
*
sizeY
)
*
ndisp
,
2
*
ndisp
,
wsz
)
);
if
(
k
.
empty
())
return
false
;
UMat
left
=
_left
.
getUMat
(),
right
=
_right
.
getUMat
();
int
cols
=
left
.
cols
,
rows
=
left
.
rows
;
_disp
.
create
(
_left
.
size
(),
CV_16S
);
UMat
disp
=
_disp
.
getUMat
();
_disp
.
setTo
((
mindisp
-
1
)
<<
4
);
Rect
roi
=
Rect
(
Point
(
wsz2
+
mindisp
+
ndisp
-
1
,
wsz2
),
Point
(
cols
-
1
-
wsz2
-
mindisp
,
rows
-
1
-
wsz2
)
);
UMat
disp
=
(
_disp
.
getUMat
())(
roi
);
size_t
globalThreads
[
3
]
=
{
left
.
cols
,
(
left
.
rows
-
left
.
rows
%
wsz
+
wsz
),
ndisp
};
size_t
localThreads
[
3
]
=
{
1
,
wsz
,
ndisp
};
int
globalX
=
disp
.
cols
/
sizeX
,
globalY
=
disp
.
rows
/
sizeY
;
globalX
+=
(
disp
.
cols
%
sizeX
)
>
0
?
1
:
0
;
globalY
+=
(
disp
.
rows
%
sizeY
)
>
0
?
1
:
0
;
size_t
globalThreads
[
3
]
=
{
globalX
,
globalY
,
N
};
size_t
localThreads
[
3
]
=
{
1
,
1
,
N
};
int
idx
=
0
;
idx
=
k
.
set
(
idx
,
ocl
::
KernelArg
::
PtrReadOnly
(
left
));
idx
=
k
.
set
(
idx
,
ocl
::
KernelArg
::
PtrReadOnly
(
right
));
idx
=
k
.
set
(
idx
,
ocl
::
KernelArg
::
WriteOnly
(
disp
));
idx
=
k
.
set
(
idx
,
state
->
minDisparity
);
idx
=
k
.
set
(
idx
,
ocl
::
KernelArg
::
WriteOnlyNoSize
(
disp
));
idx
=
k
.
set
(
idx
,
rows
);
idx
=
k
.
set
(
idx
,
cols
);
idx
=
k
.
set
(
idx
,
mindisp
);
idx
=
k
.
set
(
idx
,
ndisp
);
idx
=
k
.
set
(
idx
,
state
->
preFilterCap
);
idx
=
k
.
set
(
idx
,
state
->
textureThreshold
);
idx
=
k
.
set
(
idx
,
state
->
uniquenessRatio
);
idx
=
k
.
set
(
idx
,
sizeX
);
idx
=
k
.
set
(
idx
,
sizeY
);
return
k
.
run
(
3
,
globalThreads
,
localThreads
,
false
);
}
...
...
@@ -789,16 +805,15 @@ static bool ocl_stereobm_bf(InputArray _left, InputArray _right,
idx
=
k
.
set
(
idx
,
state
->
uniquenessRatio
);
return
k
.
run
(
2
,
globalThreads
,
NULL
,
false
);
return
false
;
}
static
bool
ocl_stereo
(
InputArray
_left
,
InputArray
_right
,
OutputArray
_disp
,
StereoBMParams
*
state
)
{
if
(
ocl
::
Device
::
getDefault
().
localMemSize
()
>
state
->
numDisparities
*
state
->
numDisparities
*
sizeof
(
short
)
)
//
if(ocl::Device::getDefault().localMemSize() > state->numDisparities * state->numDisparities * sizeof(short) )
return
ocl_stereobm_opt
(
_left
,
_right
,
_disp
,
state
);
else
return
ocl_stereobm_bf
(
_left
,
_right
,
_disp
,
state
);
//
else
//
return ocl_stereobm_bf(_left, _right, _disp, state);
}
struct
FindStereoCorrespInvoker
:
public
ParallelLoopBody
...
...
@@ -992,7 +1007,7 @@ public:
bufSize2
=
width
*
height
*
(
sizeof
(
Point_
<
short
>
)
+
sizeof
(
int
)
+
sizeof
(
uchar
));
#if CV_SSE2
bool
useShorts
=
false
;
//
params.preFilterCap <= 31 && params.SADWindowSize <= 21 && checkHardwareSupport(CV_CPU_SSE2);
bool
useShorts
=
params
.
preFilterCap
<=
31
&&
params
.
SADWindowSize
<=
21
&&
checkHardwareSupport
(
CV_CPU_SSE2
);
#else
const
bool
useShorts
=
false
;
#endif
...
...
modules/calib3d/test/opencl/test_stereobm.cpp
View file @
ddc23517
...
...
@@ -90,18 +90,18 @@ OCL_TEST_P(StereoBMFixture, StereoBM)
cv
::
ocl
::
finish
();
long
t3
=
clock
();
std
::
cout
<<
(
double
)(
t2
-
t1
)
/
CLOCKS_PER_SEC
<<
" "
<<
(
double
)(
t3
-
t2
)
/
CLOCKS_PER_SEC
<<
std
::
endl
;
/*
Mat t; absdiff(disp, udisp, t);
for(int i = 0; i<t.rows; i++)
for(int j = 0; j< t.cols; j++)
//
if(t.at<short>(i,j) > 0)
if
(
i
==
5
&&
j
==
38
)
if(t.at<short>(i,j) > 0)
// if(i== 255 && j == 375
)
printf("%d %d cv: %d ocl: %d\n", i, j, disp.at<short>(i,j), udisp.getMat(ACCESS_READ).at<short>(i,j) );
/* imshow("diff.png", t*100);
imshow("cv.png", disp*100);
imshow("ocl.png", udisp.getMat(ACCESS_READ)*100);
waitKey(0);*/
Near
(
1e-3
);
//
Near(1e-3);
}
OCL_INSTANTIATE_TEST_CASE_P
(
StereoMatcher
,
StereoBMFixture
,
testing
::
Combine
(
testing
::
Values
(
32
,
64
,
128
),
...
...
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