nareshmlx/opencv-pr huggingface dataset:
**File:** modules/imgcodecs/test/test_grfmt.cpp
**Change Type:** modified
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...
**Review Line:** 74

**Code Changes:**
```diff
@@ -71,7 +71,8 @@ TEST_P(Imgcodecs_FileMode, regression)
 
 const string all_images[] =
 {
-#if defined(HAVE_JASPER) && defined(OPENCV_IMGCODECS_ENABLE_JASPER_TESTS)
+#if (defined(HAVE_JASPER) && defined(OPENCV_IMGCODECS_ENABLE_JASPER_TESTS)) \
+    || defined(HAVE_OPENJPEG)
     "readwrite/Rome.jp2",
     "readwrite/Bretagne2.jp2",
     "readwrite/Bretagne2.jp2",
```

Review comment:
Please use: ``` #if (defined(HAVE_JASPER) && defined(OPENCV_IMGCODECS_ENABLE_JASPER_TESTS)) \ || HAVE_OPENJPEG ``` and revert related changes in CMake file.
**File:** modules/imgcodecs/test/test_read_write.cpp
**Change Type:** modified
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...

**Code Changes:**
```diff
@@ -194,7 +194,8 @@ const string exts[] = {
 #ifdef HAVE_JPEG
     "jpg",
 #endif
-#if defined(HAVE_JASPER) && defined(OPENCV_IMGCODECS_ENABLE_JASPER_TESTS)
+#if (defined(HAVE_JASPER) && defined(OPENCV_IMGCODECS_ENABLE_JASPER_TESTS)) \
+    || defined(HAVE_OPENJPEG)
     "jp2",
 #endif
 #if 0 /*defined HAVE_OPENEXR && !defined __APPLE__*/
```

Review comment:
Lets revert this condition until we will have encoder implementation.
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...
**Review Line:** 1247

**Code Changes:**
```diff
+if(HAVE_OPENJPEG)
+  status("    JPEG 2000:" "OpenJPEG (ver ${OPENJPEG_MAJOR_VERSION}.${OPENJPEG_MINOR_VERSION}.${OPENJPEG_BUILD_VERSION})")
+elseif(HAVE_JASPER)
+  status("    JPEG 2000:" JASPER_FOUND THEN "${JASPER_LIBRARY} (ver ${JASPER_VERSION_STRING})" ELSE "build Jasper (ver ${JASPER_VERSION_STRING})")
+elseif(WITH_OPENJPEG OR WITH_JASPER)
+  status("    JPEG 2000:" "NO")
 endif()
 
 if(WITH_OPENEXR OR HAVE_OPENEXR)
```

Review comment:
Let use this scheme: ``` if(HAVE_OPENJPEG) ... elseif(HAVE_JASPER) ... elseif(WITH_OPENJPEG OR WITH_JASPER) status(" JPEG 2000:" "NO") endif() ```
**File:** modules/imgcodecs/src/loadsave.cpp
**Change Type:** modified
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...

**Code Changes:**
```diff
@@ -176,6 +176,10 @@ struct ImageCodecInitializer
         decoders.push_back( makePtr<Jpeg2KDecoder>() );
         encoders.push_back( makePtr<Jpeg2KEncoder>() );
     #endif
+    #ifdef HAVE_OPENJPEG
+        decoders.push_back( makePtr<Jpeg2KOpjDecoder>() );
+        encoders.push_back( makePtr<Jpeg2KOpjEncoder>() );
+    #endif
     #ifdef HAVE_OPENEXR
         decoders.push_back( makePtr<ExrDecoder>() );
```

Review comment:
To avoid confusion (for example, in stacktraces) it makes sense to use different name, like `OpenJpegDecoder`.
**File:** modules/imgcodecs/src/loadsave.cpp
**Change Type:** modified
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...

**Code Changes:**
```diff
@@ -176,6 +176,10 @@ struct ImageCodecInitializer
         decoders.push_back( makePtr<Jpeg2KDecoder>() );
         encoders.push_back( makePtr<Jpeg2KEncoder>() );
     #endif
+    #ifdef HAVE_OPENJPEG
+        decoders.push_back( makePtr<Jpeg2KOpjDecoder>() );
+        encoders.push_back( makePtr<Jpeg2KOpjEncoder>() );
+    #endif
     #ifdef HAVE_OPENEXR
         decoders.push_back( makePtr<ExrDecoder>() );
```

Review comment:
how about `Jpeg2KOpjDecoder`?
**File:** modules/imgcodecs/test/test_grfmt.cpp
**Change Type:** modified
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...
**Review Line:** 74

**Code Changes:**
```diff
@@ -71,7 +71,8 @@ TEST_P(Imgcodecs_FileMode, regression)
 
 const string all_images[] =
 {
-#if defined(HAVE_JASPER) && defined(OPENCV_IMGCODECS_ENABLE_JASPER_TESTS)
+#if (defined(HAVE_JASPER) && defined(OPENCV_IMGCODECS_ENABLE_JASPER_TESTS)) \
+    || defined(HAVE_OPENJPEG)
     "readwrite/Rome.jp2",
     "readwrite/Bretagne2.jp2",
     "readwrite/Bretagne2.jp2",
```

Review comment:
You need to use `\` with multi-line directives.
**File:** modules/imgcodecs/test/test_grfmt.cpp
**Change Type:** modified
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...
**Review Line:** 74

**Code Changes:**
```diff
@@ -71,7 +71,8 @@ TEST_P(Imgcodecs_FileMode, regression)
 
 const string all_images[] =
 {
-#if defined(HAVE_JASPER) && defined(OPENCV_IMGCODECS_ENABLE_JASPER_TESTS)
+#if (defined(HAVE_JASPER) && defined(OPENCV_IMGCODECS_ENABLE_JASPER_TESTS)) \
+    || defined(HAVE_OPENJPEG)
     "readwrite/Rome.jp2",
     "readwrite/Bretagne2.jp2",
     "readwrite/Bretagne2.jp2",
```

Review comment:
CI already told me ;-)
**File:** modules/imgcodecs/src/loadsave.cpp
**Change Type:** modified
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...

**Code Changes:**
```diff
@@ -176,6 +176,10 @@ struct ImageCodecInitializer
         decoders.push_back( makePtr<Jpeg2KDecoder>() );
         encoders.push_back( makePtr<Jpeg2KEncoder>() );
     #endif
+    #ifdef HAVE_OPENJPEG
+        decoders.push_back( makePtr<Jpeg2KOpjDecoder>() );
+        encoders.push_back( makePtr<Jpeg2KOpjEncoder>() );
+    #endif
     #ifdef HAVE_OPENEXR
         decoders.push_back( makePtr<ExrDecoder>() );
```

Review comment:
its Jpeg2KOpjDecoder now
**File:** modules/imgcodecs/test/test_read_write.cpp
**Change Type:** modified
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...

**Code Changes:**
```diff
@@ -194,7 +194,8 @@ const string exts[] = {
 #ifdef HAVE_JPEG
     "jpg",
 #endif
-#if defined(HAVE_JASPER) && defined(OPENCV_IMGCODECS_ENABLE_JASPER_TESTS)
+#if (defined(HAVE_JASPER) && defined(OPENCV_IMGCODECS_ENABLE_JASPER_TESTS)) \
+    || defined(HAVE_OPENJPEG)
     "jp2",
 #endif
 #if 0 /*defined HAVE_OPENEXR && !defined __APPLE__*/
```

Review comment:
started an encoder branch on top of this one and moved it there https://github.com/StefanBruens/opencv/tree/jpeg2000_openjpeg_encoder
**File:** modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp
**Change Type:** added
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...
**Review Line:** 191

**Code Changes:**
```diff
+inline ChannelsIterator<Traits> operator+(typename Traits::difference_type n, const ChannelsIterator<Traits>& it)
+{
+    return it + n;
+}
+
+template<typename OutT, typename InT>
+void copyToMatImpl(std::vector<InT*>&& in, Mat& out, uint8_t shift)
+{
+    using ChannelsIt = ChannelsIterator<NonConstItTraits<OutT>>;
+
+    Size size = out.size();
```

Review comment:
doShift is a template parameter for a reason ... do not evaluate it for every pixel
**File:** modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp
**Change Type:** added
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...
**Review Line:** 191

**Code Changes:**
```diff
+inline ChannelsIterator<Traits> operator+(typename Traits::difference_type n, const ChannelsIterator<Traits>& it)
+{
+    return it + n;
+}
+
+template<typename OutT, typename InT>
+void copyToMatImpl(std::vector<InT*>&& in, Mat& out, uint8_t shift)
+{
+    using ChannelsIt = ChannelsIterator<NonConstItTraits<OutT>>;
+
+    Size size = out.size();
```

Review comment:
Actually it is evaluated once per image, basically it is possible to split functions to not evaluate `isShiftRequered` every *row* and *channel*, but for continueus mat it is evaluated only *channel* times
**File:** modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp
**Change Type:** added
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...

**Code Changes:**
```diff
@@ -0,0 +1,762 @@
+// 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) 2020, Stefan Brüns <stefan.bruens@rwth-aachen.de>
+
+#include "precomp.hpp"
+
+#ifdef HAVE_OPENJPEG
```

Review comment:
> CV_LOG_ERROR(nullptr Please use `NULL` for logger tags. It is designed as a part of identifier (`nullptr` would be broken in the future).
**File:** modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp
**Change Type:** added
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...
**Review Line:** 340

**Code Changes:**
```diff
+            parameters.tcp_rates[0] = 1000.f / std::min(std::max(params[i + 1], 1), 1000);
+            break;
+        default:
+            CV_LOG_WARNING(NULL, "OpenJPEG2000(encoder): skip unsupported parameter: " << params[i]);
+            break;
+        }
+    }
+    parameters.tcp_numlayers = 1;
+    parameters.cp_disto_alloc = 1;
+    return parameters;
+}
```

Review comment:
``` default: CV_LOG_WARNING(NULL, "OpenJPEG2000(encoder): skip unsupported parameter: " << params[i]) ``` ?
**File:** modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp
**Change Type:** added
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...

**Code Changes:**
```diff
@@ -0,0 +1,762 @@
+// 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) 2020, Stefan Brüns <stefan.bruens@rwth-aachen.de>
+
+#include "precomp.hpp"
+
+#ifdef HAVE_OPENJPEG
```

Review comment:
Add `falltru` comment to avoid compiler warnings: ``` CV_LOG_WARNING(nullptr, "OpenJPEG2000: Image has unknown color space, SRGB is assumed"); // fallthru case OPJ_CLRSPC_SRGB: ```
**File:** modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp
**Change Type:** added
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...
**Review Line:** 654

**Code Changes:**
```diff
+{
+    CV_Assert(params.size() % 2 == 0);
+
+    const int channels = img.channels();
+    CV_DbgAssert(channels > 0); // passed matrix is not empty
+    if (channels > 4)
+    {
+        CV_Error(Error::StsNotImplemented, "OpenJPEG2000: only BGR(a) and gray (+ alpha) images supported");
+    }
+
+    const int depth = img.depth();
```

Review comment:
`CV_DbgAssert(channels > 0); // passed matrix is not empty`
**File:** modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp
**Change Type:** added
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...

**Code Changes:**
```diff
@@ -0,0 +1,762 @@
+// 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) 2020, Stefan Brüns <stefan.bruens@rwth-aachen.de>
+
+#include "precomp.hpp"
+
+#ifdef HAVE_OPENJPEG
```

Review comment:
> m_filename.c_str() Looks like `imdecode()` from in-memory buffers is not supported at this moment.
**File:** modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp
**Change Type:** added
**Context:** PR #16494: RFC: Jpeg2000 OpenJPEG port - resolves #5849 relates #14058 Currently missing/incomplete: - [x] Write support - [ ] Reading of "signed" com...

**Code Changes:**
```diff
@@ -0,0 +1,762 @@
+// 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) 2020, Stefan Brüns <stefan.bruens@rwth-aachen.de>
+
+#include "precomp.hpp"
+
+#ifdef HAVE_OPENJPEG
```

Review comment:
Added support, based on the following PR: * [PR 583](https://github.com/uclouvain/openjpeg/pull/583) * [PR 1212](https://github.com/uclouvain/openjpeg/pull/1212)
**File:** modules/videoio/src/cap_ffmpeg_impl.hpp
**Change Type:** modified
**Context:** PR #9292: Using environment variable to store capture options - String is parsed by av_dict_parse_string(ENV{OPENCV_FFMPEG_CAPTURE_OPTIONS}, ";", "|")...

**Code Changes:**
```diff
@@ -781,7 +781,23 @@ bool CvCapture_FFMPEG::open( const char* _filename )
 #endif
 
 #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
+#ifndef NO_GETENV
+    char* options = getenv("OPENCV_FFMPEG_CAPTURE_OPTIONS");
+    if(options == NULL)
+    {
+        av_dict_set(&dict, "rtsp_transport", "tcp", 0);
+    }
```

Review comment:
Why is this change here? - Condition must be ">=". ">" should not be used at all for version checks. - Perhaps we should check for [53.4.0](https://github.com/FFmpeg/FFmpeg/blob/c79e7534712fa9e95a9ddde2c5e8c6815f5f2f6f/doc/APIchanges#L1986) (avformat_open_input) - These change must be propagated to many places with "dict" (av_dict_free / declaration / etc)
**File:** modules/videoio/src/cap_ffmpeg_impl.hpp
**Change Type:** modified
**Context:** PR #9292: Using environment variable to store capture options - String is parsed by av_dict_parse_string(ENV{OPENCV_FFMPEG_CAPTURE_OPTIONS}, ";", "|")...

**Code Changes:**
```diff
@@ -781,7 +781,23 @@ bool CvCapture_FFMPEG::open( const char* _filename )
 #endif
 
 #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
+#ifndef NO_GETENV
+    char* options = getenv("OPENCV_FFMPEG_CAPTURE_OPTIONS");
+    if(options == NULL)
+    {
+        av_dict_set(&dict, "rtsp_transport", "tcp", 0);
+    }
```

Review comment:
["lavu 52.17.100 / 52.7.0"](https://github.com/FFmpeg/FFmpeg/blob/c79e7534712fa9e95a9ddde2c5e8c6815f5f2f6f/doc/APIchanges#L1462) ``` #if LIBAVUTIL_BUILD >= (LIBAVUTIL_VERSION_MICRO >= 100 ? CALC_FFMPEG_VERSION(52, 17, 100) : CALC_FFMPEG_VERSION(52, 7, 0)) ```
**File:** modules/videoio/src/cap_ffmpeg_impl.hpp
**Change Type:** modified
**Context:** PR #9292: Using environment variable to store capture options - String is parsed by av_dict_parse_string(ENV{OPENCV_FFMPEG_CAPTURE_OPTIONS}, ";", "|")...

**Code Changes:**
```diff
@@ -781,7 +781,23 @@ bool CvCapture_FFMPEG::open( const char* _filename )
 #endif
 
 #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
+#ifndef NO_GETENV
+    char* options = getenv("OPENCV_FFMPEG_CAPTURE_OPTIONS");
+    if(options == NULL)
+    {
+        av_dict_set(&dict, "rtsp_transport", "tcp", 0);
+    }
```

Review comment:
Ah crap, this is a mistake. Sorry about the sloppy commits.
**File:** modules/videoio/src/cap_ffmpeg_impl.hpp
**Change Type:** modified
**Context:** PR #9292: Using environment variable to store capture options - String is parsed by av_dict_parse_string(ENV{OPENCV_FFMPEG_CAPTURE_OPTIONS}, ";", "|")...

**Code Changes:**
```diff
@@ -781,7 +781,23 @@ bool CvCapture_FFMPEG::open( const char* _filename )
 #endif
 
 #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
+#ifndef NO_GETENV
+    char* options = getenv("OPENCV_FFMPEG_CAPTURE_OPTIONS");
+    if(options == NULL)
+    {
+        av_dict_set(&dict, "rtsp_transport", "tcp", 0);
+    }
```

Review comment:
With regards to 53.4.0, that makes sense to me. However, I am already making mistakes with regards to ffmpeg version checks, so ideally I would make as few changes as possible.
**File:** cmake/OpenCVModule.cmake
**Change Type:** modified
**Context:** PR #16756: cmake: allow extra compile options for tests - Goal is tuning of build process for OpenCV accuracy tests: - speedup through applying `-O1` ...
**Review Line:** 1114

**Code Changes:**
```diff
@@ -1111,6 +1111,8 @@ macro(__ocv_parse_test_sources tests_type)
   unset(__currentvar)
 endmacro()
 
+ocv_check_environment_variables(OPENCV_TEST_EXTRA_CXX_FLAGS_Release)
+
 # this is a command for adding OpenCV performance tests to the module
 # ocv_add_perf_tests(<extra_dependencies>)
 function(ocv_add_perf_tests)
@@ -1257,6 +1259,10 @@ function(ocv_add_accuracy_tests)
```

Review comment:
Why not cmake option? Cmake option is more obvious: - mentioned in root list and documented - is present in build logs
**File:** cmake/OpenCVModule.cmake
**Change Type:** modified
**Context:** PR #16756: cmake: allow extra compile options for tests - Goal is tuning of build process for OpenCV accuracy tests: - speedup through applying `-O1` ...
**Review Line:** 1114

**Code Changes:**
```diff
@@ -1111,6 +1111,8 @@ macro(__ocv_parse_test_sources tests_type)
   unset(__currentvar)
 endmacro()
 
+ocv_check_environment_variables(OPENCV_TEST_EXTRA_CXX_FLAGS_Release)
+
 # this is a command for adding OpenCV performance tests to the module
 # ocv_add_perf_tests(<extra_dependencies>)
 function(ocv_add_perf_tests)
@@ -1257,6 +1259,10 @@ function(ocv_add_accuracy_tests)
```

Review comment:
It still can be used as cmake command-line parameter. > list Current list of options is already huge. My suggestion is to keep this option "internal", we really don't want to promote this option.
**File:** cmake/OpenCVModule.cmake
**Change Type:** modified
**Context:** PR #16756: cmake: allow extra compile options for tests - Goal is tuning of build process for OpenCV accuracy tests: - speedup through applying `-O1` ...
**Review Line:** 1114

**Code Changes:**
```diff
@@ -1111,6 +1111,8 @@ macro(__ocv_parse_test_sources tests_type)
   unset(__currentvar)
 endmacro()
 
+ocv_check_environment_variables(OPENCV_TEST_EXTRA_CXX_FLAGS_Release)
+
 # this is a command for adding OpenCV performance tests to the module
 # ocv_add_perf_tests(<extra_dependencies>)
 function(ocv_add_perf_tests)
@@ -1257,6 +1259,10 @@ function(ocv_add_accuracy_tests)
```

Review comment:
May it option not in root list, but the module list then?
**File:** modules/calib3d/include/opencv2/calib3d.hpp
**Change Type:** modified
**Context:** PR #16498: Expose maxIters in findFundamentalMat - Lets the user choose the maximum number of iterations the robust estimator runs for, similary to fi...

**Code Changes:**
```diff
@@ -1905,6 +1905,7 @@ point localization, image resolution, and the image noise.
 @param confidence Parameter used for the RANSAC and LMedS methods only. It specifies a desirable level
 of confidence (probability) that the estimated matrix is correct.
 @param mask
+@param maxIters The maximum number of robust method iterations.
 
 The epipolar geometry is described by the following equation:
 
@@ -1938,6 +1939,11 @@ stereoRectifyUncalibrated to compute the rectification transformation. :
      findFundamentalMat(points1, points2, FM_RANSAC, 3, 0.99);
```

Review comment:
This change violates OpenCV parameters order policy: - input_arrays - output_arrays (or function return if single output) - algo_parameters - optional_algo_parameters_with_default_values - optional_output_arrays - optional_other_output
**File:** modules/gapi/src/api/gproto.cpp
**Change Type:** modified
**Context:** PR #16604: G-API: Zero-height mat is cause of crash - ### Zero-height mat is cause of crash cv::GMat in; cv::GMat a, b, c, d; std::tie(a, b, c, d) = c...

**Code Changes:**
```diff
@@ -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)
```

Review comment:
There's no need to check every argument, you can return `false` early once you find a match. ALSO: `std::any_of`
**File:** modules/gapi/src/api/gproto.cpp
**Change Type:** modified
**Context:** PR #16604: G-API: Zero-height mat is cause of crash - ### Zero-height mat is cause of crash cv::GMat in; cv::GMat a, b, c, d; std::tie(a, b, c, d) = c...

**Code Changes:**
```diff
@@ -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)
```

Review comment:
what you actually need here is `holds_alternative`.
**File:** modules/gapi/src/api/gproto.cpp
**Change Type:** modified
**Context:** PR #16604: G-API: Zero-height mat is cause of crash - ### Zero-height mat is cause of crash cv::GMat in; cv::GMat a, b, c, d; std::tie(a, b, c, d) = c...

**Code Changes:**
```diff
@@ -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)
```

Review comment:
Also I'd refactor the code in other form. Lets have a function like `validate_input_arg` which itself takes a `GRunArg` and checks if the parameter is valid based on its type. If anything wrong for, say, Mat, you just throw an exception.
**File:** modules/gapi/src/api/gproto.cpp
**Change Type:** modified
**Context:** PR #16604: G-API: Zero-height mat is cause of crash - ### Zero-height mat is cause of crash cv::GMat in; cv::GMat a, b, c, d; std::tie(a, b, c, d) = c...

**Code Changes:**
```diff
@@ -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)
```

Review comment:
And yes, please start with `GRunArgs` not `GMetaArgs`.
**File:** modules/gapi/src/api/gproto.cpp
**Change Type:** modified
**Context:** PR #16604: G-API: Zero-height mat is cause of crash - ### Zero-height mat is cause of crash cv::GMat in; cv::GMat a, b, c, d; std::tie(a, b, c, d) = c...

**Code Changes:**
```diff
@@ -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)
```

Review comment:
Fixed. Another form of validation. Is it?
**File:** modules/gapi/include/opencv2/gapi/gproto.hpp
**Change Type:** modified
**Context:** PR #16604: G-API: Zero-height mat is cause of crash - ### Zero-height mat is cause of crash cv::GMat in; cv::GMat a, b, c, d; std::tie(a, b, c, d) = c...

**Code Changes:**
```diff
@@ -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
 
```

Review comment:
What's the reason in `bool` return type here if the function throws?