nareshmlx/opencv-pr huggingface dataset:
**File:** doc/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.markdown
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,252 @@
+Multi-view Camera Calibration Tutorial {#tutorial_multiview_camera_calibration}
+==========================
+
+@tableofcontents
+
+@prev_tutorial{tutorial_interactive_calibration}
+
+|    |    |
+| -: | :- |
```

Review comment:
Reference will be useful too.
**File:** doc/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.markdown
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,252 @@
+Multi-view Camera Calibration Tutorial {#tutorial_multiview_camera_calibration}
+==========================
+
+@tableofcontents
+
+@prev_tutorial{tutorial_interactive_calibration}
+
+|    |    |
+| -: | :- |
```

Review comment:
I build documentation locally and doxygen does not insert images: "Firefox cannot file file /home/alexander/opencv-next-build/doc/doxygen/html/images/1a.png"
**File:** doc/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.markdown
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,252 @@
+Multi-view Camera Calibration Tutorial {#tutorial_multiview_camera_calibration}
+==========================
+
+@tableofcontents
+
+@prev_tutorial{tutorial_interactive_calibration}
+
+|    |    |
+| -: | :- |
```

Review comment:
Direct links to doxygen documentation is bad idea. It does not work for local docs or if page is moved somewhere. Please use just full function name `cv::calibrateCamera` or `\ref`with C++ symbol name or chapter id. Doxygen will substitute related links automatically or reports if it's broken.
**File:** doc/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.markdown
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,252 @@
+Multi-view Camera Calibration Tutorial {#tutorial_multiview_camera_calibration}
+==========================
+
+@tableofcontents
+
+@prev_tutorial{tutorial_interactive_calibration}
+
+|    |    |
+| -: | :- |
```

Review comment:
2 column view does not work correctly with doxygen. You can stitch the images together and insert as single image with header or include images one by one.
**File:** modules/calib/include/opencv2/calib.hpp
**Change Type:** modified
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -1122,6 +1122,47 @@ CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints,
                                      OutputArray perViewErrors, int flags = CALIB_FIX_INTRINSIC,
                                      TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6) );
 
+/** @brief Estimates intrinsics and extrinsics (camera pose) for multi-camera system a.k.a multiview calibraton.
+
+@param[in] objPoints Calibration pattern object points. Expected shape: NUM_FRAMES x NUM_POINTS x 3. Supported data type: CV_32F.
+@param[in] imagePoints Detected pattern points on camera images. Expected shape: NUM_CAMERAS x NUM_FRAMES x NUM_POINTS x 2.
+@param[in] imageSize   Images resolution.
+@param[in] detectionMask Pattern detection mask. Each value defines if i-camera observes calibration pattern in j moment of time.
```

Review comment:
Doxygen does not parse the comment as description. Syntax issue.
**File:** modules/calib/include/opencv2/calib.hpp
**Change Type:** modified
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -1122,6 +1122,47 @@ CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints,
                                      OutputArray perViewErrors, int flags = CALIB_FIX_INTRINSIC,
                                      TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6) );
 
+/** @brief Estimates intrinsics and extrinsics (camera pose) for multi-camera system a.k.a multiview calibraton.
+
+@param[in] objPoints Calibration pattern object points. Expected shape: NUM_FRAMES x NUM_POINTS x 3. Supported data type: CV_32F.
+@param[in] imagePoints Detected pattern points on camera images. Expected shape: NUM_CAMERAS x NUM_FRAMES x NUM_POINTS x 2.
+@param[in] imageSize   Images resolution.
+@param[in] detectionMask Pattern detection mask. Each value defines if i-camera observes calibration pattern in j moment of time.
```

Review comment:
`USE_INTRINSICS_GUESS` should be renamed in cammel-case style. as soon as other parameters.
**File:** modules/calib/include/opencv2/calib.hpp
**Change Type:** modified
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -1122,6 +1122,47 @@ CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints,
                                      OutputArray perViewErrors, int flags = CALIB_FIX_INTRINSIC,
                                      TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6) );
 
+/** @brief Estimates intrinsics and extrinsics (camera pose) for multi-camera system a.k.a multiview calibraton.
+
+@param[in] objPoints Calibration pattern object points. Expected shape: NUM_FRAMES x NUM_POINTS x 3. Supported data type: CV_32F.
+@param[in] imagePoints Detected pattern points on camera images. Expected shape: NUM_CAMERAS x NUM_FRAMES x NUM_POINTS x 2.
+@param[in] imageSize   Images resolution.
+@param[in] detectionMask Pattern detection mask. Each value defines if i-camera observes calibration pattern in j moment of time.
```

Review comment:
Please add reference to calibrateCamera with `#calibrateCamera`
**File:** doc/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.markdown
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]
**Review Line:** 33

**Code Changes:**
```diff
+
+Introduction
+----
+Multiview calibration is a very important task in computer vision. It is widely used in 3D reconstruction, structure from motion, autonomous driving etc. The calibration procedure is often the first step for any vision task that must be done to obtain intrinsics and extrinsics parameters of the cameras. The accuracy of camera calibration parameters directly influence all further computations and results, hence, estimating precise intrinsincs and extrinsics is crucial.
+
+The calibration algorithms require a set of images for each camera, where on the images a calibration pattern (e.g., checkerboard, aruco etc) is visible and detected. Additionally, to get results with a real scale, the 3D distance between two neighbor points of the calibration pattern grid should be measured. For extrinsics calibration, images must share the calibration pattern obtained from different views, i.e., overlap of cameras' field of view. Moreover, images that share the pattern grid have to be taken at the same moment of time, or in other words, cameras must be synchronized. Otherwise, the extrinsics calibration will fail.
+
+The intrinsics calibration incorporates estimation of focal lengths, skew, and principal point of the camera; these parameters are combined in the intrinsic upper triangular matrix of size 3x3. Additionally, intrinsic calibration includes finding distortion parameters of the camera. The extrinsics parameters represent a relative rotation and translation between two cameras. Therefore, for \f$N\f$ cameras, a sufficient amount of correctly selected pairs of estimated relative rotations and translations is \f$N-1\f$, while extrinsics parameters for all possible pairs \f$N^2 = N * (N-1) / 2\f$ could be derived from those that are estimated. More details about intrinsics calibration could be found in this tutorial @ref tutorial_camera_calibration_pattern, and its implementation @ref cv::calibrateCamera.
+
+After intrinsics and extrinsics calibration, the projection matrices of cameras are found by combing intrinsic, rotation matrices and translation. The projection matrices enable doing triangulation (3D reconstruction), rectification, finding epipolar geometry etc.
+
```

Review comment:
I propose to add reference to calibration pattern page. File: doc/tutorials/calib3d/camera_calibration_pattern/camera_calibration_pattern.markdown. Doxygen reference: `#tutorial_camera_calibration_pattern`
**File:** doc/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.markdown
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,252 @@
+Multi-view Camera Calibration Tutorial {#tutorial_multiview_camera_calibration}
+==========================
+
+@tableofcontents
+
+@prev_tutorial{tutorial_interactive_calibration}
+
+|    |    |
+| -: | :- |
```

Review comment:
reference to `calibrateCamera` is useful here.
**File:** doc/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.markdown
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,252 @@
+Multi-view Camera Calibration Tutorial {#tutorial_multiview_camera_calibration}
+==========================
+
+@tableofcontents
+
+@prev_tutorial{tutorial_interactive_calibration}
+
+|    |    |
+| -: | :- |
```

Review comment:
Use just anchor in the page header `#tutorial_camera_calibration`. Doxygen generates links to known symbols automatically.
**File:** doc/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.markdown
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,252 @@
+Multi-view Camera Calibration Tutorial {#tutorial_multiview_camera_calibration}
+==========================
+
+@tableofcontents
+
+@prev_tutorial{tutorial_interactive_calibration}
+
+|    |    |
+| -: | :- |
```

Review comment:
The same for all API identifiers. Just use `#CALIB_RATIONAL_MODEL` to add reference.
**File:** doc/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.markdown
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,252 @@
+Multi-view Camera Calibration Tutorial {#tutorial_multiview_camera_calibration}
+==========================
+
+@tableofcontents
+
+@prev_tutorial{tutorial_interactive_calibration}
+
+|    |    |
+| -: | :- |
```

Review comment:
Use Tex notation for formulas. Formula is broken in rendered html.
**File:** doc/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.markdown
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,252 @@
+Multi-view Camera Calibration Tutorial {#tutorial_multiview_camera_calibration}
+==========================
+
+@tableofcontents
+
+@prev_tutorial{tutorial_interactive_calibration}
+
+|    |    |
+| -: | :- |
```

Review comment:
`{r, eval = FALSE}` breaks html generation.
**File:** samples/python/multiview_calibration.py
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,736 @@
+# 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.
+
+import argparse
+import glob
+import json
+import multiprocessing
+import os
```

Review comment:
`RESIZE_IMAGE=True` by default is bad idea. I propose to add command line parameter with scale. Default values should be 1.
**File:** samples/python/multiview_calibration.py
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,736 @@
+# 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.
+
+import argparse
+import glob
+import json
+import multiprocessing
+import os
```

Review comment:
`findCirclesGrid` supports color images and does color check. I propose to call cvtColor for `findChessboardCorners` only.
**File:** samples/python/multiview_calibration.py
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,736 @@
+# 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.
+
+import argparse
+import glob
+import json
+import multiprocessing
+import os
```

Review comment:
Please dump the calibration result to xml/yaml with FileStorage.
**File:** samples/python/multiview_calibration.py
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,736 @@
+# 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.
+
+import argparse
+import glob
+import json
+import multiprocessing
+import os
```

Review comment:
`traceback` is not used.
**File:** modules/calib/test/test_multiview_calib.cpp
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,151 @@
+// 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 "test_precomp.hpp"
+#include <opencv2/core/utils/logger.hpp>
+#include <opencv2/ts/cuda_test.hpp> // EXPECT_MAT_NEAR
+
+namespace opencv_test { namespace {
```

Review comment:
tolerance values are very large. dist_tol = 2e-1 is comparable with distortion coefficients.
**File:** modules/calib/src/multiview_calibration.cpp
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,848 @@
+// 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"
+#include "opencv2/core/utils/logger.hpp"
+#include "opencv2/core/softfloat.hpp"
+
+namespace cv {
```

Review comment:
It's bad idea. `Mat detection_mask_ = detection_mask` creates new cv::Mat mat with reference to user's data and then, it's could be re-written with convertTo, if element size is the same. I propose to get rid of convertTo for both buffers, use InputArray for masks and flags and add assert for type CV_8U. It allows to pass `std::vector<>` as input in C++.
**File:** modules/calib/src/multiview_calibration.cpp
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,848 @@
+// 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"
+#include "opencv2/core/utils/logger.hpp"
+#include "opencv2/core/softfloat.hpp"
+
+namespace cv {
```

Review comment:
It's not documented behavior. The result for mixed camera setup will be miss-interpreted. It leads to wrong calibration.
**File:** modules/calib/src/multiview_calibration.cpp
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]
**Review Line:** 584

**Code Changes:**
```diff
+    std::vector<std::vector<float>> points_ratio_area(NUM_CAMERAS, std::vector<float>(NUM_FRAMES));
+    multiview::imagePointsArea(imageSize, detection_mask_mat, imagePoints, points_ratio_area);
+
+    // constant threshold for angle between two camera axes in radians (=160*M_PI/180).
+    // if angle exceeds this threshold then a weight of a camera pair is lowered.
+    const double THR_PATTERN_CAMERA_ANGLES = 160*M_PI/180;
+    std::vector<std::vector<Vec3d>> rvecs_all(NUM_CAMERAS, std::vector<Vec3d>(NUM_FRAMES)),
+        tvecs_all(NUM_CAMERAS, std::vector<Vec3d>(NUM_FRAMES)),
+        opt_axes(NUM_CAMERAS, std::vector<Vec3d>(NUM_FRAMES));
+
+    std::vector<int> camera_rt_best(NUM_FRAMES, -1);
```

Review comment:
I propose to extract the constant from function to the top if the file and add detailed description for it.
**File:** modules/calib/src/multiview_calibration.cpp
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,848 @@
+// 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"
+#include "opencv2/core/utils/logger.hpp"
+#include "opencv2/core/softfloat.hpp"
+
+namespace cv {
```

Review comment:
I think this is what we were discussing with Jean-Yves and Vadim as well. If there is a mix of fisheye and pinhole cameras, then the rational model is used for intrinsics calibration. Additionally, the rational flag must be added for extrinsics calibration.
**File:** samples/python/multiview_calibration.py
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,736 @@
+# 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.
+
+import argparse
+import glob
+import json
+import multiprocessing
+import os
```

Review comment:
pickle is not portable solution and could not be easily loaded from C++ code. Use FileStorage with json or yaml instead.
**File:** samples/python/multiview_calibration.py
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,736 @@
+# 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.
+
+import argparse
+import glob
+import json
+import multiprocessing
+import os
```

Review comment:
In terms of architecture it's logical to return the calibration result as function result and save it to file in "main". File operations are not calibration concern.
**File:** samples/cpp/multiview_calibration_sample.cpp
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,173 @@
+// 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 <vector>
+#include <string>
+#include <opencv2/calib3d.hpp>
+#include <opencv2/imgcodecs.hpp>
+#include <opencv2/imgproc.hpp>
```

Review comment:
Please use OpenCV `cv::CommandLineParser` to handle input it the same way it's done for Python.
**File:** samples/cpp/multiview_calibration_sample.cpp
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]
**Review Line:** 123

**Code Changes:**
```diff
+        std::cout << "camera " << c << '\n';
+        std::cout << Rs[c] << " rotation\n";
+        std::cout << Ts[c] << " translation\n";
+        std::cout << Ks[c] << " intrinsic matrix\n";
+        std::cout << distortions[c] << " distortion\n";
+    }
+}
+
+int main (int argc, char **argv) {
+    cv::String keys =
+            "{help h usage ? || print help }"
```

Review comment:
reprojection error reporting will be useful too.
**File:** doc/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.markdown
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,252 @@
+Multi-view Camera Calibration Tutorial {#tutorial_multiview_camera_calibration}
+==========================
+
+@tableofcontents
+
+@prev_tutorial{tutorial_interactive_calibration}
+
+|    |    |
+| -: | :- |
```

Review comment:
it was renamed.
**File:** samples/python/multiview_calibration.py
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,736 @@
+# 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.
+
+import argparse
+import glob
+import json
+import multiprocessing
+import os
```

Review comment:
Sometimes resizing image is very convenient, if resolution is too big, it could take minutes to detect corners. While approximate corners could be found on the resized image and afterwards refined with cv::cornerSubPix. I added argument flag, the default parameter is now False (no resize).
**File:** modules/calib/src/multiview_calibration.cpp
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]
**Review Line:** 584

**Code Changes:**
```diff
+    std::vector<std::vector<float>> points_ratio_area(NUM_CAMERAS, std::vector<float>(NUM_FRAMES));
+    multiview::imagePointsArea(imageSize, detection_mask_mat, imagePoints, points_ratio_area);
+
+    // constant threshold for angle between two camera axes in radians (=160*M_PI/180).
+    // if angle exceeds this threshold then a weight of a camera pair is lowered.
+    const double THR_PATTERN_CAMERA_ANGLES = 160*M_PI/180;
+    std::vector<std::vector<Vec3d>> rvecs_all(NUM_CAMERAS, std::vector<Vec3d>(NUM_FRAMES)),
+        tvecs_all(NUM_CAMERAS, std::vector<Vec3d>(NUM_FRAMES)),
+        opt_axes(NUM_CAMERAS, std::vector<Vec3d>(NUM_FRAMES));
+
+    std::vector<int> camera_rt_best(NUM_FRAMES, -1);
```

Review comment:
should I use #define for this constant in the top of the file?
**File:** samples/python/multiview_calibration.py
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,736 @@
+# 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.
+
+import argparse
+import glob
+import json
+import multiprocessing
+import os
```

Review comment:
Should be `print('rvecs', rvecs)`.
**File:** doc/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.markdown
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]

**Code Changes:**
```diff
@@ -0,0 +1,252 @@
+Multi-view Camera Calibration Tutorial {#tutorial_multiview_camera_calibration}
+==========================
+
+@tableofcontents
+
+@prev_tutorial{tutorial_interactive_calibration}
+
+|    |    |
+| -: | :- |
```

Review comment:
> terminal-real-demo.png Its size is >800kb, which is large. Please try .jpg format for this image.
**File:** apps/python-calibration-generator/board.py
**Change Type:** added
**Context:** PR #22363: add multiview calibration [GSOC 2022]
**Review Line:** 5

**Code Changes:**
```diff
@@ -0,0 +1,59 @@
+# 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.
+
+import numpy as np
+
+class Board:
+    def __init__(self, w, h, square_len, euler_limit, t_limit, t_origin=None):
+        assert w >= 0 and h >= 0 and square_len >= 0
+        assert len(euler_limit) == len(t_limit) == 3
```

Review comment:
Please use short license header: https://github.com/opencv/opencv/wiki/Coding_Style_Guide#file-structure ``` // 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. ``` Use `#` instead of `//` in Python code.