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
6bf8f474
Commit
6bf8f474
authored
Jul 01, 2013
by
Roman Donchenko
Committed by
OpenCV Buildbot
Jul 01, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1051 from pengx17:2.4_fback_ocl
parents
c8cd2cf6
a5383b86
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
253 additions
and
15 deletions
+253
-15
ocl.hpp
modules/ocl/include/opencv2/ocl/ocl.hpp
+39
-0
perf_opticalflow.cpp
modules/ocl/perf/perf_opticalflow.cpp
+142
-15
optical_flow_farneback.cl
modules/ocl/src/opencl/optical_flow_farneback.cl
+0
-0
optical_flow_farneback.cpp
modules/ocl/src/optical_flow_farneback.cpp
+0
-0
test_optflow.cpp
modules/ocl/test/test_optflow.cpp
+72
-0
No files found.
modules/ocl/include/opencv2/ocl/ocl.hpp
View file @
6bf8f474
...
...
@@ -1395,6 +1395,45 @@ namespace cv
oclMat
vPyr_
[
2
];
bool
isDeviceArch11_
;
};
class
CV_EXPORTS
FarnebackOpticalFlow
{
public
:
FarnebackOpticalFlow
();
int
numLevels
;
double
pyrScale
;
bool
fastPyramids
;
int
winSize
;
int
numIters
;
int
polyN
;
double
polySigma
;
int
flags
;
void
operator
()(
const
oclMat
&
frame0
,
const
oclMat
&
frame1
,
oclMat
&
flowx
,
oclMat
&
flowy
);
void
releaseMemory
();
private
:
void
prepareGaussian
(
int
n
,
double
sigma
,
float
*
g
,
float
*
xg
,
float
*
xxg
,
double
&
ig11
,
double
&
ig03
,
double
&
ig33
,
double
&
ig55
);
void
setPolynomialExpansionConsts
(
int
n
,
double
sigma
);
void
updateFlow_boxFilter
(
const
oclMat
&
R0
,
const
oclMat
&
R1
,
oclMat
&
flowx
,
oclMat
&
flowy
,
oclMat
&
M
,
oclMat
&
bufM
,
int
blockSize
,
bool
updateMatrices
);
void
updateFlow_gaussianBlur
(
const
oclMat
&
R0
,
const
oclMat
&
R1
,
oclMat
&
flowx
,
oclMat
&
flowy
,
oclMat
&
M
,
oclMat
&
bufM
,
int
blockSize
,
bool
updateMatrices
);
oclMat
frames_
[
2
];
oclMat
pyrLevel_
[
2
],
M_
,
bufM_
,
R_
[
2
],
blurredFrame_
[
2
];
std
::
vector
<
oclMat
>
pyramid0_
,
pyramid1_
;
};
//////////////// build warping maps ////////////////////
//! builds plane warping maps
CV_EXPORTS
void
buildWarpPlaneMaps
(
Size
src_size
,
Rect
dst_roi
,
const
Mat
&
K
,
const
Mat
&
R
,
const
Mat
&
T
,
float
scale
,
oclMat
&
map_x
,
oclMat
&
map_y
);
...
...
modules/ocl/perf/perf_opticalflow.cpp
View file @
6bf8f474
...
...
@@ -136,11 +136,13 @@ PERFTEST(PyrLKOpticalFlow)
size_t
mismatch
=
0
;
for
(
int
i
=
0
;
i
<
(
int
)
nextPts
.
size
();
++
i
)
{
if
(
status
[
i
]
!=
ocl_status
.
at
<
unsigned
char
>
(
0
,
i
)){
if
(
status
[
i
]
!=
ocl_status
.
at
<
unsigned
char
>
(
0
,
i
))
{
mismatch
++
;
continue
;
}
if
(
status
[
i
]){
if
(
status
[
i
])
{
Point2f
gpu_rst
=
ocl_nextPts
.
at
<
Point2f
>
(
0
,
i
);
Point2f
cpu_rst
=
nextPts
[
i
];
if
(
fabs
(
gpu_rst
.
x
-
cpu_rst
.
x
)
>=
1.
||
fabs
(
gpu_rst
.
y
-
cpu_rst
.
y
)
>=
1.
)
...
...
@@ -193,24 +195,24 @@ PERFTEST(tvl1flow)
WARMUP_ON
;
d_alg
(
d0
,
d1
,
d_flowx
,
d_flowy
);
WARMUP_OFF
;
/*
double diff1 = 0.0, diff2 = 0.0;
if(ExceptedMatSimilar(gold[0], cv::Mat(d_flowx), 3e-3, diff1) == 1
&&ExceptedMatSimilar(gold[1], cv::Mat(d_flowy), 3e-3, diff2) == 1)
TestSystem::instance().setAccurate(1);
else
TestSystem::instance().setAccurate(0);
/*
double diff1 = 0.0, diff2 = 0.0;
if(ExceptedMatSimilar(gold[0], cv::Mat(d_flowx), 3e-3, diff1) == 1
&&ExceptedMatSimilar(gold[1], cv::Mat(d_flowy), 3e-3, diff2) == 1)
TestSystem::instance().setAccurate(1);
else
TestSystem::instance().setAccurate(0);
TestSystem::instance().setDiff(diff1);
TestSystem::instance().setDiff(diff2);
*/
TestSystem::instance().setDiff(diff1);
TestSystem::instance().setDiff(diff2);
*/
GPU_ON
;
d_alg
(
d0
,
d1
,
d_flowx
,
d_flowy
);
d_alg
.
collectGarbage
();
GPU_OFF
;
cv
::
Mat
flowx
,
flowy
;
...
...
@@ -225,4 +227,130 @@ PERFTEST(tvl1flow)
TestSystem
::
instance
().
ExceptedMatSimilar
(
gold
[
0
],
flowx
,
3e-3
);
TestSystem
::
instance
().
ExceptedMatSimilar
(
gold
[
1
],
flowy
,
3e-3
);
}
\ No newline at end of file
}
///////////// FarnebackOpticalFlow ////////////////////////
PERFTEST
(
FarnebackOpticalFlow
)
{
cv
::
Mat
frame0
=
imread
(
"rubberwhale1.png"
,
cv
::
IMREAD_GRAYSCALE
);
ASSERT_FALSE
(
frame0
.
empty
());
cv
::
Mat
frame1
=
imread
(
"rubberwhale2.png"
,
cv
::
IMREAD_GRAYSCALE
);
ASSERT_FALSE
(
frame1
.
empty
());
cv
::
ocl
::
oclMat
d_frame0
(
frame0
),
d_frame1
(
frame1
);
int
polyNs
[
2
]
=
{
5
,
7
};
double
polySigmas
[
2
]
=
{
1.1
,
1.5
};
int
farneFlags
[
2
]
=
{
0
,
cv
::
OPTFLOW_FARNEBACK_GAUSSIAN
};
bool
UseInitFlows
[
2
]
=
{
false
,
true
};
double
pyrScale
=
0.5
;
string
farneFlagStrs
[
2
]
=
{
"BoxFilter"
,
"GaussianBlur"
};
string
useInitFlowStrs
[
2
]
=
{
""
,
"UseInitFlow"
};
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
int
polyN
=
polyNs
[
i
];
double
polySigma
=
polySigmas
[
i
];
for
(
int
j
=
0
;
j
<
2
;
++
j
)
{
int
flags
=
farneFlags
[
j
];
for
(
int
k
=
0
;
k
<
2
;
++
k
)
{
bool
useInitFlow
=
UseInitFlows
[
k
];
SUBTEST
<<
"polyN("
<<
polyN
<<
"); "
<<
farneFlagStrs
[
j
]
<<
"; "
<<
useInitFlowStrs
[
k
];
cv
::
ocl
::
FarnebackOpticalFlow
farn
;
farn
.
pyrScale
=
pyrScale
;
farn
.
polyN
=
polyN
;
farn
.
polySigma
=
polySigma
;
farn
.
flags
=
flags
;
cv
::
ocl
::
oclMat
d_flowx
,
d_flowy
;
cv
::
Mat
flow
,
flowBuf
,
flowxBuf
,
flowyBuf
;
WARMUP_ON
;
farn
(
d_frame0
,
d_frame1
,
d_flowx
,
d_flowy
);
if
(
useInitFlow
)
{
cv
::
Mat
flowxy
[]
=
{
cv
::
Mat
(
d_flowx
),
cv
::
Mat
(
d_flowy
)};
cv
::
merge
(
flowxy
,
2
,
flow
);
flow
.
copyTo
(
flowBuf
);
flowxy
[
0
].
copyTo
(
flowxBuf
);
flowxy
[
1
].
copyTo
(
flowyBuf
);
farn
.
flags
|=
cv
::
OPTFLOW_USE_INITIAL_FLOW
;
farn
(
d_frame0
,
d_frame1
,
d_flowx
,
d_flowy
);
}
WARMUP_OFF
;
cv
::
calcOpticalFlowFarneback
(
frame0
,
frame1
,
flow
,
farn
.
pyrScale
,
farn
.
numLevels
,
farn
.
winSize
,
farn
.
numIters
,
farn
.
polyN
,
farn
.
polySigma
,
farn
.
flags
);
std
::
vector
<
cv
::
Mat
>
flowxy
;
cv
::
split
(
flow
,
flowxy
);
Mat
md_flowx
=
cv
::
Mat
(
d_flowx
);
Mat
md_flowy
=
cv
::
Mat
(
d_flowy
);
TestSystem
::
instance
().
ExceptedMatSimilar
(
flowxy
[
0
],
md_flowx
,
0.1
);
TestSystem
::
instance
().
ExceptedMatSimilar
(
flowxy
[
1
],
md_flowy
,
0.1
);
if
(
useInitFlow
)
{
cv
::
Mat
flowx
,
flowy
;
farn
.
flags
=
(
flags
|
cv
::
OPTFLOW_USE_INITIAL_FLOW
);
CPU_ON
;
cv
::
calcOpticalFlowFarneback
(
frame0
,
frame1
,
flowBuf
,
farn
.
pyrScale
,
farn
.
numLevels
,
farn
.
winSize
,
farn
.
numIters
,
farn
.
polyN
,
farn
.
polySigma
,
farn
.
flags
);
CPU_OFF
;
GPU_ON
;
farn
(
d_frame0
,
d_frame1
,
d_flowx
,
d_flowy
);
GPU_OFF
;
GPU_FULL_ON
;
d_frame0
.
upload
(
frame0
);
d_frame1
.
upload
(
frame1
);
d_flowx
.
upload
(
flowxBuf
);
d_flowy
.
upload
(
flowyBuf
);
farn
(
d_frame0
,
d_frame1
,
d_flowx
,
d_flowy
);
d_flowx
.
download
(
flowx
);
d_flowy
.
download
(
flowy
);
GPU_FULL_OFF
;
}
else
{
cv
::
Mat
flow
,
flowx
,
flowy
;
cv
::
ocl
::
oclMat
d_flowx
,
d_flowy
;
farn
.
flags
=
flags
;
CPU_ON
;
cv
::
calcOpticalFlowFarneback
(
frame0
,
frame1
,
flow
,
farn
.
pyrScale
,
farn
.
numLevels
,
farn
.
winSize
,
farn
.
numIters
,
farn
.
polyN
,
farn
.
polySigma
,
farn
.
flags
);
CPU_OFF
;
GPU_ON
;
farn
(
d_frame0
,
d_frame1
,
d_flowx
,
d_flowy
);
GPU_OFF
;
GPU_FULL_ON
;
d_frame0
.
upload
(
frame0
);
d_frame1
.
upload
(
frame1
);
farn
(
d_frame0
,
d_frame1
,
d_flowx
,
d_flowy
);
d_flowx
.
download
(
flowx
);
d_flowy
.
download
(
flowy
);
GPU_FULL_OFF
;
}
}
}
}
}
modules/ocl/src/opencl/optical_flow_farneback.cl
0 → 100644
View file @
6bf8f474
This diff is collapsed.
Click to expand it.
modules/ocl/src/optical_flow_farneback.cpp
0 → 100644
View file @
6bf8f474
This diff is collapsed.
Click to expand it.
modules/ocl/test/test_optflow.cpp
View file @
6bf8f474
...
...
@@ -272,6 +272,78 @@ TEST_P(Sparse, Mat)
INSTANTIATE_TEST_CASE_P
(
OCL_Video
,
Sparse
,
Combine
(
Values
(
false
,
true
),
Values
(
false
,
true
)));
//////////////////////////////////////////////////////
// FarnebackOpticalFlow
namespace
{
IMPLEMENT_PARAM_CLASS
(
PyrScale
,
double
)
IMPLEMENT_PARAM_CLASS
(
PolyN
,
int
)
CV_FLAGS
(
FarnebackOptFlowFlags
,
0
,
OPTFLOW_FARNEBACK_GAUSSIAN
)
IMPLEMENT_PARAM_CLASS
(
UseInitFlow
,
bool
)
}
PARAM_TEST_CASE
(
Farneback
,
PyrScale
,
PolyN
,
FarnebackOptFlowFlags
,
UseInitFlow
)
{
double
pyrScale
;
int
polyN
;
int
flags
;
bool
useInitFlow
;
virtual
void
SetUp
()
{
pyrScale
=
GET_PARAM
(
0
);
polyN
=
GET_PARAM
(
1
);
flags
=
GET_PARAM
(
2
);
useInitFlow
=
GET_PARAM
(
3
);
}
};
TEST_P
(
Farneback
,
Accuracy
)
{
cv
::
Mat
frame0
=
imread
(
workdir
+
"/rubberwhale1.png"
,
cv
::
IMREAD_GRAYSCALE
);
ASSERT_FALSE
(
frame0
.
empty
());
cv
::
Mat
frame1
=
imread
(
workdir
+
"/rubberwhale2.png"
,
cv
::
IMREAD_GRAYSCALE
);
ASSERT_FALSE
(
frame1
.
empty
());
double
polySigma
=
polyN
<=
5
?
1.1
:
1.5
;
cv
::
ocl
::
FarnebackOpticalFlow
farn
;
farn
.
pyrScale
=
pyrScale
;
farn
.
polyN
=
polyN
;
farn
.
polySigma
=
polySigma
;
farn
.
flags
=
flags
;
cv
::
ocl
::
oclMat
d_flowx
,
d_flowy
;
farn
(
oclMat
(
frame0
),
oclMat
(
frame1
),
d_flowx
,
d_flowy
);
cv
::
Mat
flow
;
if
(
useInitFlow
)
{
cv
::
Mat
flowxy
[]
=
{
cv
::
Mat
(
d_flowx
),
cv
::
Mat
(
d_flowy
)};
cv
::
merge
(
flowxy
,
2
,
flow
);
farn
.
flags
|=
cv
::
OPTFLOW_USE_INITIAL_FLOW
;
farn
(
oclMat
(
frame0
),
oclMat
(
frame1
),
d_flowx
,
d_flowy
);
}
cv
::
calcOpticalFlowFarneback
(
frame0
,
frame1
,
flow
,
farn
.
pyrScale
,
farn
.
numLevels
,
farn
.
winSize
,
farn
.
numIters
,
farn
.
polyN
,
farn
.
polySigma
,
farn
.
flags
);
std
::
vector
<
cv
::
Mat
>
flowxy
;
cv
::
split
(
flow
,
flowxy
);
EXPECT_MAT_SIMILAR
(
flowxy
[
0
],
d_flowx
,
0.1
);
EXPECT_MAT_SIMILAR
(
flowxy
[
1
],
d_flowy
,
0.1
);
}
INSTANTIATE_TEST_CASE_P
(
OCL_Video
,
Farneback
,
testing
::
Combine
(
testing
::
Values
(
PyrScale
(
0.3
),
PyrScale
(
0.5
),
PyrScale
(
0.8
)),
testing
::
Values
(
PolyN
(
5
),
PolyN
(
7
)),
testing
::
Values
(
FarnebackOptFlowFlags
(
0
),
FarnebackOptFlowFlags
(
cv
::
OPTFLOW_FARNEBACK_GAUSSIAN
)),
testing
::
Values
(
UseInitFlow
(
false
),
UseInitFlow
(
true
))));
#endif // HAVE_OPENCL
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