nareshmlx/opencv-pr huggingface dataset:
**File:** modules/dnn/src/layers/trilu_layer.cpp
**Change Type:** modified
**Context:** PR #27655: Added proper type handling for TRILU layer
**Review Line:** 56

**Code Changes:**
```diff
-                        auto *cur_dst = dst + ((w * h) * i + (w * l + cmin));
+                        size_t offset = (static_cast<size_t>(w) * h * i + (static_cast<size_t>(w) * l + cmin)) * elemSize;
+                        auto *cur_dst = dst + offset;
                         if (cmin < w && num_zeros > 0)
-                            std::memset(cur_dst, 0, sizeof(float) * num_zeros);
+                            std::memset(cur_dst, 0, elemSize * num_zeros);
                     }
                 }
             };
@@ -62,24 +62,21 @@ class TriluLayerImpl CV_FINAL : public TriluLayer {
             parallel_for_(Range(0, loops), fn, nstripes);
```

Review comment:
just wondering if it will be a good idea to assert `elemSize` is positive or check in `if (cmin < w && num_zeros > 0 && elemSize > 0)` . Please feel free to ignore if it is not applicable
**File:** modules/videoio/src/cap_obsensor_liborbbec.cpp
**Change Type:** modified
**Context:** PR #27610: Added timestamps support for Orbbec SDK backend in VideoIO.

**Code Changes:**
```diff
@@ -83,7 +83,31 @@ double VideoCapture_obsensor::getProperty(int propIdx) const
     case CAP_PROP_OBSENSOR_INTRINSIC_CY:
         rst = camParam.p1[3];
         break;
+    case CAP_PROP_POS_MSEC:
+    case CAP_PROP_OBSENSOR_RGB_POS_MSEC:
+        if (grabbedColorFrame)
+        {
+            rst = grabbedColorFrame->globalTimeStampUs();
+            if (rst == 0.0)
```

Review comment:
These should be in the `switch` statement.
**File:** modules/imgcodecs/test/test_png.cpp
**Change Type:** modified
**Context:** PR #27598: Fixed build with libpng older than 1.5.x and reduced test memory consumption

**Code Changes:**
```diff
@@ -19,7 +19,9 @@ TEST(Imgcodecs_Png, write_big)
     EXPECT_EQ(13917, img.rows);
 
     vector<uchar> buff;
-    ASSERT_NO_THROW(imencode(".png", img, buff, { IMWRITE_PNG_ZLIBBUFFER_SIZE, INT_MAX }));
+    bool status = false;
+    ASSERT_NO_THROW(status = imencode(".png", img, buff, { IMWRITE_PNG_ZLIBBUFFER_SIZE, 1024*1024 }));
+    ASSERT_TRUE(status);
 #ifdef HAVE_PNG
     EXPECT_EQ((size_t)816219, buff.size());
```

Review comment:
`ASSERT_NO_THROW(status = imencode(".png", img, buff, { IMWRITE_PNG_ZLIBBUFFER_SIZE, 1024*1024 }));` enough for creating the same sized buffer.
**File:** modules/imgproc/src/connectedcomponents.cpp
**Change Type:** modified
**Context:** PR #27582: Take into account overflow for connected components

**Code Changes:**
```diff
@@ -261,13 +261,24 @@ namespace cv{
 
     template<typename LabelT>
     inline static
-    void flattenL(LabelT *P, const int start, const int nElem, LabelT& k){
+    void checkLabelTypeOverflowBeforeIncrement(const LabelT numLabels) {
+        constexpr LabelT maxLabelTypeValue = std::numeric_limits<LabelT>::max();
+        CV_CheckLT(
+            numLabels,
+            maxLabelTypeValue,
```

Review comment:
You can use `CV_CheckLE` instead of new function everywhere: https://docs.opencv.org/4.x/d1/d26/check_8hpp.html#a7b8e786a57dcee88dc0cae752adab921
**File:** modules/imgproc/src/connectedcomponents.cpp
**Change Type:** modified
**Context:** PR #27582: Take into account overflow for connected components

**Code Changes:**
```diff
@@ -261,13 +261,24 @@ namespace cv{
 
     template<typename LabelT>
     inline static
-    void flattenL(LabelT *P, const int start, const int nElem, LabelT& k){
+    void checkLabelTypeOverflowBeforeIncrement(const LabelT numLabels) {
+        constexpr LabelT maxLabelTypeValue = std::numeric_limits<LabelT>::max();
+        CV_CheckLT(
+            numLabels,
+            maxLabelTypeValue,
```

Review comment:
I agree that it is better to use `CV_CheckLT` in the implementation of the new function (done). But I would prefer to use the new function everywhere instead of its implementation - it is shorter, clearer (the name of the function serves as a fairly clear comment) and if we, for example, want to change the error message in the future, then we will only need to do it in one place instead of `20`
**File:** modules/imgproc/src/distransform.cpp
**Change Type:** modified
**Context:** PR #27432: Correct IPP distanceTransform results with single thread

**Code Changes:**
```diff
@@ -796,6 +796,22 @@ void cv::distanceTransform( InputArray _src, OutputArray _dst, OutputArray _labe
                     ippFree( pBuffer );
                     if (status>=0)
                     {
+                        // https://github.com/opencv/opencv/issues/24082
+                        // There is probably a rounding issue that leads to non-deterministic behavior
+                        // between runs on positions closer to zeros by x-axis in straight direction.
+                        // As a workaround, we detect the distances that expected to be exact
+                        // number of pixels and round manually.
+                        static const float correctionDiff = 1.0f / (1 << 11);
```

Review comment:
I recommend you to add comment with link to the original bug and couple of words why the loop is needed. The reason of "clipping" is not obvious.
**File:** modules/imgproc/src/distransform.cpp
**Change Type:** modified
**Context:** PR #27432: Correct IPP distanceTransform results with single thread

**Code Changes:**
```diff
@@ -796,6 +796,22 @@ void cv::distanceTransform( InputArray _src, OutputArray _dst, OutputArray _labe
                     ippFree( pBuffer );
                     if (status>=0)
                     {
+                        // https://github.com/opencv/opencv/issues/24082
+                        // There is probably a rounding issue that leads to non-deterministic behavior
+                        // between runs on positions closer to zeros by x-axis in straight direction.
+                        // As a workaround, we detect the distances that expected to be exact
+                        // number of pixels and round manually.
+                        static const float correctionDiff = 1.0f / (1 << 11);
```

Review comment:
Sure, added the comment
**File:** modules/core/test/test_io.cpp
**Change Type:** modified
**Context:** PR #27587: core: support parsing back slash `\` in `parseKey` in FileStorage (JSON)

**Code Changes:**
```diff
@@ -1569,6 +1569,29 @@ TEST(Core_InputOutput, FileStorage_json_null_object)
     fs.release();
 }
 
+TEST(Core_InputOutput, FileStorage_json_key_backslash)
+{
+    // equivalent to json text {"\"":1,"\\":59,"Ġ\"":366,"\\\\":6852}
+    std::string test = R"({"\"":1,"\\":59,"Ġ\"":366,"\\\\":6852})";
+    FileStorage fs(test, FileStorage::READ | FileStorage::MEMORY);
+
```

Review comment:
Not clear for me. `"\"\\\"\":1,"` has a key `"\"` so equivalent in json is `{ "\"\\\"": 1}`
**File:** modules/core/test/test_io.cpp
**Change Type:** modified
**Context:** PR #27587: core: support parsing back slash `\` in `parseKey` in FileStorage (JSON)

**Code Changes:**
```diff
@@ -1569,6 +1569,29 @@ TEST(Core_InputOutput, FileStorage_json_null_object)
     fs.release();
 }
 
+TEST(Core_InputOutput, FileStorage_json_key_backslash)
+{
+    // equivalent to json text {"\"":1,"\\":59,"Ġ\"":366,"\\\\":6852}
+    std::string test = R"({"\"":1,"\\":59,"Ġ\"":366,"\\\\":6852})";
+    FileStorage fs(test, FileStorage::READ | FileStorage::MEMORY);
+
```

Review comment:
The C++ string version is slightly different since back slash is eliminated in the preprocessing stage during compiling. So to get the equivalent version in C++ from JSON text, we need to - prefix each back slash in key with a back slash, - prefix each quote in key with a back slash, - use double quote to contain the string.
**File:** modules/core/test/test_io.cpp
**Change Type:** modified
**Context:** PR #27587: core: support parsing back slash `\` in `parseKey` in FileStorage (JSON)

**Code Changes:**
```diff
@@ -1569,6 +1569,29 @@ TEST(Core_InputOutput, FileStorage_json_null_object)
     fs.release();
 }
 
+TEST(Core_InputOutput, FileStorage_json_key_backslash)
+{
+    // equivalent to json text {"\"":1,"\\":59,"Ġ\"":366,"\\\\":6852}
+    std::string test = R"({"\"":1,"\\":59,"Ġ\"":366,"\\\\":6852})";
+    FileStorage fs(test, FileStorage::READ | FileStorage::MEMORY);
+
```

Review comment:
I mean the comment above should be actual to be copied to .json file and give the same test results. However in this example: ```json { "\"": 1, "\\": 59, "Ġ\"": 366, "\\\\": 6852 } ``` ```python import json f = open("file.json", "rt"); print(json.load(f).keys()) # dict_keys(['"', '\\', 'Ġ"', '\\\\']) ``` Probably comment should be updated?
**File:** modules/core/test/test_io.cpp
**Change Type:** modified
**Context:** PR #27587: core: support parsing back slash `\` in `parseKey` in FileStorage (JSON)

**Code Changes:**
```diff
@@ -1569,6 +1569,29 @@ TEST(Core_InputOutput, FileStorage_json_null_object)
     fs.release();
 }
 
+TEST(Core_InputOutput, FileStorage_json_key_backslash)
+{
+    // equivalent to json text {"\"":1,"\\":59,"Ġ\"":366,"\\\\":6852}
+    std::string test = R"({"\"":1,"\\":59,"Ġ\"":366,"\\\\":6852})";
+    FileStorage fs(test, FileStorage::READ | FileStorage::MEMORY);
+
```

Review comment:
Do you mean the last key `"\\\\"` is not aligned? --- I don't get where is not the same test results? The `test` string translates to `{"\"":1,"\\":59,"Ġ\"":366,"\\\\":6852}` listed in the comment after compiling.
**File:** modules/core/test/test_io.cpp
**Change Type:** modified
**Context:** PR #27587: core: support parsing back slash `\` in `parseKey` in FileStorage (JSON)

**Code Changes:**
```diff
@@ -1569,6 +1569,29 @@ TEST(Core_InputOutput, FileStorage_json_null_object)
     fs.release();
 }
 
+TEST(Core_InputOutput, FileStorage_json_key_backslash)
+{
+    // equivalent to json text {"\"":1,"\\":59,"Ġ\"":366,"\\\\":6852}
+    std::string test = R"({"\"":1,"\\":59,"Ġ\"":366,"\\\\":6852})";
+    FileStorage fs(test, FileStorage::READ | FileStorage::MEMORY);
+
```

Review comment:
I got your point here. Looks like we need to actually eliminate back slash from the string before creating the node with this string as key.
**File:** modules/core/src/persistence_json.cpp
**Change Type:** modified
**Context:** PR #27587: core: support parsing back slash `\` in `parseKey` in FileStorage (JSON)

**Code Changes:**
```diff
@@ -419,18 +419,27 @@ class JSONParser : public FileStorageParser
             CV_PARSE_ERROR_CPP( "Key must start with \'\"\'" );
 
         char * beg = ptr + 1;
-
+        std::string key_name;
         do {
-            ++ptr;
-            CV_PERSISTENCE_CHECK_END_OF_BUFFER_BUG_CPP();
+            if (*ptr == '\\') { // skip the next character if current is back slash
```

Review comment:
please remove debug print
**File:** modules/core/src/persistence_json.cpp
**Change Type:** modified
**Context:** PR #27587: core: support parsing back slash `\` in `parseKey` in FileStorage (JSON)

**Code Changes:**
```diff
@@ -419,18 +419,27 @@ class JSONParser : public FileStorageParser
             CV_PARSE_ERROR_CPP( "Key must start with \'\"\'" );
 
         char * beg = ptr + 1;
-
+        std::string key_name;
         do {
-            ++ptr;
-            CV_PERSISTENCE_CHECK_END_OF_BUFFER_BUG_CPP();
+            if (*ptr == '\\') { // skip the next character if current is back slash
```

Review comment:
let's remove if not used
**File:** hal/ipp/src/warp_ipp.cpp
**Change Type:** added
**Context:** PR #27324: Moved IPP impl of warpAffine and warpPerspective to HAL

**Code Changes:**
```diff
@@ -0,0 +1,367 @@
+// 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 "ipp_hal_imgproc.hpp"
+
+#include <opencv2/core.hpp>
+#include <opencv2/core/base.hpp>
+#include "precomp_ipp.hpp"
```

Review comment:
```suggestion {{1, 0}, {1, 0}, {0, 0}, {1, 0}}, //32F ```
**File:** hal/ipp/include/ipp_hal_imgproc.hpp
**Change Type:** added
**Context:** PR #27324: Moved IPP impl of warpAffine and warpPerspective to HAL

**Code Changes:**
```diff
@@ -0,0 +1,27 @@
+// 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
+
+#ifndef __IPP_HAL_IMGPROC_HPP__
+#define __IPP_HAL_IMGPROC_HPP__
+
+#include <opencv2/core/base.hpp>
+#include "ipp_utils.hpp"
```

Review comment:
```suggestion int dst_height, const double M[9], int interpolation, int borderType, const double borderValue[4]); ```
**File:** hal/ipp/include/ipp_hal_imgproc.hpp
**Change Type:** added
**Context:** PR #27324: Moved IPP impl of warpAffine and warpPerspective to HAL

**Code Changes:**
```diff
@@ -0,0 +1,27 @@
+// 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
+
+#ifndef __IPP_HAL_IMGPROC_HPP__
+#define __IPP_HAL_IMGPROC_HPP__
+
+#include <opencv2/core/base.hpp>
+#include "ipp_utils.hpp"
```

Review comment:
The change shall be applied to avoid warning in Android build
**File:** hal/ipp/src/warp_ipp.cpp
**Change Type:** added
**Context:** PR #27324: Moved IPP impl of warpAffine and warpPerspective to HAL

**Code Changes:**
```diff
@@ -0,0 +1,367 @@
+// 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 "ipp_hal_imgproc.hpp"
+
+#include <opencv2/core.hpp>
+#include <opencv2/core/base.hpp>
+#include "precomp_ipp.hpp"
```

Review comment:
I propose to use `CV_DEPTH_MAX` instead of 7. OpenCV 5.x supports more types. The table will be just extended with zeros.
**File:** hal/ipp/src/warp_ipp.cpp
**Change Type:** added
**Context:** PR #27324: Moved IPP impl of warpAffine and warpPerspective to HAL

**Code Changes:**
```diff
@@ -0,0 +1,367 @@
+// 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 "ipp_hal_imgproc.hpp"
+
+#include <opencv2/core.hpp>
+#include <opencv2/core/base.hpp>
+#include "precomp_ipp.hpp"
```

Review comment:
I propose to use CV_DEPTH_MAX instead of 7. OpenCV 5.x supports more types. The table will be just extended with zeros.
**File:** hal/ipp/include/ipp_hal_imgproc.hpp
**Change Type:** added
**Context:** PR #27324: Moved IPP impl of warpAffine and warpPerspective to HAL
**Review Line:** 5

**Code Changes:**
```diff
@@ -0,0 +1,27 @@
+// 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
+
+#ifndef __IPP_HAL_IMGPROC_HPP__
+#define __IPP_HAL_IMGPROC_HPP__
+
+#include <opencv2/core/base.hpp>
+#include "ipp_utils.hpp"
+
```

Review comment:
Please add copyright header here and in all new files.
**File:** hal/ipp/include/ipp_hal_imgproc.hpp
**Change Type:** added
**Context:** PR #27324: Moved IPP impl of warpAffine and warpPerspective to HAL
**Review Line:** 5

**Code Changes:**
```diff
@@ -0,0 +1,27 @@
+// 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
+
+#ifndef __IPP_HAL_IMGPROC_HPP__
+#define __IPP_HAL_IMGPROC_HPP__
+
+#include <opencv2/core/base.hpp>
+#include "ipp_utils.hpp"
+
```

Review comment:
Copyrights were added.
**File:** modules/dnn/include/opencv2/dnn/all_layers.hpp
**Change Type:** modified
**Context:** PR #27508: IfLayer add to new DNN engine

**Code Changes:**
```diff
@@ -585,6 +585,18 @@ CV__DNN_INLINE_NS_BEGIN
         static Ptr<RequantizeLayer> create(const LayerParams &params);
     };
 
+    // Forward declaration for computational Graph used by IfLayer
+    class Graph;
+
+    class CV_EXPORTS IfLayer : public Layer
+    {
+    public:
```

Review comment:
IfLayer should override Layer::subgraphs() method. `then_else()` method is not needed, please, remove it.
**File:** modules/dnn/src/net_impl2.cpp
**Change Type:** modified
**Context:** PR #27508: IfLayer add to new DNN engine

**Code Changes:**
```diff
@@ -253,7 +253,6 @@ Arg Net::Impl::newArg(const std::string& name, ArgKind kind, bool allowEmptyName
     return Arg(idx);
 }
 
-
 int Net::Impl::findDim(const std::string& dimname, bool insert)
 {
     if (!dimname.empty()) {
@@ -595,7 +594,6 @@ void Net::Impl::forwardGraph(Ptr<Graph>& graph, InputArrayOfArrays inputs_,
     if (graphofs_it == graphofs.end()) {
```

Review comment:
not sure why you disabled this check
**File:** modules/dnn/src/net_impl2.cpp
**Change Type:** modified
**Context:** PR #27508: IfLayer add to new DNN engine
**Review Line:** 682

**Code Changes:**
```diff
+                layer->finalize(inpMats, outMats);
+            layer->forward(inpMats, outMats, tempMats);
+        }
+        else {
+            Ptr<IfLayer> iflayer = layer.dynamicCast<IfLayer>();
+            if (iflayer) {
+                int branch = iflayer->branch(inpMats[0]);
+                Ptr<Graph> subgraph = subgraphs->at(branch);
+                std::vector<Mat> branchInputs;
+                if (inpMats.size() > 1)
+                    branchInputs.assign(inpMats.begin() + 1, inpMats.end());
```

Review comment:
I suggest to have check for empty subgraphs first. ``` std::vector<Ptr<Graph>>* subgraphs = layer->subgraphs(); if (!subgraphs) { // main branch, true for 99.9% of layers if (finalizeLayers) layer->finalize(inpMats, outMats); layer->forward(inpMats, outMats, tempMats); } else { Ptr<IfLayer> iflayer = layer.dynamicCast<IfLayer>(); if (iflayer) { // subgraphs already contains pointer to vector where, subgraphs[0] is then, subgraphs[1] is else. Mat inp0 = inpMats[0]; CV_Assert(inp0.total() == 1u); CV_Assert(inp0.type() == CV_Bool); bool flag = inp0.at<bool>(0); auto subgraph = subgraphs->at((int)(!flag)); forwardGraph(subgraph, inpMats, outMats, false); } else { CV_Error_(Error::StsNotImplemented, "unknown layer type '%s' with subgraphs", layer->type.c_str())); } } ```
**File:** modules/dnn/test/test_onnx_conformance_layer_parser_denylist.inl.hpp
**Change Type:** modified
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -394,9 +394,6 @@
 "test_tfidfvectorizer_tf_uniandbigrams_skip5", // Issue:: Parser: Can't create layer "onnx_node_output_0!Y" of type "TfIdfVectorizer" in function 'getLayerInstance'
 "test_tile", // Issue:: Parser: ONNX/Tile: repeats being non-constant is not supported. in function 'parseTile' (layer parameters are dynamic)
 "test_tile_precomputed", //  // ---- same as above ---
-"test_top_k", // Issue:: K being input is not compatible with the current engine
-"test_top_k_negative_axis",  // ---- same as above ---
-"test_top_k_smallest",  // ---- same as above ---
 "test_training_dropout", // Issue::cvtest::norm::wrong data type
 "test_training_dropout_default",  // ---- same as above ---
 "test_training_dropout_default_mask",  // ---- same as above ---
```

Review comment:
What about remaining top_k tests?
**File:** modules/dnn/test/test_onnx_conformance_layer_parser_denylist.inl.hpp
**Change Type:** modified
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -394,9 +394,6 @@
 "test_tfidfvectorizer_tf_uniandbigrams_skip5", // Issue:: Parser: Can't create layer "onnx_node_output_0!Y" of type "TfIdfVectorizer" in function 'getLayerInstance'
 "test_tile", // Issue:: Parser: ONNX/Tile: repeats being non-constant is not supported. in function 'parseTile' (layer parameters are dynamic)
 "test_tile_precomputed", //  // ---- same as above ---
-"test_top_k", // Issue:: K being input is not compatible with the current engine
-"test_top_k_negative_axis",  // ---- same as above ---
-"test_top_k_smallest",  // ---- same as above ---
 "test_training_dropout", // Issue::cvtest::norm::wrong data type
 "test_training_dropout_default",  // ---- same as above ---
 "test_training_dropout_default_mask",  // ---- same as above ---
```

Review comment:
Removed from deny list, they're working fine
**File:** modules/dnn/src/layers/topk2_layer.cpp
**Change Type:** added
**Context:** PR #27547: Added TopK layer with dynamic K support for 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.
+
+#include "../precomp.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+
+namespace cv { namespace dnn {
+
+/*
+    TopK layer, as defined in ONNX specification:
+    https://onnx.ai/onnx/operators/onnx__TopK.html
```

Review comment:
please, add description similar to other new layers, e.g. https://github.com/opencv/opencv/blob/5.x/modules/dnn/src/layers/expand2_layer.cpp: 1) link to the description. 2) which opset's are supported.
**File:** modules/dnn/src/layers/topk2_layer.cpp
**Change Type:** added
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,218 @@
+// 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 <opencv2/dnn/shape_utils.hpp>
+
+namespace cv { namespace dnn {
+
```

Review comment:
I suggest to avoid using addOffset() and minusOffset(). Construct ComparatorGreater/ComparatorLess inside the inner loop, this is super-cheap operation, and pass the proper data there.
**File:** modules/dnn/src/layers/topk2_layer.cpp
**Change Type:** added
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,218 @@
+// 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 <opencv2/dnn/shape_utils.hpp>
+
+namespace cv { namespace dnn {
+
```

Review comment:
I believe, it's wrong. In the case of dynamic TopK "K" parameter should be taken from the tensor itself, not shape of the tensor.
**File:** modules/dnn/src/layers/topk2_layer.cpp
**Change Type:** added
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,218 @@
+// 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 <opencv2/dnn/shape_utils.hpp>
+
+namespace cv { namespace dnn {
+
```

Review comment:
you don't need std::stable_sort, because you take into account index order inside the comparator class. And you don't need std::sort, because you don't need completely sorted array. Use std::partial_sort. Also, sorting is done on array that is not continuous in memory. Please, copy elements to a temporary vector (make another AutoBuffer nearby indices) and sort them there. Actually, I recommend you to use std::vector<> of pairs of elements: ``` std::vector<std::pair<T /* or WT, see comment below */, int64_t> > sorted; for (b...) { for (j...) { for (int64_t i = 0; i < dimAxis; i++) sorted[i] = std::make_pair(data[i*... + ...], i); std::partial_sort(sorted.begin(), sorted.begin() + K, sorted.end(), cmp); // store K selected values and the corresponding indices from sorted to the target tensor ... } } ```