Commit 0aaaad1e authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

implemented gpu::addWeighted

parent 64119dd9
......@@ -593,6 +593,10 @@ namespace cv
//! computes per-element maximum of array and scalar (dst = max(src1, src2))
CV_EXPORTS void max(const GpuMat& src1, double src2, GpuMat& dst, Stream& stream = Stream::Null());
//! computes the weighted sum of two arrays
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());
////////////////////////////// Image processing //////////////////////////////
......
......@@ -685,3 +685,34 @@ PERF_TEST_P(DevInfo_Size_MatType, countNonZero, testing::Combine(testing::Values
SANITY_CHECK(dst);
}
PERF_TEST_P(DevInfo_Size_MatType, addWeighted, testing::Combine(testing::ValuesIn(devices()),
testing::Values(GPU_TYPICAL_MAT_SIZES),
testing::Values(CV_8UC1, CV_16UC1, CV_32FC1)))
{
DeviceInfo devInfo = std::tr1::get<0>(GetParam());
Size size = std::tr1::get<1>(GetParam());
int type = std::tr1::get<2>(GetParam());
setDevice(devInfo.deviceID());
Mat src1_host(size, type);
Mat src2_host(size, type);
declare.in(src1_host, src2_host, WARMUP_RNG);
GpuMat src1(src1_host);
GpuMat src2(src2_host);
GpuMat dst(size, type);
declare.time(0.5).iterations(100);
SIMPLE_TEST_CYCLE()
{
addWeighted(src1, 0.5, src2, 0.5, 0.0, dst);
}
Mat dst_host = dst;
SANITY_CHECK(dst_host);
}
This diff is collapsed.
This diff is collapsed.
......@@ -1135,7 +1135,7 @@ TEST_P(MinMax, Accuracy)
return;
PRINT_PARAM(devInfo);
PRINT_TYPE(type)
PRINT_TYPE(type);
PRINT_PARAM(size);
double minVal, maxVal;
......@@ -1216,7 +1216,7 @@ TEST_P(MinMaxLoc, Accuracy)
return;
PRINT_PARAM(devInfo);
PRINT_TYPE(type)
PRINT_TYPE(type);
PRINT_PARAM(size);
double minVal, maxVal;
......@@ -1281,7 +1281,7 @@ TEST_P(CountNonZero, Accuracy)
return;
PRINT_PARAM(devInfo);
PRINT_TYPE(type)
PRINT_TYPE(type);
PRINT_PARAM(size);
int n;
......@@ -1333,7 +1333,7 @@ TEST_P(Sum, Accuracy)
return;
PRINT_PARAM(devInfo);
PRINT_TYPE(type)
PRINT_TYPE(type);
PRINT_PARAM(size);
cv::Scalar sum;
......@@ -1385,7 +1385,7 @@ TEST_P(AbsSum, Accuracy)
return;
PRINT_PARAM(devInfo);
PRINT_TYPE(type)
PRINT_TYPE(type);
PRINT_PARAM(size);
cv::Scalar sum;
......@@ -1439,7 +1439,7 @@ TEST_P(SqrSum, Accuracy)
return;
PRINT_PARAM(devInfo);
PRINT_TYPE(type)
PRINT_TYPE(type);
PRINT_PARAM(size);
cv::Scalar sum;
......@@ -1500,7 +1500,7 @@ TEST_P(BitwiseNot, Accuracy)
return;
PRINT_PARAM(devInfo);
PRINT_TYPE(type)
PRINT_TYPE(type);
PRINT_PARAM(size);
cv::Mat dst;
......@@ -1564,7 +1564,7 @@ TEST_P(BitwiseOr, Accuracy)
return;
PRINT_PARAM(devInfo);
PRINT_TYPE(type)
PRINT_TYPE(type);
PRINT_PARAM(size);
cv::Mat dst;
......@@ -1628,7 +1628,7 @@ TEST_P(BitwiseAnd, Accuracy)
return;
PRINT_PARAM(devInfo);
PRINT_TYPE(type)
PRINT_TYPE(type);
PRINT_PARAM(size);
cv::Mat dst;
......@@ -1692,7 +1692,7 @@ TEST_P(BitwiseXor, Accuracy)
return;
PRINT_PARAM(devInfo);
PRINT_TYPE(type)
PRINT_TYPE(type);
PRINT_PARAM(size);
cv::Mat dst;
......@@ -1712,4 +1712,80 @@ INSTANTIATE_TEST_CASE_P(Arithm, BitwiseXor, testing::Combine(
testing::ValuesIn(devices()),
testing::ValuesIn(all_types())));
//////////////////////////////////////////////////////////////////////////////
// addWeighted
struct AddWeighted : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, int, int> >
{
cv::gpu::DeviceInfo devInfo;
int type1;
int type2;
int dtype;
cv::Size size;
cv::Mat src1;
cv::Mat src2;
double alpha;
double beta;
double gamma;
cv::Mat dst_gold;
virtual void SetUp()
{
devInfo = std::tr1::get<0>(GetParam());
type1 = std::tr1::get<1>(GetParam());
type2 = std::tr1::get<2>(GetParam());
dtype = std::tr1::get<3>(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));
src1 = cvtest::randomMat(rng, size, type1, 0.0, 255.0, false);
src2 = cvtest::randomMat(rng, size, type2, 0.0, 255.0, false);
alpha = rng.uniform(-10.0, 10.0);
beta = rng.uniform(-10.0, 10.0);
gamma = rng.uniform(-10.0, 10.0);
cv::addWeighted(src1, alpha, src2, beta, gamma, dst_gold, dtype);
}
};
TEST_P(AddWeighted, Accuracy)
{
if ((src1.depth() == CV_64F || src2.depth() == CV_64F || dst_gold.depth() == CV_64F) && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE))
return;
PRINT_PARAM(devInfo);
PRINT_TYPE(type1);
PRINT_TYPE(type2);
PRINT_TYPE(dtype);
PRINT_PARAM(size);
PRINT_PARAM(alpha);
PRINT_PARAM(beta);
PRINT_PARAM(gamma);
cv::Mat dst;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst;
cv::gpu::addWeighted(cv::gpu::GpuMat(src1), alpha, cv::gpu::GpuMat(src2), beta, gamma, dev_dst, dtype);
dev_dst.download(dst);
);
EXPECT_MAT_NEAR(dst_gold, dst, dtype < CV_32F ? 1.0 : 1e-12);
}
INSTANTIATE_TEST_CASE_P(Arithm, AddWeighted, testing::Combine(
testing::ValuesIn(devices()),
testing::ValuesIn(types(CV_8U, CV_64F, 1, 1)),
testing::ValuesIn(types(CV_8U, CV_64F, 1, 1)),
testing::ValuesIn(types(CV_8U, CV_64F, 1, 1))));
#endif // HAVE_CUDA
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment