Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/gapi/test/gapi_scalar_tests.cpp
16337 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
4
//
5
// Copyright (C) 2018 Intel Corporation
6
7
8
#include "test_precomp.hpp"
9
10
#include <iostream>
11
12
namespace opencv_test
13
{
14
15
TEST(GAPI_Scalar, Argument)
16
{
17
cv::Size sz(2, 2);
18
cv::Mat in_mat(sz, CV_8U);
19
20
cv::GComputationT<cv::GMat (cv::GMat, cv::GScalar)> mulS([](cv::GMat in, cv::GScalar c)
21
{
22
return in*c;
23
});
24
25
cv::Mat out_mat(sz, CV_8U);
26
mulS.apply(in_mat, cv::Scalar(2), out_mat);
27
28
cv::Mat reference = in_mat*2;
29
EXPECT_EQ(0, cv::countNonZero(cv::abs(out_mat - reference)));
30
}
31
32
TEST(GAPI_Scalar, ReturnValue)
33
{
34
const cv::Size sz(2, 2);
35
cv::Mat in_mat(sz, CV_8U, cv::Scalar(1));
36
37
cv::GComputationT<cv::GScalar (cv::GMat)> sum_of_sum([](cv::GMat in)
38
{
39
return cv::gapi::sum(in + in);
40
});
41
42
cv::Scalar out;
43
sum_of_sum.apply(in_mat, out);
44
45
EXPECT_EQ(8, out[0]);
46
}
47
48
TEST(GAPI_Scalar, TmpScalar)
49
{
50
const cv::Size sz(2, 2);
51
cv::Mat in_mat(sz, CV_8U, cv::Scalar(1));
52
53
cv::GComputationT<cv::GMat (cv::GMat)> mul_by_sum([](cv::GMat in)
54
{
55
return in * cv::gapi::sum(in);
56
});
57
58
cv::Mat out_mat(sz, CV_8U);
59
mul_by_sum.apply(in_mat, out_mat);
60
61
cv::Mat reference = cv::Mat(sz, CV_8U, cv::Scalar(4));
62
EXPECT_EQ(0, cv::countNonZero(cv::abs(out_mat - reference)));
63
}
64
65
TEST(GAPI_ScalarWithValue, Simple_Arithmetic_Pipeline)
66
{
67
GMat in;
68
GMat out = (in + 1) * 2;
69
cv::GComputation comp(in, out);
70
71
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC1);
72
cv::Mat ref_mat, out_mat;
73
74
ref_mat = (in_mat + 1) * 2;
75
comp.apply(in_mat, out_mat);
76
77
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
78
}
79
80
TEST(GAPI_ScalarWithValue, GScalar_Initilization)
81
{
82
cv::Scalar sc(2);
83
cv::GMat in;
84
cv::GScalar s(sc);
85
cv::GComputation comp(in, cv::gapi::mulC(in, s));
86
87
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC1);
88
cv::Mat ref_mat, out_mat;
89
cv::multiply(in_mat, sc, ref_mat, 1, CV_8UC1);
90
comp.apply(cv::gin(in_mat), cv::gout(out_mat));
91
92
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
93
}
94
95
TEST(GAPI_ScalarWithValue, Constant_GScalar_In_Middle_Graph)
96
{
97
cv::Scalar sc(5);
98
cv::GMat in1;
99
cv::GScalar in2;
100
cv::GScalar s(sc);
101
102
auto add_out = cv::gapi::addC(in1, in2);
103
cv::GComputation comp(cv::GIn(in1, in2), cv::GOut(cv::gapi::mulC(add_out, s)));
104
105
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC1);
106
cv::Scalar in_scalar(3);
107
108
cv::Mat ref_mat, out_mat, add_mat;
109
cv::add(in_mat, in_scalar, add_mat);
110
cv::multiply(add_mat, sc, ref_mat, 1, CV_8UC1);
111
comp.apply(cv::gin(in_mat, in_scalar), cv::gout(out_mat));
112
113
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
114
}
115
116
} // namespace opencv_test
117
118