1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge pull request #18451 from OrestChura:oc/count_non_zero

[G-API]: countNonZero() Standard Kernel Implementation

* Add countNonZero() standard kernel
 - API and documentation provided
 - OCV backend supported
 - accuracy and performance tests provided
 - some refactoring of related documentation done

* Fix GOpaque functionality for OCL Backend
 - test for OCL Opaque usage providied

* countNonZero for GPU
 - OCL Backend implementation for countNonZero() added
 - tests provided

* Addressing comments
This commit is contained in:
Orest Chura
2020-09-30 19:07:35 +03:00
committed by GitHub
parent fc1a156262
commit 40b8b58bc6
15 changed files with 235 additions and 24 deletions
+6 -1
View File
@@ -2,7 +2,7 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
// Copyright (C) 2018-2020 Intel Corporation
#include "precomp.hpp"
@@ -234,6 +234,11 @@ GScalar sum(const GMat& src)
return core::GSum::on(src);
}
GOpaque<int> countNonZero(const GMat& src)
{
return core::GCountNonZero::on(src);
}
GMat addWeighted(const GMat& src1, double alpha, const GMat& src2, double beta, double gamma, int dtype)
{
return core::GAddW::on(src1, alpha, src2, beta, gamma, dtype);
+10 -1
View File
@@ -2,7 +2,7 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
// Copyright (C) 2018-2020 Intel Corporation
#include "precomp.hpp"
@@ -342,6 +342,14 @@ GAPI_OCV_KERNEL(GCPUSum, cv::gapi::core::GSum)
}
};
GAPI_OCV_KERNEL(GCPUCountNonZero, cv::gapi::core::GCountNonZero)
{
static void run(const cv::Mat& in, int& out)
{
out = cv::countNonZero(in);
}
};
GAPI_OCV_KERNEL(GCPUAddW, cv::gapi::core::GAddW)
{
static void run(const cv::Mat& in1, double alpha, const cv::Mat& in2, double beta, double gamma, int dtype, cv::Mat& out)
@@ -679,6 +687,7 @@ cv::gapi::GKernelPackage cv::gapi::core::cpu::kernels()
, GCPUAbsDiff
, GCPUAbsDiffC
, GCPUSum
, GCPUCountNonZero
, GCPUAddW
, GCPUNormL1
, GCPUNormL2
+10 -1
View File
@@ -2,7 +2,7 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
// Copyright (C) 2018-2020 Intel Corporation
#include "precomp.hpp"
@@ -337,6 +337,14 @@ GAPI_OCL_KERNEL(GOCLSum, cv::gapi::core::GSum)
}
};
GAPI_OCL_KERNEL(GOCLCountNonZero, cv::gapi::core::GCountNonZero)
{
static void run(const cv::UMat& in, int& out)
{
out = cv::countNonZero(in);
}
};
GAPI_OCL_KERNEL(GOCLAddW, cv::gapi::core::GAddW)
{
static void run(const cv::UMat& in1, double alpha, const cv::UMat& in2, double beta, double gamma, int dtype, cv::UMat& out)
@@ -565,6 +573,7 @@ cv::gapi::GKernelPackage cv::gapi::core::ocl::kernels()
, GOCLAbsDiff
, GOCLAbsDiffC
, GOCLSum
, GOCLCountNonZero
, GOCLAddW
, GOCLNormL1
, GOCLNormL2
@@ -34,6 +34,11 @@ cv::detail::VectorRef& cv::GOCLContext::outVecRef(int output)
return util::get<cv::detail::VectorRef>(m_results.at(output));
}
cv::detail::OpaqueRef& cv::GOCLContext::outOpaqueRef(int output)
{
return util::get<cv::detail::OpaqueRef>(m_results.at(output));
}
cv::GOCLKernel::GOCLKernel()
{
}