Merge pull request #16604 from Volskig:mp/ocv-gapi-zero-height-mat

G-API: Zero-height mat is cause of crash

* Added check for zero-height Mat case

* Refactoring, added validate_input_arg func

* No bool function now
pull/16771/head
Maxim Pashchenkov 5 years ago committed by GitHub
parent 27b71d6368
commit 3befdb4ae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      modules/gapi/include/opencv2/gapi/gproto.hpp
  2. 36
      modules/gapi/src/api/gproto.cpp
  3. 1
      modules/gapi/src/compiler/gcompiled.cpp
  4. 24
      modules/gapi/test/own/mat_tests.cpp

@ -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

@ -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<cv::Mat>():
{
const auto desc = descr_of(util::get<cv::Mat>(arg));
GAPI_Assert(desc.size.height != 0 && desc.size.width != 0 && "incorrect dimensions of cv::Mat!"); break;
}
case GRunArg::index_of<cv::UMat>():
{
const auto desc = descr_of(util::get<cv::UMat>(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<cv::gapi::own::Mat>():
{
const auto desc = descr_of(util::get<cv::gapi::own::Mat>(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)
{

@ -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

@ -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

Loading…
Cancel
Save