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
98458398
Commit
98458398
authored
Mar 22, 2012
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split stabilizer into OnePassStabilizer and TwoPassStabilizer
parent
67088694
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
227 additions
and
103 deletions
+227
-103
deblurring.hpp
modules/videostab/include/opencv2/videostab/deblurring.hpp
+11
-9
global_motion.hpp
...les/videostab/include/opencv2/videostab/global_motion.hpp
+2
-0
inpainting.hpp
modules/videostab/include/opencv2/videostab/inpainting.hpp
+20
-16
motion_stabilizing.hpp
...ideostab/include/opencv2/videostab/motion_stabilizing.hpp
+29
-8
stabilizer.hpp
modules/videostab/include/opencv2/videostab/stabilizer.hpp
+80
-33
global_motion.cpp
modules/videostab/src/global_motion.cpp
+9
-3
inpainting.cpp
modules/videostab/src/inpainting.cpp
+13
-5
motion_stabilizing.cpp
modules/videostab/src/motion_stabilizing.cpp
+15
-7
precomp.hpp
modules/videostab/src/precomp.hpp
+11
-1
stabilizer.cpp
modules/videostab/src/stabilizer.cpp
+0
-0
videostab.cpp
samples/cpp/videostab.cpp
+37
-21
No files found.
modules/videostab/include/opencv2/videostab/deblurring.hpp
View file @
98458398
...
...
@@ -53,24 +53,26 @@ namespace videostab
CV_EXPORTS
float
calcBlurriness
(
const
Mat
&
frame
);
class
CV_EXPORTS
IDeblurer
class
CV_EXPORTS
DeblurerBase
{
public
:
IDeblurer
()
:
radius_
(
0
),
frames_
(
0
),
motions_
(
0
)
{}
DeblurerBase
()
:
radius_
(
0
),
frames_
(
0
),
motions_
(
0
)
{}
virtual
~
IDeblurer
()
{}
virtual
~
DeblurerBase
()
{}
virtual
void
setRadius
(
int
val
)
{
radius_
=
val
;
}
int
radius
()
const
{
return
radius_
;
}
virtual
int
radius
()
const
{
return
radius_
;
}
virtual
void
setFrames
(
const
std
::
vector
<
Mat
>
&
val
)
{
frames_
=
&
val
;
}
const
std
::
vector
<
Mat
>&
frames
()
const
{
return
*
frames_
;
}
virtual
const
std
::
vector
<
Mat
>&
frames
()
const
{
return
*
frames_
;
}
virtual
void
setMotions
(
const
std
::
vector
<
Mat
>
&
val
)
{
motions_
=
&
val
;
}
const
std
::
vector
<
Mat
>&
motions
()
const
{
return
*
motions_
;
}
virtual
const
std
::
vector
<
Mat
>&
motions
()
const
{
return
*
motions_
;
}
virtual
void
setBlurrinessRates
(
const
std
::
vector
<
float
>
&
val
)
{
blurrinessRates_
=
&
val
;
}
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
;
...
...
@@ -81,13 +83,13 @@ protected:
const
std
::
vector
<
float
>
*
blurrinessRates_
;
};
class
CV_EXPORTS
NullDeblurer
:
public
IDeblurer
class
CV_EXPORTS
NullDeblurer
:
public
DeblurerBase
{
public
:
virtual
void
deblur
(
int
/*idx*/
,
Mat
&
/*frame*/
)
{}
};
class
CV_EXPORTS
WeightingDeblurer
:
public
IDeblurer
class
CV_EXPORTS
WeightingDeblurer
:
public
DeblurerBase
{
public
:
WeightingDeblurer
();
...
...
modules/videostab/include/opencv2/videostab/global_motion.hpp
View file @
98458398
...
...
@@ -129,6 +129,8 @@ private:
float
minInlierRatio_
;
};
CV_EXPORTS
Mat
getMotion
(
int
from
,
int
to
,
const
Mat
*
motions
,
int
size
);
CV_EXPORTS
Mat
getMotion
(
int
from
,
int
to
,
const
std
::
vector
<
Mat
>
&
motions
);
}
// namespace videostab
...
...
modules/videostab/include/opencv2/videostab/inpainting.hpp
View file @
98458398
...
...
@@ -54,29 +54,31 @@ namespace cv
namespace
videostab
{
class
CV_EXPORTS
I
Inpainter
class
CV_EXPORTS
I
npainterBase
{
public
:
I
Inpainter
()
I
npainterBase
()
:
radius_
(
0
),
frames_
(
0
),
motions_
(
0
),
stabilizedFrames_
(
0
),
stabilizationMotions_
(
0
)
{}
virtual
~
I
Inpainter
()
{}
virtual
~
I
npainterBase
()
{}
virtual
void
setRadius
(
int
val
)
{
radius_
=
val
;
}
int
radius
()
const
{
return
radius_
;
}
virtual
int
radius
()
const
{
return
radius_
;
}
virtual
void
setFrames
(
const
std
::
vector
<
Mat
>
&
val
)
{
frames_
=
&
val
;
}
const
std
::
vector
<
Mat
>&
frames
()
const
{
return
*
frames_
;
}
virtual
const
std
::
vector
<
Mat
>&
frames
()
const
{
return
*
frames_
;
}
virtual
void
setMotions
(
const
std
::
vector
<
Mat
>
&
val
)
{
motions_
=
&
val
;
}
const
std
::
vector
<
Mat
>&
motions
()
const
{
return
*
motions_
;
}
virtual
const
std
::
vector
<
Mat
>&
motions
()
const
{
return
*
motions_
;
}
virtual
void
setStabilizedFrames
(
const
std
::
vector
<
Mat
>
&
val
)
{
stabilizedFrames_
=
&
val
;
}
const
std
::
vector
<
Mat
>&
stabilizedFrames
()
const
{
return
*
stabilizedFrames_
;
}
virtual
const
std
::
vector
<
Mat
>&
stabilizedFrames
()
const
{
return
*
stabilizedFrames_
;
}
virtual
void
setStabilizationMotions
(
const
std
::
vector
<
Mat
>
&
val
)
{
stabilizationMotions_
=
&
val
;
}
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
;
...
...
@@ -88,16 +90,16 @@ protected:
const
std
::
vector
<
Mat
>
*
stabilizationMotions_
;
};
class
CV_EXPORTS
NullInpainter
:
public
I
Inpainter
class
CV_EXPORTS
NullInpainter
:
public
I
npainterBase
{
public
:
virtual
void
inpaint
(
int
/*idx*/
,
Mat
&
/*frame*/
,
Mat
&
/*mask*/
)
{}
};
class
CV_EXPORTS
InpaintingPipeline
:
public
I
Inpainter
class
CV_EXPORTS
InpaintingPipeline
:
public
I
npainterBase
{
public
:
void
pushBack
(
Ptr
<
I
Inpainter
>
inpainter
)
{
inpainters_
.
push_back
(
inpainter
);
}
void
pushBack
(
Ptr
<
I
npainterBase
>
inpainter
)
{
inpainters_
.
push_back
(
inpainter
);
}
bool
empty
()
const
{
return
inpainters_
.
empty
();
}
virtual
void
setRadius
(
int
val
);
...
...
@@ -106,13 +108,15 @@ public:
virtual
void
setStabilizedFrames
(
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
);
private
:
std
::
vector
<
Ptr
<
I
Inpainter
>
>
inpainters_
;
std
::
vector
<
Ptr
<
I
npainterBase
>
>
inpainters_
;
};
class
CV_EXPORTS
ConsistentMosaicInpainter
:
public
I
Inpainter
class
CV_EXPORTS
ConsistentMosaicInpainter
:
public
I
npainterBase
{
public
:
ConsistentMosaicInpainter
();
...
...
@@ -126,7 +130,7 @@ private:
float
stdevThresh_
;
};
class
CV_EXPORTS
MotionInpainter
:
public
I
Inpainter
class
CV_EXPORTS
MotionInpainter
:
public
I
npainterBase
{
public
:
MotionInpainter
();
...
...
@@ -159,7 +163,7 @@ private:
Mat_
<
uchar
>
flowMask_
;
};
class
CV_EXPORTS
ColorAverageInpainter
:
public
I
Inpainter
class
CV_EXPORTS
ColorAverageInpainter
:
public
I
npainterBase
{
public
:
virtual
void
inpaint
(
int
idx
,
Mat
&
frame
,
Mat
&
mask
);
...
...
@@ -168,7 +172,7 @@ private:
FastMarchingMethod
fmm_
;
};
class
CV_EXPORTS
ColorInpainter
:
public
I
Inpainter
class
CV_EXPORTS
ColorInpainter
:
public
I
npainterBase
{
public
:
ColorInpainter
(
int
method
=
INPAINT_TELEA
,
double
radius
=
2.
)
...
...
modules/videostab/include/opencv2/videostab/motion_stabilizing.hpp
View file @
98458398
...
...
@@ -51,23 +51,44 @@ namespace cv
namespace
videostab
{
class
CV_EXPORTS
IMotion
Filt
er
class
CV_EXPORTS
IMotion
Stabiliz
er
{
public
:
virtual
~
IMotionFilter
()
{}
virtual
int
radius
()
const
=
0
;
virtual
Mat
apply
(
int
index
,
std
::
vector
<
Mat
>
&
Ms
)
const
=
0
;
virtual
void
stabilize
(
const
Mat
*
motions
,
int
size
,
Mat
*
stabilizationMotions
)
const
=
0
;
};
class
CV_EXPORTS
GaussianMotionFilter
:
public
IMotionFilt
er
class
CV_EXPORTS
MotionFilterBase
:
public
IMotionStabiliz
er
{
public
:
GaussianMotionFilter
(
int
radius
,
float
stdev
);
MotionFilterBase
()
:
radius_
(
0
)
{}
virtual
~
MotionFilterBase
()
{}
virtual
void
setRadius
(
int
val
)
{
radius_
=
val
;
}
virtual
int
radius
()
const
{
return
radius_
;
}
virtual
Mat
apply
(
int
idx
,
std
::
vector
<
Mat
>
&
motions
)
const
;
private
:
virtual
void
update
()
{}
virtual
Mat
stabilize
(
int
index
,
const
Mat
*
motions
,
int
size
)
const
=
0
;
virtual
void
stabilize
(
const
Mat
*
motions
,
int
size
,
Mat
*
stabilizationMotions
)
const
;
protected
:
int
radius_
;
};
class
CV_EXPORTS
GaussianMotionFilter
:
public
MotionFilterBase
{
public
:
GaussianMotionFilter
()
:
stdev_
(
-
1.
f
)
{}
void
setStdev
(
float
val
)
{
stdev_
=
val
;
}
float
stdev
()
const
{
return
stdev_
;
}
virtual
void
update
();
virtual
Mat
stabilize
(
int
index
,
const
Mat
*
motions
,
int
size
)
const
;
private
:
float
stdev_
;
std
::
vector
<
float
>
weight_
;
};
...
...
modules/videostab/include/opencv2/videostab/stabilizer.hpp
View file @
98458398
...
...
@@ -58,79 +58,126 @@ namespace cv
namespace
videostab
{
class
CV_EXPORTS
Stabilizer
:
public
IFrameSourc
e
class
CV_EXPORTS
Stabilizer
Bas
e
{
public
:
Stabilizer
();
virtual
~
StabilizerBase
()
{}
void
setLog
(
Ptr
<
ILog
>
log
)
{
log_
=
log
;
}
Ptr
<
ILog
>
log
()
const
{
return
log_
;
}
void
setFrameSource
(
Ptr
<
IFrameSource
>
val
)
{
frameSource_
=
val
;
reset
();
}
void
setRadius
(
int
val
)
{
radius_
=
val
;
}
int
radius
()
const
{
return
radius_
;
}
void
setFrameSource
(
Ptr
<
IFrameSource
>
val
)
{
frameSource_
=
val
;
}
Ptr
<
IFrameSource
>
frameSource
()
const
{
return
frameSource_
;
}
void
setMotionEstimator
(
Ptr
<
IGlobalMotionEstimator
>
val
)
{
motionEstimator_
=
val
;
}
Ptr
<
IGlobalMotionEstimator
>
motionEstimator
()
const
{
return
motionEstimator_
;
}
void
setMotionFilter
(
Ptr
<
IMotionFilter
>
val
)
{
motionFilter_
=
val
;
reset
();
}
Ptr
<
IMotionFilter
>
motionFilter
()
const
{
return
motionFilter_
;
}
void
setDeblurer
(
Ptr
<
IDeblurer
>
val
)
{
deblurer_
=
val
;
reset
();
}
Ptr
<
IDeblurer
>
deblurrer
()
const
{
return
deblurer_
;
}
void
setEstimateTrimRatio
(
bool
val
)
{
mustEstimateTrimRatio_
=
val
;
reset
();
}
bool
mustEstimateTrimRatio
()
const
{
return
mustEstimateTrimRatio_
;
}
void
setDeblurer
(
Ptr
<
DeblurerBase
>
val
)
{
deblurer_
=
val
;
}
Ptr
<
DeblurerBase
>
deblurrer
()
const
{
return
deblurer_
;
}
void
setTrimRatio
(
float
val
)
{
trimRatio_
=
val
;
reset
();
}
void
setTrimRatio
(
float
val
)
{
trimRatio_
=
val
;
}
float
trimRatio
()
const
{
return
trimRatio_
;
}
void
set
InclusionConstraint
(
bool
val
)
{
inclusionConstraint
_
=
val
;
}
bool
inclusionConstraint
()
const
{
return
inclusionConstraint
_
;
}
void
set
CorrectionForInclusion
(
bool
val
)
{
doCorrectionForInclusion
_
=
val
;
}
bool
doCorrectionForInclusion
()
const
{
return
doCorrectionForInclusion
_
;
}
void
setBorderMode
(
int
val
)
{
borderMode_
=
val
;
}
int
borderMode
()
const
{
return
borderMode_
;
}
void
setInpainter
(
Ptr
<
I
Inpainter
>
val
)
{
inpainter_
=
val
;
reset
()
;
}
Ptr
<
I
Inpainter
>
inpainter
()
const
{
return
inpainter_
;
}
void
setInpainter
(
Ptr
<
I
npainterBase
>
val
)
{
inpainter_
=
val
;
}
Ptr
<
I
npainterBase
>
inpainter
()
const
{
return
inpainter_
;
}
virtual
void
reset
();
virtual
Mat
nextFram
e
();
protected
:
StabilizerBas
e
();
private
:
void
estimateMotionsAndTrimRatio
();
void
processFirstFrame
(
Mat
&
frame
);
bool
processNextFrame
();
void
stabilizeFrame
(
int
idx
);
void
setUp
(
int
cacheSize
,
const
Mat
&
frame
);
Mat
nextStabilizedFrame
();
bool
doOneIteration
();
void
stabilizeFrame
(
const
Mat
&
stabilizationMotion
);
virtual
void
setUp
(
Mat
&
firstFrame
)
=
0
;
virtual
void
stabilizeFrame
()
=
0
;
virtual
void
estimateMotion
()
=
0
;
Ptr
<
ILog
>
log_
;
Ptr
<
IFrameSource
>
frameSource_
;
Ptr
<
IGlobalMotionEstimator
>
motionEstimator_
;
Ptr
<
IMotionFilter
>
motionFilter_
;
Ptr
<
IDeblurer
>
deblurer_
;
Ptr
<
IInpainter
>
inpainter_
;
bool
mustEstimateTrimRatio_
;
Ptr
<
DeblurerBase
>
deblurer_
;
Ptr
<
InpainterBase
>
inpainter_
;
int
radius_
;
float
trimRatio_
;
bool
inclusionConstraint_
;
int
borderMode_
;
Ptr
<
ILog
>
log_
;
bool
doCorrectionForInclusion_
;
int
borderMode_
;
Size
frameSize_
;
Mat
frameMask_
;
int
radius_
;
int
curPos_
;
int
curStabilizedPos_
;
bool
auxPassWasDone_
;
bool
doDeblurring_
;
Mat
preProcessedFrame_
;
bool
doInpainting_
;
Mat
inpaintingMask_
;
std
::
vector
<
Mat
>
frames_
;
std
::
vector
<
Mat
>
motions_
;
// motions_[i] is the motion from i
to i+1
frame
std
::
vector
<
Mat
>
motions_
;
// motions_[i] is the motion from i
-th to i+1-th
frame
std
::
vector
<
float
>
blurrinessRates_
;
std
::
vector
<
Mat
>
stabilizedFrames_
;
std
::
vector
<
Mat
>
stabilizedMasks_
;
std
::
vector
<
Mat
>
stabilizationMotions_
;
};
class
CV_EXPORTS
OnePassStabilizer
:
public
StabilizerBase
,
public
IFrameSource
{
public
:
OnePassStabilizer
();
void
setMotionFilter
(
Ptr
<
MotionFilterBase
>
val
)
{
motionFilter_
=
val
;
}
Ptr
<
MotionFilterBase
>
motionFilter
()
const
{
return
motionFilter_
;
}
virtual
void
reset
()
{
resetImpl
();
}
virtual
Mat
nextFrame
()
{
return
nextStabilizedFrame
();
}
private
:
void
resetImpl
();
virtual
void
setUp
(
Mat
&
firstFrame
);
virtual
void
estimateMotion
();
virtual
void
stabilizeFrame
();
Ptr
<
MotionFilterBase
>
motionFilter_
;
};
class
CV_EXPORTS
TwoPassStabilizer
:
public
StabilizerBase
,
public
IFrameSource
{
public
:
TwoPassStabilizer
();
void
setMotionStabilizer
(
Ptr
<
IMotionStabilizer
>
val
)
{
motionStabilizer_
=
val
;
}
Ptr
<
IMotionStabilizer
>
motionStabilizer
()
const
{
return
motionStabilizer_
;
}
void
setEstimateTrimRatio
(
bool
val
)
{
mustEstTrimRatio_
=
val
;
}
bool
mustEstimateTrimaRatio
()
const
{
return
mustEstTrimRatio_
;
}
virtual
void
reset
()
{
resetImpl
();
}
virtual
Mat
nextFrame
();
private
:
void
resetImpl
();
void
runPrePassIfNecessary
();
virtual
void
setUp
(
Mat
&
firstFrame
);
virtual
void
estimateMotion
()
{
/* do nothing as motion was estimation in pre-pass */
}
virtual
void
stabilizeFrame
();
Ptr
<
IMotionStabilizer
>
motionStabilizer_
;
bool
mustEstTrimRatio_
;
int
frameCount_
;
bool
isPrePassDone_
;
};
}
// namespace videostab
}
// namespace cv
...
...
modules/videostab/src/global_motion.cpp
View file @
98458398
...
...
@@ -296,22 +296,28 @@ Mat PyrLkRobustMotionEstimator::estimate(const Mat &frame0, const Mat &frame1)
}
Mat
getMotion
(
int
from
,
int
to
,
const
vector
<
Mat
>
&
motions
)
Mat
getMotion
(
int
from
,
int
to
,
const
Mat
*
motions
,
int
size
)
{
Mat
M
=
Mat
::
eye
(
3
,
3
,
CV_32F
);
if
(
to
>
from
)
{
for
(
int
i
=
from
;
i
<
to
;
++
i
)
M
=
at
(
i
,
motions
)
*
M
;
M
=
at
(
i
,
motions
,
size
)
*
M
;
}
else
if
(
from
>
to
)
{
for
(
int
i
=
to
;
i
<
from
;
++
i
)
M
=
at
(
i
,
motions
)
*
M
;
M
=
at
(
i
,
motions
,
size
)
*
M
;
M
=
M
.
inv
();
}
return
M
;
}
Mat
getMotion
(
int
from
,
int
to
,
const
vector
<
Mat
>
&
motions
)
{
return
getMotion
(
from
,
to
,
&
motions
[
0
],
motions
.
size
());
}
}
// namespace videostab
}
// namespace cv
modules/videostab/src/inpainting.cpp
View file @
98458398
...
...
@@ -57,7 +57,7 @@ void InpaintingPipeline::setRadius(int val)
{
for
(
size_t
i
=
0
;
i
<
inpainters_
.
size
();
++
i
)
inpainters_
[
i
]
->
setRadius
(
val
);
I
Inpainter
::
setRadius
(
val
);
I
npainterBase
::
setRadius
(
val
);
}
...
...
@@ -65,7 +65,7 @@ void InpaintingPipeline::setFrames(const vector<Mat> &val)
{
for
(
size_t
i
=
0
;
i
<
inpainters_
.
size
();
++
i
)
inpainters_
[
i
]
->
setFrames
(
val
);
I
Inpainter
::
setFrames
(
val
);
I
npainterBase
::
setFrames
(
val
);
}
...
...
@@ -73,7 +73,7 @@ void InpaintingPipeline::setMotions(const vector<Mat> &val)
{
for
(
size_t
i
=
0
;
i
<
inpainters_
.
size
();
++
i
)
inpainters_
[
i
]
->
setMotions
(
val
);
I
Inpainter
::
setMotions
(
val
);
I
npainterBase
::
setMotions
(
val
);
}
...
...
@@ -81,7 +81,7 @@ void InpaintingPipeline::setStabilizedFrames(const vector<Mat> &val)
{
for
(
size_t
i
=
0
;
i
<
inpainters_
.
size
();
++
i
)
inpainters_
[
i
]
->
setStabilizedFrames
(
val
);
I
Inpainter
::
setStabilizedFrames
(
val
);
I
npainterBase
::
setStabilizedFrames
(
val
);
}
...
...
@@ -89,7 +89,15 @@ void InpaintingPipeline::setStabilizationMotions(const vector<Mat> &val)
{
for
(
size_t
i
=
0
;
i
<
inpainters_
.
size
();
++
i
)
inpainters_
[
i
]
->
setStabilizationMotions
(
val
);
IInpainter
::
setStabilizationMotions
(
val
);
InpainterBase
::
setStabilizationMotions
(
val
);
}
void
InpaintingPipeline
::
update
()
{
for
(
size_t
i
=
0
;
i
<
inpainters_
.
size
();
++
i
)
inpainters_
[
i
]
->
update
();
InpainterBase
::
update
();
}
...
...
modules/videostab/src/motion_stabilizing.cpp
View file @
98458398
...
...
@@ -51,26 +51,34 @@ namespace cv
namespace
videostab
{
GaussianMotionFilter
::
GaussianMotionFilter
(
int
radius
,
float
stdev
)
:
radius_
(
radius
)
void
MotionFilterBase
::
stabilize
(
const
Mat
*
motions
,
int
size
,
Mat
*
stabilizationMotions
)
const
{
for
(
int
i
=
0
;
i
<
size
;
++
i
)
stabilizationMotions
[
i
]
=
stabilize
(
i
,
motions
,
size
);
}
void
GaussianMotionFilter
::
update
()
{
float
sigma
=
stdev_
>
0.
f
?
stdev_
:
sqrt
(
static_cast
<
float
>
(
radius_
));
float
sum
=
0
;
weight_
.
resize
(
2
*
radius_
+
1
);
for
(
int
i
=
-
radius_
;
i
<=
radius_
;
++
i
)
sum
+=
weight_
[
radius_
+
i
]
=
std
::
exp
(
-
i
*
i
/
(
s
tdev
*
stdev
));
sum
+=
weight_
[
radius_
+
i
]
=
std
::
exp
(
-
i
*
i
/
(
s
igma
*
sigma
));
for
(
int
i
=
-
radius_
;
i
<=
radius_
;
++
i
)
weight_
[
radius_
+
i
]
/=
sum
;
}
Mat
GaussianMotionFilter
::
apply
(
int
idx
,
vector
<
Mat
>
&
motions
)
const
Mat
GaussianMotionFilter
::
stabilize
(
int
index
,
const
Mat
*
motions
,
int
size
)
const
{
const
Mat
&
cur
=
at
(
i
dx
,
motions
);
const
Mat
&
cur
=
at
(
i
ndex
,
motions
,
size
);
Mat
res
=
Mat
::
zeros
(
cur
.
size
(),
cur
.
type
());
float
sum
=
0.
f
;
for
(
int
i
=
std
::
max
(
i
dx
-
radius_
,
0
);
i
<=
id
x
+
radius_
;
++
i
)
for
(
int
i
=
std
::
max
(
i
ndex
-
radius_
,
0
);
i
<=
inde
x
+
radius_
;
++
i
)
{
res
+=
weight_
[
radius_
+
i
-
i
dx
]
*
getMotion
(
idx
,
i
,
motions
);
sum
+=
weight_
[
radius_
+
i
-
i
d
x
];
res
+=
weight_
[
radius_
+
i
-
i
ndex
]
*
getMotion
(
index
,
i
,
motions
,
size
);
sum
+=
weight_
[
radius_
+
i
-
i
nde
x
];
}
return
res
/
sum
;
}
...
...
modules/videostab/src/precomp.hpp
View file @
98458398
...
...
@@ -62,9 +62,19 @@ inline float intensity(const cv::Point3_<uchar> &bgr)
return
0.3
f
*
bgr
.
x
+
0.59
f
*
bgr
.
y
+
0.11
f
*
bgr
.
z
;
}
template
<
typename
T
>
inline
T
&
at
(
int
index
,
const
T
*
items
,
int
size
)
{
return
items
[
cv
::
borderInterpolate
(
index
,
size
,
cv
::
BORDER_WRAP
)];
}
template
<
typename
T
>
inline
const
T
&
at
(
int
index
,
const
T
*
items
,
int
size
)
{
return
items
[
cv
::
borderInterpolate
(
index
,
size
,
cv
::
BORDER_WRAP
)];
}
template
<
typename
T
>
inline
T
&
at
(
int
index
,
std
::
vector
<
T
>
&
items
)
{
return
items
[
cv
::
borderInterpolate
(
index
,
items
.
size
(),
cv
::
BORDER_WRAP
)]
;
return
at
(
index
,
&
items
[
0
],
items
.
size
())
;
}
template
<
typename
T
>
inline
const
T
&
at
(
int
index
,
const
std
::
vector
<
T
>
&
items
)
...
...
modules/videostab/src/stabilizer.cpp
View file @
98458398
This diff is collapsed.
Click to expand it.
samples/cpp/videostab.cpp
View file @
98458398
...
...
@@ -12,7 +12,7 @@ using namespace std;
using
namespace
cv
;
using
namespace
cv
::
videostab
;
Ptr
<
Stabilizer
>
stabilizer
;
Ptr
<
IFrameSource
>
stabilizedFrames
;
double
outputFps
;
string
outputPath
;
bool
quietMode
;
...
...
@@ -25,7 +25,7 @@ void run()
VideoWriter
writer
;
Mat
stabilizedFrame
;
while
(
!
(
stabilizedFrame
=
stabilize
r
->
nextFrame
()).
empty
())
while
(
!
(
stabilizedFrame
=
stabilize
dFrames
->
nextFrame
()).
empty
())
{
if
(
!
outputPath
.
empty
())
{
...
...
@@ -87,7 +87,7 @@ void printHelp()
" Do color inpainting. The defailt is no.
\n
"
" --color-inpaint-radius=<float_number>
\n
"
" Set color inpainting radius (for ns and telea options only).
\n\n
"
" -o, --output=
<file_path>
\n
"
" -o, --output=
(no|<file_path>)
\n
"
" Set output file path explicitely. The default is stabilized.avi.
\n
"
" --fps=<int_number>
\n
"
" Set output video FPS explicitely. By default the source FPS is used.
\n
"
...
...
@@ -134,9 +134,35 @@ int main(int argc, const char **argv)
{
printHelp
();
return
0
;
}
StabilizerBase
*
stabilizer
;
GaussianMotionFilter
*
motionFilter
=
0
;
if
(
!
cmd
.
get
<
string
>
(
"stdev"
).
empty
())
{
motionFilter
=
new
GaussianMotionFilter
();
motionFilter
->
setStdev
(
cmd
.
get
<
float
>
(
"stdev"
));
}
stabilizer
=
new
Stabilizer
();
bool
isTwoPass
=
cmd
.
get
<
string
>
(
"est-trim"
)
==
"yes"
;
if
(
isTwoPass
)
{
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
;
}
else
{
OnePassStabilizer
*
onePassStabilizer
=
new
OnePassStabilizer
();
if
(
motionFilter
)
onePassStabilizer
->
setMotionFilter
(
motionFilter
);
stabilizer
=
onePassStabilizer
;
}
string
inputPath
=
cmd
.
get
<
string
>
(
"1"
);
if
(
inputPath
.
empty
())
...
...
@@ -169,16 +195,8 @@ int main(int argc, const char **argv)
stabilizer
->
setMotionEstimator
(
motionEstimator
);
int
smoothRadius
=
-
1
;
float
smoothStdev
=
-
1
;
if
(
!
cmd
.
get
<
string
>
(
"radius"
).
empty
())
smoothRadius
=
cmd
.
get
<
int
>
(
"radius"
);
if
(
!
cmd
.
get
<
string
>
(
"stdev"
).
empty
())
smoothStdev
=
cmd
.
get
<
float
>
(
"stdev"
);
if
(
smoothRadius
>
0
&&
smoothStdev
>
0
)
stabilizer
->
setMotionFilter
(
new
GaussianMotionFilter
(
smoothRadius
,
smoothStdev
));
else
if
(
smoothRadius
>
0
&&
smoothStdev
<
0
)
stabilizer
->
setMotionFilter
(
new
GaussianMotionFilter
(
smoothRadius
,
sqrt
(
static_cast
<
float
>
(
smoothRadius
))));
stabilizer
->
setRadius
(
cmd
.
get
<
int
>
(
"radius"
));
if
(
cmd
.
get
<
string
>
(
"deblur"
)
==
"yes"
)
{
...
...
@@ -188,14 +206,11 @@ int main(int argc, const char **argv)
stabilizer
->
setDeblurer
(
deblurer
);
}
if
(
!
cmd
.
get
<
string
>
(
"est-trim"
).
empty
())
stabilizer
->
setEstimateTrimRatio
(
cmd
.
get
<
string
>
(
"est-trim"
)
==
"yes"
);
if
(
!
cmd
.
get
<
string
>
(
"trim-ratio"
).
empty
())
stabilizer
->
setTrimRatio
(
cmd
.
get
<
float
>
(
"trim-ratio"
));
if
(
!
cmd
.
get
<
string
>
(
"incl-constr"
).
empty
())
stabilizer
->
set
InclusionConstraint
(
cmd
.
get
<
string
>
(
"incl-constr"
)
==
"yes"
);
stabilizer
->
set
CorrectionForInclusion
(
cmd
.
get
<
string
>
(
"incl-constr"
)
==
"yes"
);
if
(
cmd
.
get
<
string
>
(
"border-mode"
)
==
"reflect"
)
stabilizer
->
setBorderMode
(
BORDER_REFLECT
);
...
...
@@ -250,22 +265,23 @@ int main(int argc, const char **argv)
stabilizer
->
setLog
(
new
LogToStdout
());
outputPath
=
cmd
.
get
<
string
>
(
"output"
);
outputPath
=
cmd
.
get
<
string
>
(
"output"
)
!=
"no"
?
cmd
.
get
<
string
>
(
"output"
)
:
""
;
if
(
!
cmd
.
get
<
string
>
(
"fps"
).
empty
())
outputFps
=
cmd
.
get
<
double
>
(
"fps"
);
quietMode
=
cmd
.
get
<
bool
>
(
"quiet"
);
// run video processing
stabilizedFrames
=
dynamic_cast
<
IFrameSource
*>
(
stabilizer
);
run
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"error: "
<<
e
.
what
()
<<
endl
;
stabilize
r
.
release
();
stabilize
dFrames
.
release
();
return
-
1
;
}
stabilize
r
.
release
();
stabilize
dFrames
.
release
();
return
0
;
}
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