Skip to content

Commit 0868a40

Browse files
authored
Merge pull request #2006 from shimat/claude/sharp-knuth-eaa295
Fix wrong CALIB_FIX_S1_S2_S3_S4 value and add missing CalibrationFlags
2 parents 662645d + 94f0df5 commit 0868a40

2 files changed

Lines changed: 55 additions & 11 deletions

File tree

src/OpenCvSharp/Cv2/Cv2_calib.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public static double CalibrateCamera(
324324
/// <param name="e">Output essential matrix.</param>
325325
/// <param name="f">Output fundamental matrix.</param>
326326
/// <param name="perViewErrors">Output per-view RMS reprojection errors.</param>
327-
/// <param name="flags">Operation flags.</param>
327+
/// <param name="flags">Operation flags. Only <see cref="CalibrationFlags.UseExtrinsicGuess"/> is supported.</param>
328328
/// <param name="criteria">Termination criteria for the iterative optimization algorithm.</param>
329329
/// <returns>Overall RMS reprojection error.</returns>
330330
public static double RegisterCameras(
@@ -333,7 +333,7 @@ public static double RegisterCameras(
333333
InputArray cameraMatrix1, InputArray distCoeffs1, CameraModel cameraModel1,
334334
InputArray cameraMatrix2, InputArray distCoeffs2, CameraModel cameraModel2,
335335
InputOutputArray r, InputOutputArray t, OutputArray e, OutputArray f,
336-
OutputArray perViewErrors, int flags = 0, TermCriteria? criteria = null)
336+
OutputArray perViewErrors, CalibrationFlags flags = CalibrationFlags.None, TermCriteria? criteria = null)
337337
{
338338
if (objectPoints1 is null)
339339
throw new ArgumentNullException(nameof(objectPoints1));
@@ -356,7 +356,7 @@ public static double RegisterCameras(
356356
op1, op1.Length, op2, op2.Length, ip1, ip1.Length, ip2, ip2.Length,
357357
cameraMatrix1.Proxy, distCoeffs1.Proxy, (int)cameraModel1,
358358
cameraMatrix2.Proxy, distCoeffs2.Proxy, (int)cameraModel2,
359-
r.Proxy, t.Proxy, e.Proxy, f.Proxy, perViewErrors.Proxy, flags, criteria0, out var ret));
359+
r.Proxy, t.Proxy, e.Proxy, f.Proxy, perViewErrors.Proxy, (int)flags, criteria0, out var ret));
360360

361361
GC.KeepAlive(cameraMatrix1.Source);
362362
GC.KeepAlive(distCoeffs1.Source);
@@ -390,7 +390,8 @@ public static double RegisterCameras(
390390
/// <param name="rs">Output per-camera rotation matrices relative to camera 0.</param>
391391
/// <param name="ts">Output per-camera translation vectors relative to camera 0.</param>
392392
/// <param name="flagsForIntrinsics">Optional per-camera intrinsics-calibration flags (NUM_CAMERAS x 1, CV_32S).</param>
393-
/// <param name="flags">Common multi-view calibration flags.</param>
393+
/// <param name="flags">Common multi-view calibration flags.
394+
/// Only <see cref="CalibrationFlags.UseIntrinsicGuess"/> and <see cref="CalibrationFlags.UseExtrinsicGuess"/> are supported.</param>
394395
/// <param name="criteria">Termination criteria for the iterative optimization algorithm.</param>
395396
/// <returns>Overall RMS reprojection error.</returns>
396397
public static double CalibrateMultiview(
@@ -401,7 +402,7 @@ public static double CalibrateMultiview(
401402
InputArray models,
402403
out Mat[] ks, out Mat[] distortions, out Mat[] rs, out Mat[] ts,
403404
InputArray flagsForIntrinsics = default,
404-
int flags = 0,
405+
CalibrationFlags flags = CalibrationFlags.None,
405406
TermCriteria? criteria = null)
406407
{
407408
if (objPoints is null)
@@ -440,7 +441,7 @@ public static double CalibrateMultiview(
440441
imageSizeArray, imageSizeArray.Length,
441442
detectionMask.Proxy, models.Proxy,
442443
ksVec.CvPtr, distVec.CvPtr, rsVec.CvPtr, tsVec.CvPtr,
443-
flagsForIntrinsics.Proxy, flags, criteria0, out var ret));
444+
flagsForIntrinsics.Proxy, (int)flags, criteria0, out var ret));
444445

445446
ks = ksVec.ToArray();
446447
distortions = distVec.ToArray();

src/OpenCvSharp/Modules/calib/Enum/CalibrationFlags.cs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,36 @@ public enum CalibrationFlags
7777
RationalModel = 0x04000,
7878

7979
/// <summary>
80-
///
80+
/// For pinhole model only. Use thin prism distortion model with coefficients s1..s4.
8181
/// </summary>
8282
ThinPrismModel = 0x08000,
8383

8484
/// <summary>
85-
///
85+
/// For pinhole model only. The thin prism distortion coefficients are not changed during the optimization.
86+
/// 0 value is used, if UseIntrinsicGuess is not set.
8687
/// </summary>
87-
#pragma warning disable CA1069 // Enums should not have duplicate values
88-
FixS1S2S3S4 = 0x08000,
89-
#pragma warning restore CA1069
88+
FixS1S2S3S4 = 0x10000,
89+
90+
/// <summary>
91+
/// For pinhole model only. Coefficients tauX and tauY are enabled in camera matrix.
92+
/// </summary>
93+
TiltedModel = 0x40000,
94+
95+
/// <summary>
96+
/// For pinhole model only. The tauX and tauY coefficients are not changed during the optimization.
97+
/// 0 value is used, if UseIntrinsicGuess is not set.
98+
/// </summary>
99+
FixTauXTauY = 0x80000,
100+
101+
/// <summary>
102+
/// Use QR instead of SVD decomposition for solving. Faster but potentially less precise.
103+
/// </summary>
104+
UseQr = 0x100000,
105+
106+
/// <summary>
107+
/// For pinhole model only. Tangential distortion coefficients (p1, p2) are set to zeros and stay zero.
108+
/// </summary>
109+
FixTangentDist = 0x200000,
90110

91111
/// <summary>
92112
/// If it is set, camera_matrix1,2, as well as dist_coeffs1,2 are fixed, so that only extrinsic parameters are optimized.
@@ -102,4 +122,27 @@ public enum CalibrationFlags
102122
/// for stereo rectification
103123
/// </summary>
104124
ZeroDisparity = 0x00400,
125+
126+
/// <summary>
127+
/// Use LU instead of SVD decomposition for solving. Much faster but potentially less precise.
128+
/// </summary>
129+
UseLu = 1 << 17,
130+
131+
/// <summary>
132+
/// Disable Schur complement (use Bouguet calibration engine).
133+
/// </summary>
134+
#pragma warning disable CA1069 // Enums should not have duplicate values (matches native CALIB_TILTED_MODEL, per opencv2/calib.hpp)
135+
DisableSchurComplement = 1 << 18,
136+
#pragma warning restore CA1069
137+
138+
/// <summary>
139+
/// For stereo and multi-view calibration. Use user provided extrinsics (R, T) as initial point for optimization.
140+
/// </summary>
141+
UseExtrinsicGuess = 1 << 22,
142+
143+
/// <summary>
144+
/// For multiview calibration only. Use stereo correspondence approach for initial extrinsics guess.
145+
/// Limitation: all cameras should have the same type.
146+
/// </summary>
147+
StereoRegistration = 1 << 26,
105148
}

0 commit comments

Comments
 (0)