diff --git a/modules/gapi/include/opencv2/gapi/gproto.hpp b/modules/gapi/include/opencv2/gapi/gproto.hpp index fe4d3dcb78..921a588305 100644 --- a/modules/gapi/include/opencv2/gapi/gproto.hpp +++ b/modules/gapi/include/opencv2/gapi/gproto.hpp @@ -126,6 +126,10 @@ bool GAPI_EXPORTS can_describe(const GMetaArgs& metas, const GRunArgs& args); // coincides with output arguments passed to computation in cpu and ocl backends bool GAPI_EXPORTS can_describe(const GMetaArg& meta, const GRunArgP& argp); +// Validates input arguments +void GAPI_EXPORTS validate_input_arg(const GRunArg& arg); +void GAPI_EXPORTS validate_input_args(const GRunArgs& args); + } // namespace cv #endif // OPENCV_GAPI_GPROTO_HPP diff --git a/modules/gapi/src/api/gproto.cpp b/modules/gapi/src/api/gproto.cpp index c4cfca6a86..e541ba2092 100644 --- a/modules/gapi/src/api/gproto.cpp +++ b/modules/gapi/src/api/gproto.cpp @@ -197,6 +197,42 @@ bool cv::can_describe(const GMetaArgs &metas, const GRunArgs &args) }); } +void cv::validate_input_arg(const GRunArg& arg) +{ + // FIXME: It checks only Mat argument + switch (arg.index()) + { +#if !defined(GAPI_STANDALONE) + case GRunArg::index_of(): + { + const auto desc = descr_of(util::get(arg)); + GAPI_Assert(desc.size.height != 0 && desc.size.width != 0 && "incorrect dimensions of cv::Mat!"); break; + } + case GRunArg::index_of(): + { + const auto desc = descr_of(util::get(arg)); + GAPI_Assert(desc.size.height != 0 && desc.size.width != 0 && "incorrect dimensions of cv::UMat!"); break; + } +#endif // !defined(GAPI_STANDALONE) + case GRunArg::index_of(): + { + const auto desc = descr_of(util::get(arg)); + GAPI_Assert(desc.size.height != 0 && desc.size.width != 0 && "incorrect dimensions of own::Mat!"); break; + } + default: + // No extra handling + break; + } +} + +void cv::validate_input_args(const GRunArgs& args) +{ + for (const auto& arg : args) + { + validate_input_arg(arg); + } +} + namespace cv { std::ostream& operator<<(std::ostream& os, const cv::GMetaArg &arg) { diff --git a/modules/gapi/src/compiler/gcompiled.cpp b/modules/gapi/src/compiler/gcompiled.cpp index b277257513..bc1d76c79f 100644 --- a/modules/gapi/src/compiler/gcompiled.cpp +++ b/modules/gapi/src/compiler/gcompiled.cpp @@ -56,6 +56,7 @@ void cv::GCompiled::Priv::checkArgs(const cv::gimpl::GRuntimeArgs &args) const "for different metadata!")); // FIXME: Add details on what is actually wrong } + validate_input_args(args.inObjs); } bool cv::GCompiled::Priv::canReshape() const diff --git a/modules/gapi/test/own/mat_tests.cpp b/modules/gapi/test/own/mat_tests.cpp index fa3407a074..215961109f 100644 --- a/modules/gapi/test/own/mat_tests.cpp +++ b/modules/gapi/test/own/mat_tests.cpp @@ -607,4 +607,28 @@ TEST(OwnMat, CreateWithNegativeHeight) ASSERT_ANY_THROW(own_mat.create(cv::Size{1, -1}, CV_8U)); } +TEST(OwnMat, ZeroHeightMat) +{ + cv::GMat in, a, b, c, d; + std::tie(a, b, c, d) = cv::gapi::split4(in); + cv::GMat out = cv::gapi::merge3(a, b, c); + cv::Mat in_mat(cv::Size(8, 0), CV_8UC4); + cv::Mat out_mat(cv::Size(8, 8), CV_8UC3); + cv::GComputation comp(cv::GIn(in), cv::GOut(out)); + ASSERT_ANY_THROW(comp.apply(cv::gin(in_mat), cv::gout(out_mat), + cv::compile_args(cv::gapi::core::fluid::kernels()))); +} + +TEST(OwnMat, ZeroWidthMat) +{ + cv::GMat in, a, b, c, d; + std::tie(a, b, c, d) = cv::gapi::split4(in); + cv::GMat out = cv::gapi::merge3(a, b, c); + cv::Mat in_mat(cv::Size(0, 8), CV_8UC4); + cv::Mat out_mat(cv::Size(8, 8), CV_8UC3); + cv::GComputation comp(cv::GIn(in), cv::GOut(out)); + ASSERT_ANY_THROW(comp.apply(cv::gin(in_mat), cv::gout(out_mat), + cv::compile_args(cv::gapi::core::fluid::kernels()))); +} + } // namespace opencv_test