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
3a1beb1c
Commit
3a1beb1c
authored
Jul 21, 2011
by
Anatoly Baksheev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added cv::gpu::pow, ticket #1227
parent
c722128d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
188 additions
and
2 deletions
+188
-2
gpu.hpp
modules/gpu/include/opencv2/gpu/gpu.hpp
+6
-0
element_operations.cu
modules/gpu/src/cuda/element_operations.cu
+60
-0
element_operations.cpp
modules/gpu/src/element_operations.cpp
+34
-0
limits_gpu.hpp
modules/gpu/src/opencv2/gpu/device/limits_gpu.hpp
+14
-0
stereocsbp.cpp
modules/gpu/src/stereocsbp.cpp
+1
-1
test_arithm.cpp
modules/gpu/test/test_arithm.cpp
+68
-0
test_main.cpp
modules/gpu/test/test_main.cpp
+5
-1
No files found.
modules/gpu/include/opencv2/gpu/gpu.hpp
View file @
3a1beb1c
...
@@ -532,6 +532,12 @@ namespace cv
...
@@ -532,6 +532,12 @@ namespace cv
//! computes exponent of each matrix element (b = e**a)
//! computes exponent of each matrix element (b = e**a)
//! supports only CV_32FC1 type
//! supports only CV_32FC1 type
CV_EXPORTS
void
exp
(
const
GpuMat
&
a
,
GpuMat
&
b
,
Stream
&
stream
=
Stream
::
Null
());
CV_EXPORTS
void
exp
(
const
GpuMat
&
a
,
GpuMat
&
b
,
Stream
&
stream
=
Stream
::
Null
());
//! computes power of each matrix element:
// (dst(i,j) = pow( src(i,j) , power), if src.type() is integer
// (dst(i,j) = pow(fabs(src(i,j)), power), otherwise
//! supports all, except depth == CV_64F
CV_EXPORTS
void
pow
(
const
GpuMat
&
src
,
double
power
,
GpuMat
&
dst
,
Stream
&
stream
=
Stream
::
Null
());
//! computes natural logarithm of absolute value of each matrix element: b = log(abs(a))
//! computes natural logarithm of absolute value of each matrix element: b = log(abs(a))
//! supports only CV_32FC1 type
//! supports only CV_32FC1 type
...
...
modules/gpu/src/cuda/element_operations.cu
View file @
3a1beb1c
...
@@ -42,6 +42,7 @@
...
@@ -42,6 +42,7 @@
#include "opencv2/gpu/device/vecmath.hpp"
#include "opencv2/gpu/device/vecmath.hpp"
#include "opencv2/gpu/device/transform.hpp"
#include "opencv2/gpu/device/transform.hpp"
#include "opencv2/gpu/device/limits_gpu.hpp"
#include "opencv2/gpu/device/saturate_cast.hpp"
#include "opencv2/gpu/device/saturate_cast.hpp"
#include "internal_shared.hpp"
#include "internal_shared.hpp"
...
@@ -669,4 +670,63 @@ namespace cv { namespace gpu { namespace mathfunc
...
@@ -669,4 +670,63 @@ namespace cv { namespace gpu { namespace mathfunc
}
}
template void subtractCaller<short>(const DevMem2D src1, const DevMem2D src2, DevMem2D dst, cudaStream_t stream);
template void subtractCaller<short>(const DevMem2D src1, const DevMem2D src2, DevMem2D dst, cudaStream_t stream);
//////////////////////////////////////////////////////////////////////////
// pow
template<typename T, bool Signed = device::numeric_limits_gpu<T>::is_signed>
struct PowOp
{
float power;
PowOp(float power_) : power(power_) {}
template<typename T>
__device__ __forceinline__ T operator()(const T& e) const
{
return saturate_cast<T>(__powf((float)e, power));
}
};
template<typename T>
struct PowOp<T, true>
{
float power;
PowOp(float power_) : power(power_) {}
__device__ __forceinline__ float operator()(const T& e)
{
T res = saturate_cast<T>(__powf((float)e, power));
if ( (e < 0) && (1 & (int)power) )
res *= -1;
return res;
}
};
template<>
struct PowOp<float>
{
float power;
PowOp(float power_) : power(power_) {}
__device__ __forceinline__ float operator()(const float& e)
{
return __powf(fabs(e), power);
}
};
template<typename T>
void pow_caller(const DevMem2D& src, float power, DevMem2D dst, cudaStream_t stream)
{
transform((DevMem2D_<T>)src, (DevMem2D_<T>)dst, PowOp<T>(power), stream);
}
template void pow_caller<uchar>(const DevMem2D& src, float power, DevMem2D dst, cudaStream_t stream);
template void pow_caller<schar>(const DevMem2D& src, float power, DevMem2D dst, cudaStream_t stream);
template void pow_caller<short>(const DevMem2D& src, float power, DevMem2D dst, cudaStream_t stream);
template void pow_caller<ushort>(const DevMem2D& src, float power, DevMem2D dst, cudaStream_t stream);
template void pow_caller<int>(const DevMem2D& src, float power, DevMem2D dst, cudaStream_t stream);
template void pow_caller<uint>(const DevMem2D& src, float power, DevMem2D dst, cudaStream_t stream);
template void pow_caller<float>(const DevMem2D& src, float power, DevMem2D dst, cudaStream_t stream);
}}}
}}}
modules/gpu/src/element_operations.cpp
View file @
3a1beb1c
...
@@ -68,6 +68,8 @@ void cv::gpu::max(const GpuMat&, const GpuMat&, GpuMat&, Stream&) { throw_nogpu(
...
@@ -68,6 +68,8 @@ void cv::gpu::max(const GpuMat&, const GpuMat&, GpuMat&, Stream&) { throw_nogpu(
void
cv
::
gpu
::
max
(
const
GpuMat
&
,
double
,
GpuMat
&
,
Stream
&
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
max
(
const
GpuMat
&
,
double
,
GpuMat
&
,
Stream
&
)
{
throw_nogpu
();
}
double
cv
::
gpu
::
threshold
(
const
GpuMat
&
,
GpuMat
&
,
double
,
double
,
int
,
Stream
&
)
{
throw_nogpu
();
return
0.0
;}
double
cv
::
gpu
::
threshold
(
const
GpuMat
&
,
GpuMat
&
,
double
,
double
,
int
,
Stream
&
)
{
throw_nogpu
();
return
0.0
;}
void
cv
::
gpu
::
pow
(
const
GpuMat
&
,
double
,
GpuMat
&
,
Stream
&
)
{
throw_nogpu
();
}
#else
#else
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
...
@@ -768,4 +770,36 @@ double cv::gpu::threshold(const GpuMat& src, GpuMat& dst, double thresh, double
...
@@ -768,4 +770,36 @@ double cv::gpu::threshold(const GpuMat& src, GpuMat& dst, double thresh, double
return
thresh
;
return
thresh
;
}
}
////////////////////////////////////////////////////////////////////////
// pow
namespace
cv
{
namespace
gpu
{
namespace
mathfunc
{
template
<
typename
T
>
void
pow_caller
(
const
DevMem2D
&
src
,
float
power
,
DevMem2D
dst
,
cudaStream_t
stream
);
}
}
}
void
cv
::
gpu
::
pow
(
const
GpuMat
&
src
,
double
power
,
GpuMat
&
dst
,
Stream
&
stream
)
{
CV_Assert
(
src
.
depth
()
!=
CV_64F
);
dst
.
create
(
src
.
size
(),
src
.
type
());
typedef
void
(
*
caller_t
)(
const
DevMem2D
&
src
,
float
power
,
DevMem2D
dst
,
cudaStream_t
stream
);
static
const
caller_t
callers
[]
=
{
mathfunc
::
pow_caller
<
unsigned
char
>
,
mathfunc
::
pow_caller
<
signed
char
>
,
mathfunc
::
pow_caller
<
unsigned
short
>
,
mathfunc
::
pow_caller
<
short
>
,
mathfunc
::
pow_caller
<
int
>
,
mathfunc
::
pow_caller
<
float
>
};
callers
[
src
.
depth
()](
src
.
reshape
(
1
),
(
float
)
power
,
dst
.
reshape
(
1
),
StreamAccessor
::
getStream
(
stream
));
}
#endif
#endif
modules/gpu/src/opencv2/gpu/device/limits_gpu.hpp
View file @
3a1beb1c
...
@@ -87,6 +87,20 @@ namespace cv { namespace gpu { namespace device
...
@@ -87,6 +87,20 @@ namespace cv { namespace gpu { namespace device
static
const
bool
is_signed
=
(
char
)
-
1
==
-
1
;
static
const
bool
is_signed
=
(
char
)
-
1
==
-
1
;
};
};
template
<>
struct
numeric_limits_gpu
<
signed
char
>
{
typedef
char
type
;
__device__
__forceinline__
static
type
min
()
{
return
CHAR_MIN
;
};
__device__
__forceinline__
static
type
max
()
{
return
CHAR_MAX
;
};
__device__
__forceinline__
static
type
epsilon
();
__device__
__forceinline__
static
type
round_error
();
__device__
__forceinline__
static
type
denorm_min
();
__device__
__forceinline__
static
type
infinity
();
__device__
__forceinline__
static
type
quiet_NaN
();
__device__
__forceinline__
static
type
signaling_NaN
();
static
const
bool
is_signed
=
(
signed
char
)
-
1
==
-
1
;
};
template
<>
struct
numeric_limits_gpu
<
unsigned
char
>
template
<>
struct
numeric_limits_gpu
<
unsigned
char
>
{
{
typedef
unsigned
char
type
;
typedef
unsigned
char
type
;
...
...
modules/gpu/src/stereocsbp.cpp
View file @
3a1beb1c
...
@@ -107,7 +107,7 @@ void cv::gpu::StereoConstantSpaceBP::estimateRecommendedParams(int width, int he
...
@@ -107,7 +107,7 @@ void cv::gpu::StereoConstantSpaceBP::estimateRecommendedParams(int width, int he
levels
=
(
int
)
::
log
(
static_cast
<
double
>
(
mm
))
*
2
/
3
;
levels
=
(
int
)
::
log
(
static_cast
<
double
>
(
mm
))
*
2
/
3
;
if
(
levels
==
0
)
levels
++
;
if
(
levels
==
0
)
levels
++
;
nr_plane
=
(
int
)
((
float
)
ndisp
/
pow
(
2.0
,
levels
+
1
));
nr_plane
=
(
int
)
((
float
)
ndisp
/
std
::
pow
(
2.0
,
levels
+
1
));
}
}
cv
::
gpu
::
StereoConstantSpaceBP
::
StereoConstantSpaceBP
(
int
ndisp_
,
int
iters_
,
int
levels_
,
int
nr_plane_
,
cv
::
gpu
::
StereoConstantSpaceBP
::
StereoConstantSpaceBP
(
int
ndisp_
,
int
iters_
,
int
levels_
,
int
nr_plane_
,
...
...
modules/gpu/test/test_arithm.cpp
View file @
3a1beb1c
...
@@ -752,6 +752,74 @@ TEST_P(Exp, Accuracy)
...
@@ -752,6 +752,74 @@ TEST_P(Exp, Accuracy)
INSTANTIATE_TEST_CASE_P
(
Arithm
,
Exp
,
testing
::
ValuesIn
(
devices
()));
INSTANTIATE_TEST_CASE_P
(
Arithm
,
Exp
,
testing
::
ValuesIn
(
devices
()));
////////////////////////////////////////////////////////////////////////////////
// pow
struct
Pow
:
testing
::
TestWithParam
<
std
::
tr1
::
tuple
<
cv
::
gpu
::
DeviceInfo
,
int
>
>
{
cv
::
gpu
::
DeviceInfo
devInfo
;
int
type
;
double
power
;
cv
::
Size
size
;
cv
::
Mat
mat
;
cv
::
Mat
dst_gold
;
virtual
void
SetUp
()
{
devInfo
=
std
::
tr1
::
get
<
0
>
(
GetParam
());
type
=
std
::
tr1
::
get
<
1
>
(
GetParam
());
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
cv
::
RNG
&
rng
=
cvtest
::
TS
::
ptr
()
->
get_rng
();
size
=
cv
::
Size
(
rng
.
uniform
(
100
,
200
),
rng
.
uniform
(
100
,
200
));
//size = cv::Size(2, 2);
mat
=
cvtest
::
randomMat
(
rng
,
size
,
type
,
0.0
,
100.0
,
false
);
if
(
mat
.
depth
()
==
CV_32F
)
power
=
rng
.
uniform
(
1.2
f
,
3.
f
);
else
{
int
ipower
=
rng
.
uniform
(
2
,
8
);
power
=
(
float
)
ipower
;
}
cv
::
pow
(
mat
,
power
,
dst_gold
);
}
};
TEST_P
(
Pow
,
Accuracy
)
{
PRINT_PARAM
(
devInfo
);
PRINT_TYPE
(
type
);
PRINT_PARAM
(
size
);
PRINT_PARAM
(
power
);
cv
::
Mat
dst
;
ASSERT_NO_THROW
(
cv
::
gpu
::
GpuMat
gpu_res
;
cv
::
gpu
::
pow
(
cv
::
gpu
::
GpuMat
(
mat
),
power
,
gpu_res
);
gpu_res
.
download
(
dst
);
);
/*std::cout << mat << std::endl << std::endl;
std::cout << dst << std::endl << std::endl;
std::cout << dst_gold << std::endl;*/
EXPECT_MAT_NEAR
(
dst_gold
,
dst
,
1
);
}
INSTANTIATE_TEST_CASE_P
(
Arithm
,
Pow
,
testing
::
Combine
(
testing
::
ValuesIn
(
devices
()),
testing
::
Values
(
CV_32F
,
CV_32FC3
)));
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// log
// log
...
...
modules/gpu/test/test_main.cpp
View file @
3a1beb1c
...
@@ -68,9 +68,13 @@ void print_info()
...
@@ -68,9 +68,13 @@ void print_info()
#endif
#endif
int
deviceCount
=
cv
::
gpu
::
getCudaEnabledDeviceCount
();
int
deviceCount
=
cv
::
gpu
::
getCudaEnabledDeviceCount
();
int
driver
;
cudaDriverGetVersion
(
&
driver
);
printf
(
"CUDA version: %d
\n
"
,
CUDART_VERSION
);
printf
(
"CUDA Driver version: %d
\n
"
,
driver
);
printf
(
"CUDA Runtime version: %d
\n
"
,
CUDART_VERSION
);
printf
(
"CUDA device count: %d
\n\n
"
,
deviceCount
);
printf
(
"CUDA device count: %d
\n\n
"
,
deviceCount
);
for
(
int
i
=
0
;
i
<
deviceCount
;
++
i
)
for
(
int
i
=
0
;
i
<
deviceCount
;
++
i
)
{
{
...
...
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