Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
11eacb9d
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
11eacb9d
编写于
4月 25, 2012
作者:
V
Vladislav Vinogradov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Bug #1823 : fixed patch size calculation in PyrLKOpticalFlow
上级
092c1f98
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
43 deletion
+71
-43
modules/gpu/src/pyrlk.cpp
modules/gpu/src/pyrlk.cpp
+45
-33
samples/gpu/pyrlk_optical_flow.cpp
samples/gpu/pyrlk_optical_flow.cpp
+26
-10
未找到文件。
modules/gpu/src/pyrlk.cpp
浏览文件 @
11eacb9d
...
...
@@ -53,20 +53,20 @@ void cv::gpu::PyrLKOpticalFlow::dense(const GpuMat&, const GpuMat&, GpuMat&, Gpu
#else
/* !defined (HAVE_CUDA) */
namespace
cv
{
namespace
gpu
{
namespace
device
namespace
cv
{
namespace
gpu
{
namespace
device
{
namespace
pyrlk
namespace
pyrlk
{
void
loadConstants
(
int
cn
,
float
minEigThreshold
,
int2
winSize
,
int
iters
);
void
calcSharrDeriv_gpu
(
DevMem2Db
src
,
DevMem2D_
<
short
>
dx_buf
,
DevMem2D_
<
short
>
dy_buf
,
DevMem2D_
<
short
>
dIdx
,
DevMem2D_
<
short
>
dIdy
,
int
cn
,
void
calcSharrDeriv_gpu
(
DevMem2Db
src
,
DevMem2D_
<
short
>
dx_buf
,
DevMem2D_
<
short
>
dy_buf
,
DevMem2D_
<
short
>
dIdx
,
DevMem2D_
<
short
>
dIdy
,
int
cn
,
cudaStream_t
stream
=
0
);
void
lkSparse_gpu
(
DevMem2Db
I
,
DevMem2Db
J
,
DevMem2D_
<
short
>
dIdx
,
DevMem2D_
<
short
>
dIdy
,
const
float2
*
prevPts
,
float2
*
nextPts
,
uchar
*
status
,
float
*
err
,
bool
GET_MIN_EIGENVALS
,
int
ptcount
,
const
float2
*
prevPts
,
float2
*
nextPts
,
uchar
*
status
,
float
*
err
,
bool
GET_MIN_EIGENVALS
,
int
ptcount
,
int
level
,
dim3
block
,
dim3
patch
,
cudaStream_t
stream
=
0
);
void
lkDense_gpu
(
DevMem2Db
I
,
DevMem2Db
J
,
DevMem2D_
<
short
>
dIdx
,
DevMem2D_
<
short
>
dIdy
,
void
lkDense_gpu
(
DevMem2Db
I
,
DevMem2Db
J
,
DevMem2D_
<
short
>
dIdx
,
DevMem2D_
<
short
>
dIdy
,
DevMem2Df
u
,
DevMem2Df
v
,
DevMem2Df
*
err
,
bool
GET_MIN_EIGENVALS
,
cudaStream_t
stream
=
0
);
}
}}}
...
...
@@ -91,7 +91,7 @@ void cv::gpu::PyrLKOpticalFlow::buildImagePyramid(const GpuMat& img0, vector<Gpu
pyr
.
resize
(
maxLevel
+
1
);
Size
sz
=
img0
.
size
();
for
(
int
level
=
0
;
level
<=
maxLevel
;
++
level
)
{
GpuMat
temp
;
...
...
@@ -124,10 +124,33 @@ void cv::gpu::PyrLKOpticalFlow::buildImagePyramid(const GpuMat& img0, vector<Gpu
}
}
namespace
{
void
calcPatchSize
(
cv
::
Size
winSize
,
int
cn
,
dim3
&
block
,
dim3
&
patch
)
{
winSize
.
width
*=
cn
;
if
(
winSize
.
width
>
32
&&
winSize
.
width
>
2
*
winSize
.
height
)
{
block
.
x
=
32
;
block
.
y
=
8
;
}
else
{
block
.
x
=
block
.
y
=
16
;
}
patch
.
x
=
(
winSize
.
width
+
block
.
x
-
1
)
/
block
.
x
;
patch
.
y
=
(
winSize
.
height
+
block
.
y
-
1
)
/
block
.
y
;
block
.
z
=
patch
.
z
=
1
;
}
}
void
cv
::
gpu
::
PyrLKOpticalFlow
::
sparse
(
const
GpuMat
&
prevImg
,
const
GpuMat
&
nextImg
,
const
GpuMat
&
prevPts
,
GpuMat
&
nextPts
,
GpuMat
&
status
,
GpuMat
*
err
)
{
using
namespace
cv
::
gpu
::
device
::
pyrlk
;
if
(
prevPts
.
empty
())
{
nextPts
.
release
();
...
...
@@ -136,32 +159,21 @@ void cv::gpu::PyrLKOpticalFlow::sparse(const GpuMat& prevImg, const GpuMat& next
return
;
}
derivLambda
=
std
::
min
(
std
::
max
(
derivLambda
,
0.0
),
1.0
);
derivLambda
=
std
::
min
(
std
::
max
(
derivLambda
,
0.0
),
1.0
);
iters
=
std
::
min
(
std
::
max
(
iters
,
0
),
100
);
const
int
cn
=
prevImg
.
channels
();
dim3
block
;
if
(
winSize
.
width
*
cn
>
32
)
{
block
.
x
=
32
;
block
.
y
=
8
;
}
else
{
block
.
x
=
block
.
y
=
16
;
}
dim3
patch
((
winSize
.
width
*
cn
+
block
.
x
-
1
)
/
block
.
x
,
(
winSize
.
height
+
block
.
y
-
1
)
/
block
.
y
);
dim3
block
,
patch
;
calcPatchSize
(
winSize
,
cn
,
block
,
patch
);
CV_Assert
(
derivLambda
>=
0
);
CV_Assert
(
maxLevel
>=
0
&&
winSize
.
width
>
2
&&
winSize
.
height
>
2
);
CV_Assert
(
prevImg
.
size
()
==
nextImg
.
size
()
&&
prevImg
.
type
()
==
nextImg
.
type
());
CV_Assert
(
patch
.
x
>
0
&&
patch
.
x
<
6
&&
patch
.
y
>
0
&&
patch
.
y
<
6
);
CV_Assert
(
prevPts
.
rows
==
1
&&
prevPts
.
type
()
==
CV_32FC2
);
if
(
useInitialFlow
)
CV_Assert
(
nextPts
.
size
()
==
prevPts
.
size
()
&&
nextPts
.
type
()
==
CV_32FC2
);
else
...
...
@@ -176,19 +188,19 @@ void cv::gpu::PyrLKOpticalFlow::sparse(const GpuMat& prevImg, const GpuMat& next
if
(
err
)
ensureSizeIsEnough
(
1
,
prevPts
.
cols
,
CV_32FC1
,
*
err
);
// build the image pyramids.
// we pad each level with +/-winSize.{width|height}
// pixels to simplify the further patch extraction.
buildImagePyramid
(
prevImg
,
prevPyr_
,
true
);
buildImagePyramid
(
nextImg
,
nextPyr_
,
true
);
// dI/dx ~ Ix, dI/dy ~ Iy
ensureSizeIsEnough
(
prevImg
.
rows
+
winSize
.
height
*
2
,
prevImg
.
cols
+
winSize
.
width
*
2
,
CV_MAKETYPE
(
CV_16S
,
cn
),
dx_buf_
);
ensureSizeIsEnough
(
prevImg
.
rows
+
winSize
.
height
*
2
,
prevImg
.
cols
+
winSize
.
width
*
2
,
CV_MAKETYPE
(
CV_16S
,
cn
),
dy_buf_
);
loadConstants
(
cn
,
minEigThreshold
,
make_int2
(
winSize
.
width
,
winSize
.
height
),
iters
);
for
(
int
level
=
maxLevel
;
level
>=
0
;
level
--
)
...
...
@@ -204,8 +216,8 @@ void cv::gpu::PyrLKOpticalFlow::sparse(const GpuMat& prevImg, const GpuMat& next
calcSharrDeriv
(
prevPyr_
[
level
],
dIdx
,
dIdy
);
lkSparse_gpu
(
prevPyr_
[
level
],
nextPyr_
[
level
],
dIdx
,
dIdy
,
prevPts
.
ptr
<
float2
>
(),
nextPts
.
ptr
<
float2
>
(),
status
.
ptr
(),
level
==
0
&&
err
?
err
->
ptr
<
float
>
()
:
0
,
getMinEigenVals
,
prevPts
.
cols
,
lkSparse_gpu
(
prevPyr_
[
level
],
nextPyr_
[
level
],
dIdx
,
dIdy
,
prevPts
.
ptr
<
float2
>
(),
nextPts
.
ptr
<
float2
>
(),
status
.
ptr
(),
level
==
0
&&
err
?
err
->
ptr
<
float
>
()
:
0
,
getMinEigenVals
,
prevPts
.
cols
,
level
,
block
,
patch
);
}
}
...
...
@@ -214,7 +226,7 @@ void cv::gpu::PyrLKOpticalFlow::dense(const GpuMat& prevImg, const GpuMat& nextI
{
using
namespace
cv
::
gpu
::
device
::
pyrlk
;
derivLambda
=
std
::
min
(
std
::
max
(
derivLambda
,
0.0
),
1.0
);
derivLambda
=
std
::
min
(
std
::
max
(
derivLambda
,
0.0
),
1.0
);
iters
=
std
::
min
(
std
::
max
(
iters
,
0
),
100
);
...
...
@@ -222,7 +234,7 @@ void cv::gpu::PyrLKOpticalFlow::dense(const GpuMat& prevImg, const GpuMat& nextI
CV_Assert
(
prevImg
.
size
()
==
nextImg
.
size
()
&&
prevImg
.
type
()
==
nextImg
.
type
());
CV_Assert
(
derivLambda
>=
0
);
CV_Assert
(
maxLevel
>=
0
&&
winSize
.
width
>
2
&&
winSize
.
height
>
2
);
if
(
useInitialFlow
)
{
CV_Assert
(
u
.
size
()
==
prevImg
.
size
()
&&
u
.
type
()
==
CV_32FC1
);
...
...
@@ -239,7 +251,7 @@ void cv::gpu::PyrLKOpticalFlow::dense(const GpuMat& prevImg, const GpuMat& nextI
if
(
err
)
err
->
create
(
prevImg
.
size
(),
CV_32FC1
);
// build the image pyramids.
// we pad each level with +/-winSize.{width|height}
// pixels to simplify the further patch extraction.
...
...
@@ -248,12 +260,12 @@ void cv::gpu::PyrLKOpticalFlow::dense(const GpuMat& prevImg, const GpuMat& nextI
buildImagePyramid
(
nextImg
,
nextPyr_
,
true
);
buildImagePyramid
(
u
,
uPyr_
,
false
);
buildImagePyramid
(
v
,
vPyr_
,
false
);
// dI/dx ~ Ix, dI/dy ~ Iy
ensureSizeIsEnough
(
prevImg
.
rows
+
winSize
.
height
*
2
,
prevImg
.
cols
+
winSize
.
width
*
2
,
CV_16SC1
,
dx_buf_
);
ensureSizeIsEnough
(
prevImg
.
rows
+
winSize
.
height
*
2
,
prevImg
.
cols
+
winSize
.
width
*
2
,
CV_16SC1
,
dy_buf_
);
loadConstants
(
1
,
minEigThreshold
,
make_int2
(
winSize
.
width
,
winSize
.
height
),
iters
);
DevMem2Df
derr
=
err
?
*
err
:
DevMem2Df
();
...
...
@@ -271,7 +283,7 @@ void cv::gpu::PyrLKOpticalFlow::dense(const GpuMat& prevImg, const GpuMat& nextI
calcSharrDeriv
(
prevPyr_
[
level
],
dIdx
,
dIdy
);
lkDense_gpu
(
prevPyr_
[
level
],
nextPyr_
[
level
],
dIdx
,
dIdy
,
uPyr_
[
level
],
vPyr_
[
level
],
lkDense_gpu
(
prevPyr_
[
level
],
nextPyr_
[
level
],
dIdx
,
dIdy
,
uPyr_
[
level
],
vPyr_
[
level
],
level
==
0
&&
err
?
&
derr
:
0
,
getMinEigenVals
);
if
(
level
==
0
)
...
...
samples/gpu/pyrlk_optical_flow.cpp
浏览文件 @
11eacb9d
...
...
@@ -124,7 +124,7 @@ void getFlowField(const Mat& u, const Mat& v, Mat& flowField)
{
float
d
=
max
(
fabsf
(
ptr_u
[
j
]),
fabsf
(
ptr_v
[
j
]));
if
(
d
>
maxDisplacement
)
if
(
d
>
maxDisplacement
)
maxDisplacement
=
d
;
}
}
...
...
@@ -152,11 +152,16 @@ void getFlowField(const Mat& u, const Mat& v, Mat& flowField)
int
main
(
int
argc
,
const
char
*
argv
[])
{
const
char
*
keys
=
"{ h | help | false | print help message }"
"{ l | left | | specify left image }"
"{ r | right | | specify right image }"
"{ g | gray | false | use grayscale sources [PyrLK Sparse] }"
"{ p | points | 4000 | specify points count [GoodFeatureToTrack] }"
;
"{ h | help | false | print help message }"
"{ l | left | | specify left image }"
"{ r | right | | specify right image }"
"{ gray | gray | false | use grayscale sources [PyrLK Sparse] }"
"{ win_size | win_size | 21 | specify windows size [PyrLK] }"
"{ max_level | max_level | 3 | specify max level [PyrLK] }"
"{ iters | iters | 30 | specify iterations count [PyrLK] }"
"{ deriv_lambda | deriv_lambda | 0.5 | specify deriv lambda [PyrLK] }"
"{ points | points | 4000 | specify points count [GoodFeatureToTrack] }"
"{ min_dist | min_dist | 0 | specify minimal distance between points [GoodFeatureToTrack] }"
;
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
...
...
@@ -178,8 +183,13 @@ int main(int argc, const char* argv[])
}
bool
useGray
=
cmd
.
get
<
bool
>
(
"gray"
);
int
winSize
=
cmd
.
get
<
int
>
(
"win_size"
);
int
maxLevel
=
cmd
.
get
<
int
>
(
"max_level"
);
int
iters
=
cmd
.
get
<
int
>
(
"iters"
);
double
derivLambda
=
cmd
.
get
<
double
>
(
"deriv_lambda"
);
int
points
=
cmd
.
get
<
int
>
(
"points"
);
double
minDist
=
cmd
.
get
<
double
>
(
"min_dist"
);
Mat
frame0
=
imread
(
fname0
);
Mat
frame1
=
imread
(
fname1
);
...
...
@@ -210,7 +220,7 @@ int main(int argc, const char* argv[])
// goodFeaturesToTrack
GoodFeaturesToTrackDetector_GPU
detector
(
points
,
0.01
,
0.0
);
GoodFeaturesToTrackDetector_GPU
detector
(
points
,
0.01
,
minDist
);
GpuMat
d_frame0Gray
(
frame0Gray
);
GpuMat
d_prevPts
;
...
...
@@ -221,6 +231,12 @@ int main(int argc, const char* argv[])
PyrLKOpticalFlow
d_pyrLK
;
d_pyrLK
.
winSize
.
width
=
winSize
;
d_pyrLK
.
winSize
.
height
=
winSize
;
d_pyrLK
.
maxLevel
=
maxLevel
;
d_pyrLK
.
iters
=
iters
;
d_pyrLK
.
derivLambda
=
derivLambda
;
GpuMat
d_frame0
(
frame0
);
GpuMat
d_frame1
(
frame1
);
GpuMat
d_frame1Gray
(
frame1Gray
);
...
...
@@ -252,13 +268,13 @@ int main(int argc, const char* argv[])
d_pyrLK
.
dense
(
d_frame0Gray
,
d_frame1Gray
,
d_u
,
d_v
);
// Draw flow field
Mat
flowField
;
getFlowField
(
Mat
(
d_u
),
Mat
(
d_v
),
flowField
);
imshow
(
"PyrLK [Dense] Flow Field"
,
flowField
);
#ifdef HAVE_OPENGL
#ifdef HAVE_OPENGL
setOpenGlContext
(
"PyrLK [Dense]"
);
GpuMat
d_vertex
,
d_colors
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录