nareshmlx/opencv-pr huggingface dataset:
**File:** modules/videoio/src/cap_ffmpeg_impl.hpp
**Change Type:** modified
**Context:** PR #27691: FFmpeg 8.0 support.
**Review Line:** 690

**Code Changes:**
```diff
     if( video_st )
     {
 #ifdef CV_FFMPEG_CODECPAR
+// avcodec_close removed in FFmpeg release 8.0
+# if (LIBAVCODEC_BUILD < CALC_FFMPEG_VERSION(62, 11, 100))
         avcodec_close( context );
+# endif
 #endif
         video_st = NULL;
     }
@@ -2005,7 +2008,18 @@ void CvCapture_FFMPEG::get_rotation_angle()
```

Review comment:
There is avcodec_free_context at line 699. Is not it enough?
**File:** modules/videoio/src/cap_ffmpeg_impl.hpp
**Change Type:** modified
**Context:** PR #27691: FFmpeg 8.0 support.
**Review Line:** 2020

**Code Changes:**
```diff
+    AVPacketSideData* sd = video_st->codecpar->coded_side_data;
+    int nb_sd = video_st->codecpar->nb_coded_side_data;
+    if (sd && nb_sd > 0)
+    {
+        const AVPacketSideData* mtx = av_packet_side_data_get(sd,  nb_sd, AV_PKT_DATA_DISPLAYMATRIX);
+        data = mtx->data;
+    }
+# endif
     if (data)
     {
         rotation_angle = -cvRound(av_display_rotation_get((const int32_t*)data));
```

Review comment:
This segfaults if `av_packet_side_data_get` returns NULL. Which is does if there is no side data present. See https://ffmpeg.org/doxygen/8.0/group__lavc__packet__side__data.html#ga61a3a0fba92a308208c8ab957472d23c. This showed up in `videoio_encapsulate.write/7` of `opencv_test_videoio`.
**File:** samples/python/multiview_calibration.py
**Change Type:** modified
**Context:** PR #27651: fix empty intrinsics handling and minor calibration improvements

**Code Changes:**
```diff
@@ -18,9 +18,10 @@
 import numpy as np
 import yaml
 import math
+import warnings
 
 def insideImageMask(pts, w, h):
-    return np.logical_and(np.logical_and(pts[0] < w, pts[1] < h), np.logical_and(pts[0] > 0, pts[1] > 0))
+    return (pts[0] >= 0) & (pts[0] <= w - 1) & (pts[1] >= 0) & (pts[1] <= h - 1)
 
```

Review comment:
I propose to print a message that the same K and distortion is applied for all cameras.
**File:** modules/dnn/src/layers/nary_eltwise_layers.cpp
**Change Type:** modified
**Context:** PR #27710: Added Pow layer to new DNN engine
**Review Line:** 792

**Code Changes:**
```diff
         }
 
-        int type_for_dispatch = op == OPERATION::WHERE ? outputs.front().type() : inputs.front().type();
-        typeDispatch(type_for_dispatch, inputs.size(), inputs, outputs);
+        std::vector<Mat> used_inputs = inputs;
+        if (op == OPERATION::POW) {
+            CV_Assert(used_inputs.size() == 2);
+            const int out_type = outputs[0].type();
+            if (used_inputs[0].type() != out_type || used_inputs[1].type() != out_type) {
+                Mat a_conv, b_conv;
+                used_inputs[0].convertTo(a_conv, out_type);
```

Review comment:
why Pow does not use the broadcasting mechanism of all other binary operations (such as SUB or DIV)?
**File:** modules/dnn/src/layers/is_inf_layer.cpp
**Change Type:** added
**Context:** PR #27660: Added IsInf layer to new DNN engine
**Review Line:** 7

**Code Changes:**
```diff
+// 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) 2025, BigVision LLC, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include "opencv2/core/fast_math.hpp"  // for cvIsInf
+
+namespace cv {
+namespace dnn {
```

Review comment:
please, put the link to description of the operation at onnx.ai and also specify, which opsets are supported.
**File:** modules/dnn/src/layers/is_inf_layer.cpp
**Change Type:** added
**Context:** PR #27660: Added IsInf layer to new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,122 @@
+// 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) 2025, BigVision LLC, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include "opencv2/core/fast_math.hpp"  // for cvIsInf
```

Review comment:
I would split this into different loops: ``` if (detectPositive && detectNegative) { for (...) ... // just check for cvIsInf() } else if (detectPositive) { for (...) ... // cvIsInf(v) && v > 0 } else if (detectNegative) { for (...) ... // cvIsInf(v) && v < 0 } else { // report error? } ```
**File:** modules/dnn/src/layers/is_inf_layer.cpp
**Change Type:** added
**Context:** PR #27660: Added IsInf layer to new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,122 @@
+// 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) 2025, BigVision LLC, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include "opencv2/core/fast_math.hpp"  // for cvIsInf
```

Review comment:
it would be nice to make this loop parallel just to eliminate possible bottlenecks when everything else in the model graph is parallel
**File:** modules/dnn/src/layers/is_inf_layer.cpp
**Change Type:** added
**Context:** PR #27660: Added IsInf layer to new DNN engine
**Review Line:** 112

**Code Changes:**
```diff
+        const size_t total = X.total();
+        uchar* dst = Y.ptr<uchar>();
+
+        switch (depth) {
+            case CV_32F: computeIsInfMask<float>(X.ptr<float>(), dst, total, detect_pos, detect_neg);    break;
+            case CV_64F: computeIsInfMask<double>(X.ptr<double>(), dst, total, detect_pos, detect_neg);   break;
+            case CV_16F: computeIsInfMask<hfloat, float>(X.ptr<hfloat>(), dst, total, detect_pos, detect_neg); break;
+            case CV_16BF: computeIsInfMask<bfloat, float>(X.ptr<bfloat>(), dst, total, detect_pos, detect_neg); break;
+            default: CV_Error_(Error::StsError, ("IsInf: Unsupported type depth=%d", depth));
+        }
+    }
```

Review comment:
bfloat and hfloat should be supported as well. 1) Add optional WT=T parameter to computeIsInfMask. 2) Change `T v = src[i];` to `WT v = WT(src[i]);`. 3) use WT=float for hfloat and bfloat
**File:** modules/dnn/src/layers/cpu_kernels/convolution.cpp
**Change Type:** renamed
**Context:** PR #23192: DNN: Refactor the fast conv structure

**Code Changes:**
```diff
@@ -10,11 +10,19 @@
 */
 
 #include "../../precomp.hpp"
-#include "fast_convolution.hpp"
-#include "fast_convolution.simd.hpp"
+#include "convolution.hpp"
+
+#include "conv_block.simd.hpp"
+#include "layers/cpu_kernels/conv_block.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content
```

Review comment:
Calling NEON code through `opt_NEON::` requires the support of complete NEON dispatch. Using the `cpu_baseline` namespace is a temporary solution.
**File:** modules/dnn/src/layers/cpu_kernels/convolution.cpp
**Change Type:** renamed
**Context:** PR #23192: DNN: Refactor the fast conv structure

**Code Changes:**
```diff
@@ -10,11 +10,19 @@
 */
 
 #include "../../precomp.hpp"
-#include "fast_convolution.hpp"
-#include "fast_convolution.simd.hpp"
+#include "convolution.hpp"
+
+#include "conv_block.simd.hpp"
+#include "layers/cpu_kernels/conv_block.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content
```

Review comment:
AFAIK, NEON could be enabled as a baseline only. Dispatching of NEON is not supported due to issues with ABI. Ref: https://developer.arm.com/documentation/den0018/a/Compiling-NEON-Instructions/GCC-command-line-options/Option-to-enable-use-of-NEON-and-floating-point-instructions --- > convBlock_NEON in general we should not have such function names.
**File:** modules/dnn/src/layers/cpu_kernels/convolution.cpp
**Change Type:** renamed
**Context:** PR #23192: DNN: Refactor the fast conv structure

**Code Changes:**
```diff
@@ -10,11 +10,19 @@
 */
 
 #include "../../precomp.hpp"
-#include "fast_convolution.hpp"
-#include "fast_convolution.simd.hpp"
+#include "convolution.hpp"
+
+#include "conv_block.simd.hpp"
+#include "layers/cpu_kernels/conv_block.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content
```

Review comment:
How about leaving the NEON code in a separated file with `neon.hpp` suffix and `opt_NEON` namespace?
**File:** modules/dnn/src/layers/cpu_kernels/convolution.cpp
**Change Type:** renamed
**Context:** PR #23192: DNN: Refactor the fast conv structure

**Code Changes:**
```diff
@@ -10,11 +10,19 @@
 */
 
 #include "../../precomp.hpp"
-#include "fast_convolution.hpp"
-#include "fast_convolution.simd.hpp"
+#include "convolution.hpp"
+
+#include "conv_block.simd.hpp"
+#include "layers/cpu_kernels/conv_block.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content
```

Review comment:
> separated file with `neon.hpp` suffix With `.neon.cpp` suffix. Take a look how it is done here: https://github.com/opencv/opencv/blob/4.7.0/modules/imgproc/src/resize.avx2.cpp
**File:** modules/dnn/src/layers/cpu_kernels/conv_block.simd.hpp
**Change Type:** added
**Context:** PR #23192: DNN: Refactor the fast conv structure

**Code Changes:**
```diff
@@ -0,0 +1,259 @@
+// 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.
+
+#include "opencv2/core/hal/intrin.hpp"
+
+namespace cv {
+namespace dnn {
+CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
```

Review comment:
Line 11 should do the same. Code from `conv_block.neon.cpp` should be moved here as there is "no difference" against AVX+ code above.
**File:** modules/imgcodecs/src/grfmt_spng.cpp
**Change Type:** modified
**Context:** PR #27621: Add strict validation for encoding parameters

**Code Changes:**
```diff
@@ -482,6 +482,7 @@ SPngEncoder::SPngEncoder()
     m_support_metadata[IMAGE_METADATA_EXIF] = true;
     m_support_metadata[IMAGE_METADATA_XMP] = true;
     m_support_metadata[IMAGE_METADATA_ICCP] = true;
+    m_supported_encode_key = {IMWRITE_PNG_COMPRESSION, IMWRITE_PNG_STRATEGY, IMWRITE_PNG_BILEVEL, IMWRITE_PNG_FILTER, IMWRITE_PNG_ZLIBBUFFER_SIZE};
 }
 
 SPngEncoder::~SPngEncoder()
@@ -534,25 +535,56 @@ bool SPngEncoder::write(const Mat &img, const std::vector<int> &params)
 
```

Review comment:
todo: replace from early return to break
**File:** modules/imgcodecs/src/grfmt_png.cpp
**Change Type:** modified
**Context:** PR #27621: Add strict validation for encoding parameters

**Code Changes:**
```diff
@@ -913,6 +913,7 @@ PngEncoder::PngEncoder()
     memset(palette, 0, sizeof(palette));
     memset(trns, 0, sizeof(trns));
     memset(op, 0, sizeof(op));
+    m_supported_encode_key = {IMWRITE_PNG_COMPRESSION, IMWRITE_PNG_STRATEGY, IMWRITE_PNG_BILEVEL, IMWRITE_PNG_FILTER, IMWRITE_PNG_ZLIBBUFFER_SIZE};
 }
 
 PngEncoder::~PngEncoder()
@@ -983,26 +984,61 @@ bool  PngEncoder::write( const Mat& img, const std::vector<int>& params )
 
```

Review comment:
todo: replace from early return to break
**File:** modules/features2d/src/fast.cpp
**Change Type:** modified
**Context:** PR #27657: Added heuristic to allocate buffer for FAST features depending on input image resolution

**Code Changes:**
```diff
@@ -429,8 +429,10 @@ void FAST(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bool
 {
     CV_INSTRUMENT_REGION();
 
+    const size_t max_fast_features = std::max(_img.total()/100, size_t(1000)); // Simple heuristic that depends on resolution.
+
     CV_OCL_RUN(_img.isUMat() && type == FastFeatureDetector::TYPE_9_16,
-               ocl_FAST(_img, keypoints, threshold, nonmax_suppression, 10000));
+               ocl_FAST(_img, keypoints, threshold, nonmax_suppression, (int)max_fast_features));
 
```

Review comment:
there are a few typos: 1) resoption => resolution, 2) propably => probably. recommended comment: "Use a simple heuristic depending on the image resolution; can probably be reduced even further". also, sizeof(KeyPoint) is 28 bytes. If, say, image has a modest (by modern standards) resolution of 24Mpix, the buffer will have size 168Mb, which is rather big and allocation of such a buffer may slowdown the function. I suggest to reduce `max_fast_features` to `std::max(_img.total()/100, (size_t)1000);` that will give at max 10K features for 1000x1000 image and 240K features for 24Mpix image — more than enough for any kind of registration/scene recognition/loop closure algorithm.
**File:** samples/dnn/models.yml
**Change Type:** modified
**Context:** PR #27592: Added image super-resolution samples using seemoredetails model
**Review Line:** 532

**Code Changes:**
```diff
+################################################################################
+
+seemoredetails:
+  load_info:
+    url: "https://github.com/Naresh-19/opencv-superres-models/raw/main/seemore_x4v2_static512.onnx"
+    sha1: "584467bd36f5715aa12c3203bba16e4de6392034"
+  model: "seemore_x4v2_static512.onnx"
+  mean: [0.0, 0.0, 0.0]
+  scale: 0.00392
+  rgb: true
+  width: 512
```

Review comment:
Could you add link to the original repo with the model, rather than own fork? If it's not possible, please extend your repo with: - Link to the original model and/or paper. - Command line / pre-requsites to export ONNX - License information and credits.
**File:** samples/dnn/models.yml
**Change Type:** modified
**Context:** PR #27592: Added image super-resolution samples using seemoredetails model
**Review Line:** 532

**Code Changes:**
```diff
+################################################################################
+
+seemoredetails:
+  load_info:
+    url: "https://github.com/Naresh-19/opencv-superres-models/raw/main/seemore_x4v2_static512.onnx"
+    sha1: "584467bd36f5715aa12c3203bba16e4de6392034"
+  model: "seemore_x4v2_static512.onnx"
+  mean: [0.0, 0.0, 0.0]
+  scale: 0.00392
+  rgb: true
+  width: 512
```

Review comment:
Addressed 👍 : [Github](https://github.com/Naresh-19/opencv-superres-models)
**File:** modules/dnn/src/layers/nonzero_layer.cpp
**Change Type:** added
**Context:** PR #27701: Added nonzero layer to new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,243 @@
+// 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.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+#include <cstdint>
+#include <array>
```

Review comment:
maybe we can avoid a special branch just for rank == 0 case?
**File:** modules/dnn/src/layers/nonzero_layer.cpp
**Change Type:** added
**Context:** PR #27701: Added nonzero layer to new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,243 @@
+// 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.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+#include <cstdint>
+#include <array>
```

Review comment:
hfloat/bfloat should be handled with custom implementations of isNonZero: they should just check for 0x0/0x8000 case (one function is enough for both hfloat and bfloat): ``` static inline isNonZeroF16(uint16_t val) { return (val&0x7fff) != 0; } ... X.type() == CV_16F || X.type() == CV_16BF ? isNonZeroF16(*X.ptr<uint16_t>()) ``` Since hfloat/bfloat is the only case that requires `WT!=T` and this case can be solved as shown above, WT parameter in isNonZero is not needed anymore. Maybe the whole function is not needed either, just put the expression (`x!=0`) in-place. also, all other types: uint8/int8, uint16/int16, uint32/int32, uint64/int64 must be supported. It's enough to have 1
**File:** modules/dnn/src/layers/nonzero_layer.cpp
**Change Type:** added
**Context:** PR #27701: Added nonzero layer to new DNN engine
**Review Line:** 169

**Code Changes:**
```diff
+
+        const int depth = CV_MAT_DEPTH(X.type());
+        std::vector<size_t> nzcounts;
+        std::vector<size_t> nzstart;
+        size_t nnz = 0;
+        switch (depth)
+        {
+        case CV_Bool:
+        case CV_8U:
+        case CV_8S:  { nnz = computeNonZeroCountsPerStripe<uchar>(X.ptr<uchar>(), total, nstripes, nzcounts); break; }
+        case CV_16U:
```

Review comment:
put this into a template function with parallel loop inside. Compute number of non-zero elements for each stripe. After you computed number of non-zero elements in each stripe, compute cumsum: ``` constexpr int nstripes = 16; std::vector<size_t> nzcounts(nstripes, 0); std::vector<size_t> nzstart(nstripes+1, 0); parallel_for_(Range(0, nstripes), [&](const Range& range) { size_t i0 = total*range.start/nstripes; size_t i1 = total*range.end/nstripes; size_t nz = 0; for (...) { nz += ... } nzcounts[range.start] = nz; }); // nzstart = { 0, nzcounts[0], nzcounts[0] + nzcounts[1], nzcounts[0] + ... + nzcounts[2], ... } for (int i = 1; i <= nstripes; i++) { nzstart[i] = nzstart[i-1] + nzcounts[i-1]; } // allocate output of shape nzstart[nstripes] = nzcounts[0] + ... + nzcounts[nstripes-1] ... parallel_for_(Range(0, nstripes), [&](const Range& range) { size_t i0 = total*range.start/nstripes; size_t i1 = total*range.end/nstripes; size_t nzcurrstart = nzstart[range.start]; for (...) { if (nonZero(inp[i]) { outarray[nzcurrstart] = <index>; nzcurrstart++;} } });
**File:** modules/dnn/src/layers/nonzero_layer.cpp
**Change Type:** added
**Context:** PR #27701: Added nonzero layer to new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,243 @@
+// 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.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+#include <cstdint>
+#include <array>
```

Review comment:
this function is too expensive. Replace it with a nested loop, say, 3D loop: outermost iteration will cover all dimensions but the last two, the pre-last dimension and then the innermost one. or at least 2D loop: all dimensions but the last one and the innermost dimension.
**File:** modules/dnn/src/layers/nonzero_layer.cpp
**Change Type:** added
**Context:** PR #27701: Added nonzero layer to new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,243 @@
+// 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.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+#include <cstdint>
+#include <array>
```

Review comment:
again, cover all types, not just a few selected types. Put implementation into a template function
**File:** modules/dnn/src/layers/nonzero_layer.cpp
**Change Type:** added
**Context:** PR #27701: Added nonzero layer to new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,243 @@
+// 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.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+#include <cstdint>
+#include <array>
```

Review comment:
pass nstripes as function parameter, to make sure that all stages of the algorithm use exactly the same number of stripes.
**File:** modules/dnn/src/layers/nonzero_layer.cpp
**Change Type:** added
**Context:** PR #27701: Added nonzero layer to new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,243 @@
+// 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.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+#include <cstdint>
+#include <array>
```

Review comment:
why do we have this complex nested loop? Can we have a simple loop where we check inside when the last coordinate reaches the maximum possible value and then we recompute ND index (from the raw index). We can put this check before emitting next ND index, and then we don't need the initialization loop before the main loop
**File:** modules/dnn/src/layers/nonzero_layer.cpp
**Change Type:** added
**Context:** PR #27701: Added nonzero layer to new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,243 @@
+// 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.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+#include <cstdint>
+#include <array>
```

Review comment:
we don't need separate versions for CV_8U and CV_8S. we don't need separate versions for CV_16U and CV_16S. we don't need separate versions for CV_32U and CV_32S. we don't need separate versions for CV_64U and CV_64S.
**File:** modules/dnn/src/layers/nonzero_layer.cpp
**Change Type:** added
**Context:** PR #27701: Added nonzero layer to new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,243 @@
+// 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.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+#include <cstdint>
+#include <array>
```

Review comment:
can we retain only a single switch statement? All the memory allocation logic can be put into helper methods, that we will call from each branch of this switch.
**File:** modules/dnn/src/layers/nonzero_layer.cpp
**Change Type:** added
**Context:** PR #27701: Added nonzero layer to new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,243 @@
+// 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.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+#include <cstdint>
+#include <array>
```

Review comment:
use `std::array<int, CV_MAX_DIM>`
**File:** modules/dnn/src/layers/nonzero_layer.cpp
**Change Type:** added
**Context:** PR #27701: Added nonzero layer to new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,243 @@
+// 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.
+
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+#include <cstdint>
+#include <array>
```

Review comment:
do something like this: ``` coord[rank-1] = lastDimSize - 1; for (;i < i1; i++) { if (++coord[rank-1] >= lastDimSize) { // recompute all coordinates (coord) from 'i' int idxLinear = i; for (int d = rank-1; d >= 0; d--) { coord[d] = idxLinear % shape[d]; idxLinear /= shape[d]; } } if (isNonZero(data[i])) { for (int d = 0; d < rank; d++) { y[(size_t)d * nnz_total + col] = (int64_t)coord[d]; // should it be y[col*nnz_total + d]? } col++; } } ```