Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
2270c2f5
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2270c2f5
编写于
4月 26, 2012
作者:
A
Alexey Spizhevoy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactored videostab module
上级
9dfb1f77
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
41 addition
and
38 deletion
+41
-38
modules/videostab/include/opencv2/videostab/global_motion.hpp
...les/videostab/include/opencv2/videostab/global_motion.hpp
+5
-5
modules/videostab/src/global_motion.cpp
modules/videostab/src/global_motion.cpp
+36
-33
未找到文件。
modules/videostab/include/opencv2/videostab/global_motion.hpp
浏览文件 @
2270c2f5
...
...
@@ -65,12 +65,12 @@ namespace videostab
{
CV_EXPORTS
Mat
estimateGlobalMotionLeastSquares
(
int
npoints
,
Point2f
*
points0
,
Point2f
*
points1
,
int
model
=
MM_AFFINE
,
float
*
rmse
=
0
);
InputOutputArray
points0
,
InputOutputArray
points1
,
int
model
=
MM_AFFINE
,
float
*
rmse
=
0
);
CV_EXPORTS
Mat
estimateGlobalMotionRobust
(
const
std
::
vector
<
Point2f
>
&
points0
,
const
std
::
vector
<
Point2f
>
&
points1
,
int
model
=
MM_AFFINE
,
const
RansacParams
&
params
=
RansacParams
::
default2dMotion
(
MM_AFFINE
),
InputArray
points0
,
InputArray
points1
,
int
model
=
MM_AFFINE
,
const
RansacParams
&
params
=
RansacParams
::
default2dMotion
(
MM_AFFINE
),
float
*
rmse
=
0
,
int
*
ninliers
=
0
);
class
CV_EXPORTS
GlobalMotionEstimatorBase
...
...
@@ -181,7 +181,7 @@ private:
gpu
::
GpuMat
status_
;
Mat
hostPointsPrev_
,
hostPoints_
;
std
::
vector
<
Point2f
>
hostPointsPrev
Good_
,
hostPointsGood
_
;
std
::
vector
<
Point2f
>
hostPointsPrev
Tmp_
,
hostPointsTmp
_
;
std
::
vector
<
uchar
>
rejectionStatus_
;
};
#endif
...
...
modules/videostab/src/global_motion.cpp
浏览文件 @
2270c2f5
...
...
@@ -284,9 +284,12 @@ static Mat estimateGlobMotionLeastSquaresAffine(
Mat
estimateGlobalMotionLeastSquares
(
int
npoints
,
Point2f
*
points0
,
Point2f
*
points1
,
int
model
,
float
*
rmse
)
InputOutputArray
points0
,
InputOutputArray
points1
,
int
model
,
float
*
rmse
)
{
CV_Assert
(
model
<=
MM_AFFINE
);
CV_Assert
(
points0
.
type
()
==
points1
.
type
());
const
int
npoints
=
points0
.
getMat
().
checkVector
(
2
);
CV_Assert
(
points1
.
getMat
().
checkVector
(
2
)
==
npoints
);
typedef
Mat
(
*
Impl
)(
int
,
Point2f
*
,
Point2f
*
,
float
*
);
static
Impl
impls
[]
=
{
estimateGlobMotionLeastSquaresTranslation
,
...
...
@@ -295,16 +298,24 @@ Mat estimateGlobalMotionLeastSquares(
estimateGlobMotionLeastSquaresSimilarity
,
estimateGlobMotionLeastSquaresAffine
};
return
impls
[
model
](
npoints
,
points0
,
points1
,
rmse
);
Point2f
*
points0_
=
points0
.
getMat
().
ptr
<
Point2f
>
();
Point2f
*
points1_
=
points1
.
getMat
().
ptr
<
Point2f
>
();
return
impls
[
model
](
npoints
,
points0_
,
points1_
,
rmse
);
}
Mat
estimateGlobalMotionRobust
(
int
npoints
,
const
Point2f
*
points0
,
const
Point2f
*
points1
,
int
model
,
const
RansacParams
&
params
,
float
*
rmse
,
int
*
ninliers
)
InputArray
points0
,
InputArray
points1
,
int
model
,
const
RansacParams
&
params
,
float
*
rmse
,
int
*
ninliers
)
{
CV_Assert
(
model
<=
MM_AFFINE
);
CV_Assert
(
points0
.
type
()
==
points1
.
type
());
const
int
npoints
=
points0
.
getMat
().
checkVector
(
2
);
CV_Assert
(
points1
.
getMat
().
checkVector
(
2
)
==
npoints
);
const
Point2f
*
points0_
=
points0
.
getMat
().
ptr
<
Point2f
>
();
const
Point2f
*
points1_
=
points1
.
getMat
().
ptr
<
Point2f
>
();
const
int
niters
=
params
.
niters
();
// current hypothesis
...
...
@@ -338,17 +349,17 @@ Mat estimateGlobalMotionRobust(
}
for
(
int
i
=
0
;
i
<
params
.
size
;
++
i
)
{
subset0
[
i
]
=
points0
[
indices
[
i
]];
subset1
[
i
]
=
points1
[
indices
[
i
]];
subset0
[
i
]
=
points0
_
[
indices
[
i
]];
subset1
[
i
]
=
points1
_
[
indices
[
i
]];
}
Mat_
<
float
>
M
=
estimateGlobalMotionLeastSquares
(
params
.
size
,
&
subset0
[
0
],
&
subset1
[
0
],
model
,
0
);
Mat_
<
float
>
M
=
estimateGlobalMotionLeastSquares
(
subset0
,
subset1
,
model
,
0
);
int
ninliers
=
0
;
for
(
int
i
=
0
;
i
<
npoints
;
++
i
)
{
p0
=
points0
[
i
];
p1
=
points1
[
i
];
p0
=
points0_
[
i
];
p1
=
points1_
[
i
];
x
=
M
(
0
,
0
)
*
p0
.
x
+
M
(
0
,
1
)
*
p0
.
y
+
M
(
0
,
2
);
y
=
M
(
1
,
0
)
*
p0
.
x
+
M
(
1
,
1
)
*
p0
.
y
+
M
(
1
,
2
);
if
(
sqr
(
x
-
p1
.
x
)
+
sqr
(
y
-
p1
.
y
)
<
params
.
thresh
*
params
.
thresh
)
...
...
@@ -365,15 +376,15 @@ Mat estimateGlobalMotionRobust(
if
(
ninliersMax
<
params
.
size
)
// compute RMSE
bestM
=
estimateGlobalMotionLeastSquares
(
params
.
size
,
&
subset0best
[
0
],
&
subset1best
[
0
],
model
,
rmse
);
bestM
=
estimateGlobalMotionLeastSquares
(
subset0best
,
subset1best
,
model
,
rmse
);
else
{
subset0
.
resize
(
ninliersMax
);
subset1
.
resize
(
ninliersMax
);
for
(
int
i
=
0
,
j
=
0
;
i
<
npoints
;
++
i
)
{
p0
=
points0
[
i
];
p1
=
points1
[
i
];
p0
=
points0_
[
i
];
p1
=
points1_
[
i
];
x
=
bestM
(
0
,
0
)
*
p0
.
x
+
bestM
(
0
,
1
)
*
p0
.
y
+
bestM
(
0
,
2
);
y
=
bestM
(
1
,
0
)
*
p0
.
x
+
bestM
(
1
,
1
)
*
p0
.
y
+
bestM
(
1
,
2
);
if
(
sqr
(
x
-
p1
.
x
)
+
sqr
(
y
-
p1
.
y
)
<
params
.
thresh
*
params
.
thresh
)
...
...
@@ -383,8 +394,7 @@ Mat estimateGlobalMotionRobust(
j
++
;
}
}
bestM
=
estimateGlobalMotionLeastSquares
(
ninliersMax
,
&
subset0
[
0
],
&
subset1
[
0
],
model
,
rmse
);
bestM
=
estimateGlobalMotionLeastSquares
(
subset0
,
subset1
,
model
,
rmse
);
}
if
(
ninliers
)
...
...
@@ -520,8 +530,7 @@ Mat RansacMotionEstimator::estimate(const Mat &frame0, const Mat &frame1, bool *
if
(
motionModel_
!=
MM_HOMOGRAPHY
)
M
=
estimateGlobalMotionRobust
(
npoints
,
&
pointsPrevGood_
[
0
],
&
pointsGood_
[
0
],
motionModel_
,
ransacParams_
,
0
,
&
ninliers
);
pointsPrevGood_
,
pointsGood_
,
motionModel_
,
ransacParams_
,
0
,
&
ninliers
);
else
{
vector
<
uchar
>
mask
;
...
...
@@ -590,10 +599,6 @@ Mat RansacMotionEstimatorGpu::estimate(const gpu::GpuMat &frame0, const gpu::Gpu
pointsPrev_
.
download
(
hostPointsPrev_
);
points_
.
download
(
hostPoints_
);
Point2f
*
points0
=
hostPointsPrev_
.
ptr
<
Point2f
>
();
Point2f
*
points1
=
hostPoints_
.
ptr
<
Point2f
>
();
int
npoints
=
hostPointsPrev_
.
cols
;
// perfrom outlier rejection
IOutlierRejector
*
outlierRejector
=
static_cast
<
IOutlierRejector
*>
(
outlierRejector_
);
...
...
@@ -601,37 +606,35 @@ Mat RansacMotionEstimatorGpu::estimate(const gpu::GpuMat &frame0, const gpu::Gpu
{
outlierRejector_
->
process
(
frame0
.
size
(),
hostPointsPrev_
,
hostPoints_
,
rejectionStatus_
);
hostPointsPrev
Good_
.
clear
();
hostPointsPrevGood
_
.
reserve
(
hostPoints_
.
cols
);
hostPoints
Good_
.
clear
();
hostPointsGood
_
.
reserve
(
hostPoints_
.
cols
);
hostPointsPrev
Tmp_
.
clear
();
hostPointsPrevTmp
_
.
reserve
(
hostPoints_
.
cols
);
hostPoints
Tmp_
.
clear
();
hostPointsTmp
_
.
reserve
(
hostPoints_
.
cols
);
for
(
int
i
=
0
;
i
<
hostPoints_
.
cols
;
++
i
)
{
if
(
rejectionStatus_
[
i
])
{
hostPointsPrev
Good
_
.
push_back
(
hostPointsPrev_
.
at
<
Point2f
>
(
0
,
i
));
hostPoints
Good
_
.
push_back
(
hostPoints_
.
at
<
Point2f
>
(
0
,
i
));
hostPointsPrev
Tmp
_
.
push_back
(
hostPointsPrev_
.
at
<
Point2f
>
(
0
,
i
));
hostPoints
Tmp
_
.
push_back
(
hostPoints_
.
at
<
Point2f
>
(
0
,
i
));
}
}
points0
=
&
hostPointsPrevGood_
[
0
];
points1
=
&
hostPointsGood_
[
0
];
npoints
=
static_cast
<
int
>
(
hostPointsGood_
.
size
());
hostPointsPrev_
=
Mat
(
1
,
hostPointsPrevTmp_
.
size
(),
CV_32FC2
,
&
hostPointsPrevTmp_
[
0
]);
hostPoints_
=
Mat
(
1
,
hostPointsTmp_
.
size
(),
CV_32FC2
,
&
hostPointsTmp_
[
0
]);
}
// find motion
int
npoints
=
hostPoints_
.
cols
;
int
ninliers
=
0
;
Mat_
<
float
>
M
;
if
(
motionModel_
!=
MM_HOMOGRAPHY
)
M
=
estimateGlobalMotionRobust
(
npoints
,
points0
,
points1
,
motionModel_
,
ransacParams_
,
0
,
&
ninliers
);
hostPointsPrev_
,
hostPoints_
,
motionModel_
,
ransacParams_
,
0
,
&
ninliers
);
else
{
vector
<
uchar
>
mask
;
M
=
findHomography
(
Mat
(
1
,
npoints
,
CV_32FC2
,
points0
),
Mat
(
1
,
npoints
,
CV_32FC2
,
points1
),
mask
,
CV_RANSAC
,
ransacParams_
.
thresh
);
M
=
findHomography
(
hostPointsPrev_
,
hostPoints_
,
mask
,
CV_RANSAC
,
ransacParams_
.
thresh
);
for
(
int
i
=
0
;
i
<
npoints
;
++
i
)
if
(
mask
[
i
])
ninliers
++
;
}
...
...
@@ -713,8 +716,6 @@ Mat LpBasedMotionEstimator::estimate(const Mat &frame0, const Mat &frame1, bool
}
}
int
npoints
=
static_cast
<
int
>
(
pointsGood_
.
size
());
// prepare LP problem
#ifndef HAVE_CLP
...
...
@@ -727,6 +728,7 @@ Mat LpBasedMotionEstimator::estimate(const Mat &frame0, const Mat &frame1, bool
CV_Assert
(
motionModel_
<=
MM_AFFINE
&&
motionModel_
!=
MM_RIGID
);
int
npoints
=
static_cast
<
int
>
(
pointsGood_
.
size
());
int
ncols
=
6
+
2
*
npoints
;
int
nrows
=
4
*
npoints
;
...
...
@@ -852,3 +854,4 @@ Mat getMotion(int from, int to, const vector<Mat> &motions)
}
// namespace videostab
}
// namespace cv
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录