nareshmlx/opencv-pr huggingface dataset:
**File:** samples/java/tutorial_code/features/feature_description/SURFMatchingDemo.java
**Change Type:** renamed
**Context:** PR #26405: Rename features2d - This PR renames the module _features2d_ to _features_ as one of the Big OpenCV Cleanup #25007. Related PR: opencv/openc...
**Review Line:** 6

**Code Changes:**
```diff
 import org.opencv.core.MatOfDMatch;
 import org.opencv.core.MatOfKeyPoint;
-import org.opencv.features2d.DescriptorMatcher;
-import org.opencv.features2d.Features2d;
+import org.opencv.features.DescriptorMatcher;
+import org.opencv.features.Features;
 import org.opencv.highgui.HighGui;
 import org.opencv.imgcodecs.Imgcodecs;
 import org.opencv.xfeatures2d.SURF;
@@ -37,7 +37,7 @@ public void run(String[] args) {
 
```

Review comment:
I am not familiar with the java binding, and changing back to `Features2d` leads to compile errors.
**File:** modules/dnn/test/test_tflite_importer.cpp
**Change Type:** modified
**Context:** PR #26330: Modified TFLite parser for the new dnn engine
**Review Line:** 158

**Code Changes:**
```diff
@@ -155,6 +155,9 @@ TEST_P(Test_TFLite, max_unpooling)
     net.setPreferableBackend(backend);
     net.setPreferableTarget(target);
 
+    if (net.getMainGraph())
+        throw SkipTestException("The new dnn engine doesn't support forward to specified layers"); // https://github.com/opencv/opencv/issues/26349
+
     Mat input = imread(findDataFile("cv/shared/lena.png"));
     cvtColor(input, input, COLOR_BGR2RGBA);
     input = input.mul(Scalar(1, 1, 1, 0));
```

Review comment:
Please add reference to Github bug.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #26330: Modified TFLite parser for the new dnn engine
**Review Line:** 1112

**Code Changes:**
```diff
+      * @param engine select DNN engine to be used. With auto selection the new engine is used first and falls back to classic.
+      * Please pay attention that the new DNN does not support non-CPU back-ends for now.
       * @returns Net object.
       */
-    CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model);
+    CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model, int engine=ENGINE_AUTO);
 
     /** @brief Reads a network model stored in <a href="https://www.tensorflow.org/lite">TFLite</a> framework's format.
       * @param bufferModel buffer containing the content of the tflite file
+      * @param engine select DNN engine to be used. With auto selection the new engine is used first and falls back to classic.
+      * Please pay attention that the new DNN does not support non-CPU back-ends for now.
```

Review comment:
int or enum type?
**File:** modules/dnn/src/tflite/tflite_importer.cpp
**Change Type:** modified
**Context:** PR #26330: Modified TFLite parser for the new dnn engine
**Review Line:** 82

**Code Changes:**
```diff
 
     void parseFusedActivation(const Operator& op, ActivationFunctionType activ);
     void parseActivation(const Operator& op, const std::string& opcode, LayerParams& layerParams, bool isFused);
-    void addLayer(LayerParams& layerParams, const Operator& op);
-    int addPermuteLayer(const std::vector<int>& order, const std::string& permName, const std::pair<int, int>& inpId, int dtype);
+    void addLayer(LayerParams& layerParams, const Operator& op, bool additionalPreLayer = false, bool additionalPostLayer = false);
+    void addLayer(LayerParams& layerParams, const std::vector<std::string>& inputTensors, const std::vector<std::string>& outputTensors);
+    int addPermuteLayer(const std::vector<int>& order, const std::string& permName, const std::pair<int, int>& inpId, int dtype, int inpTensorId);
     int addReshapeLayer(const std::vector<int>& shape, int axis, int num_axes,
-                        const std::string& name, const std::pair<int, int>& inpId, int dtype);
-    int addFlattenLayer(int axis, int end_axis, const std::string& name, const std::pair<int, int>& inpId, int dtype);
```

Review comment:
Sorry, I forgot to add the PR description. Added it.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #26330: Modified TFLite parser for the new dnn engine
**Review Line:** 1112

**Code Changes:**
```diff
+      * @param engine select DNN engine to be used. With auto selection the new engine is used first and falls back to classic.
+      * Please pay attention that the new DNN does not support non-CPU back-ends for now.
       * @returns Net object.
       */
-    CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model);
+    CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model, int engine=ENGINE_AUTO);
 
     /** @brief Reads a network model stored in <a href="https://www.tensorflow.org/lite">TFLite</a> framework's format.
       * @param bufferModel buffer containing the content of the tflite file
+      * @param engine select DNN engine to be used. With auto selection the new engine is used first and falls back to classic.
+      * Please pay attention that the new DNN does not support non-CPU back-ends for now.
```

Review comment:
Changed to enum
**File:** modules/dnn/src/tflite/tflite_importer.cpp
**Change Type:** modified
**Context:** PR #26330: Modified TFLite parser for the new dnn engine
**Review Line:** 82

**Code Changes:**
```diff
 
     void parseFusedActivation(const Operator& op, ActivationFunctionType activ);
     void parseActivation(const Operator& op, const std::string& opcode, LayerParams& layerParams, bool isFused);
-    void addLayer(LayerParams& layerParams, const Operator& op);
-    int addPermuteLayer(const std::vector<int>& order, const std::string& permName, const std::pair<int, int>& inpId, int dtype);
+    void addLayer(LayerParams& layerParams, const Operator& op, bool additionalPreLayer = false, bool additionalPostLayer = false);
+    void addLayer(LayerParams& layerParams, const std::vector<std::string>& inputTensors, const std::vector<std::string>& outputTensors);
+    int addPermuteLayer(const std::vector<int>& order, const std::string& permName, const std::pair<int, int>& inpId, int dtype, int inpTensorId);
     int addReshapeLayer(const std::vector<int>& shape, int axis, int num_axes,
-                        const std::string& name, const std::pair<int, int>& inpId, int dtype);
-    int addFlattenLayer(int axis, int end_axis, const std::string& name, const std::pair<int, int>& inpId, int dtype);
```

Review comment:
I've added you naming for the new engine. Btw I've found out that the TFLite models don't have layer names and our parser just uses layer_outputs[0].name
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #26330: Modified TFLite parser for the new dnn engine
**Review Line:** 1112

**Code Changes:**
```diff
+      * @param engine select DNN engine to be used. With auto selection the new engine is used first and falls back to classic.
+      * Please pay attention that the new DNN does not support non-CPU back-ends for now.
       * @returns Net object.
       */
-    CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model);
+    CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model, int engine=ENGINE_AUTO);
 
     /** @brief Reads a network model stored in <a href="https://www.tensorflow.org/lite">TFLite</a> framework's format.
       * @param bufferModel buffer containing the content of the tflite file
+      * @param engine select DNN engine to be used. With auto selection the new engine is used first and falls back to classic.
+      * Please pay attention that the new DNN does not support non-CPU back-ends for now.
```

Review comment:
I reverted back to int. Enum triggers issue with Java bindings generator. I know, it should be fixed, but it's less urgent.
**File:** samples/cpp/videowriter.cpp
**Change Type:** added
**Context:** PR #25349: Videocapture samples cleanup cpp

**Code Changes:**
```diff
@@ -0,0 +1,118 @@
+/**
+  @file videowriter.cpp
+  @brief A sample for VideoWriter and VideoCapture with options to specify video codec, fps and resolution
+  @date April 05, 2024
+*/
+
+
+#include <opencv2/core.hpp>
+#include <opencv2/videoio.hpp>
```

Review comment:
The codec list depends on supported back-ends. Mjpeg is implemented by OpenCV itself. I propose to rewrite: "Supported codecs depend on OpenCV Configuration. Try one of 'h264', 'h265', 'mpeg2', 'mpeg4', 'mjpeg', 'vp8'"
**File:** samples/cpp/videowriter.cpp
**Change Type:** added
**Context:** PR #25349: Videocapture samples cleanup cpp

**Code Changes:**
```diff
@@ -0,0 +1,118 @@
+/**
+  @file videowriter.cpp
+  @brief A sample for VideoWriter and VideoCapture with options to specify video codec, fps and resolution
+  @date April 05, 2024
+*/
+
+
+#include <opencv2/core.hpp>
+#include <opencv2/videoio.hpp>
```

Review comment:
I propose to support WxH configrations like 640x480.
**File:** samples/cpp/videowriter.cpp
**Change Type:** added
**Context:** PR #25349: Videocapture samples cleanup cpp

**Code Changes:**
```diff
@@ -0,0 +1,118 @@
+/**
+  @file videowriter.cpp
+  @brief A sample for VideoWriter and VideoCapture with options to specify video codec, fps and resolution
+  @date April 05, 2024
+*/
+
+
+#include <opencv2/core.hpp>
+#include <opencv2/videoio.hpp>
```

Review comment:
I propose to make it command line parameter.
**File:** samples/cpp/videocapture_combined.cpp
**Change Type:** added
**Context:** PR #25349: Videocapture samples cleanup cpp

**Code Changes:**
```diff
@@ -0,0 +1,88 @@
+/*
+ * This sample demonstrates how to read and display frames from a video file, a camera device or an image sequence.
+ * The sample also demonstrates extracting audio buffers from a video file.
+
+ * Capturing video and audio simultaneously from camera device is not supported by OpenCV.
+*/
+
+
+#include <opencv2/core.hpp>
```

Review comment:
It may be end of stream/sequence
**File:** modules/core/src/matrix.cpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine
**Review Line:** 20

**Code Changes:**
```diff
+        layout == DATA_LAYOUT_NHWC ? "NHWC" :
+        layout == DATA_LAYOUT_BLOCK ? "NC1HWC0" :
+        layout == DATA_LAYOUT_NCDHW ? "NCDHW" :
+        layout == DATA_LAYOUT_NDHWC ? "NDHWC" :
+        layout == DATA_LAYOUT_PLANAR ? "PLANAR" :
+        layout == DATA_LAYOUT_UNKNOWN ? "Unknown" : "???";
+}
+
+bool operator == (const MatShape& size1, const MatShape& size2)
+{
+    if (size1.dims != size2.dims)
```

Review comment:
Assert? Invalid layout value means user error or memory corruption. Both of them should stop the program.
**File:** modules/dnn/src/tflite/tflite_importer.cpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine

**Code Changes:**
```diff
@@ -180,16 +180,16 @@ void TFLiteImporter::populateNet()
     std::vector<MatShape> inputsShapes(subgraph_inputs_size);
     for (size_t i = 0; i < subgraph_inputs_size; ++i)
     {
-        int idx = subgraph_inputs->Get(i);
+        size_t idx = subgraph_inputs->Get(i);
         layerIds[idx] = std::make_pair(0, i);
         const auto tensor = modelTensors->Get(idx);
         if (!tensor)
-            CV_Error(Error::StsError, cv::format("DNN/TFLite: subgraph input %d (%d) is NULL", (int)i, idx));
```

Review comment:
`%zu` for `i` makes sense too to prevent conversions.
**File:** modules/dnn/src/graph_const_fold.cpp
**Change Type:** added
**Context:** PR #26056: New dnn engine
**Review Line:** 100

**Code Changes:**
```diff
+                if (!layer->dynamicOutputShapes())
+                    netimpl->allocateLayerOutputs(layer, inpTypes, inpShapes, outTypes,
+                                                  outShapes, outOrigData, outMats, tempTypes, tempShapes, tempMats,
+                                                  netimpl->scratchBufs, false);
+                layer->finalize(inpMats, outMats);
+                layer->forward(inpMats, outMats, tempMats);
+                CV_Assert(outMats.size() == noutputs);
+                for (j = 0; j < noutputs; j++) {
+                    Arg out = outputs[j];
+                    ArgData& out_data = netimpl->args.at(out.idx);
+                    const Mat& m = outMats[j];
```

Review comment:
Missing support of other non-CPU executors and non-CPU buffers.
**File:** modules/core/include/opencv2/core/mat.hpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine

**Code Changes:**
```diff
@@ -67,6 +67,113 @@ enum AccessFlag { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25,
 CV_ENUM_FLAGS(AccessFlag)
 __CV_ENUM_FLAGS_BITWISE_AND(AccessFlag, int, AccessFlag)
 
+/**
+ * @brief Enum of data layout for model inference.
+ * @see Image2BlobParams
+ */
+enum DataLayout
+{
```

Review comment:
In general there is no such information in generic functions (MatShape doesn't contain that). So it could not be handled properly. Generic functions should receive already "handled" dynamic shapes. Basic structures should be minimal as possible.
**File:** modules/core/include/opencv2/core/mat.hpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine
**Review Line:** 170

**Code Changes:**
```diff
+    operator std::vector<int>() const;
+    std::string str() const;
+
+    int dims;
+    DataLayout layout;
+    int C;
+    int p[MAX_DIMS];
+};
+
+CV_EXPORTS bool operator == (const MatShape& shape1, const MatShape& shape2);
+CV_EXPORTS bool operator != (const MatShape& shape1, const MatShape& shape2);
```

Review comment:
Avoid one letter names. No way to properly find related code.
**File:** modules/core/include/opencv2/core/mat.hpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine
**Review Line:** 171

**Code Changes:**
```diff
+    std::string str() const;
+
+    int dims;
+    DataLayout layout;
+    int C;
+    int p[MAX_DIMS];
+};
+
+CV_EXPORTS bool operator == (const MatShape& shape1, const MatShape& shape2);
+CV_EXPORTS bool operator != (const MatShape& shape1, const MatShape& shape2);
+
```

Review comment:
The same. What is `p`?
**File:** modules/core/include/opencv2/core.hpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine
**Review Line:** 1176

**Code Changes:**
```diff
+/** @brief Broadcast the given Mat to the given shape.
+ * @param src input array
+ * @param shape target shape. Note that negative values are not supported.
+ * @param dst output array that has the given shape
+ */
+CV_EXPORTS void broadcast(InputArray src, const MatShape& shape, OutputArray dst);
+
 enum RotateFlags {
     ROTATE_90_CLOCKWISE = 0, //!<Rotate 90 degrees clockwise
     ROTATE_180 = 1, //!<Rotate 180 degrees clockwise
```

Review comment:
This violate existed rules of parameters ordering.
**File:** modules/core/include/opencv2/core/mat.hpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine
**Review Line:** 490

**Code Changes:**
```diff
+
+    void fit(Size sz, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const;
+    void fit(int rows, int cols, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const;
+    void fit(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const;
+    void fit(const MatShape& shape, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const;
+    void fitSameSize(const _InputArray& arr, int mtype) const;
+
     void release() const;
     void clear() const;
     void setTo(const _InputArray& value, const _InputArray & mask = _InputArray()) const;
@@ -876,6 +994,20 @@ class CV_EXPORTS Mat
```

Review comment:
Tests should be added too.
**File:** modules/core/include/opencv2/core/mat.hpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine

**Code Changes:**
```diff
@@ -67,6 +67,113 @@ enum AccessFlag { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25,
 CV_ENUM_FLAGS(AccessFlag)
 __CV_ENUM_FLAGS_BITWISE_AND(AccessFlag, int, AccessFlag)
 
+/**
+ * @brief Enum of data layout for model inference.
+ * @see Image2BlobParams
+ */
+enum DataLayout
+{
```

Review comment:
Consider using inheritance to avoid creation of GOD classes.
**File:** modules/core/src/matrix.cpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine
**Review Line:** 1110

**Code Changes:**
```diff
     return p;
 }
 
+MatShape Mat::shape() const
+{
+    return dims == 0 && data == 0 ? MatShape() : MatShape(dims, size.p);
+}
 
 Mat::Mat(Mat&& m) CV_NOEXCEPT
     : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data),
@@ -747,6 +1243,27 @@ void Mat::create(const std::vector<int>& _sizes, int _type)
```

Review comment:
We should not work with non-existed tensors. It is a programming error in general. `CV_Assert(data);`
**File:** modules/core/src/matrix.cpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine
**Review Line:** 1851

**Code Changes:**
```diff
 }
 
+Mat Mat::reshape(int _cn, const MatShape& _newshape) const
+{
+    if (_newshape.dims < 0) {
+        int newshape[] = {0};
+        return reshape(_cn, 1, newshape);
+    }
+    return reshape(_cn, _newshape.dims, _newshape.p);
+}
+
```

Review comment:
Looks like as an invalid usage which we should not allow.
**File:** modules/core/src/matrix_wrap.cpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine

**Code Changes:**
```diff
@@ -593,6 +593,41 @@ int _InputArray::sizend(int* arrsz, int i) const
     return d;
 }
 
+bool _InputArray::empty(int i) const
+{
+    _InputArray::KindFlag k = kind();
+    if (i >= 0) {
+        if (k == STD_VECTOR_MAT) {
+            auto mv = reinterpret_cast<const std::vector<Mat>*>(obj);
```

Review comment:
Keep code readable. One line - one variable.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine

**Code Changes:**
```diff
@@ -42,6 +42,7 @@
 #ifndef OPENCV_DNN_DNN_HPP
 #define OPENCV_DNN_DNN_HPP
 
+#include <ostream>
 #include <vector>
 #include <opencv2/core.hpp>
 #include "opencv2/core/async.hpp"
@@ -61,7 +62,6 @@ CV__DNN_INLINE_NS_BEGIN
 //! @addtogroup dnn
```

Review comment:
int => enum type
**File:** modules/dnn/src/graph_buffer_allocator.cpp
**Change Type:** added
**Context:** PR #26056: New dnn engine
**Review Line:** 332

**Code Changes:**
```diff
+};
+
+void Net::Impl::assignBuffers()
+{
+    BufferAllocator buf_allocator(this);
+    buf_allocator.assign();
+}
+
+CV__DNN_INLINE_NS_END
+}}
```

Review comment:
How to disable that? E.g for debug pursposes.
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine
**Review Line:** 2314

**Code Changes:**
```diff
@@ -2311,10 +2311,10 @@ void ONNXImporter::parseUnsqueeze(LayerParams& layerParams, const opencv_onnx::N
     int axis = axes.getIntValue(0);
     axis = axis < 0 ? axis + (int)inpShape.size() + 1 : axis;
     CV_Assert(0 <= axis && axis <= inpShape.size());
-    std::vector<int> outShape = inpShape;
+    MatShape outShape = inpShape;
     outShape.insert(outShape.begin() + axis, 1);
     layerParams.type = (depth == CV_8S) ? "ReshapeInt8" : "Reshape";
-    layerParams.set("dim", DictValue::arrayInt(&outShape[0], outShape.size()));
+    layerParams.set("dim", DictValue::arrayInt(&outShape[0], (int)outShape.size()));
     if (hasDynamicShapes)
```

Review comment:
Since we are getting symbolic inference, the shape inference in onnx importer should be dropped, am I right?
**File:** modules/dnn/src/onnx/onnx_importer2.cpp
**Change Type:** added
**Context:** PR #26056: New dnn engine

**Code Changes:**
```diff
@@ -0,0 +1,2450 @@
+// 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 "../net_impl.hpp"
+
+#include <opencv2/dnn/shape_utils.hpp>
+#include <opencv2/dnn/layer_reg.private.hpp>
```

Review comment:
I believe this can be dropped on 5.x since `Mat` can handles 0D/1D correctly.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine

**Code Changes:**
```diff
@@ -42,6 +42,7 @@
 #ifndef OPENCV_DNN_DNN_HPP
 #define OPENCV_DNN_DNN_HPP
 
+#include <ostream>
 #include <vector>
 #include <opencv2/core.hpp>
 #include "opencv2/core/async.hpp"
@@ -61,7 +62,6 @@ CV__DNN_INLINE_NS_BEGIN
 //! @addtogroup dnn
```

Review comment:
The methods are defined, but not implemented. It causes linker issue.
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine
**Review Line:** 2314

**Code Changes:**
```diff
@@ -2311,10 +2311,10 @@ void ONNXImporter::parseUnsqueeze(LayerParams& layerParams, const opencv_onnx::N
     int axis = axes.getIntValue(0);
     axis = axis < 0 ? axis + (int)inpShape.size() + 1 : axis;
     CV_Assert(0 <= axis && axis <= inpShape.size());
-    std::vector<int> outShape = inpShape;
+    MatShape outShape = inpShape;
     outShape.insert(outShape.begin() + axis, 1);
     layerParams.type = (depth == CV_8S) ? "ReshapeInt8" : "Reshape";
-    layerParams.set("dim", DictValue::arrayInt(&outShape[0], outShape.size()));
+    layerParams.set("dim", DictValue::arrayInt(&outShape[0], (int)outShape.size()));
     if (hasDynamicShapes)
```

Review comment:
yes, I removed it. But it means more cases should be handled during the inference itself.
**File:** modules/dnn/src/onnx/onnx_importer2.cpp
**Change Type:** added
**Context:** PR #26056: New dnn engine

**Code Changes:**
```diff
@@ -0,0 +1,2450 @@
+// 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 "../net_impl.hpp"
+
+#include <opencv2/dnn/shape_utils.hpp>
+#include <opencv2/dnn/layer_reg.private.hpp>
```

Review comment:
Add a wrapper for this?
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** modified
**Context:** PR #26056: New dnn engine
**Review Line:** 2314

**Code Changes:**
```diff
@@ -2311,10 +2311,10 @@ void ONNXImporter::parseUnsqueeze(LayerParams& layerParams, const opencv_onnx::N
     int axis = axes.getIntValue(0);
     axis = axis < 0 ? axis + (int)inpShape.size() + 1 : axis;
     CV_Assert(0 <= axis && axis <= inpShape.size());
-    std::vector<int> outShape = inpShape;
+    MatShape outShape = inpShape;
     outShape.insert(outShape.begin() + axis, 1);
     layerParams.type = (depth == CV_8S) ? "ReshapeInt8" : "Reshape";
-    layerParams.set("dim", DictValue::arrayInt(&outShape[0], outShape.size()));
+    layerParams.set("dim", DictValue::arrayInt(&outShape[0], (int)outShape.size()));
     if (hasDynamicShapes)
```

Review comment:
Code looks way simpler and cleaner in the new importer. I have no idea on > more cases should be handled during the inference itself though.
**File:** modules/dnn/src/onnx/onnx_importer2.cpp
**Change Type:** added
**Context:** PR #26056: New dnn engine

**Code Changes:**
```diff
@@ -0,0 +1,2450 @@
+// 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 "../net_impl.hpp"
+
+#include <opencv2/dnn/shape_utils.hpp>
+#include <opencv2/dnn/layer_reg.private.hpp>
```

Review comment:
there is `Net::newConstArg()` (and `Net::Impl::newConstArg()`) for that, which is a safe way to create new constant argument.