Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
9a64c542
Commit
9a64c542
authored
Dec 06, 2017
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1404 from terfendail:Generic_DispFilter
parents
e8ed3753
220edb81
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
55 deletions
+69
-55
disparity_filters.cpp
modules/ximgproc/src/disparity_filters.cpp
+69
-55
No files found.
modules/ximgproc/src/disparity_filters.cpp
View file @
9a64c542
...
...
@@ -122,6 +122,7 @@ protected:
public
:
static
Ptr
<
DisparityWLSFilterImpl
>
create
(
bool
_use_confidence
,
int
l_offs
,
int
r_offs
,
int
t_offs
,
int
b_offs
,
int
min_disp
);
void
filter
(
InputArray
disparity_map_left
,
InputArray
left_view
,
OutputArray
filtered_disparity_map
,
InputArray
disparity_map_right
,
Rect
ROI
,
InputArray
);
void
filter_
(
InputArray
disparity_map_left
,
InputArray
left_view
,
OutputArray
filtered_disparity_map
,
InputArray
disparity_map_right
,
Rect
ROI
);
double
getLambda
()
{
return
lambda
;}
void
setLambda
(
double
_lambda
)
{
lambda
=
_lambda
;}
...
...
@@ -218,8 +219,43 @@ Ptr<DisparityWLSFilterImpl> DisparityWLSFilterImpl::create(bool _use_confidence,
void
DisparityWLSFilterImpl
::
filter
(
InputArray
disparity_map_left
,
InputArray
left_view
,
OutputArray
filtered_disparity_map
,
InputArray
disparity_map_right
,
Rect
ROI
,
InputArray
)
{
CV_Assert
(
!
disparity_map_left
.
empty
()
&&
(
disparity_map_left
.
depth
()
==
CV_16S
)
&&
(
disparity_map_left
.
channels
()
==
1
)
);
CV_Assert
(
!
left_view
.
empty
()
&&
(
left_view
.
depth
()
==
CV_8U
)
&&
(
left_view
.
channels
()
==
3
||
left_view
.
channels
()
==
1
)
);
CV_Assert
(
!
disparity_map_left
.
empty
()
&&
(
disparity_map_left
.
channels
()
==
1
));
CV_Assert
(
!
left_view
.
empty
()
&&
(
left_view
.
depth
()
==
CV_8U
)
&&
(
left_view
.
channels
()
==
3
||
left_view
.
channels
()
==
1
));
Mat
left
,
right
,
filt_disp
;
if
(
disparity_map_left
.
depth
()
!=
CV_32F
)
{
disparity_map_left
.
getMat
().
convertTo
(
left
,
CV_32F
);
}
else
{
left
=
disparity_map_left
.
getMat
();
filt_disp
=
filtered_disparity_map
.
getMat
();
}
if
(
!
disparity_map_right
.
empty
()
&&
use_confidence
)
{
if
(
disparity_map_right
.
depth
()
!=
CV_32F
)
disparity_map_right
.
getMat
().
convertTo
(
right
,
CV_32F
);
else
right
=
disparity_map_right
.
getMat
();
}
filter_
(
left
,
left_view
,
filt_disp
,
right
,
ROI
);
if
(
disparity_map_left
.
depth
()
!=
CV_32F
){
filt_disp
.
convertTo
(
filtered_disparity_map
,
disparity_map_left
.
depth
());
}
}
void
DisparityWLSFilterImpl
::
filter_
(
InputArray
disparity_map_left
,
InputArray
left_view
,
OutputArray
filtered_disparity_map
,
InputArray
disparity_map_right
,
Rect
ROI
)
{
CV_Assert
(
!
disparity_map_left
.
empty
()
&&
(
disparity_map_left
.
depth
()
==
CV_32F
)
&&
(
disparity_map_left
.
channels
()
==
1
)
);
CV_Assert
(
!
left_view
.
empty
()
&&
(
left_view
.
depth
()
==
CV_8U
)
&&
(
left_view
.
channels
()
==
3
||
left_view
.
channels
()
==
1
)
);
Mat
disp
,
src
,
dst
;
if
(
disparity_map_left
.
size
()
!=
left_view
.
size
())
resize_factor
=
disparity_map_left
.
cols
()
/
(
float
)
left_view
.
cols
();
...
...
@@ -247,6 +283,7 @@ void DisparityWLSFilterImpl::filter(InputArray disparity_map_left, InputArray le
}
else
ROI
=
valid_disp_ROI
;
disp
=
Mat
(
disp_full_size
,
ROI
);
src
=
Mat
(
src_full_size
,
ROI
);
filtered_disparity_map
.
create
(
disp_full_size
.
size
(),
disp_full_size
.
type
());
...
...
@@ -259,14 +296,15 @@ void DisparityWLSFilterImpl::filter(InputArray disparity_map_left, InputArray le
}
else
{
CV_Assert
(
!
disparity_map_right
.
empty
()
&&
(
disparity_map_right
.
depth
()
==
CV_16S
)
&&
(
disparity_map_right
.
channels
()
==
1
)
);
CV_Assert
(
!
disparity_map_right
.
empty
()
&&
(
disparity_map_right
.
depth
()
==
CV_32F
)
&&
(
disparity_map_right
.
channels
()
==
1
)
);
CV_Assert
(
(
disparity_map_left
.
cols
()
==
disparity_map_right
.
cols
())
);
CV_Assert
(
(
disparity_map_left
.
rows
()
==
disparity_map_right
.
rows
())
);
computeConfidenceMap
(
disparity_map_left
,
disparity_map_right
);
Mat
disp_full_size
=
disparity_map_left
.
getMat
();
Mat
src_full_size
=
left_view
.
getMat
();
if
(
disp_full_size
.
size
!=
src_full_size
.
size
)
{
if
(
disp_full_size
.
size
!=
src_full_size
.
size
){
float
x_ratio
=
src_full_size
.
cols
/
(
float
)
disp_full_size
.
cols
;
float
y_ratio
=
src_full_size
.
rows
/
(
float
)
disp_full_size
.
rows
;
resize
(
disp_full_size
,
disp_full_size
,
src_full_size
.
size
());
...
...
@@ -274,9 +312,9 @@ void DisparityWLSFilterImpl::filter(InputArray disparity_map_left, InputArray le
resize
(
confidence_map
,
confidence_map
,
src_full_size
.
size
());
ROI
=
Rect
((
int
)(
valid_disp_ROI
.
x
*
x_ratio
),
(
int
)(
valid_disp_ROI
.
y
*
y_ratio
),
(
int
)(
valid_disp_ROI
.
width
*
x_ratio
),(
int
)(
valid_disp_ROI
.
height
*
y_ratio
));
}
else
}
else
{
ROI
=
valid_disp_ROI
;
}
disp
=
Mat
(
disp_full_size
,
ROI
);
src
=
Mat
(
src_full_size
,
ROI
);
filtered_disparity_map
.
create
(
disp_full_size
.
size
(),
disp_full_size
.
type
());
...
...
@@ -286,14 +324,12 @@ void DisparityWLSFilterImpl::filter(InputArray disparity_map_left, InputArray le
Mat
conf
(
confidence_map
,
ROI
);
Mat
disp_mul_conf
;
disp
.
convertTo
(
disp_mul_conf
,
CV_32F
);
disp_mul_conf
=
conf
.
mul
(
disp_mul_conf
);
disp_mul_conf
=
conf
.
mul
(
disp
);
Mat
conf_filtered
;
Ptr
<
FastGlobalSmootherFilter
>
wls
=
createFastGlobalSmootherFilter
(
src
,
lambda
,
sigma_color
);
wls
->
filter
(
disp_mul_conf
,
disp_mul_conf
);
wls
->
filter
(
conf
,
conf_filtered
);
disp_mul_conf
=
disp_mul_conf
.
mul
(
1
/
(
conf_filtered
+
EPS
));
disp_mul_conf
.
convertTo
(
dst
,
CV_16S
);
dst
=
disp_mul_conf
.
mul
(
1
/
(
conf_filtered
+
EPS
));
}
}
...
...
@@ -305,9 +341,9 @@ wls(&_wls),left_disp(&_left_disp),right_disp(&_right_disp),left_disc(&_left_disc
void
DisparityWLSFilterImpl
::
ComputeDiscontinuityAwareLRC_ParBody
::
operator
()
(
const
Range
&
range
)
const
{
shor
t
*
row_left
;
floa
t
*
row_left
;
float
*
row_left_conf
;
shor
t
*
row_right
;
floa
t
*
row_right
;
float
*
row_right_conf
;
float
*
row_dst
;
int
right_idx
;
...
...
@@ -318,9 +354,9 @@ void DisparityWLSFilterImpl::ComputeDiscontinuityAwareLRC_ParBody::operator() (c
int
thresh
=
(
int
)(
wls
->
resize_factor
*
wls
->
LRC_thresh
);
for
(
int
i
=
start
;
i
<
end
;
i
++
)
{
row_left
=
(
shor
t
*
)
left_disp
->
ptr
(
i
);
row_left
=
(
floa
t
*
)
left_disp
->
ptr
(
i
);
row_left_conf
=
(
float
*
)
left_disc
->
ptr
(
i
);
row_right
=
(
shor
t
*
)
right_disp
->
ptr
(
i
);
row_right
=
(
floa
t
*
)
right_disp
->
ptr
(
i
);
row_right_conf
=
(
float
*
)
right_disc
->
ptr
(
i
);
row_dst
=
(
float
*
)
dst
->
ptr
(
i
);
int
j_start
=
left_ROI
.
x
;
...
...
@@ -328,7 +364,7 @@ void DisparityWLSFilterImpl::ComputeDiscontinuityAwareLRC_ParBody::operator() (c
int
right_end
=
right_ROI
.
x
+
right_ROI
.
width
;
for
(
int
j
=
j_start
;
j
<
j_end
;
j
++
)
{
right_idx
=
j
-
(
row_left
[
j
]
>>
4
);
right_idx
=
j
-
(
((
int
)
row_left
[
j
])
>>
4
);
if
(
right_idx
>=
right_ROI
.
x
&&
right_idx
<
right_end
)
{
if
(
abs
(
row_left
[
j
]
+
row_right
[
right_idx
])
<
thresh
)
...
...
@@ -496,63 +532,41 @@ int readGT(String src_path,OutputArray dst)
double
computeMSE
(
InputArray
GT
,
InputArray
src
,
Rect
ROI
)
{
CV_Assert
(
!
GT
.
empty
()
&&
(
GT
.
depth
()
==
CV_16S
)
&&
(
GT
.
channels
()
==
1
)
);
CV_Assert
(
!
src
.
empty
()
&&
(
src
.
depth
()
==
CV_16S
)
&&
(
src
.
channels
()
==
1
)
);
CV_Assert
(
!
GT
.
empty
()
&&
(
GT
.
depth
()
==
CV_16S
||
GT
.
depth
()
==
CV_32F
)
&&
(
GT
.
channels
()
==
1
)
);
CV_Assert
(
!
src
.
empty
()
&&
(
src
.
depth
()
==
CV_16S
||
src
.
depth
()
==
CV_32F
)
&&
(
src
.
channels
()
==
1
)
);
CV_Assert
(
src
.
rows
()
==
GT
.
rows
()
&&
src
.
cols
()
==
GT
.
cols
()
);
double
res
=
0
;
Mat
GT_ROI
(
GT
.
getMat
(),
ROI
);
Mat
src_ROI
(
src
.
getMat
(),
ROI
);
int
cnt
=
0
;
for
(
int
i
=
0
;
i
<
src_ROI
.
rows
;
i
++
)
for
(
int
j
=
0
;
j
<
src_ROI
.
cols
;
j
++
)
{
if
(
GT_ROI
.
at
<
short
>
(
i
,
j
)
!=
UNKNOWN_DISPARITY
)
{
res
+=
(
GT_ROI
.
at
<
short
>
(
i
,
j
)
-
src_ROI
.
at
<
short
>
(
i
,
j
))
*
(
GT_ROI
.
at
<
short
>
(
i
,
j
)
-
src_ROI
.
at
<
short
>
(
i
,
j
));
cnt
++
;
}
}
res
/=
cnt
*
256
;
return
res
;
Mat
tmp
,
dtmp
,
gt_mask
=
(
GT_ROI
==
UNKNOWN_DISPARITY
);
absdiff
(
GT_ROI
,
src_ROI
,
tmp
);
tmp
.
setTo
(
0
,
gt_mask
);
multiply
(
tmp
,
tmp
,
tmp
);
tmp
.
convertTo
(
dtmp
,
CV_64FC1
);
return
sum
(
dtmp
)[
0
]
/
((
gt_mask
.
total
()
-
countNonZero
(
gt_mask
))
*
256
);
}
double
computeBadPixelPercent
(
InputArray
GT
,
InputArray
src
,
Rect
ROI
,
int
thresh
)
{
CV_Assert
(
!
GT
.
empty
()
&&
(
GT
.
depth
()
==
CV_16S
)
&&
(
GT
.
channels
()
==
1
)
);
CV_Assert
(
!
src
.
empty
()
&&
(
src
.
depth
()
==
CV_16S
)
&&
(
src
.
channels
()
==
1
)
);
CV_Assert
(
!
GT
.
empty
()
&&
(
GT
.
depth
()
==
CV_16S
||
GT
.
depth
()
==
CV_32F
)
&&
(
GT
.
channels
()
==
1
)
);
CV_Assert
(
!
src
.
empty
()
&&
(
src
.
depth
()
==
CV_16S
||
src
.
depth
()
==
CV_32F
)
&&
(
src
.
channels
()
==
1
)
);
CV_Assert
(
src
.
rows
()
==
GT
.
rows
()
&&
src
.
cols
()
==
GT
.
cols
()
);
int
bad_pixel_num
=
0
;
Mat
GT_ROI
(
GT
.
getMat
(),
ROI
);
Mat
src_ROI
(
src
.
getMat
(),
ROI
);
int
cnt
=
0
;
for
(
int
i
=
0
;
i
<
src_ROI
.
rows
;
i
++
)
for
(
int
j
=
0
;
j
<
src_ROI
.
cols
;
j
++
)
{
if
(
GT_ROI
.
at
<
short
>
(
i
,
j
)
!=
UNKNOWN_DISPARITY
)
{
if
(
abs
(
GT_ROI
.
at
<
short
>
(
i
,
j
)
-
src_ROI
.
at
<
short
>
(
i
,
j
))
>=
thresh
)
bad_pixel_num
++
;
cnt
++
;
}
}
return
(
100.0
*
bad_pixel_num
)
/
cnt
;
Mat
tmp
,
gt_mask
=
(
GT_ROI
==
UNKNOWN_DISPARITY
);
absdiff
(
GT_ROI
,
src_ROI
,
tmp
);
tmp
.
setTo
(
0
,
gt_mask
);
cv
::
threshold
(
tmp
,
tmp
,
thresh
-
1
,
1
,
THRESH_BINARY
);
return
(
100.0
*
countNonZero
(
tmp
))
/
(
gt_mask
.
total
()
-
countNonZero
(
gt_mask
));
}
void
getDisparityVis
(
InputArray
src
,
OutputArray
dst
,
double
scale
)
{
CV_Assert
(
!
src
.
empty
()
&&
(
src
.
depth
()
==
CV_16S
)
&&
(
src
.
channels
()
==
1
)
);
CV_Assert
(
!
src
.
empty
()
&&
(
src
.
depth
()
==
CV_16S
||
src
.
depth
()
==
CV_32F
)
&&
(
src
.
channels
()
==
1
)
);
Mat
srcMat
=
src
.
getMat
();
dst
.
create
(
srcMat
.
rows
,
srcMat
.
cols
,
CV_8UC1
);
Mat
&
dstMat
=
dst
.
getMatRef
();
for
(
int
i
=
0
;
i
<
dstMat
.
rows
;
i
++
)
for
(
int
j
=
0
;
j
<
dstMat
.
cols
;
j
++
)
{
if
(
srcMat
.
at
<
short
>
(
i
,
j
)
==
UNKNOWN_DISPARITY
)
dstMat
.
at
<
unsigned
char
>
(
i
,
j
)
=
0
;
else
dstMat
.
at
<
unsigned
char
>
(
i
,
j
)
=
saturate_cast
<
unsigned
char
>
(
scale
*
srcMat
.
at
<
short
>
(
i
,
j
)
/
16.0
);
}
srcMat
.
convertTo
(
dstMat
,
CV_8UC1
,
scale
/
16.0
);
dstMat
&=
(
srcMat
!=
UNKNOWN_DISPARITY
);
}
}
...
...
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