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
bf22f6f9
Commit
bf22f6f9
authored
Oct 22, 2015
by
Maksim Shabunin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #379 from sbokov:sparseMatchInterpolationSquashed
parents
25d458ef
831523ce
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
664 additions
and
3 deletions
+664
-3
CMakeLists.txt
modules/optflow/CMakeLists.txt
+1
-1
optflow.hpp
modules/optflow/include/opencv2/optflow.hpp
+27
-1
optical_flow_evaluation.cpp
modules/optflow/samples/optical_flow_evaluation.cpp
+3
-1
interfaces.cpp
modules/optflow/src/interfaces.cpp
+37
-0
sparsetodenseflow.cpp
modules/optflow/src/sparsetodenseflow.cpp
+113
-0
test_sparsetodenseflow.cpp
modules/optflow/test/test_sparsetodenseflow.cpp
+146
-0
ximgproc.bib
modules/ximgproc/doc/ximgproc.bib
+8
-0
ximgproc.hpp
modules/ximgproc/include/opencv2/ximgproc.hpp
+1
-0
sparse_match_interpolator.hpp
...oc/include/opencv2/ximgproc/sparse_match_interpolator.hpp
+132
-0
sparse_match_interpolators.cpp
modules/ximgproc/src/sparse_match_interpolators.cpp
+0
-0
test_sparse_match_interpolator.cpp
modules/ximgproc/test/test_sparse_match_interpolator.cpp
+196
-0
No files found.
modules/optflow/CMakeLists.txt
View file @
bf22f6f9
set
(
the_description
"Optical Flow Algorithms"
)
ocv_define_module
(
optflow opencv_core opencv_imgproc opencv_video opencv_highgui WRAP python
)
ocv_define_module
(
optflow opencv_core opencv_imgproc opencv_video opencv_highgui
opencv_ximgproc
WRAP python
)
modules/optflow/include/opencv2/optflow.hpp
View file @
bf22f6f9
...
...
@@ -109,7 +109,30 @@ CV_EXPORTS_W void calcOpticalFlowSF( InputArray from, InputArray to, OutputArray
double
sigma_dist
,
double
sigma_color
,
int
postprocess_window
,
double
sigma_dist_fix
,
double
sigma_color_fix
,
double
occ_thr
,
int
upscale_averaging_radius
,
double
upscale_sigma_dist
,
double
upscale_sigma_color
,
double
speed_up_thr
);
double
upscale_sigma_color
,
double
speed_up_thr
);
/** @brief Fast dense optical flow based on PyrLK sparse matches interpolation.
@param from first 8-bit 3-channel or 1-channel image.
@param to second 8-bit 3-channel or 1-channel image of the same size as from
@param flow computed flow image that has the same size as from and CV_32FC2 type
@param grid_step stride used in sparse match computation. Lower values usually
result in higher quality but slow down the algorithm.
@param k number of nearest-neighbor matches considered, when fitting a locally affine
model. Lower values can make the algorithm noticeably faster at the cost of
some quality degradation.
@param sigma parameter defining how fast the weights decrease in the locally-weighted affine
fitting. Higher values can help preserve fine details, lower values can help to get rid
of the noise in the output flow.
@param use_post_proc defines whether the ximgproc::fastGlobalSmootherFilter() is used
for post-processing after interpolation
@param fgs_lambda see the respective parameter of the ximgproc::fastGlobalSmootherFilter()
@param fgs_sigma see the respective parameter of the ximgproc::fastGlobalSmootherFilter()
*/
CV_EXPORTS_W
void
calcOpticalFlowSparseToDense
(
InputArray
from
,
InputArray
to
,
OutputArray
flow
,
int
grid_step
=
8
,
int
k
=
128
,
float
sigma
=
0.05
f
,
bool
use_post_proc
=
true
,
float
fgs_lambda
=
500.0
f
,
float
fgs_sigma
=
1.5
f
);
/** @brief Read a .flo file
...
...
@@ -165,6 +188,9 @@ CV_EXPORTS_W Ptr<DenseOpticalFlow> createOptFlow_SimpleFlow();
//! Additional interface to the Farneback's algorithm - calcOpticalFlowFarneback()
CV_EXPORTS_W
Ptr
<
DenseOpticalFlow
>
createOptFlow_Farneback
();
//! Additional interface to the SparseToDenseFlow algorithm - calcOpticalFlowSparseToDense()
CV_EXPORTS_W
Ptr
<
DenseOpticalFlow
>
createOptFlow_SparseToDense
();
//! @}
}
//optflow
...
...
modules/optflow/samples/optical_flow_evaluation.cpp
View file @
bf22f6f9
...
...
@@ -10,7 +10,7 @@ using namespace optflow;
const
String
keys
=
"{help h usage ? | | print this message }"
"{@image1 | | image1 }"
"{@image2 | | image2 }"
"{@algorithm | | [farneback, simpleflow, tvl1
or deep
flow] }"
"{@algorithm | | [farneback, simpleflow, tvl1
, deepflow or sparsetodense
flow] }"
"{@groundtruth | | path to the .flo file (optional), Middlebury format }"
"{m measure |endpoint| error measure - [endpoint or angular] }"
"{r region |all | region to compute stats about [all, discontinuities, untextured] }"
...
...
@@ -249,6 +249,8 @@ int main( int argc, char** argv )
algorithm
=
createOptFlow_DualTVL1
();
else
if
(
method
==
"deepflow"
)
algorithm
=
createOptFlow_DeepFlow
();
else
if
(
method
==
"sparsetodenseflow"
)
algorithm
=
createOptFlow_SparseToDense
();
else
{
printf
(
"Wrong method!
\n
"
);
...
...
modules/optflow/src/interfaces.cpp
View file @
bf22f6f9
...
...
@@ -177,5 +177,42 @@ Ptr<DenseOpticalFlow> createOptFlow_Farneback()
{
return
makePtr
<
OpticalFlowFarneback
>
();
}
class
OpticalFlowSparseToDense
:
public
DenseOpticalFlow
{
public
:
OpticalFlowSparseToDense
(
int
_grid_step
,
int
_k
,
float
_sigma
,
bool
_use_post_proc
,
float
_fgs_lambda
,
float
_fgs_sigma
);
void
calc
(
InputArray
I0
,
InputArray
I1
,
InputOutputArray
flow
);
void
collectGarbage
();
protected
:
int
grid_step
;
int
k
;
float
sigma
;
bool
use_post_proc
;
float
fgs_lambda
;
float
fgs_sigma
;
};
OpticalFlowSparseToDense
::
OpticalFlowSparseToDense
(
int
_grid_step
,
int
_k
,
float
_sigma
,
bool
_use_post_proc
,
float
_fgs_lambda
,
float
_fgs_sigma
)
{
grid_step
=
_grid_step
;
k
=
_k
;
sigma
=
_sigma
;
use_post_proc
=
_use_post_proc
;
fgs_lambda
=
_fgs_lambda
;
fgs_sigma
=
_fgs_sigma
;
}
void
OpticalFlowSparseToDense
::
calc
(
InputArray
I0
,
InputArray
I1
,
InputOutputArray
flow
)
{
calcOpticalFlowSparseToDense
(
I0
,
I1
,
flow
,
grid_step
,
k
,
sigma
,
use_post_proc
,
fgs_lambda
,
fgs_sigma
);
}
void
OpticalFlowSparseToDense
::
collectGarbage
()
{}
Ptr
<
DenseOpticalFlow
>
createOptFlow_SparseToDense
()
{
return
makePtr
<
OpticalFlowSparseToDense
>
(
8
,
128
,
0.05
f
,
true
,
500.0
f
,
1.5
f
);
}
}
}
modules/optflow/src/sparsetodenseflow.cpp
0 → 100644
View file @
bf22f6f9
/*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-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., 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"
#include "opencv2/ximgproc/sparse_match_interpolator.hpp"
using
namespace
std
;
namespace
cv
{
namespace
optflow
{
CV_EXPORTS_W
void
calcOpticalFlowSparseToDense
(
InputArray
from
,
InputArray
to
,
OutputArray
flow
,
int
grid_step
,
int
k
,
float
sigma
,
bool
use_post_proc
,
float
fgs_lambda
,
float
fgs_sigma
)
{
CV_Assert
(
grid_step
>
1
&&
k
>
3
&&
sigma
>
0.0001
f
&&
fgs_lambda
>
1.0
f
&&
fgs_sigma
>
0.01
f
);
CV_Assert
(
!
from
.
empty
()
&&
from
.
depth
()
==
CV_8U
&&
(
from
.
channels
()
==
3
||
from
.
channels
()
==
1
)
);
CV_Assert
(
!
to
.
empty
()
&&
to
.
depth
()
==
CV_8U
&&
(
to
.
channels
()
==
3
||
to
.
channels
()
==
1
)
);
CV_Assert
(
from
.
sameSize
(
to
)
);
Mat
prev
=
from
.
getMat
();
Mat
cur
=
to
.
getMat
();
Mat
prev_grayscale
,
cur_grayscale
;
while
(
(
prev
.
cols
/
grid_step
)
*
(
prev
.
rows
/
grid_step
)
>
SHRT_MAX
)
//ensure that the number matches is not too big
grid_step
*=
2
;
if
(
prev
.
channels
()
==
3
)
{
cvtColor
(
prev
,
prev_grayscale
,
COLOR_BGR2GRAY
);
cvtColor
(
cur
,
cur_grayscale
,
COLOR_BGR2GRAY
);
}
else
{
prev
.
copyTo
(
prev_grayscale
);
cur
.
copyTo
(
cur_grayscale
);
}
vector
<
Point2f
>
points
;
vector
<
Point2f
>
dst_points
;
vector
<
unsigned
char
>
status
;
vector
<
float
>
err
;
vector
<
Point2f
>
points_filtered
,
dst_points_filtered
;
for
(
int
i
=
0
;
i
<
prev
.
rows
;
i
+=
grid_step
)
for
(
int
j
=
0
;
j
<
prev
.
cols
;
j
+=
grid_step
)
points
.
push_back
(
Point2f
((
float
)
j
,(
float
)
i
));
calcOpticalFlowPyrLK
(
prev_grayscale
,
cur_grayscale
,
points
,
dst_points
,
status
,
err
,
Size
(
21
,
21
));
for
(
unsigned
int
i
=
0
;
i
<
points
.
size
();
i
++
)
{
if
(
status
[
i
]
!=
0
)
{
points_filtered
.
push_back
(
points
[
i
]);
dst_points_filtered
.
push_back
(
dst_points
[
i
]);
}
}
flow
.
create
(
from
.
size
(),
CV_32FC2
);
Mat
dense_flow
=
flow
.
getMat
();
Ptr
<
ximgproc
::
EdgeAwareInterpolator
>
gd
=
ximgproc
::
createEdgeAwareInterpolator
();
gd
->
setK
(
k
);
gd
->
setSigma
(
sigma
);
gd
->
setUsePostProcessing
(
use_post_proc
);
gd
->
setFGSLambda
(
fgs_lambda
);
gd
->
setFGSSigma
(
fgs_sigma
);
gd
->
interpolate
(
prev
,
points_filtered
,
cur
,
dst_points_filtered
,
dense_flow
);
}
}
}
\ No newline at end of file
modules/optflow/test/test_sparsetodenseflow.cpp
0 → 100644
View file @
bf22f6f9
/*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.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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 "test_precomp.hpp"
#include <string>
using
namespace
std
;
using
namespace
cv
;
/* ///////////////////// sparsetodenseflow_test ///////////////////////// */
class
CV_SparseToDenseFlowTest
:
public
cvtest
::
BaseTest
{
protected
:
void
run
(
int
);
};
static
bool
isFlowCorrect
(
float
u
)
{
return
!
cvIsNaN
(
u
)
&&
(
fabs
(
u
)
<
1e9
);
}
static
float
calc_rmse
(
Mat
flow1
,
Mat
flow2
)
{
float
sum
=
0
;
int
counter
=
0
;
const
int
rows
=
flow1
.
rows
;
const
int
cols
=
flow1
.
cols
;
for
(
int
y
=
0
;
y
<
rows
;
++
y
)
{
for
(
int
x
=
0
;
x
<
cols
;
++
x
)
{
Vec2f
flow1_at_point
=
flow1
.
at
<
Vec2f
>
(
y
,
x
);
Vec2f
flow2_at_point
=
flow2
.
at
<
Vec2f
>
(
y
,
x
);
float
u1
=
flow1_at_point
[
0
];
float
v1
=
flow1_at_point
[
1
];
float
u2
=
flow2_at_point
[
0
];
float
v2
=
flow2_at_point
[
1
];
if
(
isFlowCorrect
(
u1
)
&&
isFlowCorrect
(
u2
)
&&
isFlowCorrect
(
v1
)
&&
isFlowCorrect
(
v2
))
{
sum
+=
(
u1
-
u2
)
*
(
u1
-
u2
)
+
(
v1
-
v2
)
*
(
v1
-
v2
);
counter
++
;
}
}
}
return
(
float
)
sqrt
(
sum
/
(
1e-9
+
counter
));
}
void
CV_SparseToDenseFlowTest
::
run
(
int
)
{
const
float
MAX_RMSE
=
0.6
f
;
const
string
frame1_path
=
ts
->
get_data_path
()
+
"optflow/RubberWhale1.png"
;
const
string
frame2_path
=
ts
->
get_data_path
()
+
"optflow/RubberWhale2.png"
;
const
string
gt_flow_path
=
ts
->
get_data_path
()
+
"optflow/RubberWhale.flo"
;
Mat
frame1
=
imread
(
frame1_path
);
Mat
frame2
=
imread
(
frame2_path
);
if
(
frame1
.
empty
())
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"could not read image %s
\n
"
,
frame2_path
.
c_str
());
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_MISSING_TEST_DATA
);
return
;
}
if
(
frame2
.
empty
())
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"could not read image %s
\n
"
,
frame2_path
.
c_str
());
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_MISSING_TEST_DATA
);
return
;
}
if
(
frame1
.
rows
!=
frame2
.
rows
&&
frame1
.
cols
!=
frame2
.
cols
)
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"images should be of equal sizes (%s and %s)"
,
frame1_path
.
c_str
(),
frame2_path
.
c_str
());
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_MISSING_TEST_DATA
);
return
;
}
if
(
frame1
.
type
()
!=
16
||
frame2
.
type
()
!=
16
)
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"images should be of equal type CV_8UC3 (%s and %s)"
,
frame1_path
.
c_str
(),
frame2_path
.
c_str
());
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_MISSING_TEST_DATA
);
return
;
}
Mat
flow_gt
=
optflow
::
readOpticalFlow
(
gt_flow_path
);
if
(
flow_gt
.
empty
())
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"error while reading flow data from file %s"
,
gt_flow_path
.
c_str
());
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_MISSING_TEST_DATA
);
return
;
}
Mat
flow
;
optflow
::
calcOpticalFlowSparseToDense
(
frame1
,
frame2
,
flow
);
float
rmse
=
calc_rmse
(
flow_gt
,
flow
);
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"Optical flow estimation RMSE for SparseToDenseFlow algorithm : %lf
\n
"
,
rmse
);
if
(
rmse
>
MAX_RMSE
)
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"Too big rmse error : %lf ( >= %lf )
\n
"
,
rmse
,
MAX_RMSE
);
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_BAD_ACCURACY
);
return
;
}
}
TEST
(
Video_OpticalFlowSparseToDenseFlow
,
accuracy
)
{
CV_SparseToDenseFlowTest
test
;
test
.
safe_run
();
}
modules/ximgproc/doc/ximgproc.bib
View file @
bf22f6f9
...
...
@@ -77,3 +77,11 @@
year={2008},
organization={ACM}
}
@inproceedings{Revaud2015,
title={EpicFlow: Edge-Preserving Interpolation of Correspondences for Optical Flow},
author={Revaud, Jerome and Weinzaepfel, Philippe and Harchaoui, Zaid and Schmid, Cordelia},
booktitle={Computer Vision and Pattern Recognition (CVPR), IEEE Conference on},
pages={1164--1172},
year={2015}
}
modules/ximgproc/include/opencv2/ximgproc.hpp
View file @
bf22f6f9
...
...
@@ -39,6 +39,7 @@
#include "ximgproc/edge_filter.hpp"
#include "ximgproc/disparity_filter.hpp"
#include "ximgproc/sparse_match_interpolator.hpp"
#include "ximgproc/structured_edge_detection.hpp"
#include "ximgproc/seeds.hpp"
#include "ximgproc/fast_hough_transform.hpp"
...
...
modules/ximgproc/include/opencv2/ximgproc/sparse_match_interpolator.hpp
0 → 100644
View file @
bf22f6f9
/*
* 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
* (3 - clause BSD License)
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met :
*
* *Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions 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.
*
* * Neither the names of the copyright holders nor the names of the contributors
* may 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 copyright holders 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.
*/
#ifndef __OPENCV_SPARSEMATCHINTERPOLATOR_HPP__
#define __OPENCV_SPARSEMATCHINTERPOLATOR_HPP__
#ifdef __cplusplus
#include <opencv2/core.hpp>
namespace
cv
{
namespace
ximgproc
{
//! @addtogroup ximgproc_filters
//! @{
/** @brief Main interface for all filters, that take sparse matches as an
input and produce a dense per-pixel matching (optical flow) as an output.
*/
class
CV_EXPORTS_W
SparseMatchInterpolator
:
public
Algorithm
{
public
:
/** @brief Interpolate input sparse matches.
@param from_image first of the two matched images, 8-bit single-channel or three-channel.
@param from_points points of the from_image for which there are correspondences in the
to_image (Point2f vector, size shouldn't exceed 32767)
@param to_image second of the two matched images, 8-bit single-channel or three-channel.
@param to_points points in the to_image corresponding to from_points
(Point2f vector, size shouldn't exceed 32767)
@param dense_flow output dense matching (two-channel CV_32F image)
*/
CV_WRAP
virtual
void
interpolate
(
InputArray
from_image
,
InputArray
from_points
,
InputArray
to_image
,
InputArray
to_points
,
OutputArray
dense_flow
)
=
0
;
};
/** @brief Sparse match interpolation algorithm based on modified locally-weighted affine
estimator from @cite Revaud2015 and Fast Global Smoother as post-processing filter.
*/
class
CV_EXPORTS_W
EdgeAwareInterpolator
:
public
SparseMatchInterpolator
{
public
:
/** @brief K is a number of nearest-neighbor matches considered, when fitting a locally affine
model. Usually it should be around 128. However, lower values would make the interpolation
noticeably faster.
*/
CV_WRAP
virtual
void
setK
(
int
_k
)
=
0
;
/** @see setK */
CV_WRAP
virtual
int
getK
()
=
0
;
/** @brief Sigma is a parameter defining how fast the weights decrease in the locally-weighted affine
fitting. Higher values can help preserve fine details, lower values can help to get rid of noise in the
output flow.
*/
CV_WRAP
virtual
void
setSigma
(
float
_sigma
)
=
0
;
/** @see setSigma */
CV_WRAP
virtual
float
getSigma
()
=
0
;
/** @brief Lambda is a parameter defining the weight of the edge-aware term in geodesic distance,
should be in the range of 0 to 1000.
*/
CV_WRAP
virtual
void
setLambda
(
float
_lambda
)
=
0
;
/** @see setLambda */
CV_WRAP
virtual
float
getLambda
()
=
0
;
/** @brief Sets whether the fastGlobalSmootherFilter() post-processing is employed. It is turned on by
default.
*/
CV_WRAP
virtual
void
setUsePostProcessing
(
bool
_use_post_proc
)
=
0
;
/** @see setUsePostProcessing */
CV_WRAP
virtual
bool
getUsePostProcessing
()
=
0
;
/** @brief Sets the respective fastGlobalSmootherFilter() parameter.
*/
CV_WRAP
virtual
void
setFGSLambda
(
float
_lambda
)
=
0
;
/** @see setFGSLambda */
CV_WRAP
virtual
float
getFGSLambda
()
=
0
;
/** @see setFGSLambda */
CV_WRAP
virtual
void
setFGSSigma
(
float
_sigma
)
=
0
;
/** @see setFGSLambda */
CV_WRAP
virtual
float
getFGSSigma
()
=
0
;
};
/** @brief Factory method that creates an instance of the
EdgeAwareInterpolator.
*/
CV_EXPORTS_W
Ptr
<
EdgeAwareInterpolator
>
createEdgeAwareInterpolator
();
//! @}
}
}
#endif
#endif
modules/ximgproc/src/sparse_match_interpolators.cpp
0 → 100644
View file @
bf22f6f9
This diff is collapsed.
Click to expand it.
modules/ximgproc/test/test_sparse_match_interpolator.cpp
0 → 100644
View file @
bf22f6f9
/*
* 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
* (3 - clause BSD License)
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met :
*
* *Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions 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.
*
* * Neither the names of the copyright holders nor the names of the contributors
* may 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 copyright holders 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.
*/
#include "test_precomp.hpp"
#include "opencv2/ximgproc/sparse_match_interpolator.hpp"
#include <fstream>
namespace
cvtest
{
using
namespace
std
;
using
namespace
std
::
tr1
;
using
namespace
testing
;
using
namespace
perf
;
using
namespace
cv
;
using
namespace
cv
::
ximgproc
;
static
string
getDataDir
()
{
return
cvtest
::
TS
::
ptr
()
->
get_data_path
();
}
const
float
FLOW_TAG_FLOAT
=
202021.25
f
;
Mat
readOpticalFlow
(
const
String
&
path
)
{
// CV_Assert(sizeof(float) == 4);
//FIXME: ensure right sizes of int and float - here and in writeOpticalFlow()
Mat_
<
Point2f
>
flow
;
ifstream
file
(
path
.
c_str
(),
std
::
ios_base
::
binary
);
if
(
!
file
.
good
()
)
return
flow
;
// no file - return empty matrix
float
tag
;
file
.
read
((
char
*
)
&
tag
,
sizeof
(
float
));
if
(
tag
!=
FLOW_TAG_FLOAT
)
return
flow
;
int
width
,
height
;
file
.
read
((
char
*
)
&
width
,
4
);
file
.
read
((
char
*
)
&
height
,
4
);
flow
.
create
(
height
,
width
);
for
(
int
i
=
0
;
i
<
flow
.
rows
;
++
i
)
{
for
(
int
j
=
0
;
j
<
flow
.
cols
;
++
j
)
{
Point2f
u
;
file
.
read
((
char
*
)
&
u
.
x
,
sizeof
(
float
));
file
.
read
((
char
*
)
&
u
.
y
,
sizeof
(
float
));
if
(
!
file
.
good
()
)
{
flow
.
release
();
return
flow
;
}
flow
(
i
,
j
)
=
u
;
}
}
file
.
close
();
return
flow
;
}
CV_ENUM
(
GuideTypes
,
CV_8UC1
,
CV_8UC3
)
typedef
tuple
<
Size
,
GuideTypes
>
InterpolatorParams
;
typedef
TestWithParam
<
InterpolatorParams
>
InterpolatorTest
;
TEST
(
InterpolatorTest
,
ReferenceAccuracy
)
{
double
MAX_DIF
=
1.0
;
double
MAX_MEAN_DIF
=
1.0
/
256.0
;
string
dir
=
getDataDir
()
+
"cv/sparse_match_interpolator"
;
Mat
src
=
imread
(
getDataDir
()
+
"cv/optflow/RubberWhale1.png"
,
IMREAD_COLOR
);
ASSERT_FALSE
(
src
.
empty
());
Mat
ref_flow
=
readOpticalFlow
(
dir
+
"/RubberWhale_reference_result.flo"
);
ASSERT_FALSE
(
ref_flow
.
empty
());
ifstream
file
((
dir
+
"/RubberWhale_sparse_matches.txt"
).
c_str
());
float
from_x
,
from_y
,
to_x
,
to_y
;
vector
<
Point2f
>
from_points
;
vector
<
Point2f
>
to_points
;
while
(
file
>>
from_x
>>
from_y
>>
to_x
>>
to_y
)
{
from_points
.
push_back
(
Point2f
(
from_x
,
from_y
));
to_points
.
push_back
(
Point2f
(
to_x
,
to_y
));
}
cv
::
setNumThreads
(
cv
::
getNumberOfCPUs
());
Mat
res_flow
;
Ptr
<
EdgeAwareInterpolator
>
interpolator
=
createEdgeAwareInterpolator
();
interpolator
->
setK
(
128
);
interpolator
->
setSigma
(
0.05
f
);
interpolator
->
setUsePostProcessing
(
true
);
interpolator
->
setFGSLambda
(
500.0
f
);
interpolator
->
setFGSSigma
(
1.5
f
);
interpolator
->
interpolate
(
src
,
from_points
,
Mat
(),
to_points
,
res_flow
);
EXPECT_LE
(
cv
::
norm
(
res_flow
,
ref_flow
,
NORM_INF
),
MAX_DIF
);
EXPECT_LE
(
cv
::
norm
(
res_flow
,
ref_flow
,
NORM_L1
)
,
MAX_MEAN_DIF
*
res_flow
.
total
());
}
TEST_P
(
InterpolatorTest
,
MultiThreadReproducibility
)
{
if
(
cv
::
getNumberOfCPUs
()
==
1
)
return
;
double
MAX_DIF
=
1.0
;
double
MAX_MEAN_DIF
=
1.0
/
256.0
;
int
loopsCount
=
2
;
RNG
rng
(
0
);
InterpolatorParams
params
=
GetParam
();
Size
size
=
get
<
0
>
(
params
);
int
guideType
=
get
<
1
>
(
params
);
Mat
from
(
size
,
guideType
);
randu
(
from
,
0
,
255
);
int
num_matches
=
rng
.
uniform
(
5
,
SHRT_MAX
-
1
);
vector
<
Point2f
>
from_points
;
vector
<
Point2f
>
to_points
;
for
(
int
i
=
0
;
i
<
num_matches
;
i
++
)
{
from_points
.
push_back
(
Point2f
(
rng
.
uniform
(
0.01
f
,(
float
)
size
.
width
-
1.01
f
),
rng
.
uniform
(
0.01
f
,(
float
)
size
.
height
-
1.01
f
)));
to_points
.
push_back
(
Point2f
(
rng
.
uniform
(
0.01
f
,(
float
)
size
.
width
-
1.01
f
),
rng
.
uniform
(
0.01
f
,(
float
)
size
.
height
-
1.01
f
)));
}
for
(
int
iter
=
0
;
iter
<=
loopsCount
;
iter
++
)
{
int
K
=
rng
.
uniform
(
4
,
512
);
float
sigma
=
rng
.
uniform
(
0.01
f
,
0.5
f
);
float
FGSlambda
=
rng
.
uniform
(
100.0
f
,
10000.0
f
);
float
FGSsigma
=
rng
.
uniform
(
0.5
f
,
100.0
f
);
Ptr
<
EdgeAwareInterpolator
>
interpolator
=
createEdgeAwareInterpolator
();
interpolator
->
setK
(
K
);
interpolator
->
setSigma
(
sigma
);
interpolator
->
setUsePostProcessing
(
true
);
interpolator
->
setFGSLambda
(
FGSlambda
);
interpolator
->
setFGSSigma
(
FGSsigma
);
cv
::
setNumThreads
(
cv
::
getNumberOfCPUs
());
Mat
resMultiThread
;
interpolator
->
interpolate
(
from
,
from_points
,
Mat
(),
to_points
,
resMultiThread
);
cv
::
setNumThreads
(
1
);
Mat
resSingleThread
;
interpolator
->
interpolate
(
from
,
from_points
,
Mat
(),
to_points
,
resSingleThread
);
EXPECT_LE
(
cv
::
norm
(
resSingleThread
,
resMultiThread
,
NORM_INF
),
MAX_DIF
);
EXPECT_LE
(
cv
::
norm
(
resSingleThread
,
resMultiThread
,
NORM_L1
)
,
MAX_MEAN_DIF
*
resMultiThread
.
total
());
}
}
INSTANTIATE_TEST_CASE_P
(
FullSet
,
InterpolatorTest
,
Combine
(
Values
(
szODD
,
szVGA
),
GuideTypes
::
all
()));
}
\ No newline at end of file
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