nareshmlx/opencv-pr huggingface dataset:
**File:** modules/imgcodecs/src/grfmt_spng.cpp
**Change Type:** added
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -0,0 +1,754 @@
+// 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_SPNG
+
+/****************************************************************************************\
```

Review comment:
This part of the code is left when I am trying to do the necessary conversion of color formats. That was a bad mistake :). Sorry. Fixed.
**File:** modules/imgcodecs/src/grfmt_spng.cpp
**Change Type:** added
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -0,0 +1,754 @@
+// 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_SPNG
+
+/****************************************************************************************\
```

Review comment:
I changed it to ```cpp if(!result) close(); ``` Should I create a quick patch for the current PNG decoder too?
**File:** modules/imgcodecs/src/grfmt_spng.cpp
**Change Type:** added
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -0,0 +1,754 @@
+// 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_SPNG
+
+/****************************************************************************************\
```

Review comment:
```cpp void spng_ctx_free(spng_ctx *ctx) { if(ctx == NULL) return; ``` It is expected behavior but it seems unnecessary. For the future releases of spng, it might be useful to keep this line.
**File:** modules/imgcodecs/src/grfmt_spng.cpp
**Change Type:** added
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -0,0 +1,754 @@
+// 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_SPNG
+
+/****************************************************************************************\
```

Review comment:
Author of the libspng wrote this in the example for the setting the chunk limit. ```cpp /* Set memory usage limits for storing standard and unknown chunks, this is important when reading untrusted files! */ ``` I thought it was a good idea. But this limits the chunks size. Now I think it is better if I remove it. This methods equivalent is `png_set_chunk_malloc_max`. Should i keep this or remove it?
**File:** modules/imgcodecs/src/grfmt_spng.cpp
**Change Type:** added
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -0,0 +1,754 @@
+// 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_SPNG
+
+/****************************************************************************************\
```

Review comment:
I do not have strong opinion here. It's ok to have chunk limit. Please add note why you use the particular value or link to original code, if it's inherited behaviour.
**File:** cmake/OpenCVFindLibsGrfmt.cmake
**Change Type:** modified
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -221,8 +221,21 @@ if(WITH_JASPER AND NOT HAVE_OPENJPEG)
   endif()
 endif()
 
+if(WITH_SPNG)
+  set(SPNG_LIBRARY libspng CACHE INTERNAL "")
+  set(SPNG_LIBRARIES ${SPNG_LIBRARY})
+  add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libspng")
+  set(SPNG_INCLUDE_DIR "${${SPNG_LIBRARY}_SOURCE_DIR}" CACHE INTERNAL "")
+  set(SPNG_DEFINITIONS "")
```

Review comment:
I propose to uncomment the line to not have 2 codecs at a time.
**File:** cmake/OpenCVFindLibsGrfmt.cmake
**Change Type:** modified
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -221,8 +221,21 @@ if(WITH_JASPER AND NOT HAVE_OPENJPEG)
   endif()
 endif()
 
+if(WITH_SPNG)
+  set(SPNG_LIBRARY libspng CACHE INTERNAL "")
+  set(SPNG_LIBRARIES ${SPNG_LIBRARY})
+  add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libspng")
+  set(SPNG_INCLUDE_DIR "${${SPNG_LIBRARY}_SOURCE_DIR}" CACHE INTERNAL "")
+  set(SPNG_DEFINITIONS "")
```

Review comment:
This was intended to surpress CMake warning while running the workflow. I made libspng default png codec to test in the workflow. Before merge, i will uncomment that line and set `OCV_OPTION(WITH_SPNG "Include SPNG support" OFF`. So we can add libspng as optional codec, not default as we discussed in one of the GSoC meetings with the Vadim and Suleyman.
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -327,6 +327,9 @@ OCV_OPTION(WITH_OPENNI2 "Include OpenNI2 support" OFF
 OCV_OPTION(WITH_PNG "Include PNG support" ON
   VISIBLE_IF TRUE
   VERIFY HAVE_PNG)
+OCV_OPTION(WITH_SPNG "Include SPNG support" OFF
+  VISIBLE_IF TRUE
+  VERIFY HAVE_SPNG)
 OCV_OPTION(WITH_GDCM "Include DICOM support" OFF
   VISIBLE_IF TRUE
   VERIFY HAVE_GDCM)
```

Review comment:
This changes the existed behaviour (like ignoring of system libpng or 3rdparty code from the source). This contradicts with PR's title: "... as optional png codec".
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -327,6 +327,9 @@ OCV_OPTION(WITH_OPENNI2 "Include OpenNI2 support" OFF
 OCV_OPTION(WITH_PNG "Include PNG support" ON
   VISIBLE_IF TRUE
   VERIFY HAVE_PNG)
+OCV_OPTION(WITH_SPNG "Include SPNG support" OFF
+  VISIBLE_IF TRUE
+  VERIFY HAVE_SPNG)
 OCV_OPTION(WITH_GDCM "Include DICOM support" OFF
   VISIBLE_IF TRUE
   VERIFY HAVE_GDCM)
```

Review comment:
What if: - WITH_SPNG = 1 - HAVE_SPNG = 0
**File:** cmake/OpenCVFindLibsGrfmt.cmake
**Change Type:** modified
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -221,8 +221,21 @@ if(WITH_JASPER AND NOT HAVE_OPENJPEG)
   endif()
 endif()
 
+if(WITH_SPNG)
+  set(SPNG_LIBRARY libspng CACHE INTERNAL "")
+  set(SPNG_LIBRARIES ${SPNG_LIBRARY})
+  add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libspng")
+  set(SPNG_INCLUDE_DIR "${${SPNG_LIBRARY}_SOURCE_DIR}" CACHE INTERNAL "")
+  set(SPNG_DEFINITIONS "")
```

Review comment:
Above we have such mess with `set(HAVE_SPNG NO)`. Code should be separated and not messed.
**File:** modules/imgcodecs/perf/perf_png.cpp
**Change Type:** added
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -0,0 +1,41 @@
+// 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 "perf_precomp.hpp"
+
+namespace opencv_test
+{
+using namespace perf;
```

Review comment:
avoid using indentation in namespaces
**File:** modules/imgcodecs/src/grfmt_spng.cpp
**Change Type:** added
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -0,0 +1,754 @@
+// 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_SPNG
+
+/****************************************************************************************\
```

Review comment:
avoid indentation in namespaces
**File:** modules/imgcodecs/src/loadsave.cpp
**Change Type:** modified
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -167,7 +167,10 @@ struct ImageCodecInitializer
         decoders.push_back( makePtr<TiffDecoder>() );
         encoders.push_back( makePtr<TiffEncoder>() );
     #endif
-    #ifdef HAVE_PNG
+    #ifdef HAVE_SPNG
+        decoders.push_back( makePtr<SPngDecoder>() );
+        encoders.push_back( makePtr<SPngEncoder>() );
+    #elif defined(HAVE_PNG)
         decoders.push_back( makePtr<PngDecoder>() );
```

Review comment:
`#elif defined(HAVE_PNG)`
**File:** modules/imgcodecs/test/test_png.cpp
**Change Type:** modified
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -5,7 +5,7 @@
 
 namespace opencv_test { namespace {
 
-#ifdef HAVE_PNG
+#if defined(HAVE_PNG) || defined(HAVE_SPNG)
 
 TEST(Imgcodecs_Png, write_big)
 {
@@ -186,6 +186,225 @@ const string exif_files[] =
```

Review comment:
It is better to have single file per test case (you don't want to debug issue of 15th image of the test).
**File:** modules/imgcodecs/test/test_png.cpp
**Change Type:** modified
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -5,7 +5,7 @@
 
 namespace opencv_test { namespace {
 
-#ifdef HAVE_PNG
+#if defined(HAVE_PNG) || defined(HAVE_SPNG)
 
 TEST(Imgcodecs_Png, write_big)
 {
@@ -186,6 +186,225 @@ const string exif_files[] =
```

Review comment:
This is some kind of general rule for writing tests. All-in-one test is anti-pattern. They should be spitted: - again, as I mentioned - we need possibility to debug exact case without skipping other 10 cases (debugging code is time consuming task, no need to make it harder) - test code may do nothing if `glob()` returns nothing due to misconfiguration - and we will not see this in test logs - all-in-one approach blocks test filtering, disabling
**File:** 3rdparty/libspng/CMakeLists.txt
**Change Type:** added
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -0,0 +1,47 @@
+# ----------------------------------------------------------------------------
+#  CMake file for libspng. See root CMakeLists.txt
+#
+# ----------------------------------------------------------------------------
+
+project(${SPNG_LIBRARY})
+
+set(CURR_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}")
+set_property(GLOBAL PROPERTY SPNG_INCLUDE_DIR ${CURR_INCLUDE_DIR})
```

Review comment:
> `,` Does it work at all? There is no commas for arguments in CMake scripts syntax.
**File:** 3rdparty/libspng/CMakeLists.txt
**Change Type:** added
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -0,0 +1,47 @@
+# ----------------------------------------------------------------------------
+#  CMake file for libspng. See root CMakeLists.txt
+#
+# ----------------------------------------------------------------------------
+
+project(${SPNG_LIBRARY})
+
+set(CURR_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}")
+set_property(GLOBAL PROPERTY SPNG_INCLUDE_DIR ${CURR_INCLUDE_DIR})
```

Review comment:
> ZLIB_INCLUDE_DIRS There is dependency on ZLIB, which could be disabled. Need to properly handle case if zlib is disabled.
**File:** cmake/OpenCVFindLibsGrfmt.cmake
**Change Type:** modified
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -221,8 +221,21 @@ if(WITH_JASPER AND NOT HAVE_OPENJPEG)
   endif()
 endif()
 
+if(WITH_SPNG)
+  set(SPNG_LIBRARY libspng CACHE INTERNAL "")
+  set(SPNG_LIBRARIES ${SPNG_LIBRARY})
+  add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libspng")
+  set(SPNG_INCLUDE_DIR "${${SPNG_LIBRARY}_SOURCE_DIR}" CACHE INTERNAL "")
+  set(SPNG_DEFINITIONS "")
```

Review comment:
Please minimize amount of changed code (to avoid merge hell): ``` if(WITH_SPNG) ... new code endif() if(NOT HAVE_SPNG AND WITH_PNG) ... existed untouched code ... endif() ``` ```
**File:** 3rdparty/libspng/CMakeLists.txt
**Change Type:** added
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -0,0 +1,47 @@
+# ----------------------------------------------------------------------------
+#  CMake file for libspng. See root CMakeLists.txt
+#
+# ----------------------------------------------------------------------------
+
+project(${SPNG_LIBRARY})
+
+set(CURR_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}")
+set_property(GLOBAL PROPERTY SPNG_INCLUDE_DIR ${CURR_INCLUDE_DIR})
```

Review comment:
If it doesn't work then probably it is just not needed at all. So `${CURR_INCLUDE_DIR}` could be dropped completely.
**File:** 3rdparty/libspng/CMakeLists.txt
**Change Type:** added
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -0,0 +1,47 @@
+# ----------------------------------------------------------------------------
+#  CMake file for libspng. See root CMakeLists.txt
+#
+# ----------------------------------------------------------------------------
+
+project(${SPNG_LIBRARY})
+
+set(CURR_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}")
+set_property(GLOBAL PROPERTY SPNG_INCLUDE_DIR ${CURR_INCLUDE_DIR})
```

Review comment:
Is not this handled in FindLibsGrfmt CMakeList already?
**File:** 3rdparty/libspng/CMakeLists.txt
**Change Type:** added
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -0,0 +1,47 @@
+# ----------------------------------------------------------------------------
+#  CMake file for libspng. See root CMakeLists.txt
+#
+# ----------------------------------------------------------------------------
+
+project(${SPNG_LIBRARY})
+
+set(CURR_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}")
+set_property(GLOBAL PROPERTY SPNG_INCLUDE_DIR ${CURR_INCLUDE_DIR})
```

Review comment:
ZLIB is always "required" in this file.
**File:** modules/imgcodecs/test/test_png.cpp
**Change Type:** modified
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -5,7 +5,7 @@
 
 namespace opencv_test { namespace {
 
-#ifdef HAVE_PNG
+#if defined(HAVE_PNG) || defined(HAVE_SPNG)
 
 TEST(Imgcodecs_Png, write_big)
 {
@@ -186,6 +186,225 @@ const string exif_files[] =
```

Review comment:
Why do we need this `if` check?
**File:** modules/imgcodecs/test/test_png.cpp
**Change Type:** modified
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -5,7 +5,7 @@
 
 namespace opencv_test { namespace {
 
-#ifdef HAVE_PNG
+#if defined(HAVE_PNG) || defined(HAVE_SPNG)
 
 TEST(Imgcodecs_Png, write_big)
 {
@@ -186,6 +186,225 @@ const string exif_files[] =
```

Review comment:
> `pngsuite/` is a common prefix here. It could be moved to the test code
**File:** modules/imgcodecs/test/test_png.cpp
**Change Type:** modified
**Context:** PR #22226: [GSoC 2022] spng encoder/decoder added as optional png codec

**Code Changes:**
```diff
@@ -5,7 +5,7 @@
 
 namespace opencv_test { namespace {
 
-#ifdef HAVE_PNG
+#if defined(HAVE_PNG) || defined(HAVE_SPNG)
 
 TEST(Imgcodecs_Png, write_big)
 {
@@ -186,6 +186,225 @@ const string exif_files[] =
```

Review comment:
> PngSUiteFiles PngSuiteFiles or `/*nothing*/` (to avoid any prefix with duplicate naming).
**File:** samples/cpp/calibration.cpp
**Change Type:** modified
**Context:** PR #22443: [3.4] Add flag to pass initial guess for camera intrinsics into the calibration exe
**Review Line:** 70

**Code Changes:**
```diff
         "     [-p]                     # fix the principal point at the center\n"
         "     [-v]                     # flip the captured images around the horizontal axis\n"
         "     [-V]                     # use a video file, and not an image list, uses\n"
         "                              # [input_data] string for the video file name\n"
         "     [-su]                    # show undistorted images after calibration\n"
+        "     [-ws=<number_of_pixel>]  # half of search window for cornerSubPix (11 by default)\n"
+        "     [-fx=<X focal length>]   # focal length in X-dir as an initial intrinsic guess (if this flag is used, fx, fy, cx, cy must be set)\n"
+        "     [-fy=<Y focal length>]   # focal length in Y-dir as an initial intrinsic guess (if this flag is used, fx, fy, cx, cy must be set)\n"
+        "     [-cx=<X center point>]   # camera center point in X-dir as an initial intrinsic guess (if this flag is used, fx, fy, cx, cy must be set)\n"
+        "     [-cy=<Y center point>]   # camera center point in Y-dir as an initial intrinsic guess (if this flag is used, fx, fy, cx, cy must be set)\n"
+        "     [-imshow-scale           # image resize scaling factor when displaying the results (must be >= 1)\n"
```

Review comment:
Parameter backported from 4.x.
**File:** samples/cpp/calibration.cpp
**Change Type:** modified
**Context:** PR #22443: [3.4] Add flag to pass initial guess for camera intrinsics into the calibration exe
**Review Line:** 161

**Code Changes:**
```diff
     objectPoints.resize(imagePoints.size(),objectPoints[0]);
 
     double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix,
-                    distCoeffs, rvecs, tvecs, flags|CALIB_FIX_K4|CALIB_FIX_K5);
-                    ///*|CALIB_FIX_K3*/|CALIB_FIX_K4|CALIB_FIX_K5);
+                    distCoeffs, rvecs, tvecs, flags | CALIB_USE_LU);
     printf("RMS error reported by calibrateCamera: %g\n", rms);
 
     bool ok = checkRange(cameraMatrix) && checkRange(distCoeffs);
@@ -166,7 +169,6 @@ static bool runCalibration( vector<vector<Point2f> > imagePoints,
     return ok;
```

Review comment:
`CALIB_USE_LU` is used in OpenCV 4.x: https://github.com/opencv/opencv/blob/1fd45a1b8580ee90fa63c6106c78217c846247e4/samples/cpp/calibration.cpp#L173 Normally no need to pass `CALIB_FIX_K4|CALIB_FIX_K5` (`CALIB_RATIONAL_MODEL` should be explicitly passed), moreover `CALIB_FIX_K6` should be missing.
**File:** samples/cpp/calibration.cpp
**Change Type:** modified
**Context:** PR #22443: [3.4] Add flag to pass initial guess for camera intrinsics into the calibration exe
**Review Line:** 301

**Code Changes:**
```diff
@@ -296,7 +298,7 @@ static bool runAndSave(const string& outputFilename,
     bool ok = runCalibration(imagePoints, imageSize, boardSize, patternType, squareSize,
                    aspectRatio, flags, cameraMatrix, distCoeffs,
                    rvecs, tvecs, reprojErrs, totalAvgErr);
-    printf("%s. avg reprojection error = %.2f\n",
+    printf("%s. avg reprojection error = %.7f\n",
            ok ? "Calibration succeeded" : "Calibration failed",
            totalAvgErr);
 
@@ -312,11 +314,10 @@ static bool runAndSave(const string& outputFilename,
     return ok;
```

Review comment:
Backport from 4.x: https://github.com/opencv/opencv/blob/1fd45a1b8580ee90fa63c6106c78217c846247e4/samples/cpp/calibration.cpp#L332
**File:** samples/cpp/calibration.cpp
**Change Type:** modified
**Context:** PR #22443: [3.4] Add flag to pass initial guess for camera intrinsics into the calibration exe
**Review Line:** 320

**Code Changes:**
```diff
-
 int main( int argc, char** argv )
 {
     Size boardSize, imageSize;
-    float squareSize, aspectRatio;
+    float squareSize, aspectRatio = 1;
     Mat cameraMatrix, distCoeffs;
     string outputFilename;
     string inputFilename = "";
@@ -339,7 +340,10 @@ int main( int argc, char** argv )
 
```

Review comment:
Backport from 4.x: https://github.com/opencv/opencv/blob/1fd45a1b8580ee90fa63c6106c78217c846247e4/samples/cpp/calibration.cpp#L353
**File:** samples/cpp/calibration.cpp
**Change Type:** modified
**Context:** PR #22443: [3.4] Add flag to pass initial guess for camera intrinsics into the calibration exe
**Review Line:** 372

**Code Changes:**
```diff
-    aspectRatio = parser.get<float>("a");
     delay = parser.get<int>("d");
     writePoints = parser.has("op");
     writeExtrinsics = parser.has("oe");
-    if (parser.has("a"))
+    if (parser.has("a")) {
         flags |= CALIB_FIX_ASPECT_RATIO;
+        aspectRatio = parser.get<float>("a");
+    }
     if ( parser.has("zt") )
         flags |= CALIB_ZERO_TANGENT_DIST;
```

Review comment:
Backport from 4.x: https://github.com/opencv/opencv/blob/1fd45a1b8580ee90fa63c6106c78217c846247e4/samples/cpp/calibration.cpp#L404-L407
**File:** samples/cpp/calibration.cpp
**Change Type:** modified
**Context:** PR #22443: [3.4] Add flag to pass initial guess for camera intrinsics into the calibration exe
**Review Line:** 389

**Code Changes:**
```diff
     if ( parser.has("p") )
@@ -381,6 +386,24 @@ int main( int argc, char** argv )
         cameraId = parser.get<int>("@input_data");
     else
         inputFilename = parser.get<string>("@input_data");
+    int winSize = parser.get<int>("ws");
+    cameraMatrix = Mat::eye(3, 3, CV_64F);
+    if (parser.has("fx") && parser.has("fy") && parser.has("cx") && parser.has("cy"))
+    {
+        cameraMatrix.at<double>(0,0) = parser.get<double>("fx");
+        cameraMatrix.at<double>(0,2) = parser.get<double>("cx");
```

Review comment:
Backport from 4.x: https://github.com/opencv/opencv/blob/1fd45a1b8580ee90fa63c6106c78217c846247e4/samples/cpp/calibration.cpp#L421
**File:** samples/cpp/calibration.cpp
**Change Type:** modified
**Context:** PR #22443: [3.4] Add flag to pass initial guess for camera intrinsics into the calibration exe
**Review Line:** 498

**Code Changes:**
```diff
 
        // improve the found corners' coordinate accuracy
-        if( pattern == CHESSBOARD && found) cornerSubPix( viewGray, pointbuf, Size(11,11),
-            Size(-1,-1), TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 30, 0.1 ));
+        if( pattern == CHESSBOARD && found) cornerSubPix( viewGray, pointbuf, Size(winSize,winSize),
+            Size(-1,-1), TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 30, 0.0001 ));
 
         if( mode == CAPTURING && found &&
            (!capture.isOpened() || clock() - prevTimestamp > delay*1e-3*CLOCKS_PER_SEC) )
@@ -494,9 +517,9 @@ int main( int argc, char** argv )
         if( mode == CAPTURING )
```

Review comment:
Backport from 4.x: https://github.com/opencv/opencv/blob/1fd45a1b8580ee90fa63c6106c78217c846247e4/samples/cpp/calibration.cpp#L519
**File:** samples/cpp/calibration.cpp
**Change Type:** modified
**Context:** PR #22443: [3.4] Add flag to pass initial guess for camera intrinsics into the calibration exe
**Review Line:** 346

**Code Changes:**
```diff
         "{help ||}{w||}{h||}{pt|chessboard|}{n|10|}{d|1000|}{s|1|}{o|out_camera_data.yml|}"
-        "{op||}{oe||}{zt||}{a|1|}{p||}{v||}{V||}{su||}"
+        "{op||}{oe||}{zt||}{a||}{p||}{v||}{V||}{su||}"
+        "{ws|11|}"
+        "{fx||}{fy||}{cx||}{cy||}"
+        "{imshow-scale|1|}{enable-k3|1|}"
         "{@input_data|0|}");
     if (parser.has("help"))
     {
@@ -362,12 +366,13 @@ int main( int argc, char** argv )
     }
```

Review comment:
In 3.4, by default `enable-k3=1` to keep the same behavior than before with: `flags|CALIB_FIX_K4|CALIB_FIX_K5`
**File:** modules/3d/src/rgbd/normal.cpp
**Change Type:** modified
**Context:** PR #22241: More tests for normals

**Code Changes:**
```diff
@@ -225,24 +225,7 @@ class RgbdNormalsImpl : public RgbdNormals
     {
         return method;
     }
-    virtual void setMethod(RgbdNormalsMethod val) CV_OVERRIDE
-    {
-        method = val; cacheIsDirty = true;
-    }
-
-    // Helper functions for apply()
```

Review comment:
Please add explicit check for cross-product and raise assert for invalid type in else branch.