nareshmlx/opencv-pr huggingface dataset:
**File:** modules/dnn/src/dnn.cpp
**Change Type:** modified
**Context:** PR #21429: (3.4) dnn: fix API - explicit ctors, const methods - Validate: - [x] samples/dnn/dasiamrpn_tracker.py - [x] Halide build configuration - [x...

**Code Changes:**
```diff
@@ -846,11 +846,11 @@ struct BlobManager
     // layer blob.
     int numReferences(const LayerPin& lp)
     {
-        std::map<LayerPin, LayerPin>::iterator mapIt = reuseMap.find(lp);
+        std::map<LayerPin, LayerPin>::const_iterator mapIt = reuseMap.find(lp);
         CV_Assert(mapIt != reuseMap.end());
         LayerPin memHost = mapIt->second;
 
-        std::map<LayerPin, int>::iterator refIt = refCounter.find(memHost);
```

Review comment:
If we create `[pin.lid]` in layers in previous line, its `outputBlobs.size()` is zero and the condition is true, so we can get rid of const_cast.
**File:** modules/dnn/src/dnn.cpp
**Change Type:** modified
**Context:** PR #21429: (3.4) dnn: fix API - explicit ctors, const methods - Validate: - [x] samples/dnn/dasiamrpn_tracker.py - [x] Halide build configuration - [x...
**Review Line:** 1410

**Code Changes:**
```diff
         if (it == layers.end())
             CV_Error(Error::StsObjectNotFound, format("Layer with requested id=%d not found", id));
 
-        return it->second;
+        return const_cast<LayerData&>(it->second);
     }
 
-    LayerData& getLayerData(const String &layerName)
+    LayerData& getLayerData(const String &layerName) const
     {
         int id = getLayerId(layerName);
```

Review comment:
This change requires too much changes due to current. Unfortunately `LayerData` is not not preserved unmodified. It is part of "graph" model and manages graph connections too.
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
BaseLevMarq -> LevMarqBase or LevMarqSolver
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
Again, `const reference` for all input parameter. --- no underscores in names if we don't need them.
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
No fields in public API. This is the primary requirement of public OpenCV API. getter/setter should be exposed instead.
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
Looks like it is not used by user code directly. Move to src or details.
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
missing documentation
**File:** modules/core/include/opencv2/core/dualquaternion.inl.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation
**Review Line:** 161

**Code Changes:**
```diff
@@ -158,7 +158,7 @@ inline Quat<T> DualQuat<T>::getRotation(QuatAssumeType assumeUnit) const
 template <typename T>
 inline Vec<T, 3> DualQuat<T>::getTranslation(QuatAssumeType assumeUnit) const
 {
-    Quat<T> trans = 2.0 * (getDualPart() * getRealPart().inv(assumeUnit));
+    Quat<T> trans = T(2.0) * (getDualPart() * getRealPart().inv(assumeUnit));
     return Vec<T, 3>{trans[1], trans[2], trans[3]};
 }
 
```

Review comment:
Such changes should be backported to 4.x
**File:** modules/calib/src/calibration.cpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -167,8 +167,8 @@ static void subMatrix(const Mat& src, Mat& dst,
 
 static void cameraCalcJErr(const Mat& objectPoints, const Mat& imagePoints,
                            const Mat& npoints, Mat& allErrors,
-                           Mat& _param, Mat* _JtErr, Mat* _JtJ, double* _errnorm,
-                           double aspectRatio, Mat* perViewErrors,
+                           Mat& _param, bool calcJ, Mat& JtErr, Mat& JtJ, double& errnorm,
+                           double aspectRatio, Mat& perViewErrors,
                            int flags, bool optimizeObjPoints)
 {
```

Review comment:
We should have setter with TermCriteria parameter. > maxIterations = (unsigned int)(termCrit.maxCount * 2.1); > 2.1 Why?
**File:** modules/calib/src/calibration.cpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -167,8 +167,8 @@ static void subMatrix(const Mat& src, Mat& dst,
 
 static void cameraCalcJErr(const Mat& objectPoints, const Mat& imagePoints,
                            const Mat& npoints, Mat& allErrors,
-                           Mat& _param, Mat* _JtErr, Mat* _JtJ, double* _errnorm,
-                           double aspectRatio, Mat* perViewErrors,
+                           Mat& _param, bool calcJ, Mat& JtErr, Mat& JtJ, double& errnorm,
+                           double aspectRatio, Mat& perViewErrors,
                            int flags, bool optimizeObjPoints)
 {
```

Review comment:
`2.1` is a compatibility hack. Old impl counts successful iterations only, the new one counts all iterations. The proportion between them for the same run is different per use case but in average it is 2.1: `newIters = oldIters*2.1` I propose three solutions here: * to leave this hack as is (adding a comment about it in src) * to find true multiplier for each use case based on iterations elapsed statistics * remove the multiplier: it's 5.x now, we don't have to maintain such parameters compatibility
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
The motivation to leave the `Backend` in public was to let a user to construct solvers that use sparse matrices, params of SE(3) and of more exotic groups, with fixed variables and so on. I will try to move it to details to keep this possibility. (However the interface is very complicated for a user)
**File:** modules/calib/src/calibration.cpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -167,8 +167,8 @@ static void subMatrix(const Mat& src, Mat& dst,
 
 static void cameraCalcJErr(const Mat& objectPoints, const Mat& imagePoints,
                            const Mat& npoints, Mat& allErrors,
-                           Mat& _param, Mat* _JtErr, Mat* _JtJ, double* _errnorm,
-                           double aspectRatio, Mat* perViewErrors,
+                           Mat& _param, bool calcJ, Mat& JtErr, Mat& JtJ, double& errnorm,
+                           double aspectRatio, Mat& perViewErrors,
                            int flags, bool optimizeObjPoints)
 {
```

Review comment:
I think, having such a hack is fine. 1. If the problem solved is more or less well-defined (not ill-posed), the solver should converge faster than it will reach the maximum. 2. If the problem solved is ill-posed then we will do at least termCrit.maxCount iterations, so this hack may affect the speed, but not the quality. But, I believe, because the new solver uses the sparse structure of matrices, it should run even faster than the previous "dense" implementation.
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
can we try to utilize https://github.com/opencv/opencv/wiki/OE-34.-Named-Parameters? It lets to define very nice API for C++ and Python (and maybe Swift after the corresponding binding generator is revised)
**File:** modules/calib/src/calibration.cpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -167,8 +167,8 @@ static void subMatrix(const Mat& src, Mat& dst,
 
 static void cameraCalcJErr(const Mat& objectPoints, const Mat& imagePoints,
                            const Mat& npoints, Mat& allErrors,
-                           Mat& _param, Mat* _JtErr, Mat* _JtJ, double* _errnorm,
-                           double aspectRatio, Mat* perViewErrors,
+                           Mat& _param, bool calcJ, Mat& JtErr, Mat& JtJ, double& errnorm,
+                           double aspectRatio, Mat& perViewErrors,
                            int flags, bool optimizeObjPoints)
 {
```

Review comment:
Multiplier removed, statistics recalculated. Regarding `TermCriteria` usage: I'm against it, it has only one epsilon parameter and it's not obvious to what threshold in this LevMarq impl it corresponds to.
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
Implemented it as a `Settings` structure
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
`Backend` is moved to details header
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
Added docs for `Report` structure
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
If users don't need this functionality, then it is better to create internal function.
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
Move ctor implementation to .cpp file.
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
Why is here 'S' suffix? Where are you find that?
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
`inline` for all setters
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
> unsigned int This type may be non-friendly with bindings.
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
> Defined in Is it not a definition? Why does forward declaration not work here?
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
Users don't really need this constructor. As they can't use it.
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
S stands for "set" but I didn't want to give them names like `setEpsilon` to make method names more compact. Since you recommended not to use underscores, I seek other ways to name them.
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
Removed (was made to compare a passed arg with default settings constant, default arg is used instead)
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
Decided to use `setValue` names instead, looks more natural
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
Replaced by int
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
`Backend` class removed
**File:** modules/3d/include/opencv2/3d.hpp
**Change Type:** modified
**Context:** PR #21018: New LevMarq implementation

**Code Changes:**
```diff
@@ -468,77 +468,267 @@ can be found in:
  */
 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
 
-/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it
-    optimizes the target vector criteria "err"
-    (finds local minima of each target vector component absolute value).
 
-    When needed, it calls user-provided callback.
+/** @brief Type of matrix used in LevMarq solver
```

Review comment:
Fixed, see the comment below
**File:** cmake/OpenCVFindLAPACK.cmake
**Change Type:** modified
**Context:** PR #21114: Fix compile against lapack-3.10.0 - part 1

**Code Changes:**
```diff
@@ -51,6 +51,23 @@ macro(ocv_lapack_check)
     if(NOT "${OPENCV_CBLAS_H_PATH_${_lapack_impl}}" STREQUAL "${OPENCV_LAPACKE_H_PATH_${_lapack_impl}}")
       list(APPEND _lapack_content "#include \"${OPENCV_LAPACKE_H_PATH_${_lapack_impl}}\"")
     endif()
+    list(APPEND _lapack_content "
+#if defined(LAPACK_GLOBAL) || defined(LAPACK_NAME)
+/*
+ * Using netlib's reference LAPACK implementation version >= 3.4.0 (first with C interface).
+ * Use LAPACK_xxxx to transparently (via predefined lapack macros) deal with pre and post 3.9.1 versions.
+ * LAPACK 3.9.1 introduces LAPACK_FORTRAN_STRLEN_END and modifies (through preprocessing) the declarations of the following functions used in opencv
```

Review comment:
> CONFIG Why do we need to block CMake's LAPACK module?