nareshmlx/opencv-pr huggingface dataset:
**File:** cmake/OpenCVFindLibsGrfmt.cmake
**Change Type:** modified
**Context:** PR #23596: Add AVIF support through libavif.
**Review Line:** 48

**Code Changes:**
```diff
+  ocv_clear_internal_cache_vars(AVIF_LIBRARY AVIF_INCLUDE_DIR)
+  include(cmake/OpenCVFindAVIF.cmake)
+  if(AVIF_FOUND)
+    set(HAVE_AVIF 1)
+  endif()
+endif()
+
 # --- libjpeg (optional) ---
 if(WITH_JPEG)
   if(BUILD_JPEG)
```

Review comment:
For WEBP it's most probably mistake.
**File:** cmake/OpenCVFindAVIF.cmake
**Change Type:** added
**Context:** PR #23596: Add AVIF support through libavif.

**Code Changes:**
```diff
@@ -0,0 +1,46 @@
+#=============================================================================
+# Find AVIF library
+#=============================================================================
+# Find the native AVIF headers and libraries.
+#
+#  AVIF_INCLUDE_DIRS - where to find avif/avif.h, etc.
+#  AVIF_LIBRARIES    - List of libraries when using AVIF.
+#  AVIF_FOUND        - True if AVIF is found.
+#=============================================================================
```

Review comment:
The first branch does not work. Nobody defines avif target. It makes sense to use `AVIF_FOUND`, if you uncomment find_package.
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #23596: Add AVIF support through libavif.
**Review Line:** 1390

**Code Changes:**
```diff
+  if(AVIF_VERSION)
+    status("    AVIF:" AVIF_FOUND THEN "${AVIF_LIBRARY} (ver ${AVIF_VERSION})" ELSE "NO")
+  else()
+    status("    AVIF:" AVIF_FOUND THEN "${AVIF_LIBRARY}" ELSE "NO")
+  endif()
+endif()
+
 if(WITH_PNG OR HAVE_PNG OR WITH_SPNG)
   if(WITH_SPNG)
     status("    PNG:" "build-${SPNG_LIBRARY} (ver ${SPNG_VERSION})")
```

Review comment:
In my case `AVIF_LIBRARY` resolves to target name "avif". It's not informative. I propose to check `if TARGET {AVIF_LIBRARY}` and get target file name for output.
**File:** modules/imgcodecs/src/grfmt_avif.cpp
**Change Type:** added
**Context:** PR #23596: Add AVIF support through libavif.

**Code Changes:**
```diff
@@ -0,0 +1,369 @@
+// 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"
+
+#ifdef HAVE_AVIF
+
+#include <avif/avif.h>
```

Review comment:
what 10 means here?
**File:** modules/imgcodecs/test/test_avif.cpp
**Change Type:** added
**Context:** PR #23596: Add AVIF support through libavif.
**Review Line:** 142

**Code Changes:**
```diff
+  EXPECT_NO_THROW(cv::imwrite(output, img_original, encoding_params_));
+
+  // Read from file.
+  const cv::Mat img = cv::imread(output, imread_mode_);
+
+  ValidateRead(img_original, img);
+
+  EXPECT_EQ(0, remove(output.c_str()));
+}
+
+INSTANTIATE_TEST_CASE_P(
```

Review comment:
temporary file is not removed in the test.
**File:** modules/imgcodecs/test/test_avif.cpp
**Change Type:** added
**Context:** PR #23596: Add AVIF support through libavif.

**Code Changes:**
```diff
@@ -0,0 +1,355 @@
+// 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 <cstdint>
+#include <fstream>
+
+#include "test_precomp.hpp"
+
```

Review comment:
Avif specific code in test is bad idea, I propose to save the file as test data in opencv_extra.
**File:** modules/imgcodecs/test/test_avif.cpp
**Change Type:** added
**Context:** PR #23596: Add AVIF support through libavif.
**Review Line:** 352

**Code Changes:**
```diff
+    ::testing::Combine(::testing::ValuesIn({8, 10, 12}),
+                       ::testing::ValuesIn({1, 3}), ::testing::ValuesIn({50}),
+                       ::testing::ValuesIn({IMREAD_UNCHANGED, IMREAD_GRAYSCALE,
+                                            IMREAD_COLOR})));
+
+}  // namespace
+}  // namespace opencv_test
+
+#endif  // HAVE_AVIF
```

Review comment:
sure, please add it to opencv_extra.
**File:** cmake/OpenCVFindAVIF.cmake
**Change Type:** added
**Context:** PR #23596: Add AVIF support through libavif.

**Code Changes:**
```diff
@@ -0,0 +1,46 @@
+#=============================================================================
+# Find AVIF library
+#=============================================================================
+# Find the native AVIF headers and libraries.
+#
+#  AVIF_INCLUDE_DIRS - where to find avif/avif.h, etc.
+#  AVIF_LIBRARIES    - List of libraries when using AVIF.
+#  AVIF_FOUND        - True if AVIF is found.
+#=============================================================================
```

Review comment:
My bad, find_package was commented out for debug ....
**File:** modules/imgcodecs/src/grfmt_avif.cpp
**Change Type:** added
**Context:** PR #23596: Add AVIF support through libavif.

**Code Changes:**
```diff
@@ -0,0 +1,369 @@
+// 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"
+
+#ifdef HAVE_AVIF
+
+#include <avif/avif.h>
```

Review comment:
Removed: this is related to the frequency of the animation. We have no parameter for that in OpenCV. Ideally, there would be a frame duration.
**File:** modules/imgcodecs/test/test_avif.cpp
**Change Type:** added
**Context:** PR #23596: Add AVIF support through libavif.

**Code Changes:**
```diff
@@ -0,0 +1,355 @@
+// 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 <cstdint>
+#include <fstream>
+
+#include "test_precomp.hpp"
+
```

Review comment:
The files were added in https://github.com/opencv/opencv_extra/pull/1068
**File:** modules/imgcodecs/test/test_avif.cpp
**Change Type:** added
**Context:** PR #23596: Add AVIF support through libavif.

**Code Changes:**
```diff
@@ -0,0 +1,355 @@
+// 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 <cstdint>
+#include <fstream>
+
+#include "test_precomp.hpp"
+
```

Review comment:
It makes sense to make them different to ensure dimentions swap issue.
**File:** modules/imgproc/src/histogram.cpp
**Change Type:** modified
**Context:** PR #24371: Clean up the obsolete API of Universal Intrinsic

**Code Changes:**
```diff
@@ -2093,7 +2093,7 @@ double cv::compareHist( InputArray _H1, InputArray _H2, int method )
             v_float32 v_s11 = vx_setzero_f32();
             v_float32 v_s12 = vx_setzero_f32();
             v_float32 v_s22 = vx_setzero_f32();
-            for (; j <= len - v_float32::nlanes; j += v_float32::nlanes)
+            for (; j <= len - VTraits<v_float32>::vlanes(); j += VTraits<v_float32>::vlanes())
             {
                 v_float32 v_a = vx_load(h1 + j);
                 v_float32 v_b = vx_load(h2 + j);
@@ -2134,10 +2134,10 @@ double cv::compareHist( InputArray _H1, InputArray _H2, int method )
```

Review comment:
```suggestion v_result = v_add(v_result, v_src); ```
**File:** modules/imgproc/src/color_lab.cpp
**Change Type:** modified
**Context:** PR #24371: Clean up the obsolete API of Universal Intrinsic
**Review Line:** 1825

**Code Changes:**
```diff
             {
                 v_store_aligned(vxyz + (0*4+j)*vsize/4, x[j]);
@@ -1822,7 +1823,7 @@ struct RGB2Lab_b
             v_uint32 vLshift = vx_setall_u32((uint32_t)(Lshift + labDescaleShift));
             for(int k = 0; k < 4; k++)
             {
-                vL[k] = (vL[k] + vLshift) >> lab_shift2;
+                vL[k] = v_shr<lab_shift2>(v_add(vL[k], vLshift));
             }
             v_uint16 L0, L1;
             L0 = v_pack(vL[0], vL[1]);
```

Review comment:
Why has `lab_shift2` been replaced with `xyz_shift + 3`? Here and on line 1850.
**File:** modules/imgproc/src/color_lab.cpp
**Change Type:** modified
**Context:** PR #24371: Clean up the obsolete API of Universal Intrinsic

**Code Changes:**
```diff
@@ -66,7 +66,7 @@ template<typename _Tp> static inline cv::v_float32 splineInterpolate(const cv::v
     ix = v_shl<2>(ix);
 
     v_float32 t0, t1, t2, t3;
-    // assume that v_float32::nlanes == v_int32::nlanes
+    // assume that VTraits<v_float32>::vlanes() == VTraits<v_int32>::vlanes()
     if(VTraits<v_float32>::vlanes() == 4)
     {
         int32_t CV_DECL_ALIGNED(CV_SIMD_WIDTH) idx[4];
@@ -1388,16 +1388,16 @@ static inline void trilinearPackedInterpolate(const v_uint16x8& inX, const v_uin
```

Review comment:
Why has FLT_EPSILON been replaced here?
**File:** modules/imgproc/src/demosaicing.cpp
**Change Type:** modified
**Context:** PR #24371: Clean up the obsolete API of Universal Intrinsic

**Code Changes:**
```diff
@@ -188,21 +188,21 @@ class SIMDBayerInterpolator_8u
             v_uint16x8 r1 = v_reinterpret_as_u16(v_load(bayer+bayer_step));
             v_uint16x8 r2 = v_reinterpret_as_u16(v_load(bayer+bayer_step*2));
 
-            v_uint16x8 b1 = ((r0 << 8) >> 7) + ((r2 << 8) >> 7);
-            v_uint16x8 b0 = v_rotate_right<1>(b1) + b1;
-            b1 = v_rotate_right<1>(b1) << 1;
+            v_uint16x8 b1 = v_add(v_shr<7>(v_shl<8>(r0)), v_shr<7>(v_shl<8>(r2)));
+            v_uint16x8 b0 = v_add(v_rotate_right<1>(b1), b1);
+            b1 = v_shl<1>(v_rotate_right<1>(b1));
```

Review comment:
It looks like `v_merge_u16` macro has been expanded here (and below). Shouldn't we revert it back to macro?
**File:** modules/imgproc/src/demosaicing.cpp
**Change Type:** modified
**Context:** PR #24371: Clean up the obsolete API of Universal Intrinsic
**Review Line:** 1489

**Code Changes:**
```diff
+                            v_round(v_mul(v_cvt_s16f32_lo(t0), ngf0)),
+                            v_round(v_mul(v_cvt_s16f32_hi(t0), ngf1)))));
 
-                t1 = v_reinterpret_as_u16(v_reinterpret_as_s16(x0) +
+                t1 = v_reinterpret_as_u16(
+                    v_add(v_reinterpret_as_s16(x0),
                         v_pack(
-                          v_round(v_cvt_s16f32_lo(t1) * ngf0),
-                          v_round(v_cvt_s16f32_hi(t1) * ngf1)));
+                            v_round(v_mul(v_cvt_s16f32_lo(t1), ngf0)),
+                            v_round(v_mul(v_cvt_s16f32_hi(t1), ngf1)))));
```

Review comment:
Macros `v_cvt_s16f32_lo` and `v_cvt_s16f32_hi` has been expanded here too.
**File:** modules/imgproc/src/median_blur.simd.hpp
**Change Type:** modified
**Context:** PR #24371: Clean up the obsolete API of Universal Intrinsic

**Code Changes:**
```diff
@@ -179,10 +179,10 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize )
                 for (k = 0; k < 16; ++k)
                 {
 #if CV_SIMD256
-                    v_store(H.fine[k], v_mul_wrap(v256_load(h_fine + 16 * n*(16 * c + k)), v256_setall_u16(2 * r + 1)) + v256_load(H.fine[k]));
+                    v_store(H.fine[k], v_mul_wrap(v256_load(h_fine + 16 * n*(16 * c + k)), v_add(v256_setall_u16(2 * r + 1), v256_load(H.fine[k]))));
 #elif CV_SIMD128
-                    v_store(H.fine[k], v_mul_wrap(v_load(h_fine + 16 * n*(16 * c + k)), v_setall_u16((ushort)(2 * r + 1))) + v_load(H.fine[k]));
-                    v_store(H.fine[k] + 8, v_mul_wrap(v_load(h_fine + 16 * n*(16 * c + k) + 8), v_setall_u16((ushort)(2 * r + 1))) + v_load(H.fine[k] + 8));
+                    v_store(H.fine[k], v_add(v_mul_wrap(v_load(h_fine + 16 * n * (16 * c + k)), v_setall_u16((ushort)(2 * r + 1))), v_load(H.fine[k])));
```

Review comment:
Here `MAX` macro has been expanded too.
**File:** modules/imgproc/src/color_lab.cpp
**Change Type:** modified
**Context:** PR #24371: Clean up the obsolete API of Universal Intrinsic
**Review Line:** 1825

**Code Changes:**
```diff
             {
                 v_store_aligned(vxyz + (0*4+j)*vsize/4, x[j]);
@@ -1822,7 +1823,7 @@ struct RGB2Lab_b
             v_uint32 vLshift = vx_setall_u32((uint32_t)(Lshift + labDescaleShift));
             for(int k = 0; k < 4; k++)
             {
-                vL[k] = (vL[k] + vLshift) >> lab_shift2;
+                vL[k] = v_shr<lab_shift2>(v_add(vL[k], vLshift));
             }
             v_uint16 L0, L1;
             L0 = v_pack(vL[0], vL[1]);
```

Review comment:
These macros were incorrectly auto-expanded by the rewriter (clang-tidy). I have already reverted them all.
**File:** modules/dnn/CMakeLists.txt
**Change Type:** modified
**Context:** PR #24425: dnn: fix HAVE_TIMVX macro definition in dnn test

**Code Changes:**
```diff
@@ -295,6 +295,13 @@ if(TARGET ocv.3rdparty.cann AND OPENCV_TEST_DNN_CANN)
   endif()
 endif()
 
+ocv_option(OPENCV_TEST_DNN_TIMVX "Build test with TIM-VX" (HAVE_TIMVX))
+if(OPENCV_TEST_DNN_TIMVX)
+  if(TARGET opencv_test_dnn)
+    ocv_target_compile_definitions(opencv_test_dnn PRIVATE "HAVE_TIMVX=1")
+  endif()
+endif()
```

Review comment:
Why do you need it? It's internal detail of implementation and user code should not depend on it, including tests. libopencv_dnn should have dependency from TIMVX.
**File:** modules/dnn/CMakeLists.txt
**Change Type:** modified
**Context:** PR #24425: dnn: fix HAVE_TIMVX macro definition in dnn test

**Code Changes:**
```diff
@@ -295,6 +295,13 @@ if(TARGET ocv.3rdparty.cann AND OPENCV_TEST_DNN_CANN)
   endif()
 endif()
 
+ocv_option(OPENCV_TEST_DNN_TIMVX "Build test with TIM-VX" (HAVE_TIMVX))
+if(OPENCV_TEST_DNN_TIMVX)
+  if(TARGET opencv_test_dnn)
+    ocv_target_compile_definitions(opencv_test_dnn PRIVATE "HAVE_TIMVX=1")
+  endif()
+endif()
```

Review comment:
Test does not work with missing `HAVE_TIMVX` macro: https://github.com/opencv/opencv/blob/240b245105bdb69b2b624ce24f08373c2b16bfde/modules/dnn/test/test_int8_layers.cpp#L11-L22 Basically I need `HAVE_TIMVX=1`.
**File:** modules/dnn/CMakeLists.txt
**Change Type:** modified
**Context:** PR #24425: dnn: fix HAVE_TIMVX macro definition in dnn test

**Code Changes:**
```diff
@@ -295,6 +295,13 @@ if(TARGET ocv.3rdparty.cann AND OPENCV_TEST_DNN_CANN)
   endif()
 endif()
 
+ocv_option(OPENCV_TEST_DNN_TIMVX "Build test with TIM-VX" (HAVE_TIMVX))
+if(OPENCV_TEST_DNN_TIMVX)
+  if(TARGET opencv_test_dnn)
+    ocv_target_compile_definitions(opencv_test_dnn PRIVATE "HAVE_TIMVX=1")
+  endif()
+endif()
```

Review comment:
We don't need that. There is registry API: https://github.com/opencv/opencv/blob/240b245105bdb69b2b624ce24f08373c2b16bfde/modules/dnn/include/opencv2/dnn/dnn.hpp#L125-L126 And usage in tests: https://github.com/opencv/opencv/blob/240b245105bdb69b2b624ce24f08373c2b16bfde/modules/dnn/test/test_common.impl.hpp#L291-L296
**File:** modules/dnn/CMakeLists.txt
**Change Type:** modified
**Context:** PR #24425: dnn: fix HAVE_TIMVX macro definition in dnn test

**Code Changes:**
```diff
@@ -295,6 +295,13 @@ if(TARGET ocv.3rdparty.cann AND OPENCV_TEST_DNN_CANN)
   endif()
 endif()
 
+ocv_option(OPENCV_TEST_DNN_TIMVX "Build test with TIM-VX" (HAVE_TIMVX))
+if(OPENCV_TEST_DNN_TIMVX)
+  if(TARGET opencv_test_dnn)
+    ocv_target_compile_definitions(opencv_test_dnn PRIVATE "HAVE_TIMVX=1")
+  endif()
+endif()
```

Review comment:
`DNN_BACKEND_TIMVX` is not in opencv/modules/dnn/test/test_common.impl.hpp.
**File:** modules/dnn/src/dnn_utils.cpp
**Change Type:** modified
**Context:** PR #23894: Use T-API for critical parts of blobFromImagesWithParams

**Code Changes:**
```diff
@@ -22,6 +22,48 @@ Image2BlobParams::Image2BlobParams(const Scalar& scalefactor_, const Size& size_
         datalayout(datalayout_), paddingmode(mode_)
 {}
 
+void getVector(InputArrayOfArrays images_, std::vector<Mat>& images) {
+    images_.getMatVector(images);
+}
+
+void getVector(InputArrayOfArrays images_, std::vector<UMat>& images) {
+    images_.getUMatVector(images);
```

Review comment:
I forgot to take into account step() and elemSize() for the offset. Now it works on par.
**File:** modules/dnn/src/dnn_utils.cpp
**Change Type:** modified
**Context:** PR #23894: Use T-API for critical parts of blobFromImagesWithParams

**Code Changes:**
```diff
@@ -22,6 +22,48 @@ Image2BlobParams::Image2BlobParams(const Scalar& scalefactor_, const Size& size_
         datalayout(datalayout_), paddingmode(mode_)
 {}
 
+void getVector(InputArrayOfArrays images_, std::vector<Mat>& images) {
+    images_.getMatVector(images);
+}
+
+void getVector(InputArrayOfArrays images_, std::vector<UMat>& images) {
+    images_.getUMatVector(images);
```

Review comment:
Current UMat design has limitation for storing results of `.getMat()` / `.getUMat` somewhere (should be used locally only) - upstream lifetime check should pass.
**File:** modules/dnn/src/dnn_utils.cpp
**Change Type:** modified
**Context:** PR #23894: Use T-API for critical parts of blobFromImagesWithParams
**Review Line:** 86

**Code Changes:**
```diff
+        std::vector<UMat> images(1, image.getUMat());
+        blobFromImages(images, blob, scalefactor, size, mean, swapRB, crop, ddepth);
+    } else {
+        std::vector<Mat> images(1, image.getMat());
+        blobFromImages(images, blob, scalefactor, size, mean, swapRB, crop, ddepth);
+    }
 }
 
 Mat blobFromImages(InputArrayOfArrays images, double scalefactor, Size size,
@@ -52,9 +99,9 @@ void blobFromImages(InputArrayOfArrays images_, OutputArray blob_, double scalef
         Size size, const Scalar& mean_, bool swapRB, bool crop, int ddepth)
```

Review comment:
`else` do NOOP - this is wrong. Only `UMAT` and `STD_VECTOR_UMAT` should be handled in dedicated code path. All other handling should not be changed by this patch.
**File:** modules/dnn/src/dnn_utils.cpp
**Change Type:** modified
**Context:** PR #23894: Use T-API for critical parts of blobFromImagesWithParams

**Code Changes:**
```diff
@@ -22,6 +22,48 @@ Image2BlobParams::Image2BlobParams(const Scalar& scalefactor_, const Size& size_
         datalayout(datalayout_), paddingmode(mode_)
 {}
 
+void getVector(InputArrayOfArrays images_, std::vector<Mat>& images) {
+    images_.getMatVector(images);
+}
+
+void getVector(InputArrayOfArrays images_, std::vector<UMat>& images) {
+    images_.getUMatVector(images);
```

Review comment:
[e7107e7](https://github.com/opencv/opencv/pull/23894/commits/e7107e734c26f754afc8dfc8da55e98184288bc3)
**File:** modules/dnn/src/dnn_utils.cpp
**Change Type:** modified
**Context:** PR #23894: Use T-API for critical parts of blobFromImagesWithParams
**Review Line:** 86

**Code Changes:**
```diff
+        std::vector<UMat> images(1, image.getUMat());
+        blobFromImages(images, blob, scalefactor, size, mean, swapRB, crop, ddepth);
+    } else {
+        std::vector<Mat> images(1, image.getMat());
+        blobFromImages(images, blob, scalefactor, size, mean, swapRB, crop, ddepth);
+    }
 }
 
 Mat blobFromImages(InputArrayOfArrays images, double scalefactor, Size size,
@@ -52,9 +99,9 @@ void blobFromImages(InputArrayOfArrays images_, OutputArray blob_, double scalef
         Size size, const Scalar& mean_, bool swapRB, bool crop, int ddepth)
```

Review comment:
[86095e6](https://github.com/opencv/opencv/pull/23894/commits/86095e6fb3ea563e643b9f3496dbaaedaeac0d57)
**File:** modules/dnn/src/dnn_utils.cpp
**Change Type:** modified
**Context:** PR #23894: Use T-API for critical parts of blobFromImagesWithParams

**Code Changes:**
```diff
@@ -22,6 +22,48 @@ Image2BlobParams::Image2BlobParams(const Scalar& scalefactor_, const Size& size_
         datalayout(datalayout_), paddingmode(mode_)
 {}
 
+void getVector(InputArrayOfArrays images_, std::vector<Mat>& images) {
+    images_.getMatVector(images);
+}
+
+void getVector(InputArrayOfArrays images_, std::vector<UMat>& images) {
+    images_.getUMatVector(images);
```

Review comment:
[a030263](https://github.com/opencv/opencv/pull/23894/commits/a0302630d61c8546a8ff7fd93324ab3563616f65)
**File:** modules/dnn/src/dnn_utils.cpp
**Change Type:** modified
**Context:** PR #23894: Use T-API for critical parts of blobFromImagesWithParams

**Code Changes:**
```diff
@@ -22,6 +22,48 @@ Image2BlobParams::Image2BlobParams(const Scalar& scalefactor_, const Size& size_
         datalayout(datalayout_), paddingmode(mode_)
 {}
 
+void getVector(InputArrayOfArrays images_, std::vector<Mat>& images) {
+    images_.getMatVector(images);
+}
+
+void getVector(InputArrayOfArrays images_, std::vector<UMat>& images) {
+    images_.getUMatVector(images);
```

Review comment:
`.clone()` is overkill. `blob_.getMat()` return temporary object - it should be alive till `.getUMat(flag)` release. --- We don't need this method at all as there is ` _InputArray::getUMat()`: https://github.com/opencv/opencv/blob/4.8.0/modules/core/src/matrix_wrap.cpp#L126C5-L126C27
**File:** cmake/OpenCVDetectCUDA.cmake
**Change Type:** modified
**Context:** PR #24382: Enable multicore CUDA compilation
**Review Line:** 362

**Code Changes:**
```diff
 
+  # Tell NVCC the maximum number of threads to be used to execute the compilation steps in parallel
+  # (option --threads was introduced in version 11.2)
+  if(NOT CUDA_VERSION VERSION_LESS "11.2")
+    if(CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT $ENV{CMAKE_BUILD_PARALLEL_LEVEL} STREQUAL "")
+      set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "--threads=$ENV{CMAKE_BUILD_PARALLEL_LEVEL}")
+    endif()
+  endif()
+
   message(STATUS "CUDA NVCC target flags: ${CUDA_NVCC_FLAGS}")
 
```

Review comment:
The solution may break build with CMake before 3.12 as it does not define `CMAKE_BUILD_PARALLEL_LEVEL`. Also if I use GNU Make, `cmake --build . -j4` will invoke 4 instances of nvcc during parallel build with make and each nvcc instance creates 4 jobs internally. I do not think that it's expected behaviour. The `--threads` makes more sense on Windows with msbuild. It runs nvcc sequentially and internal nvcc parallelism should reduce build time.
**File:** cmake/OpenCVDetectCUDA.cmake
**Change Type:** modified
**Context:** PR #24382: Enable multicore CUDA compilation
**Review Line:** 362

**Code Changes:**
```diff
 
+  # Tell NVCC the maximum number of threads to be used to execute the compilation steps in parallel
+  # (option --threads was introduced in version 11.2)
+  if(NOT CUDA_VERSION VERSION_LESS "11.2")
+    if(CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT $ENV{CMAKE_BUILD_PARALLEL_LEVEL} STREQUAL "")
+      set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "--threads=$ENV{CMAKE_BUILD_PARALLEL_LEVEL}")
+    endif()
+  endif()
+
   message(STATUS "CUDA NVCC target flags: ${CUDA_NVCC_FLAGS}")
 
```

Review comment:
I cannot see that checking the environment variable in an older version of CMake causes errors. I have tested CMake 3.1.3 and `$ENV{CMAKE_BUILD_PARALLEL_LEVEL}` evaluates to an empty string. In our test environment the build time reduced significantly, but as you pointed out we were indeed using Windows. Do you have any suggestions? Maybe add the option only if both the environment variable and `MSVC` are set?
**File:** cmake/OpenCVDetectCUDA.cmake
**Change Type:** modified
**Context:** PR #24382: Enable multicore CUDA compilation
**Review Line:** 362

**Code Changes:**
```diff
 
+  # Tell NVCC the maximum number of threads to be used to execute the compilation steps in parallel
+  # (option --threads was introduced in version 11.2)
+  if(NOT CUDA_VERSION VERSION_LESS "11.2")
+    if(CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT $ENV{CMAKE_BUILD_PARALLEL_LEVEL} STREQUAL "")
+      set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "--threads=$ENV{CMAKE_BUILD_PARALLEL_LEVEL}")
+    endif()
+  endif()
+
   message(STATUS "CUDA NVCC target flags: ${CUDA_NVCC_FLAGS}")
 
```

Review comment:
The first item may be ignored. I understood the code incorrectly. MSVC check - yes, it's good idea.