nareshmlx/opencv-pr huggingface dataset:
**File:** modules/core/test/test_mat.cpp
**Change Type:** modified
**Context:** PR #24260: Fix undefined behavior arithmetic in copyMakeBorder and adjustROI.

**Code Changes:**
```diff
@@ -1368,6 +1368,18 @@ TEST(Core_Mat, copyNx1ToVector)
     ASSERT_PRED_FORMAT2(cvtest::MatComparator(0, 0), ref_dst16, cv::Mat_<ushort>(dst16));
 }
 
+TEST(Core_Mat, copyMakeBoderUndefinedBehavior)
+{
+    Mat1b src(4, 4), dst;
+    randu(src, Scalar(10), Scalar(100));
+    // This could trigger a (signed int)*size_t operation which is undefined behavior.
+    cv::copyMakeBorder(src, dst, 1, 1, 1, 1, cv::BORDER_REFLECT_101);
```

Review comment:
Test does not contain checks.
**File:** modules/core/src/matrix.cpp
**Change Type:** modified
**Context:** PR #24260: Fix undefined behavior arithmetic in copyMakeBorder and adjustROI.

**Code Changes:**
```diff
@@ -1128,7 +1128,7 @@ Mat& Mat::adjustROI( int dtop, int dbottom, int dleft, int dright )
     if(col1 > col2)
         std::swap(col1, col2);
 
-    data += (row1 - ofs.y)*step + (col1 - ofs.x)*esz;
+    data += (row1 - ofs.y)*(std::ptrdiff_t)step + (col1 - ofs.x)*(std::ptrdiff_t)esz;
     rows = row2 - row1; cols = col2 - col1;
     size.p[0] = rows; size.p[1] = cols;
     updateContinuityFlag();
```

Review comment:
I do not think, that it's good for 32bit platforms. M.b. `ptrdiff_t` is better for this purpose?
**File:** modules/core/src/matrix.cpp
**Change Type:** modified
**Context:** PR #24260: Fix undefined behavior arithmetic in copyMakeBorder and adjustROI.

**Code Changes:**
```diff
@@ -1128,7 +1128,7 @@ Mat& Mat::adjustROI( int dtop, int dbottom, int dleft, int dright )
     if(col1 > col2)
         std::swap(col1, col2);
 
-    data += (row1 - ofs.y)*step + (col1 - ofs.x)*esz;
+    data += (row1 - ofs.y)*(std::ptrdiff_t)step + (col1 - ofs.x)*(std::ptrdiff_t)esz;
     rows = row2 - row1; cols = col2 - col1;
     size.p[0] = rows; size.p[1] = cols;
     updateContinuityFlag();
```

Review comment:
Agreed. I did so so that we can backport to 3.4. I'll go full c++11 then?
**File:** modules/core/test/test_operations.cpp
**Change Type:** modified
**Context:** PR #24260: Fix undefined behavior arithmetic in copyMakeBorder and adjustROI.
**Review Line:** 1388

**Code Changes:**
```diff
+{
+    Mat m(6, 6, CV_8U);
+    Mat roi(m, cv::Range(2, 4), cv::Range(2, 4));
+    // This could trigger a (negative int)*size_t when updating data,
+    // which is undefined behavior.
+    roi.adjustROI(2, 2, 2, 2);
+    EXPECT_EQ(m.data, roi.data);
+}
 
 CV_ENUM(SortRowCol, SORT_EVERY_COLUMN, SORT_EVERY_ROW)
 CV_ENUM(SortOrder, SORT_ASCENDING, SORT_DESCENDING)
```

Review comment:
Well, you have a warning if compiled with ubsan. What kind of check do you want me to add?
**File:** modules/core/test/test_operations.cpp
**Change Type:** modified
**Context:** PR #24260: Fix undefined behavior arithmetic in copyMakeBorder and adjustROI.
**Review Line:** 1388

**Code Changes:**
```diff
+{
+    Mat m(6, 6, CV_8U);
+    Mat roi(m, cv::Range(2, 4), cv::Range(2, 4));
+    // This could trigger a (negative int)*size_t when updating data,
+    // which is undefined behavior.
+    roi.adjustROI(2, 2, 2, 2);
+    EXPECT_EQ(m.data, roi.data);
+}
 
 CV_ENUM(SortRowCol, SORT_EVERY_COLUMN, SORT_EVERY_ROW)
 CV_ENUM(SortOrder, SORT_ASCENDING, SORT_DESCENDING)
```

Review comment:
The test is useless in CI as it does not check values or produce exception. Please add notes about UBSAN/ASAN and some check that result roi content is valid or something like it.
**File:** modules/core/test/test_misc.cpp
**Change Type:** modified
**Context:** PR #24250: Skip test on SkipTestException at fixture's constructor (version 2)

**Code Changes:**
```diff
@@ -917,5 +917,17 @@ REGISTER_TYPED_TEST_CASE_P(Rect_Test, Overflows);
 typedef ::testing::Types<int, float, double> RectTypes;
 INSTANTIATE_TYPED_TEST_CASE_P(Negative_Test, Rect_Test, RectTypes);
 
+// Expected that SkipTestException thrown in the constructor should skip test but not fail
+struct TestFixtureSkip: public ::testing::Test {
+    TestFixtureSkip(bool throwEx = true) {
+        if (throwEx) {
+            throw SkipTestException("Skip test at constructor");
+        }
```

Review comment:
The solution makes the 2 test dependent. In case if GTest shuffles them or one of them is disabled the result will be unexpected. Why do you want to do this?
**File:** modules/core/test/test_misc.cpp
**Change Type:** modified
**Context:** PR #24250: Skip test on SkipTestException at fixture's constructor (version 2)

**Code Changes:**
```diff
@@ -917,5 +917,17 @@ REGISTER_TYPED_TEST_CASE_P(Rect_Test, Overflows);
 typedef ::testing::Types<int, float, double> RectTypes;
 INSTANTIATE_TYPED_TEST_CASE_P(Negative_Test, Rect_Test, RectTypes);
 
+// Expected that SkipTestException thrown in the constructor should skip test but not fail
+struct TestFixtureSkip: public ::testing::Test {
+    TestFixtureSkip(bool throwEx = true) {
+        if (throwEx) {
+            throw SkipTestException("Skip test at constructor");
+        }
```

Review comment:
Indeed. Removed the test.
**File:** modules/dnn/src/tensorflow/tf_importer.cpp
**Change Type:** modified
**Context:** PR #24266: Added default dimension value to tensorflow ArgMax and ArgMin layers - Added default dimension value to tensorflow ArgMax and ArgMin layers...
**Review Line:** 2675

**Code Changes:**
```diff
 
-    Mat dimension = getTensorContent(getConstBlob(layer, value_id, 1));
-    CV_Assert(dimension.total() == 1 && dimension.type() == CV_32SC1);
-    layerParams.set("axis", *dimension.ptr<int>());
+    if (layer.input_size() < 2)
+        layerParams.set("axis", 0); // default dimension is 0
+    else
+    {
+        Mat dimension = getTensorContent(getConstBlob(layer, value_id, 1));
+        CV_Assert(dimension.total() == 1 && dimension.type() == CV_32SC1);
+        layerParams.set("axis", dimension.at<int>(0));
```

Review comment:
https://www.tensorflow.org/api_docs/python/tf/math/argmax
**File:** modules/dnn/src/tensorflow/tf_importer.cpp
**Change Type:** modified
**Context:** PR #24266: Added default dimension value to tensorflow ArgMax and ArgMin layers - Added default dimension value to tensorflow ArgMax and ArgMin layers...

**Code Changes:**
```diff
@@ -2665,14 +2665,20 @@ void TFImporter::parseActivation(tensorflow::GraphDef& net, const tensorflow::No
     connectToAllBlobs(layer_id, dstNet, parsePin(layer.input(0)), id, num_inputs);
 }
 
+// ArgMin or ArgMax node
 void TFImporter::parseArg(tensorflow::GraphDef& net, const tensorflow::NodeDef& layer, LayerParams& layerParams)
 {
     const std::string& name = layer.name();
     const std::string& type = layer.op();
 
```

Review comment:
This check is not necessary. I added it to avoid future bugs.
**File:** modules/dnn/src/tensorflow/tf_importer.cpp
**Change Type:** modified
**Context:** PR #24266: Added default dimension value to tensorflow ArgMax and ArgMin layers - Added default dimension value to tensorflow ArgMax and ArgMin layers...

**Code Changes:**
```diff
@@ -2665,14 +2665,20 @@ void TFImporter::parseActivation(tensorflow::GraphDef& net, const tensorflow::No
     connectToAllBlobs(layer_id, dstNet, parsePin(layer.input(0)), id, num_inputs);
 }
 
+// ArgMin or ArgMax node
 void TFImporter::parseArg(tensorflow::GraphDef& net, const tensorflow::NodeDef& layer, LayerParams& layerParams)
 {
     const std::string& name = layer.name();
     const std::string& type = layer.op();
 
```

Review comment:
BTW, 4 lines => `CV_CheckLT(input_blob_index, layer.input_size(), "");`
**File:** modules/dnn/src/tensorflow/tf_importer.cpp
**Change Type:** modified
**Context:** PR #24266: Added default dimension value to tensorflow ArgMax and ArgMin layers - Added default dimension value to tensorflow ArgMax and ArgMin layers...

**Code Changes:**
```diff
@@ -2665,14 +2665,20 @@ void TFImporter::parseActivation(tensorflow::GraphDef& net, const tensorflow::No
     connectToAllBlobs(layer_id, dstNet, parsePin(layer.input(0)), id, num_inputs);
 }
 
+// ArgMin or ArgMax node
 void TFImporter::parseArg(tensorflow::GraphDef& net, const tensorflow::NodeDef& layer, LayerParams& layerParams)
 {
     const std::string& name = layer.name();
     const std::string& type = layer.op();
 
```

Review comment:
`dimension.at<int>(0)` looks better
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...

**Code Changes:**
```diff
@@ -5,13 +5,24 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME
     message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
 endif()
 
+if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc")
+    set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" )
+    add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES")
+endif()
+
 if(CANN_INSTALL_DIR)
```

Review comment:
Please use English for comments.
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...

**Code Changes:**
```diff
@@ -5,13 +5,24 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME
     message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
 endif()
 
+if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc")
+    set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" )
+    add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES")
+endif()
+
 if(CANN_INSTALL_DIR)
```

Review comment:
CANN version check?
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...

**Code Changes:**
```diff
@@ -5,13 +5,24 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME
     message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
 endif()
 
+if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc")
+    set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" )
+    add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES")
+endif()
+
 if(CANN_INSTALL_DIR)
```

Review comment:
${CMAKE_HOST_SYSTEM_PROCESSOR} = x86_64 or aarch64. This depends on which CPU architecture is used
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...

**Code Changes:**
```diff
@@ -5,13 +5,24 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME
     message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
 endif()
 
+if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc")
+    set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" )
+    add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES")
+endif()
+
 if(CANN_INSTALL_DIR)
```

Review comment:
I mean, that different versions of CANN SDK has different layout. M.b. we need to presume compatibility and have both branches with version check?
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...

**Code Changes:**
```diff
@@ -5,13 +5,24 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME
     message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
 endif()
 
+if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc")
+    set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" )
+    add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES")
+endif()
+
 if(CANN_INSTALL_DIR)
```

Review comment:
It's a good way. In my tests, this change is uitable for cann version 6.3 and above.
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...

**Code Changes:**
```diff
@@ -5,13 +5,24 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME
     message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
 endif()
 
+if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc")
+    set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" )
+    add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES")
+endif()
+
 if(CANN_INSTALL_DIR)
```

Review comment:
Can we use `CANN_VERSION_BELOW_6_3_ALPHA002` to make it meaningful?
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...

**Code Changes:**
```diff
@@ -5,13 +5,24 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME
     message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
 endif()
 
+if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc")
+    set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" )
+    add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES")
+endif()
+
 if(CANN_INSTALL_DIR)
```

Review comment:
Does this library exist in version below 6.3.rc1.alpha002?
**File:** modules/dnn/src/net_cann.cpp
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...
**Review Line:** 309

**Code Changes:**
```diff
         {
-            // initialize engine
+            // initialize engine   Ascend310/Ascend310P3/Ascend910B/Ascend310B
             std::map<ge::AscendString, ge::AscendString> options = {
-                {ge::AscendString(ge::ir_option::SOC_VERSION), ge::AscendString("Ascend310")},
+                {ge::AscendString(ge::ir_option::SOC_VERSION), ge::AscendString(aclrtGetSocName())},
             };
             ACL_CHECK_GRAPH_RET(ge::aclgrphBuildInitialize(options));
 
```

Review comment:
Is `aclrtGetSocName()` available in all CANN versions?
**File:** modules/dnn/src/net_cann.cpp
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...
**Review Line:** 309

**Code Changes:**
```diff
         {
-            // initialize engine
+            // initialize engine   Ascend310/Ascend310P3/Ascend910B/Ascend310B
             std::map<ge::AscendString, ge::AscendString> options = {
-                {ge::AscendString(ge::ir_option::SOC_VERSION), ge::AscendString("Ascend310")},
+                {ge::AscendString(ge::ir_option::SOC_VERSION), ge::AscendString(aclrtGetSocName())},
             };
             ACL_CHECK_GRAPH_RET(ge::aclgrphBuildInitialize(options));
 
```

Review comment:
Yes,it is available in all CANN versions.
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...
**Review Line:** 76

**Code Changes:**
```diff
-    set(lib_opsproto "${CANN_INSTALL_DIR}/opp/op_proto/built-in")
+    if (CANN_VERSION_BELOW_6_3_ALPHA002)
+        set(lib_opsproto "${CANN_INSTALL_DIR}/opp/op_proto/built-in/")
+    else()
+        if(EXISTS "${CANN_INSTALL_DIR}/opp/built-in/op_proto/lib/linux")
+            set(lib_opsproto "${CANN_INSTALL_DIR}/opp/built-in/op_proto/lib/linux/${CMAKE_HOST_SYSTEM_PROCESSOR}")
+        else()
+            set(lib_opsproto "${CANN_INSTALL_DIR}/opp/built-in/op_proto")
+        endif()
+    endif()
     find_library(found_lib_opsproto NAMES opsproto PATHS ${lib_opsproto} NO_DEFAULT_PATH)
```

Review comment:
What about Windows? Forcing Linux dependency is bad idea. You can add `If (UNIX)` and `if (WIN32)` checks.
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...

**Code Changes:**
```diff
@@ -5,13 +5,24 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME
     message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
 endif()
 
+if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc")
+    set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" )
+    add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES")
+endif()
+
 if(CANN_INSTALL_DIR)
```

Review comment:
Please merge the conditions.
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...
**Review Line:** 76

**Code Changes:**
```diff
-    set(lib_opsproto "${CANN_INSTALL_DIR}/opp/op_proto/built-in")
+    if (CANN_VERSION_BELOW_6_3_ALPHA002)
+        set(lib_opsproto "${CANN_INSTALL_DIR}/opp/op_proto/built-in/")
+    else()
+        if(EXISTS "${CANN_INSTALL_DIR}/opp/built-in/op_proto/lib/linux")
+            set(lib_opsproto "${CANN_INSTALL_DIR}/opp/built-in/op_proto/lib/linux/${CMAKE_HOST_SYSTEM_PROCESSOR}")
+        else()
+            set(lib_opsproto "${CANN_INSTALL_DIR}/opp/built-in/op_proto")
+        endif()
+    endif()
     find_library(found_lib_opsproto NAMES opsproto PATHS ${lib_opsproto} NO_DEFAULT_PATH)
```

Review comment:
There is no cann version for Windows, and the "linux" is only folder under the path of "${CANN_INSTALL_DIR}/opp/built-in/op_proto/lib/linux". So I wonder if it's necessary to make a check?
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...
**Review Line:** 76

**Code Changes:**
```diff
-    set(lib_opsproto "${CANN_INSTALL_DIR}/opp/op_proto/built-in")
+    if (CANN_VERSION_BELOW_6_3_ALPHA002)
+        set(lib_opsproto "${CANN_INSTALL_DIR}/opp/op_proto/built-in/")
+    else()
+        if(EXISTS "${CANN_INSTALL_DIR}/opp/built-in/op_proto/lib/linux")
+            set(lib_opsproto "${CANN_INSTALL_DIR}/opp/built-in/op_proto/lib/linux/${CMAKE_HOST_SYSTEM_PROCESSOR}")
+        else()
+            set(lib_opsproto "${CANN_INSTALL_DIR}/opp/built-in/op_proto")
+        endif()
+    endif()
     find_library(found_lib_opsproto NAMES opsproto PATHS ${lib_opsproto} NO_DEFAULT_PATH)
```

Review comment:
Please add `UNIX` check and warning at the very beginning.
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...

**Code Changes:**
```diff
@@ -5,13 +5,24 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME
     message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
 endif()
 
+if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc")
+    set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" )
+    add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES")
+endif()
+
 if(CANN_INSTALL_DIR)
```

Review comment:
`if (NOT UNIX)`
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...

**Code Changes:**
```diff
@@ -5,13 +5,24 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME
     message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
 endif()
 
+if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc")
+    set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" )
+    add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES")
+endif()
+
 if(CANN_INSTALL_DIR)
```

Review comment:
I propose to use message(WARNING). It's highlighted red and caught by CI.
**File:** cmake/OpenCVFindCANN.cmake
**Change Type:** modified
**Context:** PR #23936: update opencv dnn to support cann version >=6.3 - 1.modify the search path of "libopsproto.so" in OpenCVFindCANN.cmake 2.add the search pat...

**Code Changes:**
```diff
@@ -5,13 +5,24 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME
     message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
 endif()
 
+if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc")
+    set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" )
+    add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES")
+endif()
+
 if(CANN_INSTALL_DIR)
```

Review comment:
I use message(WARNING) in every place that "set(HAVE_CANN OFF)".
**File:** modules/objdetect/src/aruco/charuco_detector.cpp
**Change Type:** modified
**Context:** PR #24247: fix type cast in drawDetectedMarkers, drawDetectedCornersCharuco, drawDetectedDiamonds

**Code Changes:**
```diff
@@ -507,20 +507,27 @@ void drawDetectedCornersCharuco(InputOutputArray _image, InputArray _charucoCorn
                                 InputArray _charucoIds, Scalar cornerColor) {
     CV_Assert(!_image.getMat().empty() &&
               (_image.getMat().channels() == 1 || _image.getMat().channels() == 3));
-    CV_Assert((_charucoCorners.getMat().total() == _charucoIds.getMat().total()) ||
-              _charucoIds.getMat().total() == 0);
-
-    size_t nCorners = _charucoCorners.getMat().total();
+    CV_Assert((_charucoCorners.total() == _charucoIds.total()) ||
+              _charucoIds.total() == 0);
```

Review comment:
I propose alternative: ``` CV_Assert(_charucoCorners.channels() == 2); ... _charucoCorners.getMat().convertTo(..., ...); ```
**File:** modules/objdetect/src/aruco/charuco_detector.cpp
**Change Type:** modified
**Context:** PR #24247: fix type cast in drawDetectedMarkers, drawDetectedCornersCharuco, drawDetectedDiamonds

**Code Changes:**
```diff
@@ -507,20 +507,27 @@ void drawDetectedCornersCharuco(InputOutputArray _image, InputArray _charucoCorn
                                 InputArray _charucoIds, Scalar cornerColor) {
     CV_Assert(!_image.getMat().empty() &&
               (_image.getMat().channels() == 1 || _image.getMat().channels() == 3));
-    CV_Assert((_charucoCorners.getMat().total() == _charucoIds.getMat().total()) ||
-              _charucoIds.getMat().total() == 0);
-
-    size_t nCorners = _charucoCorners.getMat().total();
+    CV_Assert((_charucoCorners.total() == _charucoIds.total()) ||
+              _charucoIds.total() == 0);
```

Review comment:
InputArray has `total()` method. getMat() is redundant.
**File:** modules/objdetect/src/aruco/charuco_detector.cpp
**Change Type:** modified
**Context:** PR #24247: fix type cast in drawDetectedMarkers, drawDetectedCornersCharuco, drawDetectedDiamonds

**Code Changes:**
```diff
@@ -507,20 +507,27 @@ void drawDetectedCornersCharuco(InputOutputArray _image, InputArray _charucoCorn
                                 InputArray _charucoIds, Scalar cornerColor) {
     CV_Assert(!_image.getMat().empty() &&
               (_image.getMat().channels() == 1 || _image.getMat().channels() == 3));
-    CV_Assert((_charucoCorners.getMat().total() == _charucoIds.getMat().total()) ||
-              _charucoIds.getMat().total() == 0);
-
-    size_t nCorners = _charucoCorners.getMat().total();
+    CV_Assert((_charucoCorners.total() == _charucoIds.total()) ||
+              _charucoIds.total() == 0);
```

Review comment:
No need to limit type here. Just use proper conversions.