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
ecb1f0e2
Commit
ecb1f0e2
authored
Apr 04, 2012
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed some bugs in videostab module and refactored it
parent
26594536
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
114 additions
and
48 deletions
+114
-48
global_motion.hpp
...les/videostab/include/opencv2/videostab/global_motion.hpp
+0
-2
motion_stabilizing.hpp
...ideostab/include/opencv2/videostab/motion_stabilizing.hpp
+15
-4
ring_buffer.hpp
modules/videostab/include/opencv2/videostab/ring_buffer.hpp
+67
-0
videostab.hpp
modules/videostab/include/opencv2/videostab/videostab.hpp
+1
-0
deblurring.cpp
modules/videostab/src/deblurring.cpp
+1
-0
fast_marching.cpp
modules/videostab/src/fast_marching.cpp
+1
-0
frame_source.cpp
modules/videostab/src/frame_source.cpp
+1
-0
global_motion.cpp
modules/videostab/src/global_motion.cpp
+4
-9
inpainting.cpp
modules/videostab/src/inpainting.cpp
+1
-0
motion_stabilizing.cpp
modules/videostab/src/motion_stabilizing.cpp
+13
-9
optical_flow.cpp
modules/videostab/src/optical_flow.cpp
+1
-0
precomp.hpp
modules/videostab/src/precomp.hpp
+2
-20
stabilizer.cpp
modules/videostab/src/stabilizer.cpp
+7
-4
No files found.
modules/videostab/include/opencv2/videostab/global_motion.hpp
View file @
ecb1f0e2
...
@@ -132,8 +132,6 @@ private:
...
@@ -132,8 +132,6 @@ private:
float
minInlierRatio_
;
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
);
CV_EXPORTS
Mat
getMotion
(
int
from
,
int
to
,
const
std
::
vector
<
Mat
>
&
motions
);
}
// namespace videostab
}
// namespace videostab
...
...
modules/videostab/include/opencv2/videostab/motion_stabilizing.hpp
View file @
ecb1f0e2
...
@@ -44,6 +44,7 @@
...
@@ -44,6 +44,7 @@
#define __OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP__
#define __OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP__
#include <vector>
#include <vector>
#include <utility>
#include "opencv2/core/core.hpp"
#include "opencv2/core/core.hpp"
namespace
cv
namespace
cv
...
@@ -55,15 +56,24 @@ class CV_EXPORTS IMotionStabilizer
...
@@ -55,15 +56,24 @@ class CV_EXPORTS IMotionStabilizer
{
{
public
:
public
:
virtual
~
IMotionStabilizer
()
{}
virtual
~
IMotionStabilizer
()
{}
virtual
void
stabilize
(
const
Mat
*
motions
,
int
size
,
Mat
*
stabilizationMotions
)
const
=
0
;
// assumes that [range.first, range.second) is in or equals to [0, size-2]
virtual
void
stabilize
(
int
size
,
const
std
::
vector
<
Mat
>
&
motions
,
std
::
pair
<
int
,
int
>
range
,
Mat
*
stabilizationMotions
)
const
=
0
;
};
};
class
CV_EXPORTS
MotionFilterBase
:
public
IMotionStabilizer
class
CV_EXPORTS
MotionFilterBase
:
public
IMotionStabilizer
{
{
public
:
public
:
virtual
~
MotionFilterBase
()
{}
virtual
~
MotionFilterBase
()
{}
virtual
Mat
stabilize
(
int
index
,
const
Mat
*
motions
,
int
size
)
const
=
0
;
virtual
void
stabilize
(
const
Mat
*
motions
,
int
size
,
Mat
*
stabilizationMotions
)
const
;
virtual
Mat
stabilize
(
int
idx
,
const
std
::
vector
<
Mat
>
&
motions
,
std
::
pair
<
int
,
int
>
range
)
const
=
0
;
virtual
void
stabilize
(
int
size
,
const
std
::
vector
<
Mat
>
&
motions
,
std
::
pair
<
int
,
int
>
range
,
Mat
*
stabilizationMotions
)
const
;
};
};
class
CV_EXPORTS
GaussianMotionFilter
:
public
MotionFilterBase
class
CV_EXPORTS
GaussianMotionFilter
:
public
MotionFilterBase
...
@@ -75,7 +85,8 @@ public:
...
@@ -75,7 +85,8 @@ public:
int
radius
()
const
{
return
radius_
;
}
int
radius
()
const
{
return
radius_
;
}
float
stdev
()
const
{
return
stdev_
;
}
float
stdev
()
const
{
return
stdev_
;
}
virtual
Mat
stabilize
(
int
index
,
const
Mat
*
motions
,
int
size
)
const
;
virtual
Mat
stabilize
(
int
idx
,
const
std
::
vector
<
Mat
>
&
motions
,
std
::
pair
<
int
,
int
>
range
)
const
;
private
:
private
:
int
radius_
;
int
radius_
;
...
...
modules/videostab/include/opencv2/videostab/ring_buffer.hpp
0 → 100644
View file @
ecb1f0e2
/*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-2011, 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*/
#ifndef __OPENCV_VIDEOSTAB_RING_BUFFER_HPP__
#define __OPENCV_VIDEOSTAB_RING_BUFFER_HPP__
#include <vector>
#include "opencv2/imgproc/imgproc.hpp"
namespace
cv
{
namespace
videostab
{
template
<
typename
T
>
inline
T
&
at
(
int
idx
,
std
::
vector
<
T
>
&
items
)
{
return
items
[
cv
::
borderInterpolate
(
idx
,
static_cast
<
int
>
(
items
.
size
()),
cv
::
BORDER_WRAP
)];
}
template
<
typename
T
>
inline
const
T
&
at
(
int
idx
,
const
std
::
vector
<
T
>
&
items
)
{
return
items
[
cv
::
borderInterpolate
(
idx
,
static_cast
<
int
>
(
items
.
size
()),
cv
::
BORDER_WRAP
)];
}
}
// namespace videostab
}
// namespace cv
#endif
modules/videostab/include/opencv2/videostab/videostab.hpp
View file @
ecb1f0e2
...
@@ -44,5 +44,6 @@
...
@@ -44,5 +44,6 @@
#define __OPENCV_VIDEOSTAB_HPP__
#define __OPENCV_VIDEOSTAB_HPP__
#include "opencv2/videostab/stabilizer.hpp"
#include "opencv2/videostab/stabilizer.hpp"
#include "opencv2/videostab/ring_buffer.hpp"
#endif
#endif
modules/videostab/src/deblurring.cpp
View file @
ecb1f0e2
...
@@ -43,6 +43,7 @@
...
@@ -43,6 +43,7 @@
#include "precomp.hpp"
#include "precomp.hpp"
#include "opencv2/videostab/deblurring.hpp"
#include "opencv2/videostab/deblurring.hpp"
#include "opencv2/videostab/global_motion.hpp"
#include "opencv2/videostab/global_motion.hpp"
#include "opencv2/videostab/ring_buffer.hpp"
using
namespace
std
;
using
namespace
std
;
...
...
modules/videostab/src/fast_marching.cpp
View file @
ecb1f0e2
...
@@ -42,6 +42,7 @@
...
@@ -42,6 +42,7 @@
#include "precomp.hpp"
#include "precomp.hpp"
#include "opencv2/videostab/fast_marching.hpp"
#include "opencv2/videostab/fast_marching.hpp"
#include "opencv2/videostab/ring_buffer.hpp"
using
namespace
std
;
using
namespace
std
;
...
...
modules/videostab/src/frame_source.cpp
View file @
ecb1f0e2
...
@@ -42,6 +42,7 @@
...
@@ -42,6 +42,7 @@
#include "precomp.hpp"
#include "precomp.hpp"
#include "opencv2/videostab/frame_source.hpp"
#include "opencv2/videostab/frame_source.hpp"
#include "opencv2/videostab/ring_buffer.hpp"
using
namespace
std
;
using
namespace
std
;
...
...
modules/videostab/src/global_motion.cpp
View file @
ecb1f0e2
...
@@ -43,6 +43,7 @@
...
@@ -43,6 +43,7 @@
#include "precomp.hpp"
#include "precomp.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/videostab/global_motion.hpp"
#include "opencv2/videostab/global_motion.hpp"
#include "opencv2/videostab/ring_buffer.hpp"
using
namespace
std
;
using
namespace
std
;
...
@@ -333,28 +334,22 @@ Mat PyrLkRobustMotionEstimator::estimate(const Mat &frame0, const Mat &frame1)
...
@@ -333,28 +334,22 @@ Mat PyrLkRobustMotionEstimator::estimate(const Mat &frame0, const Mat &frame1)
}
}
Mat
getMotion
(
int
from
,
int
to
,
const
Mat
*
motions
,
int
size
)
Mat
getMotion
(
int
from
,
int
to
,
const
vector
<
Mat
>
&
motions
)
{
{
Mat
M
=
Mat
::
eye
(
3
,
3
,
CV_32F
);
Mat
M
=
Mat
::
eye
(
3
,
3
,
CV_32F
);
if
(
to
>
from
)
if
(
to
>
from
)
{
{
for
(
int
i
=
from
;
i
<
to
;
++
i
)
for
(
int
i
=
from
;
i
<
to
;
++
i
)
M
=
at
(
i
,
motions
,
size
)
*
M
;
M
=
at
(
i
,
motions
)
*
M
;
}
}
else
if
(
from
>
to
)
else
if
(
from
>
to
)
{
{
for
(
int
i
=
to
;
i
<
from
;
++
i
)
for
(
int
i
=
to
;
i
<
from
;
++
i
)
M
=
at
(
i
,
motions
,
size
)
*
M
;
M
=
at
(
i
,
motions
)
*
M
;
M
=
M
.
inv
();
M
=
M
.
inv
();
}
}
return
M
;
return
M
;
}
}
Mat
getMotion
(
int
from
,
int
to
,
const
vector
<
Mat
>
&
motions
)
{
return
getMotion
(
from
,
to
,
&
motions
[
0
],
motions
.
size
());
}
}
// namespace videostab
}
// namespace videostab
}
// namespace cv
}
// namespace cv
modules/videostab/src/inpainting.cpp
View file @
ecb1f0e2
...
@@ -45,6 +45,7 @@
...
@@ -45,6 +45,7 @@
#include "opencv2/videostab/inpainting.hpp"
#include "opencv2/videostab/inpainting.hpp"
#include "opencv2/videostab/global_motion.hpp"
#include "opencv2/videostab/global_motion.hpp"
#include "opencv2/videostab/fast_marching.hpp"
#include "opencv2/videostab/fast_marching.hpp"
#include "opencv2/videostab/ring_buffer.hpp"
using
namespace
std
;
using
namespace
std
;
...
...
modules/videostab/src/motion_stabilizing.cpp
View file @
ecb1f0e2
...
@@ -43,6 +43,7 @@
...
@@ -43,6 +43,7 @@
#include "precomp.hpp"
#include "precomp.hpp"
#include "opencv2/videostab/motion_stabilizing.hpp"
#include "opencv2/videostab/motion_stabilizing.hpp"
#include "opencv2/videostab/global_motion.hpp"
#include "opencv2/videostab/global_motion.hpp"
#include "opencv2/videostab/ring_buffer.hpp"
using
namespace
std
;
using
namespace
std
;
...
@@ -51,17 +52,18 @@ namespace cv
...
@@ -51,17 +52,18 @@ namespace cv
namespace
videostab
namespace
videostab
{
{
void
MotionFilterBase
::
stabilize
(
const
Mat
*
motions
,
int
size
,
Mat
*
stabilizationMotions
)
const
void
MotionFilterBase
::
stabilize
(
int
size
,
const
vector
<
Mat
>
&
motions
,
pair
<
int
,
int
>
range
,
Mat
*
stabilizationMotions
)
const
{
{
for
(
int
i
=
0
;
i
<
size
;
++
i
)
for
(
int
i
=
0
;
i
<
size
;
++
i
)
stabilizationMotions
[
i
]
=
stabilize
(
i
,
motions
,
siz
e
);
stabilizationMotions
[
i
]
=
stabilize
(
i
,
motions
,
rang
e
);
}
}
void
GaussianMotionFilter
::
setParams
(
int
radius
,
float
stdev
)
void
GaussianMotionFilter
::
setParams
(
int
radius
,
float
stdev
)
{
{
radius_
=
radius
;
radius_
=
radius
;
stdev_
=
stdev
>
0.
f
?
stdev
:
sqrt
(
static_cast
<
float
>
(
radius
_
));
stdev_
=
stdev
>
0.
f
?
stdev
:
sqrt
(
static_cast
<
float
>
(
radius
));
float
sum
=
0
;
float
sum
=
0
;
weight_
.
resize
(
2
*
radius_
+
1
);
weight_
.
resize
(
2
*
radius_
+
1
);
...
@@ -72,17 +74,19 @@ void GaussianMotionFilter::setParams(int radius, float stdev)
...
@@ -72,17 +74,19 @@ void GaussianMotionFilter::setParams(int radius, float stdev)
}
}
Mat
GaussianMotionFilter
::
stabilize
(
int
i
ndex
,
const
Mat
*
motions
,
int
siz
e
)
const
Mat
GaussianMotionFilter
::
stabilize
(
int
i
dx
,
const
vector
<
Mat
>
&
motions
,
pair
<
int
,
int
>
rang
e
)
const
{
{
const
Mat
&
cur
=
at
(
i
ndex
,
motions
,
size
);
const
Mat
&
cur
=
at
(
i
dx
,
motions
);
Mat
res
=
Mat
::
zeros
(
cur
.
size
(),
cur
.
type
());
Mat
res
=
Mat
::
zeros
(
cur
.
size
(),
cur
.
type
());
float
sum
=
0.
f
;
float
sum
=
0.
f
;
for
(
int
i
=
std
::
max
(
index
-
radius_
,
0
);
i
<=
index
+
radius_
;
++
i
)
int
iMin
=
std
::
max
(
idx
-
radius_
,
range
.
first
);
int
iMax
=
std
::
min
(
idx
+
radius_
,
range
.
second
);
for
(
int
i
=
iMin
;
i
<=
iMax
;
++
i
)
{
{
res
+=
weight_
[
radius_
+
i
-
i
ndex
]
*
getMotion
(
index
,
i
,
motions
,
size
);
res
+=
weight_
[
radius_
+
i
-
i
dx
]
*
getMotion
(
idx
,
i
,
motions
);
sum
+=
weight_
[
radius_
+
i
-
i
nde
x
];
sum
+=
weight_
[
radius_
+
i
-
i
d
x
];
}
}
return
res
/
sum
;
return
sum
>
0.
f
?
res
/
sum
:
Mat
::
eye
(
cur
.
size
(),
cur
.
type
())
;
}
}
...
...
modules/videostab/src/optical_flow.cpp
View file @
ecb1f0e2
...
@@ -43,6 +43,7 @@
...
@@ -43,6 +43,7 @@
#include "precomp.hpp"
#include "precomp.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/videostab/optical_flow.hpp"
#include "opencv2/videostab/optical_flow.hpp"
#include "opencv2/videostab/ring_buffer.hpp"
using
namespace
std
;
using
namespace
std
;
...
...
modules/videostab/src/precomp.hpp
View file @
ecb1f0e2
...
@@ -55,6 +55,8 @@
...
@@ -55,6 +55,8 @@
#include "opencv2/video/video.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/features2d/features2d.hpp"
// some aux. functions
inline
float
sqr
(
float
x
)
{
return
x
*
x
;
}
inline
float
sqr
(
float
x
)
{
return
x
*
x
;
}
inline
float
intensity
(
const
cv
::
Point3_
<
uchar
>
&
bgr
)
inline
float
intensity
(
const
cv
::
Point3_
<
uchar
>
&
bgr
)
...
@@ -62,25 +64,5 @@ inline float intensity(const cv::Point3_<uchar> &bgr)
...
@@ -62,25 +64,5 @@ inline float intensity(const cv::Point3_<uchar> &bgr)
return
0.3
f
*
bgr
.
x
+
0.59
f
*
bgr
.
y
+
0.11
f
*
bgr
.
z
;
return
0.3
f
*
bgr
.
x
+
0.59
f
*
bgr
.
y
+
0.11
f
*
bgr
.
z
;
}
}
template
<
typename
T
>
inline
T
&
at
(
int
index
,
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
at
(
index
,
&
items
[
0
],
items
.
size
());
}
template
<
typename
T
>
inline
const
T
&
at
(
int
index
,
const
std
::
vector
<
T
>
&
items
)
{
return
items
[
cv
::
borderInterpolate
(
index
,
items
.
size
(),
cv
::
BORDER_WRAP
)];
}
#endif
#endif
modules/videostab/src/stabilizer.cpp
View file @
ecb1f0e2
...
@@ -42,6 +42,7 @@
...
@@ -42,6 +42,7 @@
#include "precomp.hpp"
#include "precomp.hpp"
#include "opencv2/videostab/stabilizer.hpp"
#include "opencv2/videostab/stabilizer.hpp"
#include "opencv2/videostab/ring_buffer.hpp"
using
namespace
std
;
using
namespace
std
;
...
@@ -145,7 +146,7 @@ bool StabilizerBase::doOneIteration()
...
@@ -145,7 +146,7 @@ bool StabilizerBase::doOneIteration()
{
{
curStabilizedPos_
++
;
curStabilizedPos_
++
;
at
(
curStabilizedPos_
+
radius_
,
frames_
)
=
at
(
curPos_
,
frames_
);
at
(
curStabilizedPos_
+
radius_
,
frames_
)
=
at
(
curPos_
,
frames_
);
at
(
curStabilizedPos_
+
radius_
-
1
,
motions_
)
=
at
(
curPos_
-
1
,
motions_
);
at
(
curStabilizedPos_
+
radius_
-
1
,
motions_
)
=
Mat
::
eye
(
3
,
3
,
CV_32F
);
stabilizeFrame
();
stabilizeFrame
();
log_
->
print
(
"."
);
log_
->
print
(
"."
);
...
@@ -212,7 +213,7 @@ void OnePassStabilizer::reset()
...
@@ -212,7 +213,7 @@ void OnePassStabilizer::reset()
stabilizedFrames_
.
clear
();
stabilizedFrames_
.
clear
();
stabilizationMotions_
.
clear
();
stabilizationMotions_
.
clear
();
doDeblurring_
=
false
;
doDeblurring_
=
false
;
doInpainting_
=
false
;
doInpainting_
=
false
;
}
}
...
@@ -251,7 +252,7 @@ void OnePassStabilizer::estimateMotion()
...
@@ -251,7 +252,7 @@ void OnePassStabilizer::estimateMotion()
void
OnePassStabilizer
::
stabilizeFrame
()
void
OnePassStabilizer
::
stabilizeFrame
()
{
{
Mat
stabilizationMotion
=
motionFilter_
->
stabilize
(
curStabilizedPos_
,
&
motions_
[
0
],
motions_
.
size
(
));
Mat
stabilizationMotion
=
motionFilter_
->
stabilize
(
curStabilizedPos_
,
motions_
,
make_pair
(
0
,
curPos_
));
StabilizerBase
::
stabilizeFrame
(
stabilizationMotion
);
StabilizerBase
::
stabilizeFrame
(
stabilizationMotion
);
}
}
...
@@ -326,7 +327,9 @@ void TwoPassStabilizer::runPrePassIfNecessary()
...
@@ -326,7 +327,9 @@ void TwoPassStabilizer::runPrePassIfNecessary()
log_
->
print
(
"
\n
"
);
log_
->
print
(
"
\n
"
);
stabilizationMotions_
.
resize
(
frameCount_
);
stabilizationMotions_
.
resize
(
frameCount_
);
motionStabilizer_
->
stabilize
(
&
motions_
[
0
],
frameCount_
,
&
stabilizationMotions_
[
0
]);
motionStabilizer_
->
stabilize
(
frameCount_
,
motions_
,
make_pair
(
0
,
frameCount_
-
1
),
&
stabilizationMotions_
[
0
]);
if
(
mustEstTrimRatio_
)
if
(
mustEstTrimRatio_
)
{
{
...
...
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