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
803672fe
Commit
803672fe
authored
Dec 01, 2013
by
Ilya Lavrenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added cv::remap to T-API
parent
dcce9d70
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
240 additions
and
32 deletions
+240
-32
ocl.cpp
modules/core/src/ocl.cpp
+1
-1
umatrix.cpp
modules/core/src/umatrix.cpp
+1
-0
imgwarp.cpp
modules/imgproc/src/imgwarp.cpp
+109
-29
remap.cl
modules/imgproc/src/opencl/remap.cl
+0
-0
test_warp.cpp
modules/imgproc/test/ocl/test_warp.cpp
+128
-2
ocl_test.hpp
modules/ts/include/opencv2/ts/ocl_test.hpp
+1
-0
No files found.
modules/core/src/ocl.cpp
View file @
803672fe
...
...
@@ -1893,7 +1893,7 @@ Context2& Context2::getDefault()
// First, try to retrieve existing context of the same type.
// In its turn, Platform::getContext() may call Context2::create()
// if there is no such context.
ctx
.
create
(
Device
::
TYPE_
CPU
);
ctx
.
create
(
Device
::
TYPE_
ACCELERATOR
);
if
(
!
ctx
.
p
)
ctx
.
create
(
Device
::
TYPE_DGPU
);
if
(
!
ctx
.
p
)
...
...
modules/core/src/umatrix.cpp
View file @
803672fe
...
...
@@ -578,6 +578,7 @@ Mat UMat::getMat(int accessFlags) const
u
->
currAllocator
->
map
(
u
,
accessFlags
|
ACCESS_READ
);
CV_Assert
(
u
->
data
!=
0
);
Mat
hdr
(
dims
,
size
.
p
,
type
(),
u
->
data
+
offset
,
step
.
p
);
hdr
.
flags
=
flags
;
hdr
.
u
=
u
;
hdr
.
datastart
=
u
->
data
;
hdr
.
data
=
hdr
.
datastart
+
offset
;
...
...
modules/imgproc/src/imgwarp.cpp
View file @
803672fe
...
...
@@ -2010,6 +2010,8 @@ static bool ocl_resize( InputArray _src, OutputArray _dst, Size dsize,
iscale_x
,
iscale_y
,
1.0
f
/
(
iscale_x
*
iscale_y
));
k
.
create
(
"resizeAREA_FAST"
,
ocl
::
imgproc
::
resize_oclsrc
,
buildOption
);
if
(
k
.
empty
())
return
false
;
int
smap_tab_size
=
dst
.
cols
*
iscale_x
+
dst
.
rows
*
iscale_y
;
AutoBuffer
<
int
>
dmap_tab
(
dst
.
cols
+
dst
.
rows
),
smap_tab
(
smap_tab_size
);
...
...
@@ -2026,6 +2028,8 @@ static bool ocl_resize( InputArray _src, OutputArray _dst, Size dsize,
{
buildOption
=
buildOption
+
format
(
" -D convertToT=%s"
,
ocl
::
convertTypeStr
(
wdepth
,
depth
,
cn
,
cvt
[
0
]));
k
.
create
(
"resizeAREA"
,
ocl
::
imgproc
::
resize_oclsrc
,
buildOption
);
if
(
k
.
empty
())
return
false
;
Size
ssize
=
src
.
size
();
int
xytab_size
=
(
ssize
.
width
+
ssize
.
height
)
<<
1
;
...
...
@@ -3383,6 +3387,78 @@ private:
const
void
*
ctab
;
};
static
bool
ocl_remap
(
InputArray
_src
,
OutputArray
_dst
,
InputArray
_map1
,
InputArray
_map2
,
int
interpolation
,
int
borderType
,
const
Scalar
&
borderValue
)
{
int
cn
=
_src
.
channels
(),
type
=
_src
.
type
(),
depth
=
_src
.
depth
();
if
(
borderType
==
BORDER_TRANSPARENT
||
cn
==
3
||
!
(
interpolation
==
INTER_LINEAR
||
interpolation
==
INTER_NEAREST
)
||
_map1
.
type
()
==
CV_16SC1
||
_map2
.
type
()
==
CV_16SC1
)
return
false
;
UMat
src
=
_src
.
getUMat
(),
map1
=
_map1
.
getUMat
(),
map2
=
_map2
.
getUMat
();
if
(
(
map1
.
type
()
==
CV_16SC2
&&
(
map2
.
type
()
==
CV_16UC1
||
map2
.
empty
()))
||
(
map2
.
type
()
==
CV_16SC2
&&
(
map1
.
type
()
==
CV_16UC1
||
map1
.
empty
()))
)
{
if
(
map1
.
type
()
!=
CV_16SC2
)
std
::
swap
(
map1
,
map2
);
}
else
CV_Assert
(
map1
.
type
()
==
CV_32FC2
||
(
map1
.
type
()
==
CV_32FC1
&&
map2
.
type
()
==
CV_32FC1
)
);
_dst
.
create
(
map1
.
size
(),
type
);
UMat
dst
=
_dst
.
getUMat
();
String
kernelName
=
"remap"
;
if
(
map1
.
type
()
==
CV_32FC2
&&
map2
.
empty
())
kernelName
+=
"_32FC2"
;
else
if
(
map1
.
type
()
==
CV_16SC2
)
{
kernelName
+=
"_16SC2"
;
if
(
!
map2
.
empty
())
kernelName
+=
"_16UC1"
;
}
else
if
(
map1
.
type
()
==
CV_32FC1
&&
map2
.
type
()
==
CV_32FC1
)
kernelName
+=
"_2_32FC1"
;
else
CV_Error
(
Error
::
StsBadArg
,
"Unsupported map types"
);
static
const
char
*
const
interMap
[]
=
{
"INTER_NEAREST"
,
"INTER_LINEAR"
,
"INTER_CUBIC"
,
"INTER_LINEAR"
,
"INTER_LANCZOS"
};
static
const
char
*
const
borderMap
[]
=
{
"BORDER_CONSTANT"
,
"BORDER_REPLICATE"
,
"BORDER_REFLECT"
,
"BORDER_WRAP"
,
"BORDER_REFLECT_101"
,
"BORDER_TRANSPARENT"
};
String
buildOptions
=
format
(
"-D %s -D %s -D T=%s"
,
interMap
[
interpolation
],
borderMap
[
borderType
],
ocl
::
typeToStr
(
type
));
if
(
interpolation
!=
INTER_NEAREST
)
{
char
cvt
[
3
][
40
];
int
wdepth
=
std
::
max
(
CV_32F
,
dst
.
depth
());
buildOptions
=
buildOptions
+
format
(
" -D WT=%s -D convertToT=%s -D convertToWT=%s"
" -D convertToWT2=%s -D WT2=%s"
,
ocl
::
typeToStr
(
CV_MAKE_TYPE
(
wdepth
,
cn
)),
ocl
::
convertTypeStr
(
wdepth
,
depth
,
cn
,
cvt
[
0
]),
ocl
::
convertTypeStr
(
depth
,
wdepth
,
cn
,
cvt
[
1
]),
ocl
::
convertTypeStr
(
CV_32S
,
wdepth
,
2
,
cvt
[
2
]),
ocl
::
typeToStr
(
CV_MAKE_TYPE
(
wdepth
,
2
)));
}
ocl
::
Kernel
k
(
kernelName
.
c_str
(),
ocl
::
imgproc
::
remap_oclsrc
,
buildOptions
);
Mat
scalar
(
1
,
1
,
type
,
borderValue
);
ocl
::
KernelArg
srcarg
=
ocl
::
KernelArg
::
ReadOnly
(
src
),
dstarg
=
ocl
::
KernelArg
::
WriteOnly
(
dst
),
map1arg
=
ocl
::
KernelArg
::
ReadOnlyNoSize
(
map1
),
scalararg
=
ocl
::
KernelArg
::
Constant
((
void
*
)
scalar
.
data
,
scalar
.
elemSize
());
if
(
map2
.
empty
())
k
.
args
(
srcarg
,
dstarg
,
map1arg
,
scalararg
);
else
k
.
args
(
srcarg
,
dstarg
,
map1arg
,
ocl
::
KernelArg
::
ReadOnlyNoSize
(
map2
),
scalararg
);
size_t
globalThreads
[
2
]
=
{
dst
.
cols
,
dst
.
rows
};
return
k
.
run
(
2
,
globalThreads
,
NULL
,
false
);
}
}
void
cv
::
remap
(
InputArray
_src
,
OutputArray
_dst
,
...
...
@@ -3422,11 +3498,13 @@ void cv::remap( InputArray _src, OutputArray _dst,
remapLanczos4
<
Cast
<
double
,
double
>
,
float
,
1
>
,
0
};
Mat
src
=
_src
.
getMat
(),
map1
=
_map1
.
getMat
(),
map2
=
_map2
.
getMat
();
CV_Assert
(
_map1
.
size
().
area
()
>
0
);
CV_Assert
(
_map2
.
empty
()
||
(
_map2
.
size
()
==
_map1
.
size
()));
CV_Assert
(
map1
.
size
().
area
()
>
0
);
CV_Assert
(
!
map2
.
data
||
(
map2
.
size
()
==
map1
.
size
()))
;
if
(
ocl
::
useOpenCL
()
&&
_dst
.
isUMat
()
&&
ocl_remap
(
_src
,
_dst
,
_map1
,
_map2
,
interpolation
,
borderType
,
borderValue
))
return
;
Mat
src
=
_src
.
getMat
(),
map1
=
_map1
.
getMat
(),
map2
=
_map2
.
getMat
();
_dst
.
create
(
map1
.
size
(),
src
.
type
()
);
Mat
dst
=
_dst
.
getMat
();
if
(
dst
.
data
==
src
.
data
)
...
...
@@ -3809,6 +3887,33 @@ static bool ocl_warpTransform(InputArray _src, OutputArray _dst, InputArray _M0,
(
!
doubleSupport
&&
depth
==
CV_64F
)
||
cn
>
4
||
cn
==
3
)
return
false
;
const
char
*
const
interpolationMap
[
3
]
=
{
"NEAREST"
,
"LINEAR"
,
"CUBIC"
};
ocl
::
ProgramSource2
program
=
op_type
==
OCL_OP_AFFINE
?
ocl
::
imgproc
::
warp_affine_oclsrc
:
ocl
::
imgproc
::
warp_perspective_oclsrc
;
const
char
*
const
kernelName
=
op_type
==
OCL_OP_AFFINE
?
"warpAffine"
:
"warpPerspective"
;
ocl
::
Kernel
k
;
if
(
interpolation
==
INTER_NEAREST
)
{
k
.
create
(
kernelName
,
program
,
format
(
"-D INTER_NEAREST -D T=%s%s"
,
ocl
::
typeToStr
(
type
),
doubleSupport
?
" -D DOUBLE_SUPPORT"
:
""
));
}
else
{
char
cvt
[
2
][
50
];
wdepth
=
std
::
max
(
CV_32S
,
depth
);
k
.
create
(
kernelName
,
program
,
format
(
"-D INTER_%s -D T=%s -D WT=%s -D depth=%d -D convertToWT=%s -D convertToT=%s%s"
,
interpolationMap
[
interpolation
],
ocl
::
typeToStr
(
type
),
ocl
::
typeToStr
(
CV_MAKE_TYPE
(
wdepth
,
cn
)),
depth
,
ocl
::
convertTypeStr
(
depth
,
wdepth
,
cn
,
cvt
[
0
]),
ocl
::
convertTypeStr
(
wdepth
,
depth
,
cn
,
cvt
[
1
]),
doubleSupport
?
" -D DOUBLE_SUPPORT"
:
""
));
}
if
(
k
.
empty
())
return
false
;
UMat
src
=
_src
.
getUMat
(),
M0
;
_dst
.
create
(
dsize
.
area
()
==
0
?
src
.
size
()
:
dsize
,
src
.
type
()
);
UMat
dst
=
_dst
.
getUMat
();
...
...
@@ -3838,32 +3943,7 @@ static bool ocl_warpTransform(InputArray _src, OutputArray _dst, InputArray _M0,
}
matM
.
convertTo
(
M0
,
doubleSupport
?
CV_64F
:
CV_32F
);
const
char
*
const
interpolationMap
[
3
]
=
{
"NEAREST"
,
"LINEAR"
,
"CUBIC"
};
ocl
::
ProgramSource2
program
=
op_type
==
OCL_OP_AFFINE
?
ocl
::
imgproc
::
warp_affine_oclsrc
:
ocl
::
imgproc
::
warp_perspective_oclsrc
;
const
char
*
const
kernelName
=
op_type
==
OCL_OP_AFFINE
?
"warpAffine"
:
"warpPerspective"
;
ocl
::
Kernel
k
;
if
(
interpolation
==
INTER_NEAREST
)
{
k
.
create
(
kernelName
,
program
,
format
(
"-D INTER_NEAREST -D T=%s%s"
,
ocl
::
typeToStr
(
type
),
doubleSupport
?
" -D DOUBLE_SUPPORT"
:
""
));
}
else
{
char
cvt
[
2
][
50
];
wdepth
=
std
::
max
(
CV_32S
,
depth
);
k
.
create
(
kernelName
,
program
,
format
(
"-D INTER_%s -D T=%s -D WT=%s -D depth=%d -D convertToWT=%s -D convertToT=%s%s"
,
interpolationMap
[
interpolation
],
ocl
::
typeToStr
(
type
),
ocl
::
typeToStr
(
CV_MAKE_TYPE
(
wdepth
,
cn
)),
depth
,
ocl
::
convertTypeStr
(
depth
,
wdepth
,
cn
,
cvt
[
0
]),
ocl
::
convertTypeStr
(
wdepth
,
depth
,
cn
,
cvt
[
1
]),
doubleSupport
?
" -D DOUBLE_SUPPORT"
:
""
));
}
k
.
args
(
ocl
::
KernelArg
::
ReadOnly
(
src
),
ocl
::
KernelArg
::
WriteOnly
(
dst
),
ocl
::
KernelArg
::
PtrOnly
(
M0
),
k
.
args
(
ocl
::
KernelArg
::
ReadOnly
(
src
),
ocl
::
KernelArg
::
WriteOnly
(
dst
),
ocl
::
KernelArg
::
PtrReadOnly
(
M0
),
ocl
::
KernelArg
::
Constant
(
Mat
(
1
,
1
,
CV_MAKE_TYPE
(
wdepth
,
cn
),
borderValue
)));
size_t
globalThreads
[
2
]
=
{
dst
.
cols
,
dst
.
rows
};
...
...
modules/imgproc/src/opencl/remap.cl
0 → 100644
View file @
803672fe
This diff is collapsed.
Click to expand it.
modules/imgproc/test/ocl/test_warp.cpp
View file @
803672fe
...
...
@@ -60,6 +60,11 @@
namespace
cvtest
{
namespace
ocl
{
enum
{
noType
=
-
1
};
/////////////////////////////////////////////////////////////////////////////////////////////////
// warpAffine & warpPerspective
...
...
@@ -69,8 +74,8 @@ PARAM_TEST_CASE(WarpTestBase, MatType, Interpolation, bool, bool)
Size
dsize
;
bool
useRoi
,
mapInverse
;
TEST_DECLARE_INPUT_PARA
TEM
ER
(
src
)
TEST_DECLARE_OUTPUT_PARA
TEM
ER
(
dst
)
TEST_DECLARE_INPUT_PARA
MET
ER
(
src
)
TEST_DECLARE_OUTPUT_PARA
MET
ER
(
dst
)
virtual
void
SetUp
()
{
...
...
@@ -217,6 +222,100 @@ OCL_TEST_P(Resize, Mat)
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// remap
PARAM_TEST_CASE
(
Remap
,
MatDepth
,
Channels
,
std
::
pair
<
MatType
,
MatType
>
,
Border
,
bool
)
{
int
srcType
,
map1Type
,
map2Type
;
int
borderType
;
bool
useRoi
;
Scalar
val
;
TEST_DECLARE_INPUT_PARAMETER
(
src
)
TEST_DECLARE_INPUT_PARAMETER
(
map1
)
TEST_DECLARE_INPUT_PARAMETER
(
map2
)
TEST_DECLARE_OUTPUT_PARAMETER
(
dst
)
virtual
void
SetUp
()
{
srcType
=
CV_MAKE_TYPE
(
GET_PARAM
(
0
),
GET_PARAM
(
1
));
map1Type
=
GET_PARAM
(
2
).
first
;
map2Type
=
GET_PARAM
(
2
).
second
;
borderType
=
GET_PARAM
(
3
);
useRoi
=
GET_PARAM
(
4
);
}
void
random_roi
()
{
val
=
randomScalar
(
-
MAX_VALUE
,
MAX_VALUE
);
Size
srcROISize
=
randomSize
(
1
,
MAX_VALUE
);
Size
dstROISize
=
randomSize
(
1
,
MAX_VALUE
);
Border
srcBorder
=
randomBorder
(
0
,
useRoi
?
MAX_VALUE
:
0
);
randomSubMat
(
src
,
src_roi
,
srcROISize
,
srcBorder
,
srcType
,
5
,
256
);
Border
dstBorder
=
randomBorder
(
0
,
useRoi
?
MAX_VALUE
:
0
);
randomSubMat
(
dst
,
dst_roi
,
dstROISize
,
dstBorder
,
srcType
,
-
MAX_VALUE
,
MAX_VALUE
);
int
mapMaxValue
=
MAX_VALUE
<<
2
;
Border
map1Border
=
randomBorder
(
0
,
useRoi
?
MAX_VALUE
:
0
);
randomSubMat
(
map1
,
map1_roi
,
dstROISize
,
map1Border
,
map1Type
,
-
mapMaxValue
,
mapMaxValue
);
Border
map2Border
=
randomBorder
(
0
,
useRoi
?
MAX_VALUE
:
0
);
if
(
map2Type
!=
noType
)
{
int
mapMinValue
=
-
mapMaxValue
;
if
(
map2Type
==
CV_16UC1
||
map2Type
==
CV_16SC1
)
mapMinValue
=
0
,
mapMaxValue
=
INTER_TAB_SIZE2
;
randomSubMat
(
map2
,
map2_roi
,
dstROISize
,
map2Border
,
map2Type
,
mapMinValue
,
mapMaxValue
);
}
UMAT_UPLOAD_INPUT_PARAMETER
(
src
)
UMAT_UPLOAD_INPUT_PARAMETER
(
map1
)
UMAT_UPLOAD_OUTPUT_PARAMETER
(
dst
)
if
(
noType
!=
map2Type
)
UMAT_UPLOAD_INPUT_PARAMETER
(
map2
)
}
void
Near
(
double
threshold
=
0.0
)
{
EXPECT_MAT_NEAR
(
dst
,
udst
,
threshold
);
EXPECT_MAT_NEAR
(
dst_roi
,
udst_roi
,
threshold
);
}
};
typedef
Remap
Remap_INTER_NEAREST
;
OCL_TEST_P
(
Remap_INTER_NEAREST
,
Mat
)
{
for
(
int
j
=
0
;
j
<
test_loop_times
;
j
++
)
{
random_roi
();
OCL_OFF
(
cv
::
remap
(
src_roi
,
dst_roi
,
map1_roi
,
map2_roi
,
INTER_NEAREST
,
borderType
,
val
));
OCL_ON
(
cv
::
remap
(
usrc_roi
,
udst_roi
,
umap1_roi
,
umap2_roi
,
INTER_NEAREST
,
borderType
,
val
));
Near
(
1.0
);
}
}
typedef
Remap
Remap_INTER_LINEAR
;
OCL_TEST_P
(
Remap_INTER_LINEAR
,
Mat
)
{
for
(
int
j
=
0
;
j
<
test_loop_times
;
j
++
)
{
random_roi
();
OCL_OFF
(
cv
::
remap
(
src_roi
,
dst_roi
,
map1_roi
,
map2_roi
,
INTER_LINEAR
,
borderType
,
val
));
OCL_ON
(
cv
::
remap
(
usrc_roi
,
udst_roi
,
umap1_roi
,
umap2_roi
,
INTER_LINEAR
,
borderType
,
val
));
Near
(
2.0
);
}
}
/////////////////////////////////////////////////////////////////////////////////////
OCL_INSTANTIATE_TEST_CASE_P
(
ImgprocWarp
,
WarpAffine
,
Combine
(
...
...
@@ -245,6 +344,33 @@ OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarpResizeArea, Resize, Combine(
Values
((
Interpolation
)
INTER_AREA
),
Bool
()));
OCL_INSTANTIATE_TEST_CASE_P
(
ImgprocWarp
,
Remap_INTER_LINEAR
,
Combine
(
Values
(
CV_8U
,
CV_16U
,
CV_32F
),
Values
(
1
,
4
),
Values
(
std
::
pair
<
MatType
,
MatType
>
((
MatType
)
CV_32FC1
,
(
MatType
)
CV_32FC1
),
std
::
pair
<
MatType
,
MatType
>
((
MatType
)
CV_16SC2
,
(
MatType
)
CV_16UC1
),
std
::
pair
<
MatType
,
MatType
>
((
MatType
)
CV_32FC2
,
noType
)),
Values
((
Border
)
BORDER_CONSTANT
,
(
Border
)
BORDER_REPLICATE
,
(
Border
)
BORDER_WRAP
,
(
Border
)
BORDER_REFLECT
,
(
Border
)
BORDER_REFLECT_101
),
Bool
()));
OCL_INSTANTIATE_TEST_CASE_P
(
ImgprocWarp
,
Remap_INTER_NEAREST
,
Combine
(
Values
(
CV_8U
,
CV_16U
,
CV_32F
),
Values
(
1
,
4
),
Values
(
std
::
pair
<
MatType
,
MatType
>
((
MatType
)
CV_32FC1
,
(
MatType
)
CV_32FC1
),
std
::
pair
<
MatType
,
MatType
>
((
MatType
)
CV_32FC2
,
noType
),
std
::
pair
<
MatType
,
MatType
>
((
MatType
)
CV_16SC2
,
(
MatType
)
CV_16UC1
),
std
::
pair
<
MatType
,
MatType
>
((
MatType
)
CV_16SC2
,
noType
)),
Values
((
Border
)
BORDER_CONSTANT
,
(
Border
)
BORDER_REPLICATE
,
(
Border
)
BORDER_WRAP
,
(
Border
)
BORDER_REFLECT
,
(
Border
)
BORDER_REFLECT_101
),
Bool
()));
}
}
// namespace cvtest::ocl
#endif // HAVE_OPENCL
modules/ts/include/opencv2/ts/ocl_test.hpp
View file @
803672fe
...
...
@@ -306,6 +306,7 @@ IMPLEMENT_PARAM_CLASS(Channels, int)
#define OCL_ALL_CHANNELS Values(1, 2, 3, 4)
CV_ENUM
(
Interpolation
,
INTER_NEAREST
,
INTER_LINEAR
,
INTER_CUBIC
,
INTER_AREA
)
CV_ENUM
(
Border
,
BORDER_CONSTANT
,
BORDER_REPLICATE
,
BORDER_WRAP
,
BORDER_REFLECT
,
BORDER_REFLECT_101
)
#define OCL_INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
INSTANTIATE_TEST_CASE_P(OCL_ ## prefix, test_case_name, generator)
...
...
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