mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +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:
@@ -97,6 +97,7 @@ GAPI_TEST_FIXTURE(MaxTest, initMatsRandU, <>, 0)
|
||||
GAPI_TEST_FIXTURE(AbsDiffTest, initMatsRandU, <>, 0)
|
||||
GAPI_TEST_FIXTURE(AbsDiffCTest, initMatsRandU, <>, 0)
|
||||
GAPI_TEST_FIXTURE(SumTest, initMatrixRandU, FIXTURE_API(CompareScalars), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(CountNonZeroTest, initMatrixRandU, FIXTURE_API(CompareScalars), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(AddWeightedTest, initMatsRandU, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(NormTest, initMatrixRandU, FIXTURE_API(CompareScalars,NormTypes), 2,
|
||||
cmpF, opType)
|
||||
|
||||
@@ -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-2019 Intel Corporation
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_CORE_TESTS_INL_HPP
|
||||
@@ -614,6 +614,29 @@ TEST_P(SumTest, AccuracyTest)
|
||||
}
|
||||
}
|
||||
|
||||
#pragma push_macro("countNonZero")
|
||||
#undef countNonZero
|
||||
TEST_P(CountNonZeroTest, AccuracyTest)
|
||||
{
|
||||
int out_cnz_gapi, out_cnz_ocv;
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::countNonZero(in);
|
||||
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
c.apply(cv::gin(in_mat1), cv::gout(out_cnz_gapi), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
out_cnz_ocv = cv::countNonZero(in_mat1);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_cnz_gapi, out_cnz_ocv));
|
||||
}
|
||||
}
|
||||
#pragma pop_macro("countNonZero")
|
||||
|
||||
TEST_P(AddWeightedTest, AccuracyTest)
|
||||
{
|
||||
auto& rng = cv::theRNG();
|
||||
|
||||
@@ -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-2019 Intel Corporation
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#include "../test_precomp.hpp"
|
||||
@@ -202,6 +202,15 @@ INSTANTIATE_TEST_CASE_P(SumTestCPU, SumTest,
|
||||
Values(CORE_CPU),
|
||||
Values(AbsToleranceScalar(1e-5).to_compare_obj())));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CountNonZeroTestCPU, CountNonZeroTest,
|
||||
Combine(Values( CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1),
|
||||
Values(CORE_CPU),
|
||||
Values(AbsToleranceScalar(1e-5).to_compare_obj())));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(AbsDiffTestCPU, AbsDiffTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
|
||||
@@ -63,6 +63,14 @@ GAPI_OCV_KERNEL(OCVGeneratePoint, ThisTest::GeneratePoint)
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_OCL_KERNEL(OCLGeneratePoint, ThisTest::GeneratePoint)
|
||||
{
|
||||
static void run(const cv::UMat&, cv::Point& out)
|
||||
{
|
||||
out = cv::Point(42, 42);
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(OCVFillMat, ThisTest::FillMat)
|
||||
{
|
||||
static void run(int a, int, int, cv::Size, cv::Mat& out)
|
||||
@@ -79,6 +87,16 @@ GAPI_OCV_KERNEL(OCVPaintPoint, ThisTest::PaintPoint)
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_OCL_KERNEL(OCLPaintPoint, ThisTest::PaintPoint)
|
||||
{
|
||||
static void run(cv::Point a, int depth, int chan, cv::Size size, cv::UMat& out)
|
||||
{
|
||||
GAPI_Assert(chan == 1);
|
||||
out.create(size, CV_MAKETYPE(depth, chan));
|
||||
cv::drawMarker(out, a, cv::Scalar(77));
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(OCVGenerateOpaque, ThisTest::GenerateOpaque)
|
||||
{
|
||||
static void run(const cv::Mat& a, const cv::Mat& b, const std::string& s,
|
||||
@@ -189,6 +207,57 @@ TEST(GOpaque, TestOpaqueCustomOut2)
|
||||
EXPECT_EQ(out2.s, str2);
|
||||
}
|
||||
|
||||
TEST(GOpaque, TestOpaqueOCLBackendIn)
|
||||
{
|
||||
cv::Point p_in = {42, 42};
|
||||
cv::Mat mat_out;
|
||||
|
||||
ThisTest::GPointOpaque in;
|
||||
cv::GMat out = ThisTest::PaintPoint::on(in, CV_8U, 1, {50, 50});
|
||||
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
c.apply(cv::gin(p_in), cv::gout(mat_out),
|
||||
cv::compile_args(cv::gapi::kernels<OCLPaintPoint>()));
|
||||
|
||||
int painted = mat_out.at<uint8_t>(42, 42);
|
||||
EXPECT_EQ(painted, 77);
|
||||
}
|
||||
|
||||
TEST(GOpaque, TestOpaqueOCLBackendBetween)
|
||||
{
|
||||
cv::Size sz = {50, 50};
|
||||
int depth = CV_8U;
|
||||
int chan = 1;
|
||||
cv::Mat mat_in = cv::Mat::zeros(sz, CV_MAKETYPE(depth, chan));
|
||||
cv::Mat mat_out;
|
||||
|
||||
cv::GMat in;
|
||||
auto betw = ThisTest::GeneratePoint::on(in);
|
||||
cv::GMat out = ThisTest::PaintPoint::on(betw, depth, chan, sz);
|
||||
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
c.apply(cv::gin(mat_in), cv::gout(mat_out),
|
||||
cv::compile_args(cv::gapi::kernels<OCLGeneratePoint, OCLPaintPoint>()));
|
||||
|
||||
int painted = mat_out.at<uint8_t>(42, 42);
|
||||
EXPECT_EQ(painted, 77);
|
||||
}
|
||||
|
||||
TEST(GOpaque, TestOpaqueOCLBackendOut)
|
||||
{
|
||||
cv::Mat input = cv::Mat(52, 52, CV_8U);
|
||||
cv::Point p_out;
|
||||
|
||||
cv::GMat in;
|
||||
ThisTest::GPointOpaque out = ThisTest::GeneratePoint::on(in);
|
||||
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
c.apply(cv::gin(input), cv::gout(p_out),
|
||||
cv::compile_args(cv::gapi::kernels<OCLGeneratePoint>()));
|
||||
|
||||
EXPECT_TRUE(p_out == cv::Point(42, 42));
|
||||
}
|
||||
|
||||
TEST(GOpaque_OpaqueRef, TestMov)
|
||||
{
|
||||
// Warning: this test is testing some not-very-public APIs
|
||||
|
||||
@@ -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-2019 Intel Corporation
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#include "../test_precomp.hpp"
|
||||
@@ -192,7 +192,16 @@ INSTANTIATE_TEST_CASE_P(SumTestGPU, SumTest,
|
||||
cv::Size(128, 128)),
|
||||
Values(-1),
|
||||
Values(CORE_GPU),
|
||||
Values(AbsToleranceScalar(1e-3).to_compare_obj())));//TODO: too relaxed?
|
||||
Values(AbsToleranceScalar(1e-5).to_compare_obj())));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CountNonZeroTestGPU, CountNonZeroTest,
|
||||
Combine(Values( CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1),
|
||||
Values(CORE_GPU),
|
||||
Values(AbsToleranceScalar(1e-5).to_compare_obj())));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(AbsDiffTestGPU, AbsDiffTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
|
||||
Reference in New Issue
Block a user