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
881e8375
Commit
881e8375
authored
Nov 22, 2013
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ocl/core: added prototype for tests
parent
c1f59c4c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
373 additions
and
5 deletions
+373
-5
OpenCVModule.cmake
cmake/OpenCVModule.cmake
+4
-4
mat.hpp
modules/core/include/opencv2/core/mat.hpp
+25
-0
arithm.cpp
modules/core/src/arithm.cpp
+1
-1
test_arithm.cpp
modules/core/test/ocl/test_arithm.cpp
+177
-0
ocl_test.hpp
modules/ts/include/opencv2/ts/ocl_test.hpp
+0
-0
ocl_test.cpp
modules/ts/src/ocl_test.cpp
+166
-0
No files found.
cmake/OpenCVModule.cmake
View file @
881e8375
...
...
@@ -690,8 +690,8 @@ function(ocv_add_perf_tests)
ocv_module_include_directories
(
${
perf_deps
}
"
${
perf_path
}
"
)
if
(
NOT OPENCV_PERF_
${
the_module
}
_SOURCES
)
file
(
GLOB perf_srcs
"
${
perf_path
}
/*.cpp"
)
file
(
GLOB perf_hdrs
"
${
perf_path
}
/*.hpp"
"
${
perf_path
}
/*.h"
)
file
(
GLOB
_RECURSE
perf_srcs
"
${
perf_path
}
/*.cpp"
)
file
(
GLOB
_RECURSE
perf_hdrs
"
${
perf_path
}
/*.hpp"
"
${
perf_path
}
/*.h"
)
source_group
(
"Src"
FILES
${
perf_srcs
}
)
source_group
(
"Include"
FILES
${
perf_hdrs
}
)
set
(
OPENCV_PERF_
${
the_module
}
_SOURCES
${
perf_srcs
}
${
perf_hdrs
}
)
...
...
@@ -740,8 +740,8 @@ function(ocv_add_accuracy_tests)
ocv_module_include_directories
(
${
test_deps
}
"
${
test_path
}
"
)
if
(
NOT OPENCV_TEST_
${
the_module
}
_SOURCES
)
file
(
GLOB test_srcs
"
${
test_path
}
/*.cpp"
)
file
(
GLOB test_hdrs
"
${
test_path
}
/*.hpp"
"
${
test_path
}
/*.h"
)
file
(
GLOB
_RECURSE
test_srcs
"
${
test_path
}
/*.cpp"
)
file
(
GLOB
_RECURSE
test_hdrs
"
${
test_path
}
/*.hpp"
"
${
test_path
}
/*.h"
)
source_group
(
"Src"
FILES
${
test_srcs
}
)
source_group
(
"Include"
FILES
${
test_hdrs
}
)
set
(
OPENCV_TEST_
${
the_module
}
_SOURCES
${
test_srcs
}
${
test_hdrs
}
)
...
...
modules/core/include/opencv2/core/mat.hpp
View file @
881e8375
...
...
@@ -2340,6 +2340,31 @@ CV_EXPORTS MatExpr max(double s, const Mat& a);
CV_EXPORTS
MatExpr
abs
(
const
Mat
&
m
);
CV_EXPORTS
MatExpr
abs
(
const
MatExpr
&
e
);
namespace
traits
{
template
<
typename
T
>
struct
GetMatForRead
{
};
template
<>
struct
GetMatForRead
<
Mat
>
{
static
const
Mat
get
(
const
Mat
&
m
)
{
return
m
;
}
};
template
<>
struct
GetMatForRead
<
UMat
>
{
static
const
Mat
get
(
const
UMat
&
m
)
{
return
m
.
getMat
(
ACCESS_READ
);
}
};
}
// namespace traits
template
<
typename
T
>
const
Mat
getMatForRead
(
const
T
&
mat
)
{
return
traits
::
GetMatForRead
<
T
>::
get
(
mat
);
}
}
// cv
#include "opencv2/core/mat.inl.hpp"
...
...
modules/core/src/arithm.cpp
View file @
881e8375
...
...
@@ -1410,7 +1410,7 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
int
wtype
,
dims1
=
psrc1
->
dims
(),
dims2
=
psrc2
->
dims
();
Size
sz1
=
dims1
<=
2
?
psrc1
->
size
()
:
Size
();
Size
sz2
=
dims2
<=
2
?
psrc2
->
size
()
:
Size
();
bool
use_opencl
=
(
kind1
==
_InputArray
::
UMAT
||
kind2
==
_InputArray
::
UMAT
)
&&
bool
use_opencl
=
(
kind1
==
_InputArray
::
UMAT
||
kind2
==
_InputArray
::
UMAT
||
_dst
.
kind
()
==
_OutputArray
::
UMAT
)
&&
ocl
::
useOpenCL
()
&&
dims1
<=
2
&&
dims2
<=
2
;
bool
src1Scalar
=
checkScalar
(
*
psrc1
,
type2
,
kind1
,
kind2
);
bool
src2Scalar
=
checkScalar
(
*
psrc2
,
type1
,
kind2
,
kind1
);
...
...
modules/core/test/ocl/test_arithm.cpp
0 → 100644
View file @
881e8375
/*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.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., 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 the copyright holders 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 OpenCV Foundation 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 "test_precomp.hpp"
#include "opencv2/ts/ocl_test.hpp"
#ifdef HAVE_OPENCL
namespace
cvtest
{
namespace
ocl
{
///////////////////////// ArithmTestBase ///////////////////////////
PARAM_TEST_CASE
(
ArithmTestBase
,
MatDepth
,
Channels
,
bool
)
{
int
depth
;
int
cn
;
bool
use_roi
;
cv
::
Scalar
val
;
// declare Mat + UMat mirrors
TEST_DECLARE_INPUT_PARATEMER
(
src1
)
TEST_DECLARE_INPUT_PARATEMER
(
src2
)
TEST_DECLARE_INPUT_PARATEMER
(
mask
)
TEST_DECLARE_OUTPUT_PARATEMER
(
dst1
)
TEST_DECLARE_OUTPUT_PARATEMER
(
dst2
)
virtual
void
SetUp
()
{
depth
=
GET_PARAM
(
0
);
cn
=
GET_PARAM
(
1
);
use_roi
=
GET_PARAM
(
2
);
}
virtual
void
generateTestData
()
{
const
int
type
=
CV_MAKE_TYPE
(
depth
,
cn
);
Size
roiSize
=
randomSize
(
1
,
MAX_VALUE
);
Border
src1Border
=
randomBorder
(
0
,
use_roi
?
MAX_VALUE
:
0
);
randomSubMat
(
src1
,
src1_roi
,
roiSize
,
src1Border
,
type
,
2
,
11
);
Border
src2Border
=
randomBorder
(
0
,
use_roi
?
MAX_VALUE
:
0
);
randomSubMat
(
src2
,
src2_roi
,
roiSize
,
src2Border
,
type
,
-
1540
,
1740
);
Border
dst1Border
=
randomBorder
(
0
,
use_roi
?
MAX_VALUE
:
0
);
randomSubMat
(
dst1
,
dst1_roi
,
roiSize
,
dst1Border
,
type
,
5
,
16
);
Border
dst2Border
=
randomBorder
(
0
,
use_roi
?
MAX_VALUE
:
0
);
randomSubMat
(
dst2
,
dst2_roi
,
roiSize
,
dst2Border
,
type
,
5
,
16
);
Border
maskBorder
=
randomBorder
(
0
,
use_roi
?
MAX_VALUE
:
0
);
randomSubMat
(
mask
,
mask_roi
,
roiSize
,
maskBorder
,
CV_8UC1
,
0
,
2
);
cv
::
threshold
(
mask
,
mask
,
0.5
,
255.
,
CV_8UC1
);
val
=
cv
::
Scalar
(
rng
.
uniform
(
-
100.0
,
100.0
),
rng
.
uniform
(
-
100.0
,
100.0
),
rng
.
uniform
(
-
100.0
,
100.0
),
rng
.
uniform
(
-
100.0
,
100.0
));
UMAT_UPLOAD_INPUT_PARAMETER
(
src1
)
UMAT_UPLOAD_INPUT_PARAMETER
(
src2
)
UMAT_UPLOAD_INPUT_PARAMETER
(
mask
)
UMAT_UPLOAD_OUTPUT_PARAMETER
(
dst1
)
UMAT_UPLOAD_OUTPUT_PARAMETER
(
dst2
)
}
void
Near
(
double
threshold
=
0.
)
{
EXPECT_MAT_NEAR
(
dst1
,
udst1
,
threshold
);
EXPECT_MAT_NEAR
(
dst1_roi
,
udst1_roi
,
threshold
);
}
void
Near1
(
double
threshold
=
0.
)
{
EXPECT_MAT_NEAR
(
dst2
,
udst2
,
threshold
);
EXPECT_MAT_NEAR
(
dst2_roi
,
udst2_roi
,
threshold
);
}
};
//////////////////////////////// Add /////////////////////////////////////////////////
typedef
ArithmTestBase
Add
;
OCL_TEST_P
(
Add
,
Mat
)
{
for
(
int
j
=
0
;
j
<
test_loop_times
;
j
++
)
{
generateTestData
();
OCL_OFF
(
cv
::
add
(
src1_roi
,
src2_roi
,
dst1_roi
));
OCL_ON
(
cv
::
add
(
usrc1_roi
,
usrc2_roi
,
udst1_roi
));
Near
(
0
);
}
}
OCL_TEST_P
(
Add
,
Mat_Mask
)
{
for
(
int
j
=
0
;
j
<
test_loop_times
;
j
++
)
{
generateTestData
();
OCL_OFF
(
cv
::
add
(
src1_roi
,
src2_roi
,
dst1_roi
,
mask_roi
));
OCL_ON
(
cv
::
add
(
usrc1_roi
,
usrc2_roi
,
udst1_roi
,
umask_roi
));
Near
(
0
);
}
}
OCL_TEST_P
(
Add
,
Scalar
)
{
for
(
int
j
=
0
;
j
<
test_loop_times
;
j
++
)
{
generateTestData
();
OCL_OFF
(
cv
::
add
(
src1_roi
,
val
,
dst1_roi
));
OCL_ON
(
cv
::
add
(
usrc1_roi
,
val
,
udst1_roi
));
Near
(
1e-5
);
}
}
OCL_TEST_P
(
Add
,
Scalar_Mask
)
{
for
(
int
j
=
0
;
j
<
test_loop_times
;
j
++
)
{
generateTestData
();
OCL_OFF
(
cv
::
add
(
src1_roi
,
val
,
dst1_roi
,
mask_roi
));
OCL_ON
(
cv
::
add
(
usrc1_roi
,
val
,
udst1_roi
,
umask_roi
));
Near
(
1e-5
);
}
}
//////////////////////////////////////// Instantiation /////////////////////////////////////////
OCL_INSTANTIATE_TEST_CASE_P
(
Arithm
,
Add
,
Combine
(
OCL_ALL_DEPTHS
,
OCL_ALL_CHANNELS
,
Bool
()));
}
}
// namespace cvtest::ocl
#endif // HAVE_OPENCL
modules/ts/include/opencv2/ts/ocl_test.hpp
0 → 100644
View file @
881e8375
This diff is collapsed.
Click to expand it.
modules/ts/src/ocl_test.cpp
0 → 100644
View file @
881e8375
/*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.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., 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 the copyright holders 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 OpenCV Foundation 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 "opencv2/ts/ocl_test.hpp"
#ifdef HAVE_OPENCL
namespace
cvtest
{
namespace
ocl
{
using
namespace
cv
;
int
test_loop_times
=
1
;
// TODO Read from command line / environment
Mat
TestUtils
::
readImage
(
const
String
&
fileName
,
int
flags
)
{
return
cv
::
imread
(
cvtest
::
TS
::
ptr
()
->
get_data_path
()
+
fileName
,
flags
);
}
Mat
TestUtils
::
readImageType
(
const
String
&
fname
,
int
type
)
{
Mat
src
=
readImage
(
fname
,
CV_MAT_CN
(
type
)
==
1
?
cv
::
IMREAD_GRAYSCALE
:
cv
::
IMREAD_COLOR
);
if
(
CV_MAT_CN
(
type
)
==
4
)
{
Mat
temp
;
cv
::
cvtColor
(
src
,
temp
,
cv
::
COLOR_BGR2BGRA
);
swap
(
src
,
temp
);
}
src
.
convertTo
(
src
,
CV_MAT_DEPTH
(
type
));
return
src
;
}
double
TestUtils
::
checkNorm
(
const
Mat
&
m
)
{
return
norm
(
m
,
NORM_INF
);
}
double
TestUtils
::
checkNorm
(
const
Mat
&
m1
,
const
Mat
&
m2
)
{
return
norm
(
m1
,
m2
,
NORM_INF
);
}
double
TestUtils
::
checkSimilarity
(
const
Mat
&
m1
,
const
Mat
&
m2
)
{
Mat
diff
;
matchTemplate
(
m1
,
m2
,
diff
,
CV_TM_CCORR_NORMED
);
return
std
::
abs
(
diff
.
at
<
float
>
(
0
,
0
)
-
1.
f
);
}
double
TestUtils
::
checkRectSimilarity
(
Size
sz
,
std
::
vector
<
Rect
>&
ob1
,
std
::
vector
<
Rect
>&
ob2
)
{
double
final_test_result
=
0.0
;
size_t
sz1
=
ob1
.
size
();
size_t
sz2
=
ob2
.
size
();
if
(
sz1
!=
sz2
)
{
return
sz1
>
sz2
?
(
double
)(
sz1
-
sz2
)
:
(
double
)(
sz2
-
sz1
);
}
else
{
if
(
sz1
==
0
&&
sz2
==
0
)
return
0
;
cv
::
Mat
cpu_result
(
sz
,
CV_8UC1
);
cpu_result
.
setTo
(
0
);
for
(
vector
<
Rect
>::
const_iterator
r
=
ob1
.
begin
();
r
!=
ob1
.
end
();
r
++
)
{
cv
::
Mat
cpu_result_roi
(
cpu_result
,
*
r
);
cpu_result_roi
.
setTo
(
1
);
cpu_result
.
copyTo
(
cpu_result
);
}
int
cpu_area
=
cv
::
countNonZero
(
cpu_result
>
0
);
cv
::
Mat
gpu_result
(
sz
,
CV_8UC1
);
gpu_result
.
setTo
(
0
);
for
(
vector
<
Rect
>::
const_iterator
r2
=
ob2
.
begin
();
r2
!=
ob2
.
end
();
r2
++
)
{
cv
::
Mat
gpu_result_roi
(
gpu_result
,
*
r2
);
gpu_result_roi
.
setTo
(
1
);
gpu_result
.
copyTo
(
gpu_result
);
}
cv
::
Mat
result_
;
multiply
(
cpu_result
,
gpu_result
,
result_
);
int
result
=
cv
::
countNonZero
(
result_
>
0
);
if
(
cpu_area
!=
0
&&
result
!=
0
)
final_test_result
=
1.0
-
(
double
)
result
/
(
double
)
cpu_area
;
else
if
(
cpu_area
==
0
&&
result
!=
0
)
final_test_result
=
-
1
;
}
return
final_test_result
;
}
void
TestUtils
::
showDiff
(
const
Mat
&
src
,
const
Mat
&
gold
,
const
Mat
&
actual
,
double
eps
,
bool
alwaysShow
)
{
Mat
diff
,
diff_thresh
;
absdiff
(
gold
,
actual
,
diff
);
diff
.
convertTo
(
diff
,
CV_32F
);
threshold
(
diff
,
diff_thresh
,
eps
,
255.0
,
cv
::
THRESH_BINARY
);
if
(
alwaysShow
||
cv
::
countNonZero
(
diff_thresh
.
reshape
(
1
))
>
0
)
{
#if 0
std::cout << "Source: " << std::endl << src << std::endl;
std::cout << "Expected: " << std::endl << gold << std::endl;
std::cout << "Actual: " << std::endl << actual << std::endl;
#endif
namedWindow
(
"src"
,
WINDOW_NORMAL
);
namedWindow
(
"gold"
,
WINDOW_NORMAL
);
namedWindow
(
"actual"
,
WINDOW_NORMAL
);
namedWindow
(
"diff"
,
WINDOW_NORMAL
);
imshow
(
"src"
,
src
);
imshow
(
"gold"
,
gold
);
imshow
(
"actual"
,
actual
);
imshow
(
"diff"
,
diff
);
cv
::
waitKey
();
}
}
}}
// namespace cvtest::ocl
#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