Main Content

単一カメラのキャリブレーションの精度の評価

この例では、単一カメラ キャリブレーター アプリの使用アプリまたは関数estimateCameraParametersを使用して推定されたカメラ パラメーターの精度を評価する方法を説明します。

概要

カメラのキャリブレーションは、特別なキャリブレーション パターンのイメージを使用してカメラのパラメーターを推定するプロセスです。パラメーターには、カメラの内部パラメーター、歪み係数およびカメラの外部パラメーターがあります。カメラをキャリブレーションしたら、推定されたパラメーターの精度をいくつかの方法で評価できます。

  • カメラの相対位置とキャリブレーション パターンのプロット

  • 再投影誤差の計算

  • パラメーター推定誤差の計算

カメラのキャリブレーション

チェッカーボードのキャリブレーション パターンからなる一連のイメージを使用して、カメラ パラメーターを推定します。

% Create a set of calibration images.
images = imageDatastore(fullfile(toolboxdir("vision"), "visiondata", ...
    "calibration", "mono"));
imageFileNames = images.Files;

% Detect calibration pattern.
[imagePoints, boardSize] = detectCheckerboardPoints(imageFileNames);

% Generate world coordinates of the corners of the squares.
squareSize = 29; % millimeters
worldPoints = generateCheckerboardPoints(boardSize, squareSize);

% Calibrate the camera.
I = readimage(images, 1); 
imageSize = [size(I, 1), size(I, 2)];
[params, ~, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ...
                                     ImageSize=imageSize);

外部パラメーター

カメラとキャリブレーション パターンの相対位置をプロットすることで、キャリブレーションでの明らかな誤差を素早く検出できます。関数showExtrinsicsを使用して、カメラの座標系でキャリブレーション パターンの位置をプロットするか、パターンの座標系でカメラの位置をプロットします。パターンがカメラの背後にあったり、カメラがパターン背後にあるといった、明らかな問題点を探します。また、パターンがカメラから遠すぎないか、あるいはカメラに近すぎないかも確認します。

figure; 
showExtrinsics(params, "CameraCentric");

Figure contains an axes object. The axes object with title Extrinsic Parameters Visualization, xlabel X (mm), ylabel Z (mm) contains 23 objects of type patch, text, line.

figure; 
showExtrinsics(params, "PatternCentric");

Figure contains an axes object. The axes object with title Extrinsic Parameters Visualization, xlabel X (mm), ylabel Y (mm) contains 47 objects of type patch, text, line.

再投影誤差

再投影誤差では精度の定性的な測度が与えられます。再投影誤差は、キャリブレーション イメージ内で検出されたパターンのキーポイントと、それに対応する同じイメージに投影されたワールド ポイントとの間の距離です。関数showReprojectionErrorsでは、各キャリブレーション イメージにおける平均再投影誤差を可視化できて便利です。全体的な平均再投影誤差が大きすぎる場合、誤差が最も大きいイメージを排除してから、再度キャリブレーションを行うことを検討してください。

figure; 
showReprojectionErrors(params);

Figure contains an axes object. The axes object with title Mean Reprojection Error per Image, xlabel Images, ylabel Mean Error in Pixels contains 3 objects of type bar, line. This object represents Overall Mean Error: 0.18 pixels.

推定誤差

推定誤差は、各推定パラメーターの不確かさを表します。関数estimateCameraParametersは、オプションで estimationErrors 出力を返しますが、そこには推定された各カメラ パラメーターに対応する標準誤差が含まれます。返された標準誤差 σ (単位は対応するパラメーターと同じ) を使用して、信頼区間を計算できます。たとえば、+/- 1.96σ は 95% 信頼区間に対応します。つまり、特定のパラメーターの実際値が、その推定値の 1.96σ 以内にある確率が 95% であるということです。

displayErrors(estimationErrors, params);
			Standard Errors of Estimated Camera Parameters
			----------------------------------------------

Intrinsics
----------
Focal length (pixels):   [  714.1886 +/- 3.3219      710.3786 +/- 4.0579  ]
Principal point (pixels):[  563.6480 +/- 5.3967      355.7252 +/- 3.3036  ]
Radial distortion:       [   -0.3536 +/- 0.0091        0.1730 +/- 0.0488  ]

Extrinsics
----------
Rotation vectors:
                         [   -0.6096 +/- 0.0054       -0.1789 +/- 0.0073       -0.3835 +/- 0.0024  ]
                         [   -0.7283 +/- 0.0050       -0.0996 +/- 0.0072        0.1964 +/- 0.0027  ]
                         [   -0.6722 +/- 0.0051       -0.1444 +/- 0.0074       -0.1329 +/- 0.0026  ]
                         [   -0.5836 +/- 0.0056       -0.2901 +/- 0.0074       -0.5622 +/- 0.0025  ]
                         [   -0.3157 +/- 0.0065       -0.1441 +/- 0.0075       -0.1067 +/- 0.0011  ]
                         [   -0.7581 +/- 0.0052        0.1947 +/- 0.0072        0.4324 +/- 0.0030  ]
                         [   -0.7515 +/- 0.0051        0.0767 +/- 0.0072        0.2070 +/- 0.0029  ]
                         [   -0.6223 +/- 0.0053        0.0231 +/- 0.0073        0.3663 +/- 0.0024  ]
                         [    0.3443 +/- 0.0063       -0.2226 +/- 0.0073       -0.0437 +/- 0.0014  ]

Translation vectors (mm):
                         [ -146.0515 +/- 6.0391      -26.8685 +/- 3.7318      797.9027 +/- 3.9002  ]
                         [ -209.4356 +/- 6.9637      -59.4564 +/- 4.3578      921.8198 +/- 4.6295  ]
                         [ -129.3823 +/- 7.0907      -44.1029 +/- 4.3751      937.6831 +/- 4.4913  ]
                         [ -151.0047 +/- 6.6905      -27.3252 +/- 4.1339      884.2789 +/- 4.3925  ]
                         [ -174.9498 +/- 6.7056      -24.3498 +/- 4.1606      886.4961 +/- 4.6686  ]
                         [ -134.3095 +/- 7.8887     -103.4980 +/- 4.8925     1042.4554 +/- 4.8184  ]
                         [ -173.9844 +/- 7.6891      -73.1690 +/- 4.7812     1017.2386 +/- 4.8126  ]
                         [ -202.9445 +/- 7.4327      -87.9090 +/- 4.6482      983.6957 +/- 4.9072  ]
                         [ -319.8860 +/- 6.3213     -119.8897 +/- 4.0922      829.4582 +/- 4.9591  ]

キャリブレーションの精度を改善する方法

特定の再投影誤差または推定誤差を許容できるかどうかは、特定アプリケーションの精度要件によって決まります。キャリブレーションの精度を許容できないと判断した場合には、いくつかの方法で改善することができます。

  • キャリブレーションの設定を変更する。3 つの半径方向歪み係数を使用して、円周方向歪みもしくはせん断を推定します。

  • 使用するキャリブレーション イメージの数を増やす。イメージ内のパターンはさまざまな 3 次元方向に置かれなければならず、キーポイントが視野のすべての部分に存在するよう配置する必要があります。特に、歪み係数の推定値を改善するには、イメージのエッジとコーナーの近くにキーポイントがあることが非常に重要です。

  • 再投影誤差の大きいイメージを排除して、キャリブレーションをやり直す。

まとめ

この例では、カメラのキャリブレーション誤差を取得および解釈する方法を説明しました。

参考文献

[1] Z. Zhang. A flexible new technique for camera calibration. IEEE Transactions on Pattern Analysis and Machine Intelligence, 22(11):1330-1334, 2000.