メインコンテンツ

detectCheckerboardPoints

イメージ内のチェッカーボード パターンの検出

説明

単一イメージのチェッカーボード検出

[imagePoints,patternDims] = detectCheckerboardPoints(I) は、単一のイメージ、イメージのセット、またはステレオ イメージ ペア内のチェッカーボード キャリブレーション パターンのキーポイントを検出します。この関数は、検出点 imagePoints とチェッカーボードの次元 patternDims を返します。

[imagePoints,patternDims,imagesUsed] = detectCheckerboardPoints(imageFileNames) は、ファイル名の配列として指定された入力イメージ セット内のチェッカーボード パターンを検出します。

[imagePoints,patternDims,imagesUsed] = detectCheckerboardPoints(images) は、グレースケール イメージまたはトゥルーカラー イメージの配列として指定された入力イメージ セット内のチェッカーボード パターンを検出します。

ステレオ ペアのチェッカーボード検出

[imagePoints,patternDims,pairsUsed] = detectCheckerboardPoints(imageFileNames1,imageFileNames2) は、ファイル名の cell 配列として指定されたイメージのステレオ ペア内のチェッカーボード パターンを検出します。

[imagePoints,patternDims,pairsUsed] = detectCheckerboardPoints(images1,images2) は、グレースケール イメージまたはトゥルーカラー イメージの配列として指定されたイメージのステレオ ペア内のチェッカーボード パターンを検出します。

オプション引数

[imagePoints,patternDims,pairsUsed] = detectCheckerboardPoints(___,Name,Value) は、Name,Value ペアの引数を 1 つ以上指定したオプションを追加で使用します。指定していないプロパティは既定値になります。

すべて折りたたむ

GoPro カメラからのキャリブレーション イメージを格納する imageDatastore を作成します。

imds = imageDatastore(fullfile(toolboxdir("vision"),"visiondata","calibration","gopro"));

魚眼レンズ イメージでの使用に適した HighDistortion オプションを使用して、キャリブレーション パターンを検出します。

[imagePoints,patternDims,imagesUsed] = detectCheckerboardPoints(imds.Files(1:4),HighDistortion=true);

検出した点を表示します。

for i = 1:4
  % Read image
  I = readimage(imds,i);

  % Insert markers at detected point locations
  I = insertMarker(I,imagePoints(:,:,i),"o",MarkerColor="red",Size=10);

  % Display image
  subplot(2,2,i);
  imshow(I);
end

Figure contains 4 axes objects. Hidden axes object 1 contains an object of type image. Hidden axes object 2 contains an object of type image. Hidden axes object 3 contains an object of type image. Hidden axes object 4 contains an object of type image.

チェッカーボード パターンを含むイメージを読み込みます。

imageFileName = fullfile(toolboxdir("vision"),"visiondata","calibration","dslr","image01.jpg");
I = imread(imageFileName);

チェッカーボード点を検出します。

[imagePoints,patternDims] = detectCheckerboardPoints(I);

検出した点を表示します。

J = insertText(I,imagePoints,1:size(imagePoints,1));
J = insertMarker(J,imagePoints,"o",MarkerColor="red",Size=5);
imshow(J);
title(sprintf("Detected a %d x %d Checkerboard",patternDims));

Figure contains an axes object. The hidden axes object with title Detected a 7 x 10 Checkerboard contains an object of type image.

キャリブレーション イメージのファイル名の cell 配列を作成します。

images = imageDatastore(fullfile(toolboxdir("vision"),"visiondata",...
    "calibration","dslr"));
imageFileNames = images.Files;

イメージ内のキャリブレーション パターンを検出します。

[imagePoints,patternDims,imagesUsed] = detectCheckerboardPoints(imageFileNames,PartialDetections=false);

検出した点を表示します。

imageFileNames = imageFileNames(imagesUsed);
for i = 1:4
  I = imread(imageFileNames{i});
subplot(2, 2, i);
  imshow(I);
  hold on;
  plot(imagePoints(:,1,i),imagePoints(:,2,i),"ro");
end

Figure contains 4 axes objects. Hidden axes object 1 contains 2 objects of type image, line. One or more of the lines displays its values using only markers Hidden axes object 2 contains 2 objects of type image, line. One or more of the lines displays its values using only markers Hidden axes object 3 contains 2 objects of type image, line. One or more of the lines displays its values using only markers Hidden axes object 4 contains 2 objects of type image, line. One or more of the lines displays its values using only markers

ステレオ イメージを読み取ります。

numImages = 4;
images1 = cell(1,numImages);
images2 = cell(1,numImages);
for i = 1:numImages
    images1{i} = fullfile(matlabroot,'toolbox','vision',...
        'visiondata','calibration','stereo','left',sprintf('left%02d.png',i));
    images2{i} = fullfile(matlabroot,'toolbox','vision',...
        'visiondata','calibration','stereo','right',sprintf('right%02d.png',i));
end

イメージ内のチェッカーボードを検出します。

[imagePoints,patternDims,pairsUsed] = ...
    detectCheckerboardPoints(images1,images2);

images1 の点を表示します。

images1 = images1(pairsUsed);
figure;
for i = 1:numel(images1)
      I = imread(images1{i});
      subplot(2,2,i);
      imshow(I); 
      hold on; 
      plot(imagePoints(:,1,i,1),imagePoints(:,2,i,1),'ro');
end 
annotation('textbox',[0 0.9 1 0.1],'String','Camera 1',...
    'EdgeColor','none','HorizontalAlignment','center')

Figure contains 4 axes objects. Hidden axes object 1 contains 2 objects of type image, line. One or more of the lines displays its values using only markers Hidden axes object 2 contains 2 objects of type image, line. One or more of the lines displays its values using only markers Hidden axes object 3 contains 2 objects of type image, line. One or more of the lines displays its values using only markers Hidden axes object 4 contains 2 objects of type image, line. One or more of the lines displays its values using only markers

images2 の点を表示します。

images2 = images2(pairsUsed);
figure;
for i = 1:numel(images2)
      I = imread(images2{i});
      subplot(2, 2, i);
      imshow(I);
      hold on; 
      plot(imagePoints(:,1,i,2),imagePoints(:,2,i,2),'ro');
end 
annotation('textbox',[0 0.9 1 0.1],'String','Camera 2',...
    'EdgeColor','none','HorizontalAlignment','center')

Figure contains 4 axes objects. Hidden axes object 1 contains 2 objects of type image, line. One or more of the lines displays its values using only markers Hidden axes object 2 contains 2 objects of type image, line. One or more of the lines displays its values using only markers Hidden axes object 3 contains 2 objects of type image, line. One or more of the lines displays its values using only markers Hidden axes object 4 contains 2 objects of type image, line. One or more of the lines displays its values using only markers

入力引数

すべて折りたたむ

入力イメージ。M x N x 3 のトゥルーカラー、または MN 列の 2 次元グレースケールとして指定します。入力イメージは、実数で非スパースでなければなりません。関数で検出できるチェッカーボードの最小サイズは 4 行 4 列の正方形です。

データ型: single | double | int16 | uint8 | uint16 | logical

イメージ ファイル名。N 個のファイル名の N 要素 cell 配列として指定します。

カメラ 1 イメージのファイル名。N 個のファイル名の N 要素 cell 配列として指定します。この配列に含まれているイメージは、ステレオ ペアを形成する imageFileNames2 に含まれているイメージと同じ順序でなければなりません。

カメラ 2 イメージのファイル名。N 個のファイル名の N 要素 cell 配列として指定します。この配列に含まれているイメージは、ステレオ ペアを形成する imageFileNames1 に含まれているイメージと同じ順序でなければなりません。

イメージ。グレースケール イメージまたはトゥルーカラー イメージのセットを含む H x W x B x F の配列として指定します。入力の次元は次のとおりです。

H はイメージの高さを表します。
W はイメージの幅を表します。
B はカラー チャネルを表します。値 1 はグレースケール イメージ、値 3 はトゥルーカラー イメージを示します。
F はイメージ フレーム数を表します。

カメラ 1 からのステレオ ペア イメージ。グレースケール イメージまたはトゥルーカラー イメージのセットを含む H x W x B x F の配列として指定します。入力の次元は次のとおりです。

H はイメージの高さを表します。
W はイメージの幅を表します。
B はカラー チャネルを表します。値 1 はグレースケール イメージ、値 3 はトゥルーカラー イメージを示します。
F はイメージ フレーム数を表します。

カメラ 2 からのステレオ ペア イメージ。グレースケール イメージまたはトゥルーカラー イメージのセットを含む H x W x B x F の配列として指定します。入力の次元は次のとおりです。

H はイメージの高さを表します。
W はイメージの幅を表します。
B はカラー チャネルを表します。値 1 はグレースケール イメージ、値 3 はトゥルーカラー イメージを示します。
F はイメージ フレーム数を表します。

名前と値の引数

すべて折りたたむ

オプションの引数のペアを Name1=Value1,...,NameN=ValueN として指定します。ここで、Name は引数名で、Value は対応する値です。名前と値の引数は他の引数の後に指定しなければなりませんが、ペアの順序は重要ではありません。

R2021a より前では、コンマを使用して名前と値をそれぞれ区切り、Name を引用符で囲みます。

例: 'MinCornerMetric', '0.15'

コーナー メトリクスの最小しきい値。非負のスカラーとして指定します。イメージにノイズが含まれている場合や、テクスチャが多く使用されている場合、この値を増やして誤ったコーナー検出の数を削減します。'HighDistortion' プロパティを false に設定すると、関数は既定値を 0.15 に設定します。'HighDistortion' プロパティを true に設定すると、関数は既定値を 0.12 に設定します。値を小さくすると、コーナー検出が増加します。

強い歪み。false または true として指定します。イメージに強い歪みが含まれているときは、'HighDistortion'true に設定します。これは、魚眼カメラなどの広角カメラで一般的です。イメージに強い歪みが含まれていないときは、'HighDistortion'false に設定します。'HighDistortion'true に設定すると、イメージの歪みに対する復元力は高まりますが、処理速度は低下します。

部分検出。true または false として指定します。部分的に検出されたチェッカーボードを返すには、'PartialDetections'true に設定します。この関数は、欠損しているキーポイント検出を [NaN,NaN] 座標で埋めます。部分的に検出されたチェッカーボードを破棄するには、'PartialDetections'false に設定します。このプロパティは、ステレオ イメージ ペアでは無視されます。

出力引数

すべて折りたたむ

検出されたチェッカーボードのコーナーの座標。1 つのイメージの場合は M 行 2 列の行列として返されます。複数のイメージの場合、点は M x 2 x number of images の配列として返され、イメージのステレオ ペアの場合、点は M x 2 x number of pairs x number of cameras の配列として返されます。

ステレオ ペアの場合、imagePoints(:,:,:,1) は最初のイメージ セットの点で、imagePoints(:,:,:,2) は 2 番目のイメージ セットの点です。出力には M 個の [x y] 座標が含まれます。各座標は、チェッカーボードで正方形のコーナーが検出された点を表します。関数によって返される点の数は、検出された正方形の数を示す patternDims の値によって決まります。関数はサブピクセルの精度で点を検出します。

関数は点の数 M を次のように計算します。

M = prod(patternDims-1)。

チェッカーボードを検出できない場合は次のようになります。
imagePoints = []
patternDims = [0,0]

imageFileNames 入力を指定すると、関数は imagePointsM x 2 x N の配列として返すことができます。この配列では、N はチェッカーボードが検出されたイメージの数を表します。チェッカーボードが検出できない場合、関数は imagePoints を次に設定します。

Checkerboard indicating the origin (0,0) as the lower-right corner of the first box in the upper-left corner of the checkerboard.

単一カメラのイメージのみの場合:

  • 完全なチェッカーボードが検出できない場合、関数は、imagePoints で欠損しているコーナーの x-y 座標として [NaN,NaN] を使用して、部分的に検出されたチェッカーボードを返します。この既定の動作は、名前と値の引数 'PartialDetections' を使用して変更できます。

  • 可能な場合、関数は、部分的に検出されたチェッカーボードの原点の位置とコーナーの配置が、全体が表示された状態のチェッカーボードと一致するように、その向きを設定します。関数が入力イメージのいずれにおいても完全なチェッカーボードを検出できない場合、検出された最大サイズのチェッカーボードが参照チェッカーボードとして使用され、このボードの次元が patternDims に返されます。

パターンの次元。2 要素ベクトル [height, width] として返されます。パターンの次元は正方形の数で表されます。

Checkboard showing width and height measurements and the origin.

チェッカーボードが検出できない場合、関数は patternDims[0,0] に設定します。

パターン検出結果。N 行 1 列の logical ベクトルとして返されます。ここで、N はイメージの数です。関数は、イメージ内でコーナーが正常に検出された場合は 1 (true) を返し、コーナーが検出されなかった場合は 0 (false) を返します。

関数は、キーポイントの正常な検出結果に基づいて、チェッカーボードのコーナーを推定します。検出プロセスのいずれかのステップが失敗した場合、関数はそのイメージのコーナーを返さず、logical ベクトル内の対応する値が false となります。

ステレオ ペアのパターン検出結果。N 行 1 列の logical ベクトルとして返されます。ここで、N はイメージの数です。関数は、ステレオ イメージ ペア内でコーナーが正常に検出された場合は 1 (true) を返し、コーナーが検出されなかった場合は 0 (false) を返します。

ステレオ ペア パターン検出の場合、チェッカーボードを検出するには、両方のイメージでチェッカーボード全体が表示されている必要があります。単一カメラのキャリブレーションとは異なり、ステレオ イメージ ペアでは部分的に検出されたチェッカーボードが除外されます。

参照

[1] Geiger, A., F. Moosmann, O. Car, and B. Schuster. "Automatic Camera and Range Sensor Calibration using a Single Shot," International Conference on Robotics and Automation (ICRA), St. Paul, USA, May 2012.

拡張機能

すべて展開する

バージョン履歴

R2014a で導入