LoginSignup
2
0

More than 3 years have passed since last update.

2.2.1 カメラキャリブレーション:アプリケーション

Posted at

目次へのリンク

MATLABによる画像処理・コンピュータービジョン入門目次

概要

MATLABによるカメラキャリブレーションのワークフローについて紹介します。

Computer Vision Toolbox™の「カメラキャリブレーター」アプリを活用します。

初期化

Code
clear; clc; close all; imtool close all

カメラキャリブレーション用の画像の確認

Code
imageFolder = fullfile(toolboxdir('vision'), 'visiondata', ...
    'calibration', 'mono');
winopen(imageFolder);

カメラキャリブレーターの起動

Code
squareSize = 29;  % 1マスのサイズ(単位:mm)
cameraCalibrator(imageFolder,squareSize);

画像から自動的にチェッカーボードが検出される

チェッカーボードが検出されなかった画像は除外されます。

image_0_png.jpg

キャリブレーションを実行

アプリ上で「キャリブレーション」をクリックし、キャリブレーションを実行します。

image_1_png.jpg

キャリブレーションの結果を確認

再投影誤差やカメラの外部パラメータを可視化し、キャリブレーションの妥当性を確認します。

再投影誤差が極端に大きいチェッカーボード画像はブレが大きいなどキャリブレーションに適していない場合もあります。

その場合は対象画像を除外して再度キャリブレーションを実行します。

image_2_png.jpg

実行結果のエクスポート

推定結果のカメラパラメーターをワークスペースにエクスポートします。

image_3_png.jpg

エクスポートしたカメラパラメーターの確認

Code
cameraParams
Output
cameraParams = 
  cameraParameters のプロパティ:

   Camera Intrinsics
                         Intrinsics: [1x1 cameraIntrinsics]

   Camera Extrinsics
                   RotationMatrices: [3x3x9 double]
                 TranslationVectors: [9x3 double]

   Accuracy of Estimation
              MeanReprojectionError: 0.1832
                 ReprojectionErrors: [54x2x9 double]
                  ReprojectedPoints: [54x2x9 double]

   Calibration Settings
                        NumPatterns: 9
                        WorldPoints: [54x2 double]
                         WorldUnits: 'mm'
                       EstimateSkew: 0
    NumRadialDistortionCoefficients: 2
       EstimateTangentialDistortion: 0

Code
cameraParams.Intrinsics % 内部パラメーター
Output
ans = 
  cameraIntrinsics のプロパティ:

             FocalLength: [714.1886 710.3786]
          PrincipalPoint: [563.6480 355.7251]
               ImageSize: [712 1072]
        RadialDistortion: [-0.3536 0.1730]
    TangentialDistortion: [0 0]
                    Skew: 0
         IntrinsicMatrix: [3x3 double]

エクスポートしたカメラパラメーターを使って画像の歪補正

Code
imds = imageDatastore(imageFolder);
origI = imds.readimage(1);
figure;imshow(origI)

figure_0_png.jpg

Code
[undistI, ~] = undistortImage(origI, cameraParams);
figure;imshowpair(origI,undistI);truesize;

figure_1_png.jpg

まとめ

MATLABによるカメラキャリブレーションのワークフローについて紹介しました。

アプリを活用することによってカメラキャリブレーションを効率的に試行錯誤できます。

参考

謝辞

本記事は @eigs さんのlivescript2markdownを使わせていただいてます。

目次へのリンク

MATLABによる画像処理・コンピュータービジョン入門目次

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0