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
311d7993
Commit
311d7993
authored
Jan 23, 2013
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #299 from branch 'bitwangyaoyao_ocl' into 2.4
parents
78dc44a7
e05112a3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
230 additions
and
95 deletions
+230
-95
OpenCVDetectOpenCL.cmake
cmake/OpenCVDetectOpenCL.cmake
+67
-7
ocl.hpp
modules/ocl/include/opencv2/ocl/ocl.hpp
+2
-2
filtering.cpp
modules/ocl/src/filtering.cpp
+0
-0
haar.cpp
modules/ocl/src/haar.cpp
+33
-40
arithm_mul.cl
modules/ocl/src/kernels/arithm_mul.cl
+21
-0
haarobjectdetect_scaled2.cl
modules/ocl/src/kernels/haarobjectdetect_scaled2.cl
+0
-0
pyrlk.cl
modules/ocl/src/kernels/pyrlk.cl
+0
-0
pyrlk_no_image.cl
modules/ocl/src/kernels/pyrlk_no_image.cl
+0
-0
pyrlk.cpp
modules/ocl/src/pyrlk.cpp
+102
-41
test_pyrlk.cpp
modules/ocl/test/test_pyrlk.cpp
+5
-5
No files found.
cmake/OpenCVDetectOpenCL.cmake
View file @
311d7993
...
@@ -2,18 +2,78 @@ if(APPLE)
...
@@ -2,18 +2,78 @@ if(APPLE)
set
(
OPENCL_FOUND YES
)
set
(
OPENCL_FOUND YES
)
set
(
OPENCL_LIBRARIES
"-framework OpenCL"
)
set
(
OPENCL_LIBRARIES
"-framework OpenCL"
)
else
()
else
()
#
find_package(OpenCL QUIET)
find_package
(
OpenCL QUIET
)
if
(
WITH_OPENCLAMDFFT
)
if
(
WITH_OPENCLAMDFFT
)
set
(
CLAMDFFT_SEARCH_PATH $ENV{CLAMDFFT_PATH}
)
if
(
NOT CLAMDFFT_SEARCH_PATH
)
if
(
WIN32
)
set
(
CLAMDFFT_SEARCH_PATH
"C:
\\
Program Files (x86)
\\
AMD
\\
clAmdFft"
)
endif
()
endif
()
set
(
CLAMDFFT_INCLUDE_SEARCH_PATH
${
CLAMDFFT_SEARCH_PATH
}
/include
)
if
(
UNIX
)
if
(
CMAKE_SIZEOF_VOID_P EQUAL 4
)
set
(
CLAMDFFT_LIB_SEARCH_PATH /usr/lib
)
else
()
set
(
CLAMDFFT_LIB_SEARCH_PATH /usr/lib64
)
endif
()
else
()
if
(
CMAKE_SIZEOF_VOID_P EQUAL 4
)
set
(
CLAMDFFT_LIB_SEARCH_PATH
${
CLAMDFFT_SEARCH_PATH
}
\\lib32\\import
)
else
()
set
(
CLAMDFFT_LIB_SEARCH_PATH
${
CLAMDFFT_SEARCH_PATH
}
\\lib64\\import
)
endif
()
endif
()
find_path
(
CLAMDFFT_INCLUDE_DIR
find_path
(
CLAMDFFT_INCLUDE_DIR
NAMES clAmdFft.h
)
NAMES clAmdFft.h
find_library
(
CLAMDFFT_LIBRARIES
PATHS
${
CLAMDFFT_INCLUDE_SEARCH_PATH
}
NAMES clAmdFft.Runtime
)
PATH_SUFFIXES clAmdFft
NO_DEFAULT_PATH
)
find_library
(
CLAMDFFT_LIBRARY
NAMES clAmdFft.Runtime
PATHS
${
CLAMDFFT_LIB_SEARCH_PATH
}
NO_DEFAULT_PATH
)
if
(
CLAMDFFT_LIBRARY
)
set
(
CLAMDFFT_LIBRARIES
${
CLAMDFFT_LIBRARY
}
)
else
()
set
(
CLAMDFFT_LIBRARIES
""
)
endif
()
endif
()
endif
()
if
(
WITH_OPENCLAMDBLAS
)
if
(
WITH_OPENCLAMDBLAS
)
set
(
CLAMDBLAS_SEARCH_PATH $ENV{CLAMDBLAS_PATH}
)
if
(
NOT CLAMDBLAS_SEARCH_PATH
)
if
(
WIN32
)
set
(
CLAMDBLAS_SEARCH_PATH
"C:
\\
Program Files (x86)
\\
AMD
\\
clAmdBlas"
)
endif
()
endif
()
set
(
CLAMDBLAS_INCLUDE_SEARCH_PATH
${
CLAMDBLAS_SEARCH_PATH
}
/include
)
if
(
UNIX
)
if
(
CMAKE_SIZEOF_VOID_P EQUAL 4
)
set
(
CLAMDBLAS_LIB_SEARCH_PATH /usr/lib
)
else
()
set
(
CLAMDBLAS_LIB_SEARCH_PATH /usr/lib64
)
endif
()
else
()
if
(
CMAKE_SIZEOF_VOID_P EQUAL 4
)
set
(
CLAMDBLAS_LIB_SEARCH_PATH
${
CLAMDBLAS_SEARCH_PATH
}
\\lib32\\import
)
else
()
set
(
CLAMDBLAS_LIB_SEARCH_PATH
${
CLAMDBLAS_SEARCH_PATH
}
\\lib64\\import
)
endif
()
endif
()
find_path
(
CLAMDBLAS_INCLUDE_DIR
find_path
(
CLAMDBLAS_INCLUDE_DIR
NAMES clAmdBlas.h
)
NAMES clAmdBlas.h
find_library
(
CLAMDBLAS_LIBRARIES
PATHS
${
CLAMDBLAS_INCLUDE_SEARCH_PATH
}
NAMES clAmdBlas
)
PATH_SUFFIXES clAmdBlas
NO_DEFAULT_PATH
)
find_library
(
CLAMDBLAS_LIBRARY
NAMES clAmdBlas
PATHS
${
CLAMDBLAS_LIB_SEARCH_PATH
}
NO_DEFAULT_PATH
)
if
(
CLAMDBLAS_LIBRARY
)
set
(
CLAMDBLAS_LIBRARIES
${
CLAMDBLAS_LIBRARY
}
)
else
()
set
(
CLAMDBLAS_LIBRARIES
""
)
endif
()
endif
()
endif
()
# Try AMD/ATI Stream SDK
# Try AMD/ATI Stream SDK
if
(
NOT OPENCL_FOUND
)
if
(
NOT OPENCL_FOUND
)
...
...
modules/ocl/include/opencv2/ocl/ocl.hpp
View file @
311d7993
...
@@ -41,8 +41,8 @@
...
@@ -41,8 +41,8 @@
//
//
//M*/
//M*/
#ifndef __OPENCV_
GPU
_HPP__
#ifndef __OPENCV_
OCL
_HPP__
#define __OPENCV_
GPU
_HPP__
#define __OPENCV_
OCL
_HPP__
#include <memory>
#include <memory>
#include <vector>
#include <vector>
...
...
modules/ocl/src/filtering.cpp
View file @
311d7993
This diff is collapsed.
Click to expand it.
modules/ocl/src/haar.cpp
View file @
311d7993
...
@@ -63,13 +63,13 @@ using namespace std;
...
@@ -63,13 +63,13 @@ using namespace std;
namespace
cv
namespace
cv
{
{
namespace
ocl
namespace
ocl
{
{
///////////////////////////OpenCL kernel strings///////////////////////////
///////////////////////////OpenCL kernel strings///////////////////////////
extern
const
char
*
haarobjectdetect
;
extern
const
char
*
haarobjectdetect
;
extern
const
char
*
haarobjectdetectbackup
;
extern
const
char
*
haarobjectdetectbackup
;
extern
const
char
*
haarobjectdetect_scaled2
;
extern
const
char
*
haarobjectdetect_scaled2
;
}
}
}
}
/* these settings affect the quality of detection: change with care */
/* these settings affect the quality of detection: change with care */
...
@@ -883,13 +883,6 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS
...
@@ -883,13 +883,6 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS
bool
findBiggestObject
=
(
flags
&
CV_HAAR_FIND_BIGGEST_OBJECT
)
!=
0
;
bool
findBiggestObject
=
(
flags
&
CV_HAAR_FIND_BIGGEST_OBJECT
)
!=
0
;
// bool roughSearch = (flags & CV_HAAR_DO_ROUGH_SEARCH) != 0;
// bool roughSearch = (flags & CV_HAAR_DO_ROUGH_SEARCH) != 0;
//the Intel HD Graphics is unsupported
if
(
gimg
.
clCxt
->
impl
->
devName
.
find
(
"Intel(R) HD Graphics"
)
!=
string
::
npos
)
{
cout
<<
" Intel HD GPU device unsupported "
<<
endl
;
return
NULL
;
}
//double t = 0;
//double t = 0;
if
(
maxSize
.
height
==
0
||
maxSize
.
width
==
0
)
if
(
maxSize
.
height
==
0
||
maxSize
.
width
==
0
)
{
{
...
@@ -937,7 +930,7 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS
...
@@ -937,7 +930,7 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS
if
(
gimg
.
cols
<
minSize
.
width
||
gimg
.
rows
<
minSize
.
height
)
if
(
gimg
.
cols
<
minSize
.
width
||
gimg
.
rows
<
minSize
.
height
)
CV_Error
(
CV_StsError
,
"Image too small"
);
CV_Error
(
CV_StsError
,
"Image too small"
);
if
(
flags
&
CV_HAAR_SCALE_IMAGE
)
if
(
(
flags
&
CV_HAAR_SCALE_IMAGE
)
&&
gimg
.
clCxt
->
impl
->
devName
.
find
(
"Intel(R) HD Graphics"
)
==
string
::
npos
)
{
{
CvSize
winSize0
=
cascade
->
orig_window_size
;
CvSize
winSize0
=
cascade
->
orig_window_size
;
//float scalefactor = 1.1f;
//float scalefactor = 1.1f;
...
@@ -2170,41 +2163,41 @@ CvType haar_type( CV_TYPE_NAME_HAAR, gpuIsHaarClassifier,
...
@@ -2170,41 +2163,41 @@ CvType haar_type( CV_TYPE_NAME_HAAR, gpuIsHaarClassifier,
namespace cv
namespace cv
{
{
HaarClassifierCascade::HaarClassifierCascade() {}
HaarClassifierCascade::HaarClassifierCascade() {}
HaarClassifierCascade::HaarClassifierCascade(const String &filename)
HaarClassifierCascade::HaarClassifierCascade(const String &filename)
{
{
load(filename);
load(filename);
}
}
bool HaarClassifierCascade::load(const String &filename)
bool HaarClassifierCascade::load(const String &filename)
{
{
cascade = Ptr<CvHaarClassifierCascade>((CvHaarClassifierCascade *)cvLoad(filename.c_str(), 0, 0, 0));
cascade = Ptr<CvHaarClassifierCascade>((CvHaarClassifierCascade *)cvLoad(filename.c_str(), 0, 0, 0));
return (CvHaarClassifierCascade *)cascade != 0;
return (CvHaarClassifierCascade *)cascade != 0;
}
}
void HaarClassifierCascade::detectMultiScale( const Mat &image,
void HaarClassifierCascade::detectMultiScale( const Mat &image,
Vector<Rect> &objects, double scaleFactor,
Vector<Rect> &objects, double scaleFactor,
int minNeighbors, int flags,
int minNeighbors, int flags,
Size minSize )
Size minSize )
{
{
MemStorage storage(cvCreateMemStorage(0));
MemStorage storage(cvCreateMemStorage(0));
CvMat _image = image;
CvMat _image = image;
CvSeq *_objects = gpuHaarDetectObjects( &_image, cascade, storage, scaleFactor,
CvSeq *_objects = gpuHaarDetectObjects( &_image, cascade, storage, scaleFactor,
minNeighbors, flags, minSize );
minNeighbors, flags, minSize );
Seq<Rect>(_objects).copyTo(objects);
Seq<Rect>(_objects).copyTo(objects);
}
}
int HaarClassifierCascade::runAt(Point pt, int startStage, int) const
int HaarClassifierCascade::runAt(Point pt, int startStage, int) const
{
{
return gpuRunHaarClassifierCascade(cascade, pt, startStage);
return gpuRunHaarClassifierCascade(cascade, pt, startStage);
}
}
void HaarClassifierCascade::setImages( const Mat &sum, const Mat &sqsum,
void HaarClassifierCascade::setImages( const Mat &sum, const Mat &sqsum,
const Mat &tilted, double scale )
const Mat &tilted, double scale )
{
{
CvMat _sum = sum, _sqsum = sqsum, _tilted = tilted;
CvMat _sum = sum, _sqsum = sqsum, _tilted = tilted;
gpuSetImagesForHaarClassifierCascade( cascade, &_sum, &_sqsum, &_tilted, scale );
gpuSetImagesForHaarClassifierCascade( cascade, &_sum, &_sqsum, &_tilted, scale );
}
}
}
}
#endif
#endif
...
@@ -2579,11 +2572,11 @@ CvPoint pt, int start_stage */)
...
@@ -2579,11 +2572,11 @@ CvPoint pt, int start_stage */)
namespace
cv
namespace
cv
{
{
namespace
ocl
namespace
ocl
{
{
struct
gpuHaarDetectObjects_ScaleImage_Invoker
struct
gpuHaarDetectObjects_ScaleImage_Invoker
{
{
gpuHaarDetectObjects_ScaleImage_Invoker
(
const
CvHaarClassifierCascade
*
_cascade
,
gpuHaarDetectObjects_ScaleImage_Invoker
(
const
CvHaarClassifierCascade
*
_cascade
,
int
_stripSize
,
double
_factor
,
int
_stripSize
,
double
_factor
,
const
Mat
&
_sum1
,
const
Mat
&
_sqsum1
,
Mat
*
_norm1
,
const
Mat
&
_sum1
,
const
Mat
&
_sqsum1
,
Mat
*
_norm1
,
...
@@ -2623,11 +2616,11 @@ namespace cv
...
@@ -2623,11 +2616,11 @@ namespace cv
Mat
sum1
,
sqsum1
,
*
norm1
,
*
mask1
;
Mat
sum1
,
sqsum1
,
*
norm1
,
*
mask1
;
Rect
equRect
;
Rect
equRect
;
ConcurrentRectVector
*
vec
;
ConcurrentRectVector
*
vec
;
};
};
struct
gpuHaarDetectObjects_ScaleCascade_Invoker
struct
gpuHaarDetectObjects_ScaleCascade_Invoker
{
{
gpuHaarDetectObjects_ScaleCascade_Invoker
(
const
CvHaarClassifierCascade
*
_cascade
,
gpuHaarDetectObjects_ScaleCascade_Invoker
(
const
CvHaarClassifierCascade
*
_cascade
,
Size
_winsize
,
const
Range
&
_xrange
,
double
_ystep
,
Size
_winsize
,
const
Range
&
_xrange
,
double
_ystep
,
size_t
_sumstep
,
const
int
**
_p
,
const
int
**
_pq
,
size_t
_sumstep
,
const
int
**
_p
,
const
int
**
_pq
,
...
@@ -2686,9 +2679,9 @@ namespace cv
...
@@ -2686,9 +2679,9 @@ namespace cv
const
int
**
p
;
const
int
**
p
;
const
int
**
pq
;
const
int
**
pq
;
ConcurrentRectVector
*
vec
;
ConcurrentRectVector
*
vec
;
};
};
}
}
}
}
/*
/*
...
...
modules/ocl/src/kernels/arithm_mul.cl
View file @
311d7993
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
//
//
//
@Authors
//
@Authors
//
Jia
Haipeng,
jiahaipeng95@gmail.com
//
Jia
Haipeng,
jiahaipeng95@gmail.com
//
Dachuan
Zhao,
dachuan@multicorewareinc.com
//
//
//
Redistribution
and
use
in
source
and
binary
forms,
with
or
without
modification,
//
Redistribution
and
use
in
source
and
binary
forms,
with
or
without
modification,
//
are
permitted
provided
that
the
following
conditions
are
met:
//
are
permitted
provided
that
the
following
conditions
are
met:
...
@@ -260,3 +261,22 @@ __kernel void arithm_mul_D6 (__global double *src1, int src1_step, int src1_offs
...
@@ -260,3 +261,22 @@ __kernel void arithm_mul_D6 (__global double *src1, int src1_step, int src1_offs
}
}
}
}
#
endif
#
endif
__kernel
void
arithm_muls_D5
(
__global
float
*src1,
int
src1_step,
int
src1_offset,
__global
float
*dst,
int
dst_step,
int
dst_offset,
int
rows,
int
cols,
int
dst_step1,
float
scalar
)
{
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
if
(
x
<
cols
&&
y
<
rows
)
{
int
src1_index
=
mad24
(
y,
src1_step,
(
x
<<
2
)
+
src1_offset
)
;
int
dst_index
=
mad24
(
y,
dst_step,
(
x
<<
2
)
+
dst_offset
)
;
float
data1
=
*
((
__global
float
*
)((
__global
char
*
)
src1
+
src1_index
))
;
float
tmp
=
data1
*
scalar
;
*
((
__global
float
*
)((
__global
char
*
)
dst
+
dst_index
))
=
tmp
;
}
}
\ No newline at end of file
modules/ocl/src/kernels/haarobjectdetect_scaled2.cl
View file @
311d7993
This diff is collapsed.
Click to expand it.
modules/ocl/src/kernels/pyrlk.cl
View file @
311d7993
This diff is collapsed.
Click to expand it.
modules/ocl/src/kernels/pyrlk_no_image.cl
0 → 100644
View file @
311d7993
This diff is collapsed.
Click to expand it.
modules/ocl/src/pyrlk.cpp
View file @
311d7993
...
@@ -48,23 +48,24 @@ using namespace cv::ocl;
...
@@ -48,23 +48,24 @@ using namespace cv::ocl;
#if !defined (HAVE_OPENCL)
#if !defined (HAVE_OPENCL)
void
cv
::
ocl
::
PyrLKOpticalFlow
::
sparse
(
const
oclMat
&
,
const
oclMat
&
,
const
oclMat
&
,
oclMat
&
,
oclMat
&
,
oclMat
*
)
{
}
void
cv
::
ocl
::
PyrLKOpticalFlow
::
sparse
(
const
oclMat
&
,
const
oclMat
&
,
const
oclMat
&
,
oclMat
&
,
oclMat
&
,
oclMat
&
)
{
}
void
cv
::
ocl
::
PyrLKOpticalFlow
::
dense
(
const
oclMat
&
,
const
oclMat
&
,
oclMat
&
,
oclMat
&
,
oclMat
*
)
{
}
void
cv
::
ocl
::
PyrLKOpticalFlow
::
dense
(
const
oclMat
&
,
const
oclMat
&
,
oclMat
&
,
oclMat
&
,
oclMat
*
)
{
}
#else
/* !defined (HAVE_OPENCL) */
#else
/* !defined (HAVE_OPENCL) */
namespace
cv
namespace
cv
{
{
namespace
ocl
namespace
ocl
{
{
///////////////////////////OpenCL kernel strings///////////////////////////
///////////////////////////OpenCL kernel strings///////////////////////////
extern
const
char
*
pyrlk
;
extern
const
char
*
pyrlk
;
extern
const
char
*
operator_setTo
;
extern
const
char
*
pyrlk_no_image
;
extern
const
char
*
operator_convertTo
;
extern
const
char
*
operator_setTo
;
extern
const
char
*
operator_copyToM
;
extern
const
char
*
operator_convertTo
;
extern
const
char
*
arithm_mul
;
extern
const
char
*
operator_copyToM
;
extern
const
char
*
pyr_down
;
extern
const
char
*
arithm_mul
;
}
extern
const
char
*
pyr_down
;
}
}
}
struct
dim3
struct
dim3
...
@@ -84,8 +85,8 @@ struct int2
...
@@ -84,8 +85,8 @@ struct int2
namespace
namespace
{
{
void
calcPatchSize
(
cv
::
Size
winSize
,
int
cn
,
dim3
&
block
,
dim3
&
patch
,
bool
isDeviceArch11
)
void
calcPatchSize
(
cv
::
Size
winSize
,
int
cn
,
dim3
&
block
,
dim3
&
patch
,
bool
isDeviceArch11
)
{
{
winSize
.
width
*=
cn
;
winSize
.
width
*=
cn
;
if
(
winSize
.
width
>
32
&&
winSize
.
width
>
2
*
winSize
.
height
)
if
(
winSize
.
width
>
32
&&
winSize
.
width
>
2
*
winSize
.
height
)
...
@@ -103,7 +104,7 @@ namespace
...
@@ -103,7 +104,7 @@ namespace
patch
.
y
=
(
winSize
.
height
+
block
.
y
-
1
)
/
block
.
y
;
patch
.
y
=
(
winSize
.
height
+
block
.
y
-
1
)
/
block
.
y
;
block
.
z
=
patch
.
z
=
1
;
block
.
z
=
patch
.
z
=
1
;
}
}
}
}
inline
int
divUp
(
int
total
,
int
grain
)
inline
int
divUp
(
int
total
,
int
grain
)
...
@@ -530,7 +531,7 @@ void arithmetic_run(const oclMat &src1, oclMat &dst, string kernelName, const ch
...
@@ -530,7 +531,7 @@ void arithmetic_run(const oclMat &src1, oclMat &dst, string kernelName, const ch
void
multiply_cus
(
const
oclMat
&
src1
,
oclMat
&
dst
,
float
scalar
)
void
multiply_cus
(
const
oclMat
&
src1
,
oclMat
&
dst
,
float
scalar
)
{
{
arithmetic_run
(
src1
,
dst
,
"arithm_muls"
,
&
pyrlk
,
(
void
*
)(
&
scalar
));
arithmetic_run
(
src1
,
dst
,
"arithm_muls"
,
&
arithm_mul
,
(
void
*
)(
&
scalar
));
}
}
void
pyrdown_run_cus
(
const
oclMat
&
src
,
const
oclMat
&
dst
)
void
pyrdown_run_cus
(
const
oclMat
&
src
,
const
oclMat
&
dst
)
...
@@ -735,46 +736,69 @@ void releaseTexture(cl_mem texture)
...
@@ -735,46 +736,69 @@ void releaseTexture(cl_mem texture)
}
}
void
lkSparse_run
(
oclMat
&
I
,
oclMat
&
J
,
void
lkSparse_run
(
oclMat
&
I
,
oclMat
&
J
,
const
oclMat
&
prevPts
,
oclMat
&
nextPts
,
oclMat
&
status
,
oclMat
*
err
,
bool
GET_MIN_EIGENVALS
,
int
ptcount
,
const
oclMat
&
prevPts
,
oclMat
&
nextPts
,
oclMat
&
status
,
oclMat
&
err
,
bool
/*GET_MIN_EIGENVALS*/
,
int
ptcount
,
int
level
,
/*dim3 block, */
dim3
patch
,
Size
winSize
,
int
iters
)
int
level
,
/*dim3 block, */
dim3
patch
,
Size
winSize
,
int
iters
)
{
{
Context
*
clCxt
=
I
.
clCxt
;
Context
*
clCxt
=
I
.
clCxt
;
char
platform
[
256
]
=
{
0
};
cl_platform_id
pid
;
clGetDeviceInfo
(
*
clCxt
->
impl
->
devices
,
CL_DEVICE_PLATFORM
,
sizeof
(
pid
),
&
pid
,
NULL
);
clGetPlatformInfo
(
pid
,
CL_PLATFORM_NAME
,
256
,
platform
,
NULL
);
std
::
string
namestr
=
platform
;
bool
isImageSupported
=
true
;
if
(
namestr
.
find
(
"NVIDIA"
)
!=
string
::
npos
||
namestr
.
find
(
"Intel"
)
!=
string
::
npos
)
isImageSupported
=
false
;
int
elemCntPerRow
=
I
.
step
/
I
.
elemSize
();
string
kernelName
=
"lkSparse"
;
string
kernelName
=
"lkSparse"
;
size_t
localThreads
[
3
]
=
{
8
,
32
,
1
};
size_t
globalThreads
[
3
]
=
{
8
*
ptcount
,
32
,
1
};
size_t
localThreads
[
3
]
=
{
8
,
isImageSupported
?
8
:
32
,
1
};
size_t
globalThreads
[
3
]
=
{
8
*
ptcount
,
isImageSupported
?
8
:
32
,
1
};
int
cn
=
I
.
oclchannels
();
int
cn
=
I
.
oclchannels
();
bool
calcErr
;
char
calcErr
;
if
(
err
)
if
(
level
==
0
)
{
{
calcErr
=
true
;
calcErr
=
1
;
}
}
else
else
{
{
calcErr
=
false
;
calcErr
=
0
;
}
}
calcErr
=
true
;
cl_mem
ITex
=
bindTexture
(
I
,
I
.
depth
(),
cn
);
cl_mem
JTex
=
bindTexture
(
J
,
J
.
depth
(),
cn
);
vector
<
pair
<
size_t
,
const
void
*>
>
args
;
vector
<
pair
<
size_t
,
const
void
*>
>
args
;
cl_mem
ITex
;
cl_mem
JTex
;
if
(
isImageSupported
)
{
ITex
=
bindTexture
(
I
,
I
.
depth
(),
cn
);
JTex
=
bindTexture
(
J
,
J
.
depth
(),
cn
);
}
else
{
ITex
=
(
cl_mem
)
I
.
data
;
JTex
=
(
cl_mem
)
J
.
data
;
}
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
ITex
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
ITex
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
JTex
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
JTex
));
//cl_mem clmD = clCreateBuffer(clCxt, CL_MEM_READ_WRITE, ptcount * sizeof(float), NULL, NULL);
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
prevPts
.
data
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
prevPts
.
data
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
prevPts
.
step
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
prevPts
.
step
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
nextPts
.
data
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
nextPts
.
data
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
nextPts
.
step
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
nextPts
.
step
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
status
.
data
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
status
.
data
));
//args.push_back( make_pair( sizeof(cl_mem), (void *)&(err->data)
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
err
.
data
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
level
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
level
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
I
.
rows
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
I
.
rows
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
I
.
cols
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
I
.
cols
));
if
(
!
isImageSupported
)
{
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
elemCntPerRow
)
);
}
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
patch
.
x
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
patch
.
x
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
patch
.
y
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
patch
.
y
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
cn
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
cn
));
...
@@ -782,27 +806,29 @@ void lkSparse_run(oclMat &I, oclMat &J,
...
@@ -782,27 +806,29 @@ void lkSparse_run(oclMat &I, oclMat &J,
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
winSize
.
height
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
winSize
.
height
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
iters
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
iters
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_char
),
(
void
*
)
&
calcErr
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_char
),
(
void
*
)
&
calcErr
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_char
),
(
void
*
)
&
GET_MIN_EIGENVALS
));
//
args.push_back( make_pair( sizeof(cl_char), (void *)&GET_MIN_EIGENVALS ));
if
(
isImageSupported
)
{
openCLExecuteKernel2
(
clCxt
,
&
pyrlk
,
kernelName
,
globalThreads
,
localThreads
,
args
,
I
.
oclchannels
(),
I
.
depth
(),
CLFLUSH
);
openCLExecuteKernel2
(
clCxt
,
&
pyrlk
,
kernelName
,
globalThreads
,
localThreads
,
args
,
I
.
oclchannels
(),
I
.
depth
(),
CLFLUSH
);
releaseTexture
(
ITex
);
releaseTexture
(
ITex
);
releaseTexture
(
JTex
);
releaseTexture
(
JTex
);
}
else
{
//printf("Warning: The image2d_t is not supported by the device. Using alternative method!\n");
openCLExecuteKernel2
(
clCxt
,
&
pyrlk_no_image
,
kernelName
,
globalThreads
,
localThreads
,
args
,
I
.
oclchannels
(),
I
.
depth
(),
CLFLUSH
);
}
}
}
void
cv
::
ocl
::
PyrLKOpticalFlow
::
sparse
(
const
oclMat
&
prevImg
,
const
oclMat
&
nextImg
,
const
oclMat
&
prevPts
,
oclMat
&
nextPts
,
oclMat
&
status
,
oclMat
*
err
)
void
cv
::
ocl
::
PyrLKOpticalFlow
::
sparse
(
const
oclMat
&
prevImg
,
const
oclMat
&
nextImg
,
const
oclMat
&
prevPts
,
oclMat
&
nextPts
,
oclMat
&
status
,
oclMat
*
err
)
{
{
if
(
prevImg
.
clCxt
->
impl
->
devName
.
find
(
"Intel(R) HD Graphics"
)
!=
string
::
npos
)
{
cout
<<
" Intel HD GPU device unsupported "
<<
endl
;
return
;
}
if
(
prevPts
.
empty
())
if
(
prevPts
.
empty
())
{
{
nextPts
.
release
();
nextPts
.
release
();
status
.
release
();
status
.
release
();
if
(
err
)
err
->
release
();
//
if (err) err->release();
return
;
return
;
}
}
...
@@ -836,8 +862,15 @@ void cv::ocl::PyrLKOpticalFlow::sparse(const oclMat &prevImg, const oclMat &next
...
@@ -836,8 +862,15 @@ void cv::ocl::PyrLKOpticalFlow::sparse(const oclMat &prevImg, const oclMat &next
//status.setTo(Scalar::all(1));
//status.setTo(Scalar::all(1));
setTo
(
status
,
Scalar
::
all
(
1
));
setTo
(
status
,
Scalar
::
all
(
1
));
//if (err)
bool
errMat
=
false
;
// ensureSizeIsEnough(1, prevPts.cols, CV_32FC1, *err);
if
(
!
err
)
{
err
=
new
oclMat
(
1
,
prevPts
.
cols
,
CV_32FC1
);
errMat
=
true
;
}
else
ensureSizeIsEnough
(
1
,
prevPts
.
cols
,
CV_32FC1
,
*
err
);
//ensureSizeIsEnough(1, prevPts.cols, CV_32FC1, err);
// build the image pyramids.
// build the image pyramids.
...
@@ -872,17 +905,22 @@ void cv::ocl::PyrLKOpticalFlow::sparse(const oclMat &prevImg, const oclMat &next
...
@@ -872,17 +905,22 @@ void cv::ocl::PyrLKOpticalFlow::sparse(const oclMat &prevImg, const oclMat &next
for
(
int
level
=
maxLevel
;
level
>=
0
;
level
--
)
for
(
int
level
=
maxLevel
;
level
>=
0
;
level
--
)
{
{
lkSparse_run
(
prevPyr_
[
level
],
nextPyr_
[
level
],
lkSparse_run
(
prevPyr_
[
level
],
nextPyr_
[
level
],
prevPts
,
nextPts
,
status
,
level
==
0
&&
err
?
err
:
0
,
getMinEigenVals
,
prevPts
.
cols
,
prevPts
,
nextPts
,
status
,
*
err
,
getMinEigenVals
,
prevPts
.
cols
,
level
,
/*block, */
patch
,
winSize
,
iters
);
level
,
/*block, */
patch
,
winSize
,
iters
);
}
}
clFinish
(
prevImg
.
clCxt
->
impl
->
clCmdQueue
);
clFinish
(
prevImg
.
clCxt
->
impl
->
clCmdQueue
);
if
(
errMat
)
delete
err
;
}
}
void
lkDense_run
(
oclMat
&
I
,
oclMat
&
J
,
oclMat
&
u
,
oclMat
&
v
,
void
lkDense_run
(
oclMat
&
I
,
oclMat
&
J
,
oclMat
&
u
,
oclMat
&
v
,
oclMat
&
prevU
,
oclMat
&
prevV
,
oclMat
*
err
,
Size
winSize
,
int
iters
)
oclMat
&
prevU
,
oclMat
&
prevV
,
oclMat
*
err
,
Size
winSize
,
int
iters
)
{
{
Context
*
clCxt
=
I
.
clCxt
;
Context
*
clCxt
=
I
.
clCxt
;
bool
isImageSupported
=
clCxt
->
impl
->
devName
.
find
(
"Intel(R) HD Graphics"
)
==
string
::
npos
;
int
elemCntPerRow
=
I
.
step
/
I
.
elemSize
();
string
kernelName
=
"lkDense"
;
string
kernelName
=
"lkDense"
;
...
@@ -901,8 +939,19 @@ void lkDense_run(oclMat &I, oclMat &J, oclMat &u, oclMat &v,
...
@@ -901,8 +939,19 @@ void lkDense_run(oclMat &I, oclMat &J, oclMat &u, oclMat &v,
calcErr
=
false
;
calcErr
=
false
;
}
}
cl_mem
ITex
=
bindTexture
(
I
,
I
.
depth
(),
cn
);
cl_mem
ITex
;
cl_mem
JTex
=
bindTexture
(
J
,
J
.
depth
(),
cn
);
cl_mem
JTex
;
if
(
isImageSupported
)
{
ITex
=
bindTexture
(
I
,
I
.
depth
(),
cn
);
JTex
=
bindTexture
(
J
,
J
.
depth
(),
cn
);
}
else
{
ITex
=
(
cl_mem
)
I
.
data
;
JTex
=
(
cl_mem
)
J
.
data
;
}
//int2 halfWin = {(winSize.width - 1) / 2, (winSize.height - 1) / 2};
//int2 halfWin = {(winSize.width - 1) / 2, (winSize.height - 1) / 2};
//const int patchWidth = 16 + 2 * halfWin.x;
//const int patchWidth = 16 + 2 * halfWin.x;
...
@@ -926,15 +975,27 @@ void lkDense_run(oclMat &I, oclMat &J, oclMat &u, oclMat &v,
...
@@ -926,15 +975,27 @@ void lkDense_run(oclMat &I, oclMat &J, oclMat &u, oclMat &v,
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
I
.
cols
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
I
.
cols
));
//args.push_back( make_pair( sizeof(cl_mem), (void *)&(*err).data ));
//args.push_back( make_pair( sizeof(cl_mem), (void *)&(*err).data ));
//args.push_back( make_pair( sizeof(cl_int), (void *)&(*err).step ));
//args.push_back( make_pair( sizeof(cl_int), (void *)&(*err).step ));
if
(
!
isImageSupported
)
{
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
elemCntPerRow
)
);
}
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
winSize
.
width
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
winSize
.
width
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
winSize
.
height
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
winSize
.
height
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
iters
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
iters
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_char
),
(
void
*
)
&
calcErr
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_char
),
(
void
*
)
&
calcErr
));
if
(
isImageSupported
)
{
openCLExecuteKernel2
(
clCxt
,
&
pyrlk
,
kernelName
,
globalThreads
,
localThreads
,
args
,
I
.
oclchannels
(),
I
.
depth
(),
CLFLUSH
);
openCLExecuteKernel2
(
clCxt
,
&
pyrlk
,
kernelName
,
globalThreads
,
localThreads
,
args
,
I
.
oclchannels
(),
I
.
depth
(),
CLFLUSH
);
releaseTexture
(
ITex
);
releaseTexture
(
ITex
);
releaseTexture
(
JTex
);
releaseTexture
(
JTex
);
}
else
{
//printf("Warning: The image2d_t is not supported by the device. Using alternative method!\n");
openCLExecuteKernel2
(
clCxt
,
&
pyrlk_no_image
,
kernelName
,
globalThreads
,
localThreads
,
args
,
I
.
oclchannels
(),
I
.
depth
(),
CLFLUSH
);
}
}
}
void
cv
::
ocl
::
PyrLKOpticalFlow
::
dense
(
const
oclMat
&
prevImg
,
const
oclMat
&
nextImg
,
oclMat
&
u
,
oclMat
&
v
,
oclMat
*
err
)
void
cv
::
ocl
::
PyrLKOpticalFlow
::
dense
(
const
oclMat
&
prevImg
,
const
oclMat
&
nextImg
,
oclMat
&
u
,
oclMat
&
v
,
oclMat
*
err
)
...
...
modules/ocl/test/test_pyrlk.cpp
View file @
311d7993
...
@@ -118,9 +118,9 @@ TEST_P(Sparse, Mat)
...
@@ -118,9 +118,9 @@ TEST_P(Sparse, Mat)
cv
::
Mat
status_mat
(
1
,
d_status
.
cols
,
CV_8UC1
,
(
void
*
)
&
status
[
0
]);
cv
::
Mat
status_mat
(
1
,
d_status
.
cols
,
CV_8UC1
,
(
void
*
)
&
status
[
0
]);
d_status
.
download
(
status_mat
);
d_status
.
download
(
status_mat
);
//
std::vector<float> err(d_err.cols);
std
::
vector
<
float
>
err
(
d_err
.
cols
);
//
cv::Mat err_mat(1, d_err.cols, CV_32FC1, (void*)&err[0]);
cv
::
Mat
err_mat
(
1
,
d_err
.
cols
,
CV_32FC1
,
(
void
*
)
&
err
[
0
]);
//
d_err.download(err_mat);
d_err
.
download
(
err_mat
);
std
::
vector
<
cv
::
Point2f
>
nextPts_gold
;
std
::
vector
<
cv
::
Point2f
>
nextPts_gold
;
std
::
vector
<
unsigned
char
>
status_gold
;
std
::
vector
<
unsigned
char
>
status_gold
;
...
@@ -153,9 +153,9 @@ TEST_P(Sparse, Mat)
...
@@ -153,9 +153,9 @@ TEST_P(Sparse, Mat)
}
}
}
}
double
bad_ratio
=
static_cast
<
double
>
(
mistmatch
)
/
(
nextPts
.
size
()
*
2
);
double
bad_ratio
=
static_cast
<
double
>
(
mistmatch
)
/
(
nextPts
.
size
());
ASSERT_LE
(
bad_ratio
,
0.0
5
f
);
ASSERT_LE
(
bad_ratio
,
0.0
2
f
);
}
}
...
...
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