mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge pull request #20184 from sivanov-work:fix_gapi_empty_input
G-API: Add standalone fix for graph empty input * Add sandalone fix for graph empty input * Apply some review comments * Fix whitespace * Apply review comment: make Mat check more deeper * Apply some comments * Remove tracer apply exception throwing * Apply comments: move validatio into gproto_priv.hpp * Apply minor text correction * Fix alignment, remove try-catch
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "api/gorigin.hpp"
|
||||
#include "api/gproto_priv.hpp"
|
||||
#include "logger.hpp"
|
||||
|
||||
// FIXME: it should be a visitor!
|
||||
// FIXME: Reimplement with traits?
|
||||
@@ -201,6 +202,52 @@ bool cv::can_describe(const GMetaArgs &metas, const GRunArgs &args)
|
||||
});
|
||||
}
|
||||
|
||||
void cv::gimpl::proto::validate_input_meta_arg(const cv::GMetaArg& meta)
|
||||
{
|
||||
switch (meta.index())
|
||||
{
|
||||
case cv::GMetaArg::index_of<cv::GMatDesc>():
|
||||
{
|
||||
cv::gimpl::proto::validate_input_meta(cv::util::get<GMatDesc>(meta)); //may throw
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void cv::gimpl::proto::validate_input_meta(const cv::GMatDesc& meta)
|
||||
{
|
||||
if (meta.dims.empty())
|
||||
{
|
||||
if (!(meta.size.height > 0 && meta.size.width > 0))
|
||||
{
|
||||
cv::util::throw_error
|
||||
(std::logic_error(
|
||||
"Image format is invalid. Size must contain positive values"
|
||||
", got width: " + std::to_string(meta.size.width ) +
|
||||
(", height: ") + std::to_string(meta.size.height)));
|
||||
}
|
||||
|
||||
if (!(meta.chan > 0))
|
||||
{
|
||||
cv::util::throw_error
|
||||
(std::logic_error(
|
||||
"Image format is invalid. Channel mustn't be negative value, got channel: " +
|
||||
std::to_string(meta.chan)));
|
||||
}
|
||||
}
|
||||
|
||||
if (!(meta.depth >= 0))
|
||||
{
|
||||
cv::util::throw_error
|
||||
(std::logic_error(
|
||||
"Image format is invalid. Depth must be positive value, got depth: " +
|
||||
std::to_string(meta.depth)));
|
||||
}
|
||||
// All checks are ok
|
||||
}
|
||||
|
||||
// FIXME: Is it tested for all types?
|
||||
// FIXME: Where does this validation happen??
|
||||
void cv::validate_input_arg(const GRunArg& arg)
|
||||
@@ -212,13 +259,15 @@ void cv::validate_input_arg(const GRunArg& arg)
|
||||
case GRunArg::index_of<cv::UMat>():
|
||||
{
|
||||
const auto desc = cv::descr_of(util::get<cv::UMat>(arg));
|
||||
GAPI_Assert(desc.size.height != 0 && desc.size.width != 0 && "incorrect dimensions of cv::UMat!"); break;
|
||||
cv::gimpl::proto::validate_input_meta(desc); //may throw
|
||||
break;
|
||||
}
|
||||
#endif // !defined(GAPI_STANDALONE)
|
||||
case GRunArg::index_of<cv::Mat>():
|
||||
{
|
||||
const auto desc = cv::descr_of(util::get<cv::Mat>(arg));
|
||||
GAPI_Assert(desc.size.height != 0 && desc.size.width != 0 && "incorrect dimensions of Mat!"); break;
|
||||
cv::gimpl::proto::validate_input_meta(desc); //may throw
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// No extra handling
|
||||
@@ -228,9 +277,13 @@ void cv::validate_input_arg(const GRunArg& arg)
|
||||
|
||||
void cv::validate_input_args(const GRunArgs& args)
|
||||
{
|
||||
GAPI_LOG_DEBUG(nullptr, "Total count: " << args.size());
|
||||
size_t index = 0;
|
||||
for (const auto& arg : args)
|
||||
{
|
||||
GAPI_LOG_DEBUG(nullptr, "Process index: " << index);
|
||||
validate_input_arg(arg);
|
||||
index ++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@ GProtoArg rewrap (const GArg &arg);
|
||||
// FIXME:: GAPI_EXPORTS because of tests only!!
|
||||
GAPI_EXPORTS const void* ptr (const GRunArgP &arg);
|
||||
|
||||
void validate_input_meta_arg(const GMetaArg& meta);
|
||||
void validate_input_meta(const GMatDesc& meta);
|
||||
|
||||
} // proto
|
||||
} // gimpl
|
||||
} // cv
|
||||
|
||||
@@ -343,19 +343,26 @@ void cv::gimpl::GCompiler::validateInputMeta()
|
||||
return false; // should never happen
|
||||
};
|
||||
|
||||
GAPI_LOG_DEBUG(nullptr, "Total count: " << m_metas.size());
|
||||
for (const auto meta_arg_idx : ade::util::indexed(ade::util::zip(m_metas, c_expr.m_ins)))
|
||||
{
|
||||
const auto &meta = std::get<0>(ade::util::value(meta_arg_idx));
|
||||
const auto &proto = std::get<1>(ade::util::value(meta_arg_idx));
|
||||
|
||||
const auto index = ade::util::index(meta_arg_idx);
|
||||
GAPI_LOG_DEBUG(nullptr, "Process index: " << index);
|
||||
|
||||
// check types validity
|
||||
if (!meta_matches(meta, proto))
|
||||
{
|
||||
const auto index = ade::util::index(meta_arg_idx);
|
||||
util::throw_error(std::logic_error
|
||||
("GComputation object type / metadata descriptor mismatch "
|
||||
"(argument " + std::to_string(index) + ")"));
|
||||
// FIXME: report what we've got and what we've expected
|
||||
}
|
||||
|
||||
// check value consistency
|
||||
gimpl::proto::validate_input_meta_arg(meta); //may throw
|
||||
}
|
||||
// All checks are ok
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class GAPI_EXPORTS GCompiler
|
||||
cv::gapi::GKernelPackage m_all_kernels;
|
||||
cv::gapi::GNetPackage m_all_networks;
|
||||
|
||||
// Patters built from transformations
|
||||
// Patterns built from transformations
|
||||
std::vector<std::unique_ptr<ade::Graph>> m_all_patterns;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user