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
02d34bda
Commit
02d34bda
authored
12 years ago
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored videostab module
parent
79e20706
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
137 additions
and
183 deletions
+137
-183
global_motion.hpp
...les/videostab/include/opencv2/videostab/global_motion.hpp
+79
-72
stabilizer.hpp
modules/videostab/include/opencv2/videostab/stabilizer.hpp
+3
-3
wobble_suppression.hpp
...ideostab/include/opencv2/videostab/wobble_suppression.hpp
+3
-3
global_motion.cpp
modules/videostab/src/global_motion.cpp
+0
-0
stabilizer.cpp
modules/videostab/src/stabilizer.cpp
+1
-1
wobble_suppression.cpp
modules/videostab/src/wobble_suppression.cpp
+1
-3
videostab.cpp
samples/cpp/videostab.cpp
+50
-101
No files found.
modules/videostab/include/opencv2/videostab/global_motion.hpp
View file @
02d34bda
...
...
@@ -57,8 +57,6 @@
#include "opencv2/gpu/gpu.hpp"
#endif
// TODO remove code duplications (in cpp too)
namespace
cv
{
namespace
videostab
...
...
@@ -73,10 +71,65 @@ CV_EXPORTS Mat estimateGlobalMotionRobust(
const
RansacParams
&
params
=
RansacParams
::
default2dMotion
(
MM_AFFINE
),
float
*
rmse
=
0
,
int
*
ninliers
=
0
);
class
CV_EXPORTS
Global
MotionEstimatorBase
class
CV_EXPORTS
MotionEstimatorBase
{
public
:
virtual
~
GlobalMotionEstimatorBase
()
{}
virtual
~
MotionEstimatorBase
()
{}
virtual
void
setMotionModel
(
MotionModel
val
)
{
motionModel_
=
val
;
}
virtual
MotionModel
motionModel
()
const
{
return
motionModel_
;
}
virtual
Mat
estimate
(
InputArray
points0
,
InputArray
points1
,
bool
*
ok
=
0
)
=
0
;
protected
:
MotionEstimatorBase
(
MotionModel
model
)
{
setMotionModel
(
model
);
}
private
:
MotionModel
motionModel_
;
};
class
CV_EXPORTS
MotionEstimatorRansacL2
:
public
MotionEstimatorBase
{
public
:
MotionEstimatorRansacL2
(
MotionModel
model
=
MM_AFFINE
);
void
setRansacParams
(
const
RansacParams
&
val
)
{
ransacParams_
=
val
;
}
RansacParams
ransacParams
()
const
{
return
ransacParams_
;
}
void
setMinInlierRatio
(
float
val
)
{
minInlierRatio_
=
val
;
}
float
minInlierRatio
()
const
{
return
minInlierRatio_
;
}
virtual
Mat
estimate
(
InputArray
points0
,
InputArray
points1
,
bool
*
ok
=
0
);
private
:
RansacParams
ransacParams_
;
float
minInlierRatio_
;
};
class
CV_EXPORTS
MotionEstimatorL1
:
public
MotionEstimatorBase
{
public
:
MotionEstimatorL1
(
MotionModel
model
=
MM_AFFINE
);
virtual
Mat
estimate
(
InputArray
points0
,
InputArray
points1
,
bool
*
ok
);
private
:
std
::
vector
<
double
>
obj_
,
collb_
,
colub_
;
std
::
vector
<
double
>
elems_
,
rowlb_
,
rowub_
;
std
::
vector
<
int
>
rows_
,
cols_
;
void
set
(
int
row
,
int
col
,
double
coef
)
{
rows_
.
push_back
(
row
);
cols_
.
push_back
(
col
);
elems_
.
push_back
(
coef
);
}
};
class
CV_EXPORTS
ImageMotionEstimatorBase
{
public
:
virtual
~
ImageMotionEstimatorBase
()
{}
virtual
void
setMotionModel
(
MotionModel
val
)
{
motionModel_
=
val
;
}
virtual
MotionModel
motionModel
()
const
{
return
motionModel_
;
}
...
...
@@ -84,12 +137,13 @@ public:
virtual
Mat
estimate
(
const
Mat
&
frame0
,
const
Mat
&
frame1
,
bool
*
ok
=
0
)
=
0
;
protected
:
Global
MotionEstimatorBase
(
MotionModel
model
)
{
setMotionModel
(
model
);
}
Image
MotionEstimatorBase
(
MotionModel
model
)
{
setMotionModel
(
model
);
}
private
:
MotionModel
motionModel_
;
};
class
CV_EXPORTS
FromFileMotionReader
:
public
Global
MotionEstimatorBase
class
CV_EXPORTS
FromFileMotionReader
:
public
Image
MotionEstimatorBase
{
public
:
FromFileMotionReader
(
const
std
::
string
&
path
);
...
...
@@ -100,50 +154,45 @@ private:
std
::
ifstream
file_
;
};
class
CV_EXPORTS
ToFileMotionWriter
:
public
Global
MotionEstimatorBase
class
CV_EXPORTS
ToFileMotionWriter
:
public
Image
MotionEstimatorBase
{
public
:
ToFileMotionWriter
(
const
std
::
string
&
path
,
Ptr
<
GlobalMotionEstimatorBase
>
estimator
);
ToFileMotionWriter
(
const
std
::
string
&
path
,
Ptr
<
ImageMotionEstimatorBase
>
estimator
);
virtual
void
setMotionModel
(
MotionModel
val
)
{
motionEstimator_
->
setMotionModel
(
val
);
}
virtual
MotionModel
motionModel
()
const
{
return
motionEstimator_
->
motionModel
();
}
virtual
Mat
estimate
(
const
Mat
&
frame0
,
const
Mat
&
frame1
,
bool
*
ok
=
0
);
private
:
std
::
ofstream
file_
;
Ptr
<
GlobalMotionEstimatorBase
>
e
stimator_
;
Ptr
<
ImageMotionEstimatorBase
>
motionE
stimator_
;
};
class
CV_EXPORTS
RansacMotionEstimator
:
public
Global
MotionEstimatorBase
class
CV_EXPORTS
KeypointBasedMotionEstimator
:
public
Image
MotionEstimatorBase
{
public
:
RansacMotionEstimator
(
MotionModel
model
=
MM_AFFINE
);
KeypointBasedMotionEstimator
(
Ptr
<
MotionEstimatorBase
>
estimator
);
virtual
void
setMotionModel
(
MotionModel
val
)
{
motionEstimator_
->
setMotionModel
(
val
);
}
virtual
MotionModel
motionModel
()
const
{
return
motionEstimator_
->
motionModel
();
}
void
setDetector
(
Ptr
<
FeatureDetector
>
val
)
{
detector_
=
val
;
}
Ptr
<
FeatureDetector
>
detector
()
const
{
return
detector_
;
}
void
setOptFlowEstimator
(
Ptr
<
ISparseOptFlowEstimator
>
val
)
{
optFlowEstimator_
=
val
;
}
Ptr
<
ISparseOptFlowEstimator
>
optFlowEstimator
()
const
{
return
optFlowEstimator_
;
}
void
setGridSize
(
Size
val
)
{
gridSize_
=
val
;
}
Size
gridSize
()
const
{
return
gridSize_
;
}
void
setRansacParams
(
const
RansacParams
&
val
)
{
ransacParams_
=
val
;
}
RansacParams
ransacParams
()
const
{
return
ransacParams_
;
}
void
setOpticalFlowEstimator
(
Ptr
<
ISparseOptFlowEstimator
>
val
)
{
optFlowEstimator_
=
val
;
}
Ptr
<
ISparseOptFlowEstimator
>
opticalFlowEstimator
()
const
{
return
optFlowEstimator_
;
}
void
setOutlierRejector
(
Ptr
<
IOutlierRejector
>
val
)
{
outlierRejector_
=
val
;
}
Ptr
<
IOutlierRejector
>
outlierRejector
()
const
{
return
outlierRejector_
;
}
void
setMinInlierRatio
(
float
val
)
{
minInlierRatio_
=
val
;
}
float
minInlierRatio
()
const
{
return
minInlierRatio_
;
}
virtual
Mat
estimate
(
const
Mat
&
frame0
,
const
Mat
&
frame1
,
bool
*
ok
=
0
);
private
:
Ptr
<
MotionEstimatorBase
>
motionEstimator_
;
Ptr
<
FeatureDetector
>
detector_
;
Ptr
<
ISparseOptFlowEstimator
>
optFlowEstimator_
;
Size
gridSize_
;
RansacParams
ransacParams_
;
Ptr
<
IOutlierRejector
>
outlierRejector_
;
float
minInlierRatio_
;
std
::
vector
<
uchar
>
status_
;
std
::
vector
<
KeyPoint
>
keypointsPrev_
;
...
...
@@ -152,29 +201,25 @@ private:
};
#if HAVE_OPENCV_GPU
class
CV_EXPORTS
RansacMotionEstimatorGpu
:
public
Global
MotionEstimatorBase
class
CV_EXPORTS
KeypointBasedMotionEstimatorGpu
:
public
Image
MotionEstimatorBase
{
public
:
RansacMotionEstimatorGpu
(
MotionModel
model
=
MM_AFFINE
);
KeypointBasedMotionEstimatorGpu
(
Ptr
<
MotionEstimatorBase
>
estimator
);
v
oid
setRansacParams
(
const
RansacParams
&
val
)
{
ransacParams_
=
val
;
}
RansacParams
ransacParams
()
const
{
return
ransacParams_
;
}
v
irtual
void
setMotionModel
(
MotionModel
val
)
{
motionEstimator_
->
setMotionModel
(
val
)
;
}
virtual
MotionModel
motionModel
()
const
{
return
motionEstimator_
->
motionModel
()
;
}
void
setOutlierRejector
(
Ptr
<
IOutlierRejector
>
val
)
{
outlierRejector_
=
val
;
}
Ptr
<
IOutlierRejector
>
outlierRejector
()
const
{
return
outlierRejector_
;
}
void
setMinInlierRatio
(
float
val
)
{
minInlierRatio_
=
val
;
}
float
minInlierRatio
()
const
{
return
minInlierRatio_
;
}
virtual
Mat
estimate
(
const
Mat
&
frame0
,
const
Mat
&
frame1
,
bool
*
ok
=
0
);
Mat
estimate
(
const
gpu
::
GpuMat
&
frame0
,
const
gpu
::
GpuMat
&
frame1
,
bool
*
ok
=
0
);
private
:
Ptr
<
MotionEstimatorBase
>
motionEstimator_
;
gpu
::
GoodFeaturesToTrackDetector_GPU
detector_
;
SparsePyrLkOptFlowEstimatorGpu
optFlowEstimator_
;
RansacParams
ransacParams_
;
Ptr
<
IOutlierRejector
>
outlierRejector_
;
float
minInlierRatio_
;
gpu
::
GpuMat
frame0_
,
grayFrame0_
,
frame1_
;
gpu
::
GpuMat
pointsPrev_
,
points_
;
...
...
@@ -186,44 +231,6 @@ private:
};
#endif
class
CV_EXPORTS
LpBasedMotionEstimator
:
public
GlobalMotionEstimatorBase
{
public
:
LpBasedMotionEstimator
(
MotionModel
model
=
MM_AFFINE
);
void
setDetector
(
Ptr
<
FeatureDetector
>
val
)
{
detector_
=
val
;
}
Ptr
<
FeatureDetector
>
detector
()
const
{
return
detector_
;
}
void
setOptFlowEstimator
(
Ptr
<
ISparseOptFlowEstimator
>
val
)
{
optFlowEstimator_
=
val
;
}
Ptr
<
ISparseOptFlowEstimator
>
optFlowEstimator
()
const
{
return
optFlowEstimator_
;
}
void
setOutlierRejector
(
Ptr
<
IOutlierRejector
>
val
)
{
outlierRejector_
=
val
;
}
Ptr
<
IOutlierRejector
>
outlierRejector
()
const
{
return
outlierRejector_
;
}
virtual
Mat
estimate
(
const
Mat
&
frame0
,
const
Mat
&
frame1
,
bool
*
ok
);
private
:
Ptr
<
FeatureDetector
>
detector_
;
Ptr
<
ISparseOptFlowEstimator
>
optFlowEstimator_
;
Ptr
<
IOutlierRejector
>
outlierRejector_
;
std
::
vector
<
uchar
>
status_
;
std
::
vector
<
KeyPoint
>
keypointsPrev_
;
std
::
vector
<
Point2f
>
pointsPrev_
,
points_
;
std
::
vector
<
Point2f
>
pointsPrevGood_
,
pointsGood_
;
std
::
vector
<
double
>
obj_
,
collb_
,
colub_
;
std
::
vector
<
int
>
rows_
,
cols_
;
std
::
vector
<
double
>
elems_
,
rowlb_
,
rowub_
;
void
set
(
int
row
,
int
col
,
double
coef
)
{
rows_
.
push_back
(
row
);
cols_
.
push_back
(
col
);
elems_
.
push_back
(
coef
);
}
};
CV_EXPORTS
Mat
getMotion
(
int
from
,
int
to
,
const
std
::
vector
<
Mat
>
&
motions
);
}
// namespace videostab
...
...
This diff is collapsed.
Click to expand it.
modules/videostab/include/opencv2/videostab/stabilizer.hpp
View file @
02d34bda
...
...
@@ -74,8 +74,8 @@ public:
void
setFrameSource
(
Ptr
<
IFrameSource
>
val
)
{
frameSource_
=
val
;
}
Ptr
<
IFrameSource
>
frameSource
()
const
{
return
frameSource_
;
}
void
setMotionEstimator
(
Ptr
<
Global
MotionEstimatorBase
>
val
)
{
motionEstimator_
=
val
;
}
Ptr
<
Global
MotionEstimatorBase
>
motionEstimator
()
const
{
return
motionEstimator_
;
}
void
setMotionEstimator
(
Ptr
<
Image
MotionEstimatorBase
>
val
)
{
motionEstimator_
=
val
;
}
Ptr
<
Image
MotionEstimatorBase
>
motionEstimator
()
const
{
return
motionEstimator_
;
}
void
setDeblurer
(
Ptr
<
DeblurerBase
>
val
)
{
deblurer_
=
val
;
}
Ptr
<
DeblurerBase
>
deblurrer
()
const
{
return
deblurer_
;
}
...
...
@@ -107,7 +107,7 @@ protected:
Ptr
<
ILog
>
log_
;
Ptr
<
IFrameSource
>
frameSource_
;
Ptr
<
Global
MotionEstimatorBase
>
motionEstimator_
;
Ptr
<
Image
MotionEstimatorBase
>
motionEstimator_
;
Ptr
<
DeblurerBase
>
deblurer_
;
Ptr
<
InpainterBase
>
inpainter_
;
int
radius_
;
...
...
This diff is collapsed.
Click to expand it.
modules/videostab/include/opencv2/videostab/wobble_suppression.hpp
View file @
02d34bda
...
...
@@ -64,8 +64,8 @@ public:
virtual
~
WobbleSuppressorBase
()
{}
void
setMotionEstimator
(
Ptr
<
Global
MotionEstimatorBase
>
val
)
{
motionEstimator_
=
val
;
}
Ptr
<
Global
MotionEstimatorBase
>
motionEstimator
()
const
{
return
motionEstimator_
;
}
void
setMotionEstimator
(
Ptr
<
Image
MotionEstimatorBase
>
val
)
{
motionEstimator_
=
val
;
}
Ptr
<
Image
MotionEstimatorBase
>
motionEstimator
()
const
{
return
motionEstimator_
;
}
virtual
void
suppress
(
int
idx
,
const
Mat
&
frame
,
Mat
&
result
)
=
0
;
...
...
@@ -85,7 +85,7 @@ public:
virtual
const
std
::
vector
<
Mat
>&
stabilizationMotions
()
const
{
return
*
stabilizationMotions_
;
}
protected
:
Ptr
<
Global
MotionEstimatorBase
>
motionEstimator_
;
Ptr
<
Image
MotionEstimatorBase
>
motionEstimator_
;
int
frameCount_
;
const
std
::
vector
<
Mat
>
*
motions_
;
const
std
::
vector
<
Mat
>
*
motions2_
;
...
...
This diff is collapsed.
Click to expand it.
modules/videostab/src/global_motion.cpp
View file @
02d34bda
This diff is collapsed.
Click to expand it.
modules/videostab/src/stabilizer.cpp
View file @
02d34bda
...
...
@@ -58,7 +58,7 @@ StabilizerBase::StabilizerBase()
{
setLog
(
new
LogToStdout
());
setFrameSource
(
new
NullFrameSource
());
setMotionEstimator
(
new
RansacMotionEstimator
(
));
setMotionEstimator
(
new
KeypointBasedMotionEstimator
(
new
MotionEstimatorRansacL2
()
));
setDeblurer
(
new
NullDeblurer
());
setInpainter
(
new
NullInpainter
());
setRadius
(
15
);
...
...
This diff is collapsed.
Click to expand it.
modules/videostab/src/wobble_suppression.cpp
View file @
02d34bda
...
...
@@ -53,9 +53,7 @@ namespace videostab
WobbleSuppressorBase
::
WobbleSuppressorBase
()
:
motions_
(
0
),
stabilizationMotions_
(
0
)
{
RansacMotionEstimator
*
est
=
new
RansacMotionEstimator
();
est
->
setMotionModel
(
MM_HOMOGRAPHY
);
est
->
setRansacParams
(
RansacParams
::
default2dMotion
(
MM_HOMOGRAPHY
));
setMotionEstimator
(
new
KeypointBasedMotionEstimator
(
new
MotionEstimatorRansacL2
(
MM_HOMOGRAPHY
)));
}
...
...
This diff is collapsed.
Click to expand it.
samples/cpp/videostab.cpp
View file @
02d34bda
...
...
@@ -85,8 +85,6 @@ void printHelp()
" Minimum inlier ratio to decide if estimated motion is OK. The default is 0.1.
\n
"
" --nkps=<int_number>
\n
"
" Number of keypoints to find in each frame. The default is 1000.
\n
"
" --extra-kps=<int_number>
\n
"
" Extra keypoint grid size for motion estimation. The default is 0.
\n
"
" --local-outlier-rejection=(yes|no)
\n
"
" Perform local outlier rejection. The default is no.
\n\n
"
" -sm, --save-motions=(<file_path>|no)
\n
"
...
...
@@ -154,8 +152,6 @@ void printHelp()
" Minimum inlier ratio to decide if estimated motion is OK. The default is 0.1.
\n
"
" --ws-nkps=<int_number>
\n
"
" Number of keypoints to find in each frame. The default is 1000.
\n
"
" --ws-extra-kps=<int_number>
\n
"
" Extra keypoint grid size for motion estimation. The default is 0.
\n
"
" --ws-local-outlier-rejection=(yes|no)
\n
"
" Perform local outlier rejection. The default is no.
\n\n
"
" -sm2, --save-motions2=(<file_path>|no)
\n
"
...
...
@@ -181,24 +177,22 @@ class IMotionEstimatorBuilder
{
public
:
virtual
~
IMotionEstimatorBuilder
()
{}
virtual
Ptr
<
Global
MotionEstimatorBase
>
build
()
=
0
;
virtual
Ptr
<
Image
MotionEstimatorBase
>
build
()
=
0
;
protected
:
IMotionEstimatorBuilder
(
CommandLineParser
&
cmd
)
:
cmd
(
cmd
)
{}
CommandLineParser
cmd
;
};
class
RansacMotionEstimator
Builder
:
public
IMotionEstimatorBuilder
class
MotionEstimatorRansacL2
Builder
:
public
IMotionEstimatorBuilder
{
public
:
RansacMotionEstimatorBuilder
(
CommandLineParser
&
cmd
,
const
string
&
prefix
=
""
)
:
IMotionEstimatorBuilder
(
cmd
),
prefix
(
prefix
)
{}
MotionEstimatorRansacL2Builder
(
CommandLineParser
&
cmd
,
bool
gpu
,
const
string
&
prefix
=
""
)
:
IMotionEstimatorBuilder
(
cmd
),
gpu
(
gpu
),
prefix
(
prefix
)
{}
virtual
Ptr
<
Global
MotionEstimatorBase
>
build
()
virtual
Ptr
<
Image
MotionEstimatorBase
>
build
()
{
RansacMotionEstimator
*
est
=
new
RansacMotionEstimator
(
motionModel
(
arg
(
prefix
+
"model"
)));
est
->
setDetector
(
new
GoodFeaturesToTrackDetector
(
argi
(
prefix
+
"nkps"
)));
MotionEstimatorRansacL2
*
est
=
new
MotionEstimatorRansacL2
(
motionModel
(
arg
(
prefix
+
"model"
)));
RansacParams
ransac
=
est
->
ransacParams
();
if
(
arg
(
prefix
+
"subset"
)
!=
"auto"
)
...
...
@@ -208,97 +202,76 @@ public:
ransac
.
eps
=
argf
(
prefix
+
"outlier-ratio"
);
est
->
setRansacParams
(
ransac
);
est
->
set
GridSize
(
Size
(
argi
(
prefix
+
"extra-kps"
),
argi
(
prefix
+
"extra-kps"
)
));
est
->
set
MinInlierRatio
(
argf
(
prefix
+
"min-inlier-ratio"
));
Ptr
<
IOutlierRejector
>
outlierRejector
=
new
NullOutlierRejector
();
if
(
arg
(
prefix
+
"local-outlier-rejection"
)
==
"yes"
)
{
TranslationBasedLocalOutlierRejector
*
tor
=
new
TranslationBasedLocalOutlierRejector
();
RansacParams
ransacParams
=
tor
->
ransacParams
();
TranslationBasedLocalOutlierRejector
*
t
bl
or
=
new
TranslationBasedLocalOutlierRejector
();
RansacParams
ransacParams
=
t
bl
or
->
ransacParams
();
if
(
arg
(
prefix
+
"thresh"
)
!=
"auto"
)
ransacParams
.
thresh
=
argf
(
prefix
+
"thresh"
);
tor
->
setRansacParams
(
ransacParams
);
outlierRejector
=
tor
;
t
bl
or
->
setRansacParams
(
ransacParams
);
outlierRejector
=
t
bl
or
;
}
est
->
setOutlierRejector
(
outlierRejector
);
est
->
setMinInlierRatio
(
argf
(
prefix
+
"min-inlier-ratio"
));
return
est
;
}
private
:
string
prefix
;
};
#if HAVE_OPENCV_GPU
class
RansacMotionEstimatorBuilderGpu
:
public
IMotionEstimatorBuilder
{
public
:
RansacMotionEstimatorBuilderGpu
(
CommandLineParser
&
cmd
,
const
string
&
prefix
=
""
)
:
IMotionEstimatorBuilder
(
cmd
),
prefix
(
prefix
)
{}
virtual
Ptr
<
GlobalMotionEstimatorBase
>
build
()
{
RansacMotionEstimatorGpu
*
est
=
new
RansacMotionEstimatorGpu
(
motionModel
(
arg
(
prefix
+
"model"
)));
RansacParams
ransac
=
est
->
ransacParams
();
if
(
arg
(
prefix
+
"subset"
)
!=
"auto"
)
ransac
.
size
=
argi
(
prefix
+
"subset"
);
if
(
arg
(
prefix
+
"thresh"
)
!=
"auto"
)
ransac
.
thresh
=
argi
(
prefix
+
"thresh"
);
ransac
.
eps
=
argf
(
prefix
+
"outlier-ratio"
);
est
->
setRansacParams
(
ransac
);
Ptr
<
IOutlierRejector
>
outlierRejector
=
new
NullOutlierRejector
();
if
(
arg
(
prefix
+
"local-outlier-rejection"
)
==
"yes"
)
if
(
gpu
)
{
TranslationBasedLocalOutlierRejector
*
tor
=
new
TranslationBasedLocalOutlierRejector
();
RansacParams
ransacParams
=
tor
->
ransacParams
();
if
(
arg
(
prefix
+
"thresh"
)
!=
"auto"
)
ransacParams
.
thresh
=
argf
(
prefix
+
"thresh"
);
tor
->
setRansacParams
(
ransacParams
);
outlierRejector
=
tor
;
KeypointBasedMotionEstimatorGpu
*
kbest
=
new
KeypointBasedMotionEstimatorGpu
(
est
);
kbest
->
setOutlierRejector
(
outlierRejector
);
return
kbest
;
}
est
->
setOutlierRejector
(
outlierRejector
);
est
->
setMinInlierRatio
(
argf
(
prefix
+
"min-inlier-ratio"
));
#endif
return
est
;
KeypointBasedMotionEstimator
*
kbest
=
new
KeypointBasedMotionEstimator
(
est
);
kbest
->
setDetector
(
new
GoodFeaturesToTrackDetector
(
argi
(
prefix
+
"nkps"
)));
kbest
->
setOutlierRejector
(
outlierRejector
);
return
kbest
;
}
private
:
bool
gpu
;
string
prefix
;
};
#endif
class
LpBasedMotionEstimator
Builder
:
public
IMotionEstimatorBuilder
class
MotionEstimatorL1
Builder
:
public
IMotionEstimatorBuilder
{
public
:
LpBasedMotionEstimatorBuilder
(
CommandLineParser
&
cmd
,
const
string
&
prefix
=
""
)
:
IMotionEstimatorBuilder
(
cmd
),
prefix
(
prefix
)
{}
MotionEstimatorL1Builder
(
CommandLineParser
&
cmd
,
bool
gpu
,
const
string
&
prefix
=
""
)
:
IMotionEstimatorBuilder
(
cmd
),
gpu
(
gpu
),
prefix
(
prefix
)
{}
virtual
Ptr
<
Global
MotionEstimatorBase
>
build
()
virtual
Ptr
<
Image
MotionEstimatorBase
>
build
()
{
LpBasedMotionEstimator
*
est
=
new
LpBasedMotionEstimator
(
motionModel
(
arg
(
prefix
+
"model"
)));
est
->
setDetector
(
new
GoodFeaturesToTrackDetector
(
argi
(
prefix
+
"nkps"
)));
MotionEstimatorL1
*
est
=
new
MotionEstimatorL1
(
motionModel
(
arg
(
prefix
+
"model"
)));
Ptr
<
IOutlierRejector
>
outlierRejector
=
new
NullOutlierRejector
();
if
(
arg
(
prefix
+
"local-outlier-rejection"
)
==
"yes"
)
{
TranslationBasedLocalOutlierRejector
*
tor
=
new
TranslationBasedLocalOutlierRejector
();
RansacParams
ransacParams
=
tor
->
ransacParams
();
TranslationBasedLocalOutlierRejector
*
t
bl
or
=
new
TranslationBasedLocalOutlierRejector
();
RansacParams
ransacParams
=
t
bl
or
->
ransacParams
();
if
(
arg
(
prefix
+
"thresh"
)
!=
"auto"
)
ransacParams
.
thresh
=
argf
(
prefix
+
"thresh"
);
tor
->
setRansacParams
(
ransacParams
);
outlierRejector
=
tor
;
tblor
->
setRansacParams
(
ransacParams
);
outlierRejector
=
tblor
;
}
#if HAVE_OPENCV_GPU
if
(
gpu
)
{
KeypointBasedMotionEstimatorGpu
*
kbest
=
new
KeypointBasedMotionEstimatorGpu
(
est
);
kbest
->
setOutlierRejector
(
outlierRejector
);
return
kbest
;
}
est
->
setOutlierRejector
(
outlierRejector
);
#endif
return
est
;
KeypointBasedMotionEstimator
*
kbest
=
new
KeypointBasedMotionEstimator
(
est
);
kbest
->
setDetector
(
new
GoodFeaturesToTrackDetector
(
argi
(
prefix
+
"nkps"
)));
kbest
->
setOutlierRejector
(
outlierRejector
);
return
kbest
;
}
private
:
bool
gpu
;
string
prefix
;
};
...
...
@@ -399,40 +372,16 @@ int main(int argc, const char **argv)
// prepare motion estimation builders
Ptr
<
IMotionEstimatorBuilder
>
motionEstBuilder
;
#if HAVE_OPENCV_GPU
if
(
arg
(
"gpu"
)
==
"yes"
)
{
if
(
arg
(
"lin-prog-motion-est"
)
==
"yes"
)
motionEstBuilder
=
new
LpBasedMotionEstimatorBuilder
(
cmd
);
else
motionEstBuilder
=
new
RansacMotionEstimatorBuilderGpu
(
cmd
);
}
if
(
arg
(
"lin-prog-motion-est"
)
==
"yes"
)
motionEstBuilder
=
new
MotionEstimatorL1Builder
(
cmd
,
arg
(
"gpu"
)
==
"yes"
);
else
#endif
{
if
(
arg
(
"lin-prog-motion-est"
)
==
"yes"
)
motionEstBuilder
=
new
LpBasedMotionEstimatorBuilder
(
cmd
);
else
motionEstBuilder
=
new
RansacMotionEstimatorBuilder
(
cmd
);
}
motionEstBuilder
=
new
MotionEstimatorRansacL2Builder
(
cmd
,
arg
(
"gpu"
)
==
"yes"
);
Ptr
<
IMotionEstimatorBuilder
>
wsMotionEstBuilder
;
#if HAVE_OPENCV_GPU
if
(
arg
(
"gpu"
)
==
"yes"
)
{
if
(
arg
(
"ws-lp"
)
==
"yes"
)
wsMotionEstBuilder
=
new
LpBasedMotionEstimatorBuilder
(
cmd
,
"ws-"
);
else
wsMotionEstBuilder
=
new
RansacMotionEstimatorBuilderGpu
(
cmd
,
"ws-"
);
}
if
(
arg
(
"ws-lp"
)
==
"yes"
)
wsMotionEstBuilder
=
new
MotionEstimatorL1Builder
(
cmd
,
arg
(
"gpu"
)
==
"yes"
,
"ws-"
);
else
#endif
{
if
(
arg
(
"ws-lp"
)
==
"yes"
)
wsMotionEstBuilder
=
new
LpBasedMotionEstimatorBuilder
(
cmd
,
"ws-"
);
else
wsMotionEstBuilder
=
new
RansacMotionEstimatorBuilder
(
cmd
,
"ws-"
);
}
wsMotionEstBuilder
=
new
MotionEstimatorRansacL2Builder
(
cmd
,
arg
(
"gpu"
)
==
"yes"
,
"ws-"
);
// determine whether we must use one pass or two pass stabilizer
bool
isTwoPass
=
...
...
This diff is collapsed.
Click to expand it.
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