主要内容

本页采用了机器翻译。点击此处可查看英文原文。

detectCheckerboardPoints

检测图像中的棋盘格图案

说明

单帧棋盘格检测

[imagePoints,patternDims] = detectCheckerboardPoints(I) 可在单个图像、一组图像或立体图像对中检测棋盘格标定图案的关键点。该函数返回检测到的点 imagePoints 以及棋盘格的维度 patternDims

示例

[imagePoints,patternDims,imagesUsed] = detectCheckerboardPoints(imageFileNames) 会在一组输入图像中检测棋盘格图案,这些图像以文件名数组的形式提供。

[imagePoints,patternDims,imagesUsed] = detectCheckerboardPoints(images) 用于在一组输入图像中检测棋盘格图案,这些图像以灰度或真彩色图像数组的形式提供。

立体图像对棋盘格检测

[imagePoints,patternDims,pairsUsed] = detectCheckerboardPoints(imageFileNames1,imageFileNames2) 用于在以元胞数组形式提供的立体图像对中检测棋盘格图案。

[imagePoints,patternDims,pairsUsed] = detectCheckerboardPoints(images1,images2) 可在立体图像对中检测棋盘格图案,这些图像对以灰度或真彩色图像数组的形式提供。

可选参量

[imagePoints,patternDims,pairsUsed] = detectCheckerboardPoints(___,Name,Value) 使用由一个或多个 Name,Value 成对参量指定的附加选项。未指定的属性具有默认值。

示例

全部折叠

创建一个名为 imageDatastore 的文件夹,其中包含来自 GoPro 相机的标定图像。

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.

创建一个包含标定图像文件名的元胞数组。

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 × N × 3 的真彩色图像,或 M × N 的二维灰度图像。输入图像必须为非稀疏实矩阵。该函数能够检测最小尺寸为 4×4 格的棋盘格图案。

数据类型: single | double | int16 | uint8 | uint16 | logical

图像文件名,指定为由 N 个文件名组成的 N-元胞数组。

相机 1 的图像文件名,指定为一个由 N 个文件名组成的 N-元胞数组。该数组中的图像顺序必须与 imageFileNames2 中的图像顺序一致,以形成立体图像对。

相机 2 图像的文件名,指定为一个由 N 个文件名组成的 N-元胞数组。该数组中的图像顺序必须与 imageFileNames1 中的图像顺序一致,以形成立体图像对。

图像,指定为一个 H×W×B×F 数组,其中包含一组灰度或真彩色图像。输入维度如下:

H 表示图像高度。
W 表示图像宽度。
B 代表颜色通道。值 1 表示灰度图像,值 3 表示真彩色图像。
F 表示图像帧的数量。

来自相机 1 的立体成对图像,指定为一个 H×W×B×F 数组,其中包含一组灰度或真彩色图像。输入维度如下:

H 表示图像高度。
W 表示图像宽度。
B 代表颜色通道。值 1 表示灰度图像,值 3 表示真彩色图像。
F 表示图像帧的数量。

来自相机 2 的立体成对图像,指定为一个 H×W×B×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。该值减小会导致角点检测数量增加。

高畸变,指定为 falsetrue。当图像存在严重畸变时(这通常是广角相机,例如鱼眼镜头,的典型特征),请将 'HighDistortion' 设置为 true。当图像未出现严重畸变时,将 'HighDistortion' 设置为 false。将 'HighDistortion' 设置为 true 可以提高对图像畸变的鲁棒性,但会降低处理速度。

部分检测,指定为 truefalse。将 'PartialDetections' 设置为 true,以返回部分检测到的棋盘格图案。该函数会用 [NaN,NaN] 坐标填充缺失的关键点检测结果。将 'PartialDetections' 设置为 false,以舍弃部分检测到的棋盘格图案。对于立体图像对,该属性将被忽略。

输出参量

全部折叠

检测到的棋盘格角坐标,以 M×2 矩阵的形式返回,对应单个图像。对于多个图像,该函数将坐标以 M×2×number of images 数组的形式返回;对于立体图像对,该函数将坐标以 M×2×number of pairs×number of cameras 数组的形式返回。

对于立体图像对,imagePoints(:,:,:,1) 是来自第一组图像的点,而 imagePoints(:,:,:,2) 是来自第二组图像的点。输出包含 M 个 [x y] 坐标。每个坐标代表棋盘上检测到方块角点的某个位置。该函数返回的点数取决于 patternDims 的值,该值表示检测到的正方形数量。该函数能以亚像素精度检测点的位置。

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

该函数按以下方式计算点数 M

M = prod(patternDims-1)。

如果无法检测到棋盘格:
imagePoints = []
patternDims = [0,0]

当指定 imageFileNames 作为输入时,该函数可以返回 imagePoints,其形式为一个 M×2×N 的数组。在此数组中,N 表示检测到棋盘格图案的图像数量。如果无法检测到棋盘格,该函数将返回 imagePoints,作为以下两种选项之一:

仅适用于单相机图像:

  • 如果无法检测到完整的棋盘格,该函数将返回一个部分检测到的棋盘格,其中 [NaN,NaN] 表示 x-y 坐标,用于表示 imagePoints 中缺失的角点。可以使用 'PartialDetections' 名称-值参量来修改此默认行为。

  • 在可能的情况下,该函数会调整部分检测到的棋盘格的方向,使其原点位置和角点的排列与完全可见的棋盘格保持一致。如果该函数无法在任何输入图像中检测到完整的棋盘格,则将检测到的最大棋盘格用作参考棋盘格,并通过 patternDims 返回该棋盘格的维度。

图案维度,以包含两个元素的向量 [height, width] 形式返回。图案的维度以方格的数量来表示。

Checkboard showing width and height measurements and the origin.

如果无法检测到棋盘格,该函数会将 patternDims 设置为 [0,0]

图案检测结果以 N×1 逻辑向量的形式返回,其中 N 表示图像的数量。如果成功在图像中检测到角点,该函数返回 1 (true);如果未检测到角点,则返回 0 (false)。

该函数基于对关键点的成功检测,对棋盘格的角点进行估计。如果检测过程中的任何一步失败,该函数将不会返回该图像的角点,且逻辑向量中的相应值为 false。

立体图像对图案检测,结果以 N×1 逻辑向量的形式返回,其中 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 中推出