nareshmlx/opencv-pr huggingface dataset:
**File:** modules/dnn/src/layers/recurrent_layers.cpp
**Change Type:** modified
**Context:** PR #20658: dnn: LSTM optimisation
**Review Line:** 461

**Code Changes:**
```diff
+                }
+                else
+#endif
+                {
+                    gemm(hInternal, Wh, 1, gates, 1, gates, GEMM_2_T);  //+Wh * h_{t-1}
+                }
 
                 Mat gateI = gates.colRange(0*numOut, 1*numOut);
                 Mat gateF = gates.colRange(1*numOut, 2*numOut);
```

Review comment:
Good point, I hadn't noticed that. I think it might require a bit of a rethink to avoid having lots of copy/paste code for peepholes. The obvious thing is to add a helper which handles the dispatching, and that should be separate to the recurrent layers so it's reusable. It should probably also be a class to avoid `checkHardwareSupport` on each call. I'll have a think and suggest a design.
**File:** modules/dnn/src/layers/recurrent_layers.cpp
**Change Type:** modified
**Context:** PR #20658: dnn: LSTM optimisation
**Review Line:** 461

**Code Changes:**
```diff
+                }
+                else
+#endif
+                {
+                    gemm(hInternal, Wh, 1, gates, 1, gates, GEMM_2_T);  //+Wh * h_{t-1}
+                }
 
                 Mat gateI = gates.colRange(0*numOut, 1*numOut);
                 Mat gateF = gates.colRange(1*numOut, 2*numOut);
```

Review comment:
the existing PR can be merged as-is since it already adds speedup. you can send these changes (for peephole) later, in a separate PR
**File:** modules/dnn/src/dnn.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -45,6 +45,7 @@
 #include "ie_ngraph.hpp"
 #include "op_vkcom.hpp"
 #include "op_cuda.hpp"
+#include "op_webnn.hpp"
 
 #ifdef HAVE_CUDA
 #include "cuda4dnn/init.hpp"
@@ -224,6 +225,13 @@ class BackendRegistry
 #endif
```

Review comment:
Please remove the commented code.
**File:** modules/dnn/src/layers/pooling_layer.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -46,6 +46,7 @@
 #include "../op_cuda.hpp"
 #include "../op_halide.hpp"
 #include "../op_inf_engine.hpp"
+#include "../op_webnn.hpp"
 
 #ifdef HAVE_DNN_NGRAPH
 #include "../ie_ngraph.hpp"
@@ -85,6 +86,7 @@ typedef int HALIDE_DIFF_T;
 #include "../cuda4dnn/primitives/max_unpooling.hpp"
```

Review comment:
Probably you can log the other type of pooling are not supported by WebNN backend.
**File:** modules/dnn/src/layers/pooling_layer.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -46,6 +46,7 @@
 #include "../op_cuda.hpp"
 #include "../op_halide.hpp"
 #include "../op_inf_engine.hpp"
+#include "../op_webnn.hpp"
 
 #ifdef HAVE_DNN_NGRAPH
 #include "../ie_ngraph.hpp"
@@ -85,6 +86,7 @@ typedef int HALIDE_DIFF_T;
 #include "../cuda4dnn/primitives/max_unpooling.hpp"
```

Review comment:
please remove the commented code.
**File:** modules/dnn/src/layers/pooling_layer.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...
**Review Line:** 692

**Code Changes:**
```diff
+        else if (type == AVE)
+        {
+            auto operand = webnnGraphBuilder.AveragePool2d(webnnInpOperand, options.AsPtr());
+            return Ptr<BackendNode>(new WebnnBackendNode(operand));
+        } else {
+            CV_Error(Error::StsNotImplemented, "Unsupported pooling type");
+        }
+    }
+#endif // HAVE_WEBNN
 
     class PoolingInvoker : public ParallelLoopBody
```

Review comment:
It would be good to log which type of pooling is not supported.
**File:** modules/dnn/src/op_webnn.cpp
**Change Type:** added
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -0,0 +1,249 @@
+// 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 <fstream>
+#include "op_webnn.hpp"
+
+#include <opencv2/core/utils/configuration.private.hpp>
+#include <opencv2/core/utils/logger.hpp>
```

Review comment:
remove the commented code.
**File:** modules/dnn/src/op_webnn.cpp
**Change Type:** added
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -0,0 +1,249 @@
+// 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 <fstream>
+#include "op_webnn.hpp"
+
+#include <opencv2/core/utils/configuration.private.hpp>
+#include <opencv2/core/utils/logger.hpp>
```

Review comment:
turn this into a logger or remove it.
**File:** modules/dnn/src/layers/pooling_layer.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...
**Review Line:** 692

**Code Changes:**
```diff
+        else if (type == AVE)
+        {
+            auto operand = webnnGraphBuilder.AveragePool2d(webnnInpOperand, options.AsPtr());
+            return Ptr<BackendNode>(new WebnnBackendNode(operand));
+        } else {
+            CV_Error(Error::StsNotImplemented, "Unsupported pooling type");
+        }
+    }
+#endif // HAVE_WEBNN
 
     class PoolingInvoker : public ParallelLoopBody
```

Review comment:
Hi Ningxin, I noticed that this line of code won't run actually since if ```type != MAX && type != AVE```, the ```supportBackend()``` function will return false. The reason why I add this code here is to avoid the error that "the function may return void" during the compiling process. To report which type of pooling is not supported, a CV_LOG_WARNING can be added to the ```supportBackend()``` function.
**File:** modules/dnn/src/layers/batch_norm_layer.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -15,6 +15,7 @@ Implementation of Batch Normalization layer.
 #include "../op_halide.hpp"
 #include "../op_inf_engine.hpp"
 #include "../ie_ngraph.hpp"
+#include "../op_webnn.hpp"
 
 #include <opencv2/dnn/shape_utils.hpp>
 
@@ -172,6 +173,7 @@ class BatchNormLayerImpl CV_FINAL : public BatchNormLayer
         return (backendId == DNN_BACKEND_OPENCV) ||
```

Review comment:
I would suggest to move `BuildConstant` to `op_webnn.h` and `op_webnn.cpp`, so other layers could share the implementation.
**File:** modules/dnn/src/op_webnn.hpp
**Change Type:** added
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -0,0 +1,171 @@
+// 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 __OPENCV_DNN_OP_WEBNN_HPP__
+#define __OPENCV_DNN_OP_WEBNN_HPP__
+
+#include "opencv2/core/cvdef.h"
+#include "opencv2/core/cvstd.hpp"
```

Review comment:
Should you add namespace for webnn related methods, say `webnn::getShape`? BTW, webnn defines `dimensions` as `vector<int32_t>`. So it would be better to change this method signature to ```c++ std::vector<int32_t> getDimensions(const Mat& mat); ```
**File:** modules/dnn/src/layers/batch_norm_layer.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -15,6 +15,7 @@ Implementation of Batch Normalization layer.
 #include "../op_halide.hpp"
 #include "../op_inf_engine.hpp"
 #include "../ie_ngraph.hpp"
+#include "../op_webnn.hpp"
 
 #include <opencv2/dnn/shape_utils.hpp>
 
@@ -172,6 +173,7 @@ class BatchNormLayerImpl CV_FINAL : public BatchNormLayer
         return (backendId == DNN_BACKEND_OPENCV) ||
```

Review comment:
What's the reason to add this `tryQuantize` for batch norm layer and others?
**File:** modules/dnn/src/layers/batch_norm_layer.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -15,6 +15,7 @@ Implementation of Batch Normalization layer.
 #include "../op_halide.hpp"
 #include "../op_inf_engine.hpp"
 #include "../ie_ngraph.hpp"
+#include "../op_webnn.hpp"
 
 #include <opencv2/dnn/shape_utils.hpp>
 
@@ -172,6 +173,7 @@ class BatchNormLayerImpl CV_FINAL : public BatchNormLayer
         return (backendId == DNN_BACKEND_OPENCV) ||
```

Review comment:
Hi Ningxin, this `tryQuantize` function seems to be a newly added function in the main branch.
**File:** modules/dnn/src/layers/batch_norm_layer.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -15,6 +15,7 @@ Implementation of Batch Normalization layer.
 #include "../op_halide.hpp"
 #include "../op_inf_engine.hpp"
 #include "../ie_ngraph.hpp"
+#include "../op_webnn.hpp"
 
 #include <opencv2/dnn/shape_utils.hpp>
 
@@ -172,6 +173,7 @@ class BatchNormLayerImpl CV_FINAL : public BatchNormLayer
         return (backendId == DNN_BACKEND_OPENCV) ||
```

Review comment:
When I upload my new codes, github reminds me that there are some conflicts since the main branch added this `tryQuantize` function but my PR didn't. Thus, in order to resolve the possible conflicts, I added this function to my PR.
**File:** modules/dnn/src/layers/batch_norm_layer.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -15,6 +15,7 @@ Implementation of Batch Normalization layer.
 #include "../op_halide.hpp"
 #include "../op_inf_engine.hpp"
 #include "../ie_ngraph.hpp"
+#include "../op_webnn.hpp"
 
 #include <opencv2/dnn/shape_utils.hpp>
 
@@ -172,6 +173,7 @@ class BatchNormLayerImpl CV_FINAL : public BatchNormLayer
         return (backendId == DNN_BACKEND_OPENCV) ||
```

Review comment:
this comes from upstream merged PR #20228 (some experimental whole network int8 quantization...)
**File:** modules/dnn/src/dnn.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -45,6 +45,7 @@
 #include "ie_ngraph.hpp"
 #include "op_vkcom.hpp"
 #include "op_cuda.hpp"
+#include "op_webnn.hpp"
 
 #ifdef HAVE_CUDA
 #include "cuda4dnn/init.hpp"
@@ -224,6 +225,13 @@ class BackendRegistry
 #endif
```

Review comment:
Why do we need this change?
**File:** modules/dnn/src/layers/convolution_layer.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -47,6 +47,7 @@
 #include "../op_inf_engine.hpp"
 #include "../ie_ngraph.hpp"
 #include "../op_vkcom.hpp"
+#include "../op_webnn.hpp"
 
 #include <opencv2/core/utils/configuration.private.hpp>
 #include <opencv2/core/utils/logger.hpp>
@@ -80,13 +81,19 @@ class BaseConvolutionLayerImpl : public ConvolutionLayer
 public:
```

Review comment:
Avoid code duplication in conditions. Use `return false;` after warning and `return true;` below.
**File:** modules/dnn/src/op_webnn.hpp
**Change Type:** added
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -0,0 +1,171 @@
+// 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 __OPENCV_DNN_OP_WEBNN_HPP__
+#define __OPENCV_DNN_OP_WEBNN_HPP__
+
+#include "opencv2/core/cvdef.h"
+#include "opencv2/core/cvstd.hpp"
```

Review comment:
Perhaps this is not accurate and should be removed (from all new files).
**File:** cmake/OpenCVDetectWebNN.cmake
**Change Type:** added
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -0,0 +1,49 @@
+if(NOT EMSCRIPTEN)
+  if(WITH_WEBNN)
+    ocv_check_environment_variables(WEBNN_HEADER_DIRS)
+    ocv_check_environment_variables(WEBNN_INCLUDE_DIRS)
+    ocv_check_environment_variables(WEBNN_LIBRARIES)
+    if(NOT DEFINED WEBNN_HEADER_DIRS)
+      set(WEBNN_HEADER_DIRS "$ENV{WEBNN_NATIVE_DIR}/gen/src/include")
+    endif()
+    if(NOT DEFINED WEBNN_INCLUDE_DIRS)
```

Review comment:
> `${VALID_WEBNN}` `${}` is not needed here.
**File:** cmake/OpenCVDetectWebNN.cmake
**Change Type:** added
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -0,0 +1,49 @@
+if(NOT EMSCRIPTEN)
+  if(WITH_WEBNN)
+    ocv_check_environment_variables(WEBNN_HEADER_DIRS)
+    ocv_check_environment_variables(WEBNN_INCLUDE_DIRS)
+    ocv_check_environment_variables(WEBNN_LIBRARIES)
+    if(NOT DEFINED WEBNN_HEADER_DIRS)
+      set(WEBNN_HEADER_DIRS "$ENV{WEBNN_NATIVE_DIR}/gen/src/include")
+    endif()
+    if(NOT DEFINED WEBNN_INCLUDE_DIRS)
```

Review comment:
no need to clear these vars
**File:** cmake/OpenCVDetectWebNN.cmake
**Change Type:** added
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -0,0 +1,49 @@
+if(NOT EMSCRIPTEN)
+  if(WITH_WEBNN)
+    ocv_check_environment_variables(WEBNN_HEADER_DIRS)
+    ocv_check_environment_variables(WEBNN_INCLUDE_DIRS)
+    ocv_check_environment_variables(WEBNN_LIBRARIES)
+    if(NOT DEFINED WEBNN_HEADER_DIRS)
+      set(WEBNN_HEADER_DIRS "$ENV{WEBNN_NATIVE_DIR}/gen/src/include")
+    endif()
+    if(NOT DEFINED WEBNN_INCLUDE_DIRS)
```

Review comment:
> `if(NOT EMSCRIPTEN)` Used in both blocks. If this is expected, then blocks should be merged.
**File:** cmake/OpenCVDetectWebNN.cmake
**Change Type:** added
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -0,0 +1,49 @@
+if(NOT EMSCRIPTEN)
+  if(WITH_WEBNN)
+    ocv_check_environment_variables(WEBNN_HEADER_DIRS)
+    ocv_check_environment_variables(WEBNN_INCLUDE_DIRS)
+    ocv_check_environment_variables(WEBNN_LIBRARIES)
+    if(NOT DEFINED WEBNN_HEADER_DIRS)
+      set(WEBNN_HEADER_DIRS "$ENV{WEBNN_NATIVE_DIR}/gen/src/include")
+    endif()
+    if(NOT DEFINED WEBNN_INCLUDE_DIRS)
```

Review comment:
> `$ENV{WEBNN_NATIVE_DIR}` It is better to use CMake variable instead (you can still initialize this from environment, see usage of `ocv_check_environment_variables`).
**File:** cmake/OpenCVDetectWebNN.cmake
**Change Type:** added
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -0,0 +1,49 @@
+if(NOT EMSCRIPTEN)
+  if(WITH_WEBNN)
+    ocv_check_environment_variables(WEBNN_HEADER_DIRS)
+    ocv_check_environment_variables(WEBNN_INCLUDE_DIRS)
+    ocv_check_environment_variables(WEBNN_LIBRARIES)
+    if(NOT DEFINED WEBNN_HEADER_DIRS)
+      set(WEBNN_HEADER_DIRS "$ENV{WEBNN_NATIVE_DIR}/gen/src/include")
+    endif()
+    if(NOT DEFINED WEBNN_INCLUDE_DIRS)
```

Review comment:
> native What is about Emscripten case?
**File:** modules/dnn/CMakeLists.txt
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -19,6 +19,10 @@ if(OPENCV_DNN_OPENCL AND HAVE_OPENCL)
   add_definitions(-DCV_OCL4DNN=1)
 endif()
 
+if(WITH_WEBNN AND HAVE_WEBNN)
+  add_definitions(-DHAVE_WEBNN=1)
+endif()
+
 ocv_option(OPENCV_DNN_CUDA "Build with CUDA support"
     HAVE_CUDA
```

Review comment:
Don't use tabs. Indentation in CMake scripts is 2 spaces.
**File:** modules/dnn/src/layers/batch_norm_layer.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -15,6 +15,7 @@ Implementation of Batch Normalization layer.
 #include "../op_halide.hpp"
 #include "../op_inf_engine.hpp"
 #include "../ie_ngraph.hpp"
+#include "../op_webnn.hpp"
 
 #include <opencv2/dnn/shape_utils.hpp>
 
@@ -172,6 +173,7 @@ class BatchNormLayerImpl CV_FINAL : public BatchNormLayer
         return (backendId == DNN_BACKEND_OPENCV) ||
```

Review comment:
Hi Ningxin, I have re-based my codes on current upstream master repo. This should be fixed now.
**File:** modules/dnn/src/layers/convolution_layer.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -47,6 +47,7 @@
 #include "../op_inf_engine.hpp"
 #include "../ie_ngraph.hpp"
 #include "../op_vkcom.hpp"
+#include "../op_webnn.hpp"
 
 #include <opencv2/core/utils/configuration.private.hpp>
 #include <opencv2/core/utils/logger.hpp>
@@ -80,13 +81,19 @@ class BaseConvolutionLayerImpl : public ConvolutionLayer
 public:
```

Review comment:
This has been fixed with the new commit.
**File:** cmake/OpenCVDetectWebNN.cmake
**Change Type:** added
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -0,0 +1,49 @@
+if(NOT EMSCRIPTEN)
+  if(WITH_WEBNN)
+    ocv_check_environment_variables(WEBNN_HEADER_DIRS)
+    ocv_check_environment_variables(WEBNN_INCLUDE_DIRS)
+    ocv_check_environment_variables(WEBNN_LIBRARIES)
+    if(NOT DEFINED WEBNN_HEADER_DIRS)
+      set(WEBNN_HEADER_DIRS "$ENV{WEBNN_NATIVE_DIR}/gen/src/include")
+    endif()
+    if(NOT DEFINED WEBNN_INCLUDE_DIRS)
```

Review comment:
Fixed now.
**File:** modules/dnn/CMakeLists.txt
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -19,6 +19,10 @@ if(OPENCV_DNN_OPENCL AND HAVE_OPENCL)
   add_definitions(-DCV_OCL4DNN=1)
 endif()
 
+if(WITH_WEBNN AND HAVE_WEBNN)
+  add_definitions(-DHAVE_WEBNN=1)
+endif()
+
 ocv_option(OPENCV_DNN_CUDA "Build with CUDA support"
     HAVE_CUDA
```

Review comment:
Fixed now.
**File:** cmake/OpenCVDetectWebNN.cmake
**Change Type:** added
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -0,0 +1,49 @@
+if(NOT EMSCRIPTEN)
+  if(WITH_WEBNN)
+    ocv_check_environment_variables(WEBNN_HEADER_DIRS)
+    ocv_check_environment_variables(WEBNN_INCLUDE_DIRS)
+    ocv_check_environment_variables(WEBNN_LIBRARIES)
+    if(NOT DEFINED WEBNN_HEADER_DIRS)
+      set(WEBNN_HEADER_DIRS "$ENV{WEBNN_NATIVE_DIR}/gen/src/include")
+    endif()
+    if(NOT DEFINED WEBNN_INCLUDE_DIRS)
```

Review comment:
2 space indentation
**File:** samples/dnn/classification.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -1,5 +1,6 @@
 #include <fstream>
 #include <sstream>
+#include <iostream>
 
 #include <opencv2/dnn.hpp>
 #include <opencv2/imgproc.hpp>
@@ -17,14 +18,16 @@ std::string keys =
     "{ std              | 0.0 0.0 0.0 | Preprocess input image by dividing on a standard deviation.}"
     "{ crop             | false | Preprocess input image by center cropping.}"
```

Review comment:
It is better to use external `TickMeter` instead of `.getPerfProfile()`
**File:** samples/dnn/classification.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -1,5 +1,6 @@
 #include <fstream>
 #include <sstream>
+#include <iostream>
 
 #include <opencv2/dnn.hpp>
 #include <opencv2/imgproc.hpp>
@@ -17,14 +18,16 @@ std::string keys =
     "{ std              | 0.0 0.0 0.0 | Preprocess input image by dividing on a standard deviation.}"
     "{ crop             | false | Preprocess input image by center cropping.}"
```

Review comment:
> `double t;` Prefer to declare variables near its usage. It significantly increases code readability.
**File:** samples/dnn/classification.cpp
**Change Type:** modified
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -1,5 +1,6 @@
 #include <fstream>
 #include <sstream>
+#include <iostream>
 
 #include <opencv2/dnn.hpp>
 #include <opencv2/imgproc.hpp>
@@ -17,14 +18,16 @@ std::string keys =
     "{ std              | 0.0 0.0 0.0 | Preprocess input image by dividing on a standard deviation.}"
     "{ crop             | false | Preprocess input image by center cropping.}"
```

Review comment:
Probably not needed
**File:** modules/dnn/src/webnn/README.md
**Change Type:** added
**Context:** PR #20406: [GSoC] OpenCV.js: Accelerate OpenCV.js DNN via WebNN - ### Overview Proposal: OpenCV.js: Accelerate OpenCV.js DNN via WebNN Mentor: Ningxin...

**Code Changes:**
```diff
@@ -0,0 +1,11 @@
+## Build Instructions
+
+### Build WebNN-native and set the environment variable
+
+Refer to [WebNN's build instructions](https://github.com/webmachinelearning/webnn-native) to complete the build of WebNN-native.
+
+Set environment variable `WEBNN_NATIVE_DIR` to enable native DNN_BACKEND_WEBNN build: `export WEBNN_NATIVE_DIR=${PATH_TO_WebNN}`. Please let `WEBNN_NATIVE_DIR` points the output directory of webnn-native build (e.g. webnn-native/out/Release).
+
+### Test native DNN_BACKEND_WEBNN backend
```

Review comment:
> https://docs.opencv.org/master Direct URL links on docs.opencv.org are not allowed. Use doxygen references instead.