2018-09-27 02:50:39 +08:00
|
|
|
// This file is part of OpenCV project.
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
|
|
#include "test_precomp.hpp"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <ade/util/algorithm.hpp>
|
|
|
|
|
|
|
|
namespace opencv_test
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ThisTest
|
|
|
|
{
|
|
|
|
using GPointArray = cv::GArray<cv::Point>;
|
|
|
|
G_TYPED_KERNEL(GeneratePoints, <GPointArray(GMat)>, "test.array.out_const")
|
|
|
|
{
|
|
|
|
static GArrayDesc outMeta(const GMatDesc&) { return empty_array_desc(); }
|
|
|
|
};
|
|
|
|
G_TYPED_KERNEL(FindCorners, <GPointArray(GMat)>, "test.array.out")
|
|
|
|
{
|
|
|
|
static GArrayDesc outMeta(const GMatDesc&) { return empty_array_desc(); }
|
|
|
|
};
|
|
|
|
G_TYPED_KERNEL(CountCorners, <GScalar(GPointArray)>, "test.array.in")
|
|
|
|
{
|
|
|
|
static GScalarDesc outMeta(const GArrayDesc &) { return empty_scalar_desc(); }
|
|
|
|
};
|
|
|
|
} // namespace ThisTest
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
GAPI_OCV_KERNEL(OCVGeneratePoints, ThisTest::GeneratePoints)
|
|
|
|
{
|
|
|
|
static void run(cv::Mat, std::vector<cv::Point> &out)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
out.emplace_back(i, i);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
GAPI_OCV_KERNEL(OCVFindCorners, ThisTest::FindCorners)
|
|
|
|
{
|
|
|
|
static void run(cv::Mat in, std::vector<cv::Point> &out)
|
|
|
|
{
|
|
|
|
cv::goodFeaturesToTrack(in, out, 1024, 0.01, 3);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
GAPI_OCV_KERNEL(OCVCountCorners, ThisTest::CountCorners)
|
|
|
|
{
|
|
|
|
static void run(const std::vector<cv::Point> &in, cv::Scalar &out)
|
|
|
|
{
|
|
|
|
out[0] = static_cast<double>(in.size());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
cv::Mat cross(int w, int h)
|
|
|
|
{
|
|
|
|
cv::Mat mat = cv::Mat::eye(h, w, CV_8UC1)*255;
|
|
|
|
cv::Mat yee;
|
|
|
|
cv::flip(mat, yee, 0); // X-axis
|
|
|
|
mat |= yee; // make an "X" matrix;
|
|
|
|
return mat;
|
|
|
|
}
|
|
|
|
} // (anonymous namespace)
|
|
|
|
|
|
|
|
TEST(GArray, TestReturnValue)
|
|
|
|
{
|
|
|
|
// FIXME: Make .apply() able to take compile arguments
|
|
|
|
cv::GComputationT<ThisTest::GPointArray(cv::GMat)> c(ThisTest::FindCorners::on);
|
|
|
|
auto cc = c.compile(cv::GMatDesc{CV_8U,1,{32,32}},
|
|
|
|
cv::compile_args(cv::gapi::kernels<OCVFindCorners>()));
|
|
|
|
|
|
|
|
// Prepare input matrix
|
|
|
|
cv::Mat input = cross(32, 32);
|
|
|
|
|
|
|
|
std::vector<cv::Point> points;
|
|
|
|
cc(input, points);
|
|
|
|
|
|
|
|
// OCV goodFeaturesToTrack should find 5 points here (with these settings)
|
|
|
|
EXPECT_EQ(5u, points.size());
|
|
|
|
EXPECT_TRUE(ade::util::find(points, cv::Point(16,16)) != points.end());
|
|
|
|
EXPECT_TRUE(ade::util::find(points, cv::Point(30,30)) != points.end());
|
|
|
|
EXPECT_TRUE(ade::util::find(points, cv::Point( 1,30)) != points.end());
|
|
|
|
EXPECT_TRUE(ade::util::find(points, cv::Point(30, 1)) != points.end());
|
|
|
|
EXPECT_TRUE(ade::util::find(points, cv::Point( 1, 1)) != points.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GArray, TestInputArg)
|
|
|
|
{
|
|
|
|
cv::GComputationT<cv::GScalar(ThisTest::GPointArray)> c(ThisTest::CountCorners::on);
|
|
|
|
auto cc = c.compile(cv::empty_array_desc(),
|
|
|
|
cv::compile_args(cv::gapi::kernels<OCVCountCorners>()));
|
|
|
|
|
|
|
|
const std::vector<cv::Point> arr = {cv::Point(1,1), cv::Point(2,2)};
|
|
|
|
cv::Scalar out;
|
|
|
|
cc(arr, out);
|
|
|
|
EXPECT_EQ(2, out[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GArray, TestPipeline)
|
|
|
|
{
|
|
|
|
cv::GComputationT<cv::GScalar(cv::GMat)> c([](cv::GMat in)
|
|
|
|
{
|
|
|
|
return ThisTest::CountCorners::on(ThisTest::FindCorners::on(in));
|
|
|
|
});
|
|
|
|
auto cc = c.compile(cv::GMatDesc{CV_8U,1,{32,32}},
|
|
|
|
cv::compile_args(cv::gapi::kernels<OCVFindCorners, OCVCountCorners>()));
|
|
|
|
|
|
|
|
cv::Mat input = cross(32, 32);
|
|
|
|
cv::Scalar out;
|
|
|
|
cc(input, out);
|
|
|
|
EXPECT_EQ(5, out[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GArray, NoAggregationBetweenRuns)
|
|
|
|
{
|
|
|
|
cv::GComputationT<cv::GScalar(cv::GMat)> c([](cv::GMat in)
|
|
|
|
{
|
|
|
|
return ThisTest::CountCorners::on(ThisTest::GeneratePoints::on(in));
|
|
|
|
});
|
|
|
|
auto cc = c.compile(cv::GMatDesc{CV_8U,1,{32,32}},
|
|
|
|
cv::compile_args(cv::gapi::kernels<OCVGeneratePoints, OCVCountCorners>()));
|
|
|
|
|
|
|
|
cv::Mat input = cv::Mat::eye(32, 32, CV_8UC1);
|
|
|
|
cv::Scalar out;
|
|
|
|
|
|
|
|
cc(input, out);
|
|
|
|
EXPECT_EQ(10, out[0]);
|
|
|
|
|
|
|
|
// Last kernel in the graph counts number of elements in array, returned by the previous kernel
|
|
|
|
// (in this test, this variable is constant).
|
|
|
|
// After 10 executions, this number MUST remain the same - 1st kernel is adding new values on every
|
|
|
|
// run, but it is graph's responsibility to reset internal object state.
|
|
|
|
cv::Scalar out2;
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
cc(input, out2);
|
|
|
|
}
|
|
|
|
EXPECT_EQ(10, out2[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GArray, TestIntermediateOutput)
|
|
|
|
{
|
|
|
|
using Result = std::tuple<ThisTest::GPointArray, cv::GScalar>;
|
|
|
|
cv::GComputationT<Result(cv::GMat)> c([](cv::GMat in)
|
|
|
|
{
|
|
|
|
auto corners = ThisTest::GeneratePoints::on(in);
|
|
|
|
return std::make_tuple(corners, ThisTest::CountCorners::on(corners));
|
|
|
|
});
|
|
|
|
|
|
|
|
cv::Mat in_mat = cv::Mat::eye(32, 32, CV_8UC1);
|
|
|
|
std::vector<cv::Point> out_points;
|
|
|
|
cv::Scalar out_count;
|
|
|
|
|
|
|
|
auto cc = c.compile(cv::descr_of(in_mat),
|
|
|
|
cv::compile_args(cv::gapi::kernels<OCVGeneratePoints, OCVCountCorners>()));
|
|
|
|
cc(in_mat, out_points, out_count);
|
|
|
|
|
|
|
|
EXPECT_EQ(10u, out_points.size());
|
|
|
|
EXPECT_EQ(10, out_count[0]);
|
|
|
|
}
|
Merge pull request #15216 from dmatveev:dm/ng-0010-g-api-streaming-api
* G-API-NG/Streaming: Introduced a Streaming API
Now a GComputation can be compiled in a special "streaming" way
and then "played" on a video stream.
Currently only VideoCapture is supported as an input source.
* G-API-NG/Streaming: added threading & real streaming
* G-API-NG/Streaming: Added tests & docs on Copy kernel
- Added very simple pipeline tests, not all data types are covered yet
(in fact, only GMat is tested now);
- Started testing non-OCV backends in the streaming mode;
- Added required fixes to Fluid backend, likely it works OK now;
- Added required fixes to OCL backend, and now it is likely broken
- Also added a UMat-based (OCL) version of Copy kernel
* G-API-NG/Streaming: Added own concurrent queue class
- Used only if TBB is not available
* G-API-NG/Streaming: Fixing various issues
- Added missing header to CMakeLists.txt
- Fixed various CI issues and warnings
* G-API-NG/Streaming: Fixed a compile-time GScalar queue deadlock
- GStreamingExecutor blindly created island's input queues for
compile-time (value-initialized) GScalars which didn't have any
producers, making island actor threads wait there forever
* G-API-NG/Streaming: Dropped own version of Copy kernel
One was added into master already
* G-API-NG/Streaming: Addressed GArray<T> review comments
- Added tests on mov()
- Removed unnecessary changes in garray.hpp
* G-API-NG/Streaming: Added Doxygen comments to new public APIs
Also fixed some other comments in the code
* G-API-NG/Streaming: Removed debug info, added some comments & renamed vars
* G-API-NG/Streaming: Fixed own-vs-cv abstraction leak
- Now every island is triggered with own:: (instead of cv::)
data objects as inputs;
- Changes in Fluid backend required to support cv::Mat/Scalar were
reverted;
* G-API-NG/Streaming: use holds_alternative<> instead of index/index_of test
- Also fixed regression test comments
- Also added metadata check comments for GStreamingCompiled
* G-API-NG/Streaming: Made start()/stop() more robust
- Fixed various possible deadlocks
- Unified the shutdown code
- Added more tests covering different corner cases on start/stop
* G-API-NG/Streaming: Finally fixed Windows crashes
In fact the problem hasn't been Windows-only.
Island thread popped data from queues without preserving the Cmd
objects and without taking the ownership over data acquired so when
islands started to process the data, this data may be already freed.
Linux version worked only by occasion.
* G-API-NG/Streaming: Fixed (I hope so) Windows warnings
* G-API-NG/Streaming: fixed typos in internal comments
- Also added some more explanation on Streaming/OpenCL status
* G-API-NG/Streaming: Added more unit tests on streaming
- Various start()/stop()/setSource() call flow combinations
* G-API-NG/Streaming: Added tests on own concurrent bounded queue
* G-API-NG/Streaming: Added more tests on various data types, + more
- Vector/Scalar passed as input;
- Vector/Scalar passed in-between islands;
- Some more assertions;
- Also fixed a deadlock problem when inputs are mixed (1 constant, 1 stream)
* G-API-NG/Streaming: Added tests on output data types handling
- Vector
- Scalar
* G-API-NG/Streaming: Fixed test issues with IE + Windows warnings
* G-API-NG/Streaming: Decoupled G-API from videoio
- Now the core G-API doesn't use a cv::VideoCapture directly,
it comes in via an abstract interface;
- Polished a little bit the setSource()/start()/stop() semantics,
now setSource() is mandatory before ANY call to start().
* G-API-NG/Streaming: Fix STANDALONE build (errors brought by render)
2019-10-19 00:29:58 +08:00
|
|
|
|
|
|
|
TEST(GArray_VectorRef, TestMov)
|
|
|
|
{
|
|
|
|
// Warning: this test is testing some not-very-public APIs
|
|
|
|
// Test how VectorRef's mov() (aka poor man's move()) is working.
|
|
|
|
|
|
|
|
using I = int;
|
|
|
|
using V = std::vector<I>;
|
|
|
|
const V vgold = { 1, 2, 3};
|
|
|
|
V vtest = vgold;
|
|
|
|
const I* vptr = vtest.data();
|
|
|
|
|
|
|
|
cv::detail::VectorRef vref(vtest);
|
|
|
|
cv::detail::VectorRef vmov;
|
|
|
|
vmov.reset<I>();
|
|
|
|
|
|
|
|
EXPECT_EQ(vgold, vref.rref<I>());
|
|
|
|
|
|
|
|
vmov.mov(vref);
|
|
|
|
EXPECT_EQ(vgold, vmov.rref<I>());
|
|
|
|
EXPECT_EQ(vptr, vmov.rref<I>().data());
|
|
|
|
EXPECT_EQ(V{}, vref.rref<I>());
|
|
|
|
EXPECT_EQ(V{}, vtest);
|
|
|
|
}
|
2018-09-27 02:50:39 +08:00
|
|
|
} // namespace opencv_test
|