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
5ec8c51b
Commit
5ec8c51b
authored
Apr 25, 2013
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
switched to Input/Output Array in gpu::absdiff
parent
3ee12cbe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
59 deletions
+64
-59
gpuarithm.hpp
modules/gpuarithm/include/opencv2/gpuarithm.hpp
+3
-5
element_operations.cpp
modules/gpuarithm/src/element_operations.cpp
+32
-54
test_element_operations.cpp
modules/gpuarithm/test/test_element_operations.cpp
+29
-0
No files found.
modules/gpuarithm/include/opencv2/gpuarithm.hpp
View file @
5ec8c51b
...
...
@@ -69,6 +69,9 @@ static inline void divide(double src1, InputArray src2, OutputArray dst, int dty
divide
(
src1
,
src2
,
dst
,
1.0
,
dtype
,
stream
);
}
//! computes element-wise absolute difference of two arrays (dst = abs(src1 - src2))
CV_EXPORTS
void
absdiff
(
InputArray
src1
,
InputArray
src2
,
OutputArray
dst
,
Stream
&
stream
=
Stream
::
Null
());
//! computes the weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma)
CV_EXPORTS
void
addWeighted
(
const
GpuMat
&
src1
,
double
alpha
,
const
GpuMat
&
src2
,
double
beta
,
double
gamma
,
GpuMat
&
dst
,
int
dtype
=
-
1
,
Stream
&
stream
=
Stream
::
Null
());
...
...
@@ -79,11 +82,6 @@ static inline void scaleAdd(const GpuMat& src1, double alpha, const GpuMat& src2
addWeighted
(
src1
,
alpha
,
src2
,
1.0
,
0.0
,
dst
,
-
1
,
stream
);
}
//! computes element-wise absolute difference of two arrays (c = abs(a - b))
CV_EXPORTS
void
absdiff
(
const
GpuMat
&
a
,
const
GpuMat
&
b
,
GpuMat
&
c
,
Stream
&
stream
=
Stream
::
Null
());
//! computes element-wise absolute difference of array and scalar (c = abs(a - s))
CV_EXPORTS
void
absdiff
(
const
GpuMat
&
a
,
const
Scalar
&
s
,
GpuMat
&
c
,
Stream
&
stream
=
Stream
::
Null
());
//! computes absolute value of each matrix element
//! supports CV_16S and CV_32F depth
CV_EXPORTS
void
abs
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
Stream
&
stream
=
Stream
::
Null
());
...
...
modules/gpuarithm/src/element_operations.cpp
View file @
5ec8c51b
...
...
@@ -55,8 +55,7 @@ void cv::gpu::multiply(InputArray, InputArray, OutputArray, double, int, Stream&
void
cv
::
gpu
::
divide
(
InputArray
,
InputArray
,
OutputArray
,
double
,
int
,
Stream
&
)
{
throw_no_cuda
();
}
void
cv
::
gpu
::
absdiff
(
const
GpuMat
&
,
const
GpuMat
&
,
GpuMat
&
,
Stream
&
)
{
throw_no_cuda
();
}
void
cv
::
gpu
::
absdiff
(
const
GpuMat
&
,
const
Scalar
&
,
GpuMat
&
,
Stream
&
)
{
throw_no_cuda
();
}
void
cv
::
gpu
::
absdiff
(
InputArray
,
InputArray
,
OutputArray
,
Stream
&
)
{
throw_no_cuda
();
}
void
cv
::
gpu
::
abs
(
const
GpuMat
&
,
GpuMat
&
,
Stream
&
)
{
throw_no_cuda
();
}
...
...
@@ -1380,37 +1379,24 @@ namespace arithm
void
absDiffMat
(
PtrStepSzb
src1
,
PtrStepSzb
src2
,
PtrStepSzb
dst
,
cudaStream_t
stream
);
}
void
cv
::
gpu
::
absdiff
(
const
GpuMat
&
src1
,
const
GpuMat
&
src2
,
GpuMat
&
dst
,
Stream
&
s
)
static
void
absDiffMat
(
const
GpuMat
&
src1
,
const
GpuMat
&
src2
,
GpuMat
&
dst
,
const
GpuMat
&
,
double
,
Stream
&
_stream
)
{
using
namespace
arithm
;
typedef
void
(
*
func_t
)(
PtrStepSzb
src1
,
PtrStepSzb
src2
,
PtrStepSzb
dst
,
cudaStream_t
stream
);
static
const
func_t
funcs
[]
=
{
absDiffMat
<
unsigned
char
>
,
absDiffMat
<
signed
char
>
,
absDiffMat
<
unsigned
short
>
,
absDiffMat
<
short
>
,
absDiffMat
<
int
>
,
absDiffMat
<
float
>
,
absDiffMat
<
double
>
a
rithm
::
a
bsDiffMat
<
unsigned
char
>
,
a
rithm
::
a
bsDiffMat
<
signed
char
>
,
a
rithm
::
a
bsDiffMat
<
unsigned
short
>
,
a
rithm
::
a
bsDiffMat
<
short
>
,
a
rithm
::
a
bsDiffMat
<
int
>
,
a
rithm
::
a
bsDiffMat
<
float
>
,
a
rithm
::
a
bsDiffMat
<
double
>
};
const
int
depth
=
src1
.
depth
();
const
int
cn
=
src1
.
channels
();
CV_Assert
(
depth
<=
CV_64F
);
CV_Assert
(
src2
.
type
()
==
src1
.
type
()
&&
src2
.
size
()
==
src1
.
size
()
);
if
(
depth
==
CV_64F
)
{
if
(
!
deviceSupports
(
NATIVE_DOUBLE
))
CV_Error
(
cv
::
Error
::
StsUnsupportedFormat
,
"The device doesn't support double"
);
}
dst
.
create
(
src1
.
size
(),
src1
.
type
());
cudaStream_t
stream
=
StreamAccessor
::
getStream
(
s
);
cudaStream_t
stream
=
StreamAccessor
::
getStream
(
_stream
);
PtrStepSzb
src1_
(
src1
.
rows
,
src1
.
cols
*
cn
,
src1
.
data
,
src1
.
step
);
PtrStepSzb
src2_
(
src1
.
rows
,
src1
.
cols
*
cn
,
src2
.
data
,
src2
.
step
);
...
...
@@ -1430,10 +1416,10 @@ void cv::gpu::absdiff(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Strea
{
const
int
vcols
=
src1_
.
cols
>>
2
;
absDiffMat_v4
(
PtrStepSz
<
unsigned
int
>
(
src1_
.
rows
,
vcols
,
(
unsigned
int
*
)
src1_
.
data
,
src1_
.
step
),
PtrStepSz
<
unsigned
int
>
(
src1_
.
rows
,
vcols
,
(
unsigned
int
*
)
src2_
.
data
,
src2_
.
step
),
PtrStepSz
<
unsigned
int
>
(
src1_
.
rows
,
vcols
,
(
unsigned
int
*
)
dst_
.
data
,
dst_
.
step
),
stream
);
a
rithm
::
a
bsDiffMat_v4
(
PtrStepSz
<
unsigned
int
>
(
src1_
.
rows
,
vcols
,
(
unsigned
int
*
)
src1_
.
data
,
src1_
.
step
),
PtrStepSz
<
unsigned
int
>
(
src1_
.
rows
,
vcols
,
(
unsigned
int
*
)
src2_
.
data
,
src2_
.
step
),
PtrStepSz
<
unsigned
int
>
(
src1_
.
rows
,
vcols
,
(
unsigned
int
*
)
dst_
.
data
,
dst_
.
step
),
stream
);
return
;
}
...
...
@@ -1441,10 +1427,10 @@ void cv::gpu::absdiff(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Strea
{
const
int
vcols
=
src1_
.
cols
>>
1
;
absDiffMat_v2
(
PtrStepSz
<
unsigned
int
>
(
src1_
.
rows
,
vcols
,
(
unsigned
int
*
)
src1_
.
data
,
src1_
.
step
),
PtrStepSz
<
unsigned
int
>
(
src1_
.
rows
,
vcols
,
(
unsigned
int
*
)
src2_
.
data
,
src2_
.
step
),
PtrStepSz
<
unsigned
int
>
(
src1_
.
rows
,
vcols
,
(
unsigned
int
*
)
dst_
.
data
,
dst_
.
step
),
stream
);
a
rithm
::
a
bsDiffMat_v2
(
PtrStepSz
<
unsigned
int
>
(
src1_
.
rows
,
vcols
,
(
unsigned
int
*
)
src1_
.
data
,
src1_
.
step
),
PtrStepSz
<
unsigned
int
>
(
src1_
.
rows
,
vcols
,
(
unsigned
int
*
)
src2_
.
data
,
src2_
.
step
),
PtrStepSz
<
unsigned
int
>
(
src1_
.
rows
,
vcols
,
(
unsigned
int
*
)
dst_
.
data
,
dst_
.
step
),
stream
);
return
;
}
...
...
@@ -1465,36 +1451,28 @@ namespace arithm
void
absDiffScalar
(
PtrStepSzb
src1
,
double
val
,
PtrStepSzb
dst
,
cudaStream_t
stream
);
}
void
cv
::
gpu
::
absdiff
(
const
GpuMat
&
src1
,
const
Scalar
&
src2
,
GpuMat
&
dst
,
Stream
&
stream
)
static
void
absDiffScalar
(
const
GpuMat
&
src
,
Scalar
val
,
bool
,
GpuMat
&
dst
,
const
GpuMat
&
,
double
,
Stream
&
stream
)
{
using
namespace
arithm
;
typedef
void
(
*
func_t
)(
PtrStepSzb
src1
,
double
val
,
PtrStepSzb
dst
,
cudaStream_t
stream
);
static
const
func_t
funcs
[]
=
{
absDiffScalar
<
unsigned
char
,
float
>
,
absDiffScalar
<
signed
char
,
float
>
,
absDiffScalar
<
unsigned
short
,
float
>
,
absDiffScalar
<
short
,
float
>
,
absDiffScalar
<
int
,
float
>
,
absDiffScalar
<
float
,
float
>
,
absDiffScalar
<
double
,
double
>
a
rithm
::
a
bsDiffScalar
<
unsigned
char
,
float
>
,
a
rithm
::
a
bsDiffScalar
<
signed
char
,
float
>
,
a
rithm
::
a
bsDiffScalar
<
unsigned
short
,
float
>
,
a
rithm
::
a
bsDiffScalar
<
short
,
float
>
,
a
rithm
::
a
bsDiffScalar
<
int
,
float
>
,
a
rithm
::
a
bsDiffScalar
<
float
,
float
>
,
a
rithm
::
a
bsDiffScalar
<
double
,
double
>
};
const
int
depth
=
src1
.
depth
();
CV_Assert
(
depth
<=
CV_64F
);
CV_Assert
(
src1
.
channels
()
==
1
);
if
(
depth
==
CV_64F
)
{
if
(
!
deviceSupports
(
NATIVE_DOUBLE
))
CV_Error
(
cv
::
Error
::
StsUnsupportedFormat
,
"The device doesn't support double"
);
}
const
int
depth
=
src
.
depth
();
dst
.
create
(
src1
.
size
(),
src1
.
type
());
funcs
[
depth
](
src
,
val
[
0
],
dst
,
StreamAccessor
::
getStream
(
stream
));
}
funcs
[
depth
](
src1
,
src2
.
val
[
0
],
dst
,
StreamAccessor
::
getStream
(
stream
));
void
cv
::
gpu
::
absdiff
(
InputArray
src1
,
InputArray
src2
,
OutputArray
dst
,
Stream
&
stream
)
{
arithm_op
(
src1
,
src2
,
dst
,
noArray
(),
1.0
,
-
1
,
stream
,
absDiffMat
,
absDiffScalar
);
}
//////////////////////////////////////////////////////////////////////////////
...
...
modules/gpuarithm/test/test_element_operations.cpp
View file @
5ec8c51b
...
...
@@ -1433,6 +1433,35 @@ GPU_TEST_P(AbsDiff, Scalar)
}
}
GPU_TEST_P
(
AbsDiff
,
Scalar_First
)
{
cv
::
Mat
src
=
randomMat
(
size
,
depth
);
cv
::
Scalar
val
=
randomScalar
(
0.0
,
255.0
);
if
(
depth
==
CV_64F
&&
!
supportFeature
(
devInfo
,
cv
::
gpu
::
NATIVE_DOUBLE
))
{
try
{
cv
::
gpu
::
GpuMat
dst
;
cv
::
gpu
::
absdiff
(
val
,
loadMat
(
src
),
dst
);
}
catch
(
const
cv
::
Exception
&
e
)
{
ASSERT_EQ
(
cv
::
Error
::
StsUnsupportedFormat
,
e
.
code
);
}
}
else
{
cv
::
gpu
::
GpuMat
dst
=
createMat
(
size
,
depth
,
useRoi
);
cv
::
gpu
::
absdiff
(
val
,
loadMat
(
src
,
useRoi
),
dst
);
cv
::
Mat
dst_gold
;
cv
::
absdiff
(
val
,
src
,
dst_gold
);
EXPECT_MAT_NEAR
(
dst_gold
,
dst
,
depth
<=
CV_32F
?
1.0
:
1e-5
);
}
}
INSTANTIATE_TEST_CASE_P
(
GPU_Arithm
,
AbsDiff
,
testing
::
Combine
(
ALL_DEVICES
,
DIFFERENT_SIZES
,
...
...
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