Skip to content

Commit b866890

Browse files
author
Vladislav Vinogradov
committed
switched to Input/Output Array in abs, sqr, sqrt, exp, log, pow
1 parent 5ec8c51 commit b866890

File tree

3 files changed

+170
-158
lines changed

3 files changed

+170
-158
lines changed

modules/gpuarithm/include/opencv2/gpuarithm.hpp

+20-26
Original file line numberDiff line numberDiff line change
@@ -72,41 +72,35 @@ static inline void divide(double src1, InputArray src2, OutputArray dst, int dty
7272
//! computes element-wise absolute difference of two arrays (dst = abs(src1 - src2))
7373
CV_EXPORTS void absdiff(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
7474

75-
//! computes the weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma)
76-
CV_EXPORTS void addWeighted(const GpuMat& src1, double alpha, const GpuMat& src2, double beta, double gamma, GpuMat& dst,
77-
int dtype = -1, Stream& stream = Stream::Null());
78-
79-
//! adds scaled array to another one (dst = alpha*src1 + src2)
80-
static inline void scaleAdd(const GpuMat& src1, double alpha, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null())
81-
{
82-
addWeighted(src1, alpha, src2, 1.0, 0.0, dst, -1, stream);
83-
}
84-
8575
//! computes absolute value of each matrix element
86-
//! supports CV_16S and CV_32F depth
87-
CV_EXPORTS void abs(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
76+
CV_EXPORTS void abs(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
8877

8978
//! computes square of each pixel in an image
90-
//! supports CV_8U, CV_16U, CV_16S and CV_32F depth
91-
CV_EXPORTS void sqr(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
79+
CV_EXPORTS void sqr(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
9280

9381
//! computes square root of each pixel in an image
94-
//! supports CV_8U, CV_16U, CV_16S and CV_32F depth
95-
CV_EXPORTS void sqrt(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
82+
CV_EXPORTS void sqrt(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
9683

97-
//! computes exponent of each matrix element (b = e**a)
98-
//! supports CV_8U, CV_16U, CV_16S and CV_32F depth
99-
CV_EXPORTS void exp(const GpuMat& a, GpuMat& b, Stream& stream = Stream::Null());
84+
//! computes exponent of each matrix element
85+
CV_EXPORTS void exp(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
10086

101-
//! computes natural logarithm of absolute value of each matrix element: b = log(abs(a))
102-
//! supports CV_8U, CV_16U, CV_16S and CV_32F depth
103-
CV_EXPORTS void log(const GpuMat& a, GpuMat& b, Stream& stream = Stream::Null());
87+
//! computes natural logarithm of absolute value of each matrix element
88+
CV_EXPORTS void log(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
10489

10590
//! computes power of each matrix element:
106-
// (dst(i,j) = pow( src(i,j) , power), if src.type() is integer
107-
// (dst(i,j) = pow(fabs(src(i,j)), power), otherwise
108-
//! supports all, except depth == CV_64F
109-
CV_EXPORTS void pow(const GpuMat& src, double power, GpuMat& dst, Stream& stream = Stream::Null());
91+
//! (dst(i,j) = pow( src(i,j) , power), if src.type() is integer
92+
//! (dst(i,j) = pow(fabs(src(i,j)), power), otherwise
93+
CV_EXPORTS void pow(InputArray src, double power, OutputArray dst, Stream& stream = Stream::Null());
94+
95+
//! computes the weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma)
96+
CV_EXPORTS void addWeighted(const GpuMat& src1, double alpha, const GpuMat& src2, double beta, double gamma, GpuMat& dst,
97+
int dtype = -1, Stream& stream = Stream::Null());
98+
99+
//! adds scaled array to another one (dst = alpha*src1 + src2)
100+
static inline void scaleAdd(const GpuMat& src1, double alpha, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null())
101+
{
102+
addWeighted(src1, alpha, src2, 1.0, 0.0, dst, -1, stream);
103+
}
110104

111105
//! compares elements of two arrays (c = a <cmpop> b)
112106
CV_EXPORTS void compare(const GpuMat& a, const GpuMat& b, GpuMat& c, int cmpop, Stream& stream = Stream::Null());

modules/gpuarithm/src/element_operations.cpp

+91-73
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ void cv::gpu::divide(InputArray, InputArray, OutputArray, double, int, Stream&)
5757

5858
void cv::gpu::absdiff(InputArray, InputArray, OutputArray, Stream&) { throw_no_cuda(); }
5959

60-
void cv::gpu::abs(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
60+
void cv::gpu::abs(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
6161

62-
void cv::gpu::sqr(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
62+
void cv::gpu::sqr(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
6363

64-
void cv::gpu::sqrt(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
64+
void cv::gpu::sqrt(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
6565

66-
void cv::gpu::exp(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
66+
void cv::gpu::exp(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
6767

68-
void cv::gpu::log(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
68+
void cv::gpu::log(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
6969

70-
void cv::gpu::pow(const GpuMat&, double, GpuMat&, Stream&) { throw_no_cuda(); }
70+
void cv::gpu::pow(InputArray, double, OutputArray, Stream&) { throw_no_cuda(); }
7171

7272
void cv::gpu::compare(const GpuMat&, const GpuMat&, GpuMat&, int, Stream&) { throw_no_cuda(); }
7373
void cv::gpu::compare(const GpuMat&, Scalar, GpuMat&, int, Stream&) { throw_no_cuda(); }
@@ -1484,7 +1484,7 @@ namespace arithm
14841484
void absMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
14851485
}
14861486

1487-
void cv::gpu::abs(const GpuMat& src, GpuMat& dst, Stream& stream)
1487+
void cv::gpu::abs(InputArray _src, OutputArray _dst, Stream& stream)
14881488
{
14891489
using namespace arithm;
14901490

@@ -1500,6 +1500,8 @@ void cv::gpu::abs(const GpuMat& src, GpuMat& dst, Stream& stream)
15001500
absMat<double>
15011501
};
15021502

1503+
GpuMat src = _src.getGpuMat();
1504+
15031505
const int depth = src.depth();
15041506

15051507
CV_Assert( depth <= CV_64F );
@@ -1511,7 +1513,8 @@ void cv::gpu::abs(const GpuMat& src, GpuMat& dst, Stream& stream)
15111513
CV_Error(cv::Error::StsUnsupportedFormat, "The device doesn't support double");
15121514
}
15131515

1514-
dst.create(src.size(), src.type());
1516+
_dst.create(src.size(), src.type());
1517+
GpuMat dst = _dst.getGpuMat();
15151518

15161519
funcs[depth](src, dst, StreamAccessor::getStream(stream));
15171520
}
@@ -1525,7 +1528,7 @@ namespace arithm
15251528
void sqrMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
15261529
}
15271530

1528-
void cv::gpu::sqr(const GpuMat& src, GpuMat& dst, Stream& stream)
1531+
void cv::gpu::sqr(InputArray _src, OutputArray _dst, Stream& stream)
15291532
{
15301533
using namespace arithm;
15311534

@@ -1541,6 +1544,8 @@ void cv::gpu::sqr(const GpuMat& src, GpuMat& dst, Stream& stream)
15411544
sqrMat<double>
15421545
};
15431546

1547+
GpuMat src = _src.getGpuMat();
1548+
15441549
const int depth = src.depth();
15451550

15461551
CV_Assert( depth <= CV_64F );
@@ -1552,7 +1557,8 @@ void cv::gpu::sqr(const GpuMat& src, GpuMat& dst, Stream& stream)
15521557
CV_Error(cv::Error::StsUnsupportedFormat, "The device doesn't support double");
15531558
}
15541559

1555-
dst.create(src.size(), src.type());
1560+
_dst.create(src.size(), src.type());
1561+
GpuMat dst = _dst.getGpuMat();
15561562

15571563
funcs[depth](src, dst, StreamAccessor::getStream(stream));
15581564
}
@@ -1566,7 +1572,7 @@ namespace arithm
15661572
void sqrtMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
15671573
}
15681574

1569-
void cv::gpu::sqrt(const GpuMat& src, GpuMat& dst, Stream& stream)
1575+
void cv::gpu::sqrt(InputArray _src, OutputArray _dst, Stream& stream)
15701576
{
15711577
using namespace arithm;
15721578

@@ -1582,6 +1588,8 @@ void cv::gpu::sqrt(const GpuMat& src, GpuMat& dst, Stream& stream)
15821588
sqrtMat<double>
15831589
};
15841590

1591+
GpuMat src = _src.getGpuMat();
1592+
15851593
const int depth = src.depth();
15861594

15871595
CV_Assert( depth <= CV_64F );
@@ -1593,7 +1601,52 @@ void cv::gpu::sqrt(const GpuMat& src, GpuMat& dst, Stream& stream)
15931601
CV_Error(cv::Error::StsUnsupportedFormat, "The device doesn't support double");
15941602
}
15951603

1596-
dst.create(src.size(), src.type());
1604+
_dst.create(src.size(), src.type());
1605+
GpuMat dst = _dst.getGpuMat();
1606+
1607+
funcs[depth](src, dst, StreamAccessor::getStream(stream));
1608+
}
1609+
1610+
////////////////////////////////////////////////////////////////////////
1611+
// exp
1612+
1613+
namespace arithm
1614+
{
1615+
template <typename T>
1616+
void expMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
1617+
}
1618+
1619+
void cv::gpu::exp(InputArray _src, OutputArray _dst, Stream& stream)
1620+
{
1621+
using namespace arithm;
1622+
1623+
typedef void (*func_t)(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
1624+
static const func_t funcs[] =
1625+
{
1626+
expMat<unsigned char>,
1627+
expMat<signed char>,
1628+
expMat<unsigned short>,
1629+
expMat<short>,
1630+
expMat<int>,
1631+
expMat<float>,
1632+
expMat<double>
1633+
};
1634+
1635+
GpuMat src = _src.getGpuMat();
1636+
1637+
const int depth = src.depth();
1638+
1639+
CV_Assert( depth <= CV_64F );
1640+
CV_Assert( src.channels() == 1 );
1641+
1642+
if (depth == CV_64F)
1643+
{
1644+
if (!deviceSupports(NATIVE_DOUBLE))
1645+
CV_Error(cv::Error::StsUnsupportedFormat, "The device doesn't support double");
1646+
}
1647+
1648+
_dst.create(src.size(), src.type());
1649+
GpuMat dst = _dst.getGpuMat();
15971650

15981651
funcs[depth](src, dst, StreamAccessor::getStream(stream));
15991652
}
@@ -1607,7 +1660,7 @@ namespace arithm
16071660
void logMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
16081661
}
16091662

1610-
void cv::gpu::log(const GpuMat& src, GpuMat& dst, Stream& stream)
1663+
void cv::gpu::log(InputArray _src, OutputArray _dst, Stream& stream)
16111664
{
16121665
using namespace arithm;
16131666

@@ -1623,6 +1676,8 @@ void cv::gpu::log(const GpuMat& src, GpuMat& dst, Stream& stream)
16231676
logMat<double>
16241677
};
16251678

1679+
GpuMat src = _src.getGpuMat();
1680+
16261681
const int depth = src.depth();
16271682

16281683
CV_Assert( depth <= CV_64F );
@@ -1634,50 +1689,54 @@ void cv::gpu::log(const GpuMat& src, GpuMat& dst, Stream& stream)
16341689
CV_Error(cv::Error::StsUnsupportedFormat, "The device doesn't support double");
16351690
}
16361691

1637-
dst.create(src.size(), src.type());
1692+
_dst.create(src.size(), src.type());
1693+
GpuMat dst = _dst.getGpuMat();
16381694

16391695
funcs[depth](src, dst, StreamAccessor::getStream(stream));
16401696
}
16411697

16421698
////////////////////////////////////////////////////////////////////////
1643-
// exp
1699+
// pow
16441700

16451701
namespace arithm
16461702
{
1647-
template <typename T>
1648-
void expMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
1703+
template<typename T> void pow(PtrStepSzb src, double power, PtrStepSzb dst, cudaStream_t stream);
16491704
}
16501705

1651-
void cv::gpu::exp(const GpuMat& src, GpuMat& dst, Stream& stream)
1706+
void cv::gpu::pow(InputArray _src, double power, OutputArray _dst, Stream& stream)
16521707
{
1653-
using namespace arithm;
1654-
1655-
typedef void (*func_t)(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
1708+
typedef void (*func_t)(PtrStepSzb src, double power, PtrStepSzb dst, cudaStream_t stream);
16561709
static const func_t funcs[] =
16571710
{
1658-
expMat<unsigned char>,
1659-
expMat<signed char>,
1660-
expMat<unsigned short>,
1661-
expMat<short>,
1662-
expMat<int>,
1663-
expMat<float>,
1664-
expMat<double>
1711+
arithm::pow<unsigned char>,
1712+
arithm::pow<signed char>,
1713+
arithm::pow<unsigned short>,
1714+
arithm::pow<short>,
1715+
arithm::pow<int>,
1716+
arithm::pow<float>,
1717+
arithm::pow<double>
16651718
};
16661719

1720+
GpuMat src = _src.getGpuMat();
1721+
16671722
const int depth = src.depth();
1723+
const int cn = src.channels();
16681724

1669-
CV_Assert( depth <= CV_64F );
1670-
CV_Assert( src.channels() == 1 );
1725+
CV_Assert(depth <= CV_64F);
16711726

16721727
if (depth == CV_64F)
16731728
{
16741729
if (!deviceSupports(NATIVE_DOUBLE))
16751730
CV_Error(cv::Error::StsUnsupportedFormat, "The device doesn't support double");
16761731
}
16771732

1678-
dst.create(src.size(), src.type());
1733+
_dst.create(src.size(), src.type());
1734+
GpuMat dst = _dst.getGpuMat();
16791735

1680-
funcs[depth](src, dst, StreamAccessor::getStream(stream));
1736+
PtrStepSzb src_(src.rows, src.cols * cn, src.data, src.step);
1737+
PtrStepSzb dst_(src.rows, src.cols * cn, dst.data, dst.step);
1738+
1739+
funcs[depth](src_, power, dst_, StreamAccessor::getStream(stream));
16811740
}
16821741

16831742
//////////////////////////////////////////////////////////////////////////////
@@ -2562,47 +2621,6 @@ void cv::gpu::max(const GpuMat& src, double val, GpuMat& dst, Stream& stream)
25622621
funcs[depth](src, cast_func[depth](val), dst, StreamAccessor::getStream(stream));
25632622
}
25642623

2565-
////////////////////////////////////////////////////////////////////////
2566-
// pow
2567-
2568-
namespace arithm
2569-
{
2570-
template<typename T> void pow(PtrStepSzb src, double power, PtrStepSzb dst, cudaStream_t stream);
2571-
}
2572-
2573-
void cv::gpu::pow(const GpuMat& src, double power, GpuMat& dst, Stream& stream)
2574-
{
2575-
typedef void (*func_t)(PtrStepSzb src, double power, PtrStepSzb dst, cudaStream_t stream);
2576-
static const func_t funcs[] =
2577-
{
2578-
arithm::pow<unsigned char>,
2579-
arithm::pow<signed char>,
2580-
arithm::pow<unsigned short>,
2581-
arithm::pow<short>,
2582-
arithm::pow<int>,
2583-
arithm::pow<float>,
2584-
arithm::pow<double>
2585-
};
2586-
2587-
const int depth = src.depth();
2588-
const int cn = src.channels();
2589-
2590-
CV_Assert(depth <= CV_64F);
2591-
2592-
if (depth == CV_64F)
2593-
{
2594-
if (!deviceSupports(NATIVE_DOUBLE))
2595-
CV_Error(cv::Error::StsUnsupportedFormat, "The device doesn't support double");
2596-
}
2597-
2598-
dst.create(src.size(), src.type());
2599-
2600-
PtrStepSzb src_(src.rows, src.cols * cn, src.data, src.step);
2601-
PtrStepSzb dst_(src.rows, src.cols * cn, dst.data, dst.step);
2602-
2603-
funcs[depth](src_, power, dst_, StreamAccessor::getStream(stream));
2604-
}
2605-
26062624
////////////////////////////////////////////////////////////////////////
26072625
// addWeighted
26082626

0 commit comments

Comments
 (0)