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
3e23bb6d
Commit
3e23bb6d
authored
Apr 02, 2012
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored videostab module and sample
parent
5fe49347
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
150 additions
and
174 deletions
+150
-174
deblurring.hpp
modules/videostab/include/opencv2/videostab/deblurring.hpp
+0
-2
global_motion.hpp
...les/videostab/include/opencv2/videostab/global_motion.hpp
+1
-0
inpainting.hpp
modules/videostab/include/opencv2/videostab/inpainting.hpp
+0
-4
motion_stabilizing.hpp
...ideostab/include/opencv2/videostab/motion_stabilizing.hpp
+6
-0
stabilizer.hpp
modules/videostab/include/opencv2/videostab/stabilizer.hpp
+1
-1
inpainting.cpp
modules/videostab/src/inpainting.cpp
+0
-8
stabilizer.cpp
modules/videostab/src/stabilizer.cpp
+16
-24
videostab.cpp
samples/cpp/videostab.cpp
+126
-135
No files found.
modules/videostab/include/opencv2/videostab/deblurring.hpp
View file @
3e23bb6d
...
@@ -72,8 +72,6 @@ public:
...
@@ -72,8 +72,6 @@ public:
virtual
void
setBlurrinessRates
(
const
std
::
vector
<
float
>
&
val
)
{
blurrinessRates_
=
&
val
;
}
virtual
void
setBlurrinessRates
(
const
std
::
vector
<
float
>
&
val
)
{
blurrinessRates_
=
&
val
;
}
virtual
const
std
::
vector
<
float
>&
blurrinessRates
()
const
{
return
*
blurrinessRates_
;
}
virtual
const
std
::
vector
<
float
>&
blurrinessRates
()
const
{
return
*
blurrinessRates_
;
}
virtual
void
update
()
{}
virtual
void
deblur
(
int
idx
,
Mat
&
frame
)
=
0
;
virtual
void
deblur
(
int
idx
,
Mat
&
frame
)
=
0
;
protected
:
protected
:
...
...
modules/videostab/include/opencv2/videostab/global_motion.hpp
View file @
3e23bb6d
...
@@ -72,6 +72,7 @@ struct CV_EXPORTS RansacParams
...
@@ -72,6 +72,7 @@ struct CV_EXPORTS RansacParams
float
eps
;
// max outliers ratio
float
eps
;
// max outliers ratio
float
prob
;
// probability of success
float
prob
;
// probability of success
RansacParams
()
:
size
(
0
),
thresh
(
0
),
eps
(
0
),
prob
(
0
)
{}
RansacParams
(
int
size
,
float
thresh
,
float
eps
,
float
prob
)
RansacParams
(
int
size
,
float
thresh
,
float
eps
,
float
prob
)
:
size
(
size
),
thresh
(
thresh
),
eps
(
eps
),
prob
(
prob
)
{}
:
size
(
size
),
thresh
(
thresh
),
eps
(
eps
),
prob
(
prob
)
{}
...
...
modules/videostab/include/opencv2/videostab/inpainting.hpp
View file @
3e23bb6d
...
@@ -78,8 +78,6 @@ public:
...
@@ -78,8 +78,6 @@ public:
virtual
void
setStabilizationMotions
(
const
std
::
vector
<
Mat
>
&
val
)
{
stabilizationMotions_
=
&
val
;
}
virtual
void
setStabilizationMotions
(
const
std
::
vector
<
Mat
>
&
val
)
{
stabilizationMotions_
=
&
val
;
}
virtual
const
std
::
vector
<
Mat
>&
stabilizationMotions
()
const
{
return
*
stabilizationMotions_
;
}
virtual
const
std
::
vector
<
Mat
>&
stabilizationMotions
()
const
{
return
*
stabilizationMotions_
;
}
virtual
void
update
()
{}
virtual
void
inpaint
(
int
idx
,
Mat
&
frame
,
Mat
&
mask
)
=
0
;
virtual
void
inpaint
(
int
idx
,
Mat
&
frame
,
Mat
&
mask
)
=
0
;
protected
:
protected
:
...
@@ -108,8 +106,6 @@ public:
...
@@ -108,8 +106,6 @@ public:
virtual
void
setStabilizedFrames
(
const
std
::
vector
<
Mat
>
&
val
);
virtual
void
setStabilizedFrames
(
const
std
::
vector
<
Mat
>
&
val
);
virtual
void
setStabilizationMotions
(
const
std
::
vector
<
Mat
>
&
val
);
virtual
void
setStabilizationMotions
(
const
std
::
vector
<
Mat
>
&
val
);
virtual
void
update
();
virtual
void
inpaint
(
int
idx
,
Mat
&
frame
,
Mat
&
mask
);
virtual
void
inpaint
(
int
idx
,
Mat
&
frame
,
Mat
&
mask
);
private
:
private
:
...
...
modules/videostab/include/opencv2/videostab/motion_stabilizing.hpp
View file @
3e23bb6d
...
@@ -79,6 +79,12 @@ class CV_EXPORTS GaussianMotionFilter : public MotionFilterBase
...
@@ -79,6 +79,12 @@ class CV_EXPORTS GaussianMotionFilter : public MotionFilterBase
{
{
public
:
public
:
GaussianMotionFilter
()
:
stdev_
(
-
1.
f
)
{}
GaussianMotionFilter
()
:
stdev_
(
-
1.
f
)
{}
GaussianMotionFilter
(
int
radius
,
float
stdev
=
-
1.
f
)
{
setRadius
(
radius
);
setStdev
(
stdev
);
update
();
}
void
setStdev
(
float
val
)
{
stdev_
=
val
;
}
void
setStdev
(
float
val
)
{
stdev_
=
val
;
}
float
stdev
()
const
{
return
stdev_
;
}
float
stdev
()
const
{
return
stdev_
;
}
...
...
modules/videostab/include/opencv2/videostab/stabilizer.hpp
View file @
3e23bb6d
...
@@ -160,7 +160,7 @@ public:
...
@@ -160,7 +160,7 @@ public:
void
setEstimateTrimRatio
(
bool
val
)
{
mustEstTrimRatio_
=
val
;
}
void
setEstimateTrimRatio
(
bool
val
)
{
mustEstTrimRatio_
=
val
;
}
bool
mustEstimateTrimaRatio
()
const
{
return
mustEstTrimRatio_
;
}
bool
mustEstimateTrimaRatio
()
const
{
return
mustEstTrimRatio_
;
}
virtual
void
reset
()
{
resetImpl
();
}
virtual
void
reset
()
;
virtual
Mat
nextFrame
();
virtual
Mat
nextFrame
();
// available after pre-pass, before it's empty
// available after pre-pass, before it's empty
...
...
modules/videostab/src/inpainting.cpp
View file @
3e23bb6d
...
@@ -93,14 +93,6 @@ void InpaintingPipeline::setStabilizationMotions(const vector<Mat> &val)
...
@@ -93,14 +93,6 @@ void InpaintingPipeline::setStabilizationMotions(const vector<Mat> &val)
}
}
void
InpaintingPipeline
::
update
()
{
for
(
size_t
i
=
0
;
i
<
inpainters_
.
size
();
++
i
)
inpainters_
[
i
]
->
update
();
InpainterBase
::
update
();
}
void
InpaintingPipeline
::
inpaint
(
int
idx
,
Mat
&
frame
,
Mat
&
mask
)
void
InpaintingPipeline
::
inpaint
(
int
idx
,
Mat
&
frame
,
Mat
&
mask
)
{
{
for
(
size_t
i
=
0
;
i
<
inpainters_
.
size
();
++
i
)
for
(
size_t
i
=
0
;
i
<
inpainters_
.
size
();
++
i
)
...
...
modules/videostab/src/stabilizer.cpp
View file @
3e23bb6d
...
@@ -70,12 +70,10 @@ void StabilizerBase::setUp(int cacheSize, const Mat &frame)
...
@@ -70,12 +70,10 @@ void StabilizerBase::setUp(int cacheSize, const Mat &frame)
doInpainting_
=
dynamic_cast
<
NullInpainter
*>
(
inpainter
)
==
0
;
doInpainting_
=
dynamic_cast
<
NullInpainter
*>
(
inpainter
)
==
0
;
if
(
doInpainting_
)
if
(
doInpainting_
)
{
{
inpainter_
->
setRadius
(
radius_
);
inpainter_
->
setFrames
(
frames_
);
inpainter_
->
setFrames
(
frames_
);
inpainter_
->
setMotions
(
motions_
);
inpainter_
->
setMotions
(
motions_
);
inpainter_
->
setStabilizedFrames
(
stabilizedFrames_
);
inpainter_
->
setStabilizedFrames
(
stabilizedFrames_
);
inpainter_
->
setStabilizationMotions
(
stabilizationMotions_
);
inpainter_
->
setStabilizationMotions
(
stabilizationMotions_
);
inpainter_
->
update
();
}
}
DeblurerBase
*
deblurer
=
static_cast
<
DeblurerBase
*>
(
deblurer_
);
DeblurerBase
*
deblurer
=
static_cast
<
DeblurerBase
*>
(
deblurer_
);
...
@@ -86,11 +84,9 @@ void StabilizerBase::setUp(int cacheSize, const Mat &frame)
...
@@ -86,11 +84,9 @@ void StabilizerBase::setUp(int cacheSize, const Mat &frame)
float
blurriness
=
calcBlurriness
(
frame
);
float
blurriness
=
calcBlurriness
(
frame
);
for
(
int
i
=
-
radius_
;
i
<=
0
;
++
i
)
for
(
int
i
=
-
radius_
;
i
<=
0
;
++
i
)
at
(
i
,
blurrinessRates_
)
=
blurriness
;
at
(
i
,
blurrinessRates_
)
=
blurriness
;
deblurer_
->
setRadius
(
radius_
);
deblurer_
->
setFrames
(
frames_
);
deblurer_
->
setFrames
(
frames_
);
deblurer_
->
setMotions
(
motions_
);
deblurer_
->
setMotions
(
motions_
);
deblurer_
->
setBlurrinessRates
(
blurrinessRates_
);
deblurer_
->
setBlurrinessRates
(
blurrinessRates_
);
deblurer_
->
update
();
}
}
log_
->
print
(
"processing frames"
);
log_
->
print
(
"processing frames"
);
...
@@ -242,7 +238,6 @@ void OnePassStabilizer::setUp(Mat &firstFrame)
...
@@ -242,7 +238,6 @@ void OnePassStabilizer::setUp(Mat &firstFrame)
at
(
0
,
frames_
)
=
firstFrame
;
at
(
0
,
frames_
)
=
firstFrame
;
motionFilter_
->
setRadius
(
radius_
);
motionFilter_
->
update
();
motionFilter_
->
update
();
StabilizerBase
::
setUp
(
cacheSize
,
firstFrame
);
StabilizerBase
::
setUp
(
cacheSize
,
firstFrame
);
...
@@ -267,7 +262,22 @@ TwoPassStabilizer::TwoPassStabilizer()
...
@@ -267,7 +262,22 @@ TwoPassStabilizer::TwoPassStabilizer()
{
{
setMotionStabilizer
(
new
GaussianMotionFilter
());
setMotionStabilizer
(
new
GaussianMotionFilter
());
setEstimateTrimRatio
(
false
);
setEstimateTrimRatio
(
false
);
resetImpl
();
reset
();
}
void
TwoPassStabilizer
::
reset
()
{
isPrePassDone_
=
false
;
frameCount_
=
0
;
curPos_
=
-
1
;
curStabilizedPos_
=
-
1
;
frames_
.
clear
();
motions_
.
clear
();
stabilizedFrames_
.
clear
();
stabilizationMotions_
.
clear
();
doDeblurring_
=
false
;
doInpainting_
=
false
;
}
}
...
@@ -288,21 +298,6 @@ vector<Mat> TwoPassStabilizer::motions() const
...
@@ -288,21 +298,6 @@ vector<Mat> TwoPassStabilizer::motions() const
}
}
void
TwoPassStabilizer
::
resetImpl
()
{
isPrePassDone_
=
false
;
frameCount_
=
0
;
curPos_
=
-
1
;
curStabilizedPos_
=
-
1
;
frames_
.
clear
();
motions_
.
clear
();
stabilizedFrames_
.
clear
();
stabilizationMotions_
.
clear
();
doDeblurring_
=
false
;
doInpainting_
=
false
;
}
void
TwoPassStabilizer
::
runPrePassIfNecessary
()
void
TwoPassStabilizer
::
runPrePassIfNecessary
()
{
{
if
(
!
isPrePassDone_
)
if
(
!
isPrePassDone_
)
...
@@ -335,10 +330,7 @@ void TwoPassStabilizer::runPrePassIfNecessary()
...
@@ -335,10 +330,7 @@ void TwoPassStabilizer::runPrePassIfNecessary()
IMotionStabilizer
*
motionStabilizer
=
static_cast
<
IMotionStabilizer
*>
(
motionStabilizer_
);
IMotionStabilizer
*
motionStabilizer
=
static_cast
<
IMotionStabilizer
*>
(
motionStabilizer_
);
MotionFilterBase
*
motionFilterBase
=
dynamic_cast
<
MotionFilterBase
*>
(
motionStabilizer
);
MotionFilterBase
*
motionFilterBase
=
dynamic_cast
<
MotionFilterBase
*>
(
motionStabilizer
);
if
(
motionFilterBase
)
if
(
motionFilterBase
)
{
motionFilterBase
->
setRadius
(
radius_
);
motionFilterBase
->
update
();
motionFilterBase
->
update
();
}
stabilizationMotions_
.
resize
(
frameCount_
);
stabilizationMotions_
.
resize
(
frameCount_
);
motionStabilizer_
->
stabilize
(
&
motions_
[
0
],
frameCount_
,
&
stabilizationMotions_
[
0
]);
motionStabilizer_
->
stabilize
(
&
motions_
[
0
],
frameCount_
,
&
stabilizationMotions_
[
0
]);
...
...
samples/cpp/videostab.cpp
View file @
3e23bb6d
...
@@ -9,11 +9,16 @@
...
@@ -9,11 +9,16 @@
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/videostab/videostab.hpp"
#include "opencv2/videostab/videostab.hpp"
#define arg(name) cmd.get<string>(name)
#define argb(name) cmd.get<bool>(name)
#define argi(name) cmd.get<int>(name)
#define argf(name) cmd.get<float>(name)
#define argd(name) cmd.get<double>(name)
using
namespace
std
;
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
;
using
namespace
cv
::
videostab
;
using
namespace
cv
::
videostab
;
Ptr
<
IFrameSource
>
stabilizedFrames
;
Ptr
<
IFrameSource
>
stabilizedFrames
;
string
saveMotionsPath
;
string
saveMotionsPath
;
double
outputFps
;
double
outputFps
;
...
@@ -61,6 +66,7 @@ private:
...
@@ -61,6 +66,7 @@ private:
size_t
pos_
;
size_t
pos_
;
};
};
void
run
()
void
run
()
{
{
VideoWriter
writer
;
VideoWriter
writer
;
...
@@ -128,14 +134,15 @@ void printHelp()
...
@@ -128,14 +134,15 @@ void printHelp()
" --min-inlier-ratio=<float_number>
\n
"
" --min-inlier-ratio=<float_number>
\n
"
" Minimum inlier ratio to decide if estimated motion is OK. The default is 0.1,
\n
"
" Minimum inlier ratio to decide if estimated motion is OK. The default is 0.1,
\n
"
" but you may want to increase it.
\n\n
"
" but you may want to increase it.
\n\n
"
" --save-motions=
<file_path>
\n
"
" --save-motions=
(<file_path>|no)
\n
"
" Save estimated motions into file.
\n
"
" Save estimated motions into file.
The default is no.
\n
"
" --load-motions=
<file_path>
\n
"
" --load-motions=
(<file_path>|no)
\n
"
" Load motions from file.
\n\n
"
" Load motions from file.
The default is no.
\n\n
"
" -r, --radius=<int_number>
\n
"
" -r, --radius=<int_number>
\n
"
" Set smoothing radius. The default is 15.
\n
"
" Set sliding window radius. The default is 15.
\n
"
" --stdev=<float_number>
\n
"
" --stdev=(<float_number>|auto)
\n
"
" Set smoothing weights standard deviation. The default is sqrt(radius).
\n\n
"
" Set smoothing weights standard deviation. The default is sqrt(radius),
\n
"
" i.e. auto.
\n\n
"
" --deblur=(yes|no)
\n
"
" --deblur=(yes|no)
\n
"
" Do deblurring.
\n
"
" Do deblurring.
\n
"
" --deblur-sens=<float_number>
\n
"
" --deblur-sens=<float_number>
\n
"
...
@@ -160,10 +167,11 @@ void printHelp()
...
@@ -160,10 +167,11 @@ void printHelp()
" --color-inpaint=(no|average|ns|telea)
\n
"
" --color-inpaint=(no|average|ns|telea)
\n
"
" Do color inpainting. The defailt is no.
\n
"
" Do color inpainting. The defailt is no.
\n
"
" --color-inpaint-radius=<float_number>
\n
"
" --color-inpaint-radius=<float_number>
\n
"
" Set color inpainting radius (for ns and telea options only).
\n\n
"
" Set color inpainting radius (for ns and telea options only).
\n
"
" The default is 2.0
\n\n
"
" -o, --output=(no|<file_path>)
\n
"
" -o, --output=(no|<file_path>)
\n
"
" Set output file path explicitely. The default is stabilized.avi.
\n
"
" Set output file path explicitely. The default is stabilized.avi.
\n
"
" --fps=
<int_number>
\n
"
" --fps=
(<int_number>|auto)
\n
"
" Set output video FPS explicitely. By default the source FPS is used.
\n
"
" Set output video FPS explicitely. By default the source FPS is used.
\n
"
" -q, --quiet
\n
"
" -q, --quiet
\n
"
" Don't show output video frames.
\n\n
"
" Don't show output video frames.
\n\n
"
...
@@ -179,182 +187,165 @@ int main(int argc, const char **argv)
...
@@ -179,182 +187,165 @@ int main(int argc, const char **argv)
{
{
const
char
*
keys
=
const
char
*
keys
=
"{ 1 | | | | }"
"{ 1 | | | | }"
"{ m | model | | }"
"{ m | model |
affine
| }"
"{ | min-inlier-ratio | | }"
"{ | min-inlier-ratio |
0.1
| }"
"{ | outlier-ratio | | }"
"{ | outlier-ratio |
0.5
| }"
"{ | save-motions | | }"
"{ | save-motions |
no
| }"
"{ | load-motions | | }"
"{ | load-motions |
no
| }"
"{ r | radius | | }"
"{ r | radius |
15
| }"
"{ | stdev | | }"
"{ | stdev |
auto
| }"
"{ | deblur | | }"
"{ | deblur |
no
| }"
"{ | deblur-sens | | }"
"{ | deblur-sens |
0.1
| }"
"{ | est-trim | yes | }"
"{ | est-trim | yes | }"
"{ t | trim-ratio | | }"
"{ t | trim-ratio |
0.0
| }"
"{ | incl-constr | | }"
"{ | incl-constr |
no
| }"
"{ | border-mode | | }"
"{ | border-mode |
replicate
| }"
"{ | mosaic | | }"
"{ | mosaic |
no
| }"
"{ | mosaic-stdev | | }"
"{ | mosaic-stdev |
10.0
| }"
"{ | motion-inpaint | | }"
"{ | motion-inpaint |
no
| }"
"{ | dist-thresh | | }"
"{ | dist-thresh |
5.0
| }"
"{ | color-inpaint | no | }"
"{ | color-inpaint | no | }"
"{ | color-inpaint-radius | | }"
"{ | color-inpaint-radius |
2
| }"
"{ o | output | stabilized.avi | }"
"{ o | output | stabilized.avi | }"
"{ | fps | | }"
"{ | fps |
auto
| }"
"{ q | quiet | false | }"
"{ q | quiet | false | }"
"{ h | help | false | }"
;
"{ h | help | false | }"
;
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
// parse command arguments
// parse command arguments
if
(
cmd
.
get
<
bool
>
(
"help"
))
if
(
argb
(
"help"
))
{
{
printHelp
();
printHelp
();
return
0
;
return
0
;
}
}
StabilizerBase
*
stabilizer
;
StabilizerBase
*
stabilizer
;
GaussianMotionFilter
*
motionFilter
=
0
;
if
(
!
cmd
.
get
<
string
>
(
"stdev"
).
empty
())
{
motionFilter
=
new
GaussianMotionFilter
();
motionFilter
->
setStdev
(
cmd
.
get
<
float
>
(
"stdev"
));
}
if
(
!
cmd
.
get
<
string
>
(
"save-motions"
).
empty
())
saveMotionsPath
=
cmd
.
get
<
string
>
(
"save-motions"
);
bool
isTwoPass
=
cmd
.
get
<
string
>
(
"est-trim"
)
==
"yes"
||
!
cmd
.
get
<
string
>
(
"save-motions"
).
empty
();
bool
isTwoPass
=
arg
(
"est-trim"
)
==
"yes"
||
arg
(
"save-motions"
)
!=
"no"
;
if
(
isTwoPass
)
if
(
isTwoPass
)
{
{
TwoPassStabilizer
*
twoPassStabilizer
=
new
TwoPassStabilizer
();
TwoPassStabilizer
*
twoPassStabilizer
=
new
TwoPassStabilizer
();
if
(
!
cmd
.
get
<
string
>
(
"est-trim"
).
empty
())
twoPassStabilizer
->
setEstimateTrimRatio
(
cmd
.
get
<
string
>
(
"est-trim"
)
==
"yes"
);
if
(
motionFilter
)
twoPassStabilizer
->
setMotionStabilizer
(
motionFilter
);
stabilizer
=
twoPassStabilizer
;
stabilizer
=
twoPassStabilizer
;
twoPassStabilizer
->
setEstimateTrimRatio
(
arg
(
"est-trim"
)
==
"yes"
);
if
(
arg
(
"stdev"
)
==
"auto"
)
twoPassStabilizer
->
setMotionStabilizer
(
new
GaussianMotionFilter
(
argi
(
"radius"
)));
else
twoPassStabilizer
->
setMotionStabilizer
(
new
GaussianMotionFilter
(
argi
(
"radius"
),
argf
(
"stdev"
)));
}
}
else
else
{
{
OnePassStabilizer
*
onePassStabilizer
=
new
OnePassStabilizer
();
OnePassStabilizer
*
onePassStabilizer
=
new
OnePassStabilizer
();
if
(
motionFilter
)
onePassStabilizer
->
setMotionFilter
(
motionFilter
);
stabilizer
=
onePassStabilizer
;
stabilizer
=
onePassStabilizer
;
if
(
arg
(
"stdev"
)
==
"auto"
)
onePassStabilizer
->
setMotionFilter
(
new
GaussianMotionFilter
(
argi
(
"radius"
)));
else
onePassStabilizer
->
setMotionFilter
(
new
GaussianMotionFilter
(
argi
(
"radius"
),
argf
(
"stdev"
)));
}
}
stabilizedFrames
=
dynamic_cast
<
IFrameSource
*>
(
stabilizer
);
string
inputPath
=
arg
(
"1"
);
if
(
inputPath
.
empty
())
throw
runtime_error
(
"specify video file path"
);
string
inputPath
=
cmd
.
get
<
string
>
(
"1"
);
VideoFileSource
*
source
=
new
VideoFileSource
(
inputPath
);
if
(
inputPath
.
empty
())
cout
<<
"frame count: "
<<
source
->
frameCount
()
<<
endl
;
throw
runtime_error
(
"specify video file path"
);
if
(
arg
(
"fps"
)
==
"auto"
)
outputFps
=
source
->
fps
();
else
outputFps
=
argd
(
"fps"
);
stabilizer
->
setFrameSource
(
source
);
VideoFileSource
*
frameSource
=
new
VideoFileSource
(
inputPath
);
outputFps
=
frameSource
->
fps
();
if
(
arg
(
"load-motions"
)
==
"no"
)
stabilizer
->
setFrameSource
(
frameSource
);
cout
<<
"frame count: "
<<
frameSource
->
frameCount
()
<<
endl
;
PyrLkRobustMotionEstimator
*
motionEstimator
=
new
PyrLkRobustMotionEstimator
();
if
(
cmd
.
get
<
string
>
(
"model"
)
==
"transl"
)
motionEstimator
->
setMotionModel
(
TRANSLATION
);
else
if
(
cmd
.
get
<
string
>
(
"model"
)
==
"transl_and_scale"
)
motionEstimator
->
setMotionModel
(
TRANSLATION_AND_SCALE
);
else
if
(
cmd
.
get
<
string
>
(
"model"
)
==
"linear_sim"
)
motionEstimator
->
setMotionModel
(
LINEAR_SIMILARITY
);
else
if
(
cmd
.
get
<
string
>
(
"model"
)
==
"affine"
)
motionEstimator
->
setMotionModel
(
AFFINE
);
else
if
(
!
cmd
.
get
<
string
>
(
"model"
).
empty
())
throw
runtime_error
(
"unknow motion mode: "
+
cmd
.
get
<
string
>
(
"model"
));
if
(
!
cmd
.
get
<
string
>
(
"outlier-ratio"
).
empty
())
{
{
RansacParams
ransacParams
=
motionEstimator
->
ransacParams
();
RansacParams
ransac
;
ransacParams
.
eps
=
cmd
.
get
<
float
>
(
"outlier-ratio"
);
PyrLkRobustMotionEstimator
*
est
=
new
PyrLkRobustMotionEstimator
();
motionEstimator
->
setRansacParams
(
ransacParams
);
Ptr
<
IGlobalMotionEstimator
>
est_
(
est
);
if
(
arg
(
"model"
)
==
"transl"
)
{
est
->
setMotionModel
(
TRANSLATION
);
ransac
=
RansacParams
::
translationMotionStd
();
}
else
if
(
arg
(
"model"
)
==
"transl_and_scale"
)
{
est
->
setMotionModel
(
TRANSLATION_AND_SCALE
);
ransac
=
RansacParams
::
translationAndScale2dMotionStd
();
}
else
if
(
arg
(
"model"
)
==
"linear_sim"
)
{
est
->
setMotionModel
(
LINEAR_SIMILARITY
);
ransac
=
RansacParams
::
linearSimilarityMotionStd
();
}
else
if
(
arg
(
"model"
)
==
"affine"
)
{
est
->
setMotionModel
(
AFFINE
);
ransac
=
RansacParams
::
affine2dMotionStd
();
}
else
throw
runtime_error
(
"unknown motion model: "
+
arg
(
"model"
));
ransac
.
eps
=
argf
(
"outlier-ratio"
);
est
->
setRansacParams
(
ransac
);
est
->
setMinInlierRatio
(
argf
(
"min-inlier-ratio"
));
stabilizer
->
setMotionEstimator
(
est_
);
}
}
if
(
!
cmd
.
get
<
string
>
(
"min-inlier-ratio"
).
empty
())
else
motionEstimator
->
setMinInlierRatio
(
cmd
.
get
<
float
>
(
"min-inlier-ratio"
));
stabilizer
->
setMotionEstimator
(
new
GlobalMotionReader
(
arg
(
"load-motions"
)));
stabilizer
->
setMotionEstimator
(
motionEstimator
);
if
(
!
cmd
.
get
<
string
>
(
"load-motions"
).
empty
())
stabilizer
->
setMotionEstimator
(
new
GlobalMotionReader
(
cmd
.
get
<
string
>
(
"load-motions"
)));
if
(
!
cmd
.
get
<
string
>
(
"radius"
).
empty
()
)
if
(
arg
(
"save-motions"
)
!=
"no"
)
s
tabilizer
->
setRadius
(
cmd
.
get
<
int
>
(
"radius"
)
);
s
aveMotionsPath
=
arg
(
"save-motions"
);
if
(
cmd
.
get
<
string
>
(
"deblur"
)
==
"yes"
)
stabilizer
->
setRadius
(
argi
(
"radius"
));
if
(
arg
(
"deblur"
)
==
"yes"
)
{
{
WeightingDeblurer
*
deblurer
=
new
WeightingDeblurer
();
WeightingDeblurer
*
deblurer
=
new
WeightingDeblurer
();
if
(
!
cmd
.
get
<
string
>
(
"deblur-sens"
).
empty
())
deblurer
->
setRadius
(
argi
(
"radius"
));
deblurer
->
setSensitivity
(
cmd
.
get
<
float
>
(
"deblur-sens"
));
deblurer
->
setSensitivity
(
argf
(
"deblur-sens"
));
stabilizer
->
setDeblurer
(
deblurer
);
stabilizer
->
setDeblurer
(
deblurer
);
}
}
if
(
!
cmd
.
get
<
string
>
(
"trim-ratio"
).
empty
())
stabilizer
->
setTrimRatio
(
argf
(
"trim-ratio"
));
stabilizer
->
setTrimRatio
(
cmd
.
get
<
float
>
(
"trim-ratio"
)
);
stabilizer
->
setCorrectionForInclusion
(
arg
(
"incl-constr"
)
==
"yes"
);
if
(
!
cmd
.
get
<
string
>
(
"incl-constr"
).
empty
())
if
(
arg
(
"border-mode"
)
==
"reflect"
)
stabilizer
->
setCorrectionForInclusion
(
cmd
.
get
<
string
>
(
"incl-constr"
)
==
"yes"
);
if
(
cmd
.
get
<
string
>
(
"border-mode"
)
==
"reflect"
)
stabilizer
->
setBorderMode
(
BORDER_REFLECT
);
stabilizer
->
setBorderMode
(
BORDER_REFLECT
);
else
if
(
cmd
.
get
<
string
>
(
"border-mode"
)
==
"replicate"
)
else
if
(
arg
(
"border-mode"
)
==
"replicate"
)
stabilizer
->
setBorderMode
(
BORDER_REPLICATE
);
stabilizer
->
setBorderMode
(
BORDER_REPLICATE
);
else
if
(
cmd
.
get
<
string
>
(
"border-mode"
)
==
"const"
)
else
if
(
arg
(
"border-mode"
)
==
"const"
)
stabilizer
->
setBorderMode
(
BORDER_CONSTANT
);
stabilizer
->
setBorderMode
(
BORDER_CONSTANT
);
else
if
(
!
cmd
.
get
<
string
>
(
"border-mode"
).
empty
())
else
throw
runtime_error
(
"unknown border extrapolation mode: "
+
cmd
.
get
<
string
>
(
"border-mode"
));
throw
runtime_error
(
"unknown border extrapolation mode: "
+
cmd
.
get
<
string
>
(
"border-mode"
));
InpaintingPipeline
*
inpainters
=
new
InpaintingPipeline
();
InpaintingPipeline
*
inpainters
=
new
InpaintingPipeline
();
if
(
cmd
.
get
<
string
>
(
"mosaic"
)
==
"yes"
)
Ptr
<
InpainterBase
>
inpainters_
(
inpainters
);
if
(
arg
(
"mosaic"
)
==
"yes"
)
{
{
ConsistentMosaicInpainter
*
inpainter
=
new
ConsistentMosaicInpainter
();
ConsistentMosaicInpainter
*
inp
=
new
ConsistentMosaicInpainter
();
if
(
!
cmd
.
get
<
string
>
(
"mosaic-stdev"
).
empty
())
inp
->
setStdevThresh
(
argf
(
"mosaic-stdev"
));
inpainter
->
setStdevThresh
(
cmd
.
get
<
float
>
(
"mosaic-stdev"
));
inpainters
->
pushBack
(
inp
);
inpainters
->
pushBack
(
inpainter
);
}
}
if
(
cmd
.
get
<
string
>
(
"motion-inpaint"
)
==
"yes"
)
if
(
arg
(
"motion-inpaint"
)
==
"yes"
)
{
{
MotionInpainter
*
inpainter
=
new
MotionInpainter
();
MotionInpainter
*
inp
=
new
MotionInpainter
();
if
(
!
cmd
.
get
<
string
>
(
"dist-thresh"
).
empty
())
inp
->
setDistThreshold
(
argf
(
"dist-thresh"
));
inpainter
->
setDistThreshold
(
cmd
.
get
<
float
>
(
"dist-thresh"
));
inpainters
->
pushBack
(
inp
);
inpainters
->
pushBack
(
inpainter
);
}
}
if
(
!
cmd
.
get
<
string
>
(
"color-inpaint"
).
empty
())
if
(
arg
(
"color-inpaint"
)
==
"average"
)
inpainters
->
pushBack
(
new
ColorAverageInpainter
());
else
if
(
arg
(
"color-inpaint"
)
==
"ns"
)
inpainters
->
pushBack
(
new
ColorInpainter
(
INPAINT_NS
,
argd
(
"color-inpaint-radius"
)));
else
if
(
arg
(
"color-inpaint"
)
==
"telea"
)
inpainters
->
pushBack
(
new
ColorInpainter
(
INPAINT_TELEA
,
argd
(
"color-inpaint-radius"
)));
else
if
(
arg
(
"color-inpaint"
)
!=
"no"
)
throw
runtime_error
(
"unknown color inpainting method: "
+
arg
(
"color-inpaint"
));
if
(
!
inpainters
->
empty
())
{
{
if
(
cmd
.
get
<
string
>
(
"color-inpaint"
)
==
"average"
)
inpainters
->
setRadius
(
argi
(
"radius"
));
inpainters
->
pushBack
(
new
ColorAverageInpainter
());
stabilizer
->
setInpainter
(
inpainters_
);
else
if
(
!
cmd
.
get
<
string
>
(
"color-inpaint-radius"
).
empty
())
{
float
radius
=
cmd
.
get
<
float
>
(
"color-inpaint-radius"
);
if
(
cmd
.
get
<
string
>
(
"color-inpaint"
)
==
"ns"
)
inpainters
->
pushBack
(
new
ColorInpainter
(
INPAINT_NS
,
radius
));
else
if
(
cmd
.
get
<
string
>
(
"color-inpaint"
)
==
"telea"
)
inpainters
->
pushBack
(
new
ColorInpainter
(
INPAINT_TELEA
,
radius
));
else
if
(
cmd
.
get
<
string
>
(
"color-inpaint"
)
!=
"no"
)
throw
runtime_error
(
"unknown color inpainting method: "
+
cmd
.
get
<
string
>
(
"color-inpaint"
));
}
else
{
if
(
cmd
.
get
<
string
>
(
"color-inpaint"
)
==
"ns"
)
inpainters
->
pushBack
(
new
ColorInpainter
(
INPAINT_NS
));
else
if
(
cmd
.
get
<
string
>
(
"color-inpaint"
)
==
"telea"
)
inpainters
->
pushBack
(
new
ColorInpainter
(
INPAINT_TELEA
));
else
if
(
cmd
.
get
<
string
>
(
"color-inpaint"
)
!=
"no"
)
throw
runtime_error
(
"unknown color inpainting method: "
+
cmd
.
get
<
string
>
(
"color-inpaint"
));
}
}
}
if
(
!
inpainters
->
empty
())
stabilizer
->
setInpainter
(
inpainters
);
stabilizer
->
setLog
(
new
LogToStdout
());
stabilizer
->
setLog
(
new
LogToStdout
());
outputPath
=
cmd
.
get
<
string
>
(
"output"
)
!=
"no"
?
cmd
.
get
<
string
>
(
"output"
)
:
""
;
if
(
arg
(
"output"
)
!=
"no"
)
outputPath
=
arg
(
"output"
);
if
(
!
cmd
.
get
<
string
>
(
"fps"
).
empty
())
outputFps
=
cmd
.
get
<
double
>
(
"fps"
);
quietMode
=
cmd
.
get
<
bool
>
(
"quiet"
);
quietMode
=
argb
(
"quite"
);
stabilizedFrames
=
dynamic_cast
<
IFrameSource
*>
(
stabilizer
);
run
();
run
();
}
}
...
...
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