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
78e89890
Commit
78e89890
authored
Sep 17, 2012
by
yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add PyrLK to ocl module
parent
0e9405e5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
240 additions
and
0 deletions
+240
-0
matrix_operations.hpp
modules/ocl/include/opencv2/ocl/matrix_operations.hpp
+12
-0
ocl.hpp
modules/ocl/include/opencv2/ocl/ocl.hpp
+60
-0
pyrlk.cl
modules/ocl/src/kernels/pyrlk.cl
+0
-0
matrix_operations.cpp
modules/ocl/src/matrix_operations.cpp
+1
-0
pyrlk.cpp
modules/ocl/src/pyrlk.cpp
+0
-0
test_pyrlk.cpp
modules/ocl/test/test_pyrlk.cpp
+167
-0
No files found.
modules/ocl/include/opencv2/ocl/matrix_operations.hpp
View file @
78e89890
...
...
@@ -460,6 +460,18 @@ namespace cv
a
.
swap
(
b
);
}
inline
void
ensureSizeIsEnough
(
int
rows
,
int
cols
,
int
type
,
oclMat
&
m
)
{
if
(
m
.
type
()
==
type
&&
m
.
rows
>=
rows
&&
m
.
cols
>=
cols
)
m
=
m
(
Rect
(
0
,
0
,
cols
,
rows
));
else
m
.
create
(
rows
,
cols
,
type
);
}
inline
void
ensureSizeIsEnough
(
Size
size
,
int
type
,
oclMat
&
m
)
{
ensureSizeIsEnough
(
size
.
height
,
size
.
width
,
type
,
m
);
}
}
/* end of namespace ocl */
}
/* end of namespace cv */
...
...
modules/ocl/include/opencv2/ocl/ocl.hpp
View file @
78e89890
...
...
@@ -1125,6 +1125,66 @@ namespace cv
explicit
BruteForceMatcher_OCL
(
Hamming
/*d*/
)
:
BruteForceMatcher_OCL_base
(
HammingDist
)
{}
};
/////////////////////////////// PyrLKOpticalFlow /////////////////////////////////////
class
CV_EXPORTS
PyrLKOpticalFlow
{
public
:
PyrLKOpticalFlow
()
{
winSize
=
Size
(
21
,
21
);
maxLevel
=
3
;
iters
=
30
;
derivLambda
=
0.5
;
useInitialFlow
=
false
;
minEigThreshold
=
1e-4
f
;
getMinEigenVals
=
false
;
isDeviceArch11_
=
false
;
}
void
sparse
(
const
oclMat
&
prevImg
,
const
oclMat
&
nextImg
,
const
oclMat
&
prevPts
,
oclMat
&
nextPts
,
oclMat
&
status
,
oclMat
*
err
=
0
);
void
dense
(
const
oclMat
&
prevImg
,
const
oclMat
&
nextImg
,
oclMat
&
u
,
oclMat
&
v
,
oclMat
*
err
=
0
);
Size
winSize
;
int
maxLevel
;
int
iters
;
double
derivLambda
;
bool
useInitialFlow
;
float
minEigThreshold
;
bool
getMinEigenVals
;
void
releaseMemory
()
{
dx_calcBuf_
.
release
();
dy_calcBuf_
.
release
();
prevPyr_
.
clear
();
nextPyr_
.
clear
();
dx_buf_
.
release
();
dy_buf_
.
release
();
}
private
:
void
calcSharrDeriv
(
const
oclMat
&
src
,
oclMat
&
dx
,
oclMat
&
dy
);
void
buildImagePyramid
(
const
oclMat
&
img0
,
vector
<
oclMat
>&
pyr
,
bool
withBorder
);
oclMat
dx_calcBuf_
;
oclMat
dy_calcBuf_
;
vector
<
oclMat
>
prevPyr_
;
vector
<
oclMat
>
nextPyr_
;
oclMat
dx_buf_
;
oclMat
dy_buf_
;
oclMat
uPyr_
[
2
];
oclMat
vPyr_
[
2
];
bool
isDeviceArch11_
;
};
}
}
...
...
modules/ocl/src/kernels/pyrlk.cl
0 → 100644
View file @
78e89890
This diff is collapsed.
Click to expand it.
modules/ocl/src/matrix_operations.cpp
View file @
78e89890
...
...
@@ -916,6 +916,7 @@ oclMat cv::ocl::oclMat::reshape(int new_cn, int new_rows) const
CV_Error
(
CV_BadNumChannels
,
"The total width is not divisible by the new number of channels"
);
hdr
.
cols
=
new_width
;
hdr
.
wholecols
=
new_width
;
hdr
.
flags
=
(
hdr
.
flags
&
~
CV_MAT_CN_MASK
)
|
((
new_cn
-
1
)
<<
CV_CN_SHIFT
);
return
hdr
;
...
...
modules/ocl/src/pyrlk.cpp
0 → 100644
View file @
78e89890
This diff is collapsed.
Click to expand it.
modules/ocl/test/test_pyrlk.cpp
0 → 100644
View file @
78e89890
/*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.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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*/
#include "precomp.hpp"
#include <iomanip>
#ifdef HAVE_OPENCL
using
namespace
cv
;
using
namespace
cv
::
ocl
;
using
namespace
cvtest
;
using
namespace
testing
;
using
namespace
std
;
//#define DUMP
/////////////////////////////////////////////////////////////////////////////////////////////////
// BroxOpticalFlow
#define BROX_OPTICAL_FLOW_DUMP_FILE "opticalflow/brox_optical_flow.bin"
#define BROX_OPTICAL_FLOW_DUMP_FILE_CC20 "opticalflow/brox_optical_flow_cc20.bin"
/////////////////////////////////////////////////////////////////////////////////////////////////
// PyrLKOpticalFlow
//IMPLEMENT_PARAM_CLASS(UseGray, bool)
PARAM_TEST_CASE
(
Sparse
,
bool
,
bool
)
{
bool
useGray
;
bool
UseSmart
;
virtual
void
SetUp
()
{
UseSmart
=
GET_PARAM
(
0
);
useGray
=
GET_PARAM
(
0
);
}
};
TEST_P
(
Sparse
,
Mat
)
{
cv
::
Mat
frame0
=
readImage
(
"../../../samples/gpu/rubberwhale1.png"
,
useGray
?
cv
::
IMREAD_GRAYSCALE
:
cv
::
IMREAD_COLOR
);
ASSERT_FALSE
(
frame0
.
empty
());
cv
::
Mat
frame1
=
readImage
(
"../../../samples/gpu/rubberwhale2.png"
,
useGray
?
cv
::
IMREAD_GRAYSCALE
:
cv
::
IMREAD_COLOR
);
ASSERT_FALSE
(
frame1
.
empty
());
cv
::
Mat
gray_frame
;
if
(
useGray
)
gray_frame
=
frame0
;
else
cv
::
cvtColor
(
frame0
,
gray_frame
,
cv
::
COLOR_BGR2GRAY
);
std
::
vector
<
cv
::
Point2f
>
pts
;
cv
::
goodFeaturesToTrack
(
gray_frame
,
pts
,
1000
,
0.01
,
0.0
);
cv
::
ocl
::
oclMat
d_pts
;
cv
::
Mat
pts_mat
(
1
,
(
int
)
pts
.
size
(),
CV_32FC2
,
(
void
*
)
&
pts
[
0
]);
d_pts
.
upload
(
pts_mat
);
cv
::
ocl
::
PyrLKOpticalFlow
pyrLK
;
cv
::
ocl
::
oclMat
oclFrame0
;
cv
::
ocl
::
oclMat
oclFrame1
;
cv
::
ocl
::
oclMat
d_nextPts
;
cv
::
ocl
::
oclMat
d_status
;
cv
::
ocl
::
oclMat
d_err
;
oclFrame0
=
frame0
;
oclFrame1
=
frame1
;
pyrLK
.
sparse
(
oclFrame0
,
oclFrame1
,
d_pts
,
d_nextPts
,
d_status
,
&
d_err
);
std
::
vector
<
cv
::
Point2f
>
nextPts
(
d_nextPts
.
cols
);
cv
::
Mat
nextPts_mat
(
1
,
d_nextPts
.
cols
,
CV_32FC2
,
(
void
*
)
&
nextPts
[
0
]);
d_nextPts
.
download
(
nextPts_mat
);
std
::
vector
<
unsigned
char
>
status
(
d_status
.
cols
);
cv
::
Mat
status_mat
(
1
,
d_status
.
cols
,
CV_8UC1
,
(
void
*
)
&
status
[
0
]);
d_status
.
download
(
status_mat
);
std
::
vector
<
float
>
err
(
d_err
.
cols
);
cv
::
Mat
err_mat
(
1
,
d_err
.
cols
,
CV_32FC1
,
(
void
*
)
&
err
[
0
]);
d_err
.
download
(
err_mat
);
std
::
vector
<
cv
::
Point2f
>
nextPts_gold
;
std
::
vector
<
unsigned
char
>
status_gold
;
std
::
vector
<
float
>
err_gold
;
cv
::
calcOpticalFlowPyrLK
(
frame0
,
frame1
,
pts
,
nextPts_gold
,
status_gold
,
err_gold
);
ASSERT_EQ
(
nextPts_gold
.
size
(),
nextPts
.
size
());
ASSERT_EQ
(
status_gold
.
size
(),
status
.
size
());
size_t
mistmatch
=
0
;
for
(
size_t
i
=
0
;
i
<
nextPts
.
size
();
++
i
)
{
if
(
status
[
i
]
!=
status_gold
[
i
])
{
++
mistmatch
;
continue
;
}
if
(
status
[
i
])
{
cv
::
Point2i
a
=
nextPts
[
i
];
cv
::
Point2i
b
=
nextPts_gold
[
i
];
bool
eq
=
std
::
abs
(
a
.
x
-
b
.
x
)
<
1
&&
std
::
abs
(
a
.
y
-
b
.
y
)
<
1
;
//float errdiff = std::abs(err[i] - err_gold[i]);
float
errdiff
=
0.0
f
;
if
(
!
eq
||
errdiff
>
1e-1
)
++
mistmatch
;
}
}
double
bad_ratio
=
static_cast
<
double
>
(
mistmatch
)
/
(
nextPts
.
size
()
*
2
);
ASSERT_LE
(
bad_ratio
,
0.05
f
);
}
INSTANTIATE_TEST_CASE_P
(
Video
,
Sparse
,
Combine
(
Values
(
false
,
true
),
Values
(
false
)));
#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