Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

単眼魚眼カメラの構成

この例では、魚眼カメラ モデルをピンホール モデルに変換し、対応する単眼カメラ センサーのシミュレーションを構築する方法を説明します。この例では、魚眼カメラをキャリブレーションしてmonoCameraオブジェクトを構成する方法を学習します。

概要

車両に取り付けられた単眼カメラ センサーをシミュレートするには、次の手順に従います。

  1. チェッカーボードを使用してカメラをキャリブレーションすることにより、カメラの内部パラメーターを推定します。内部パラメーターは、魚眼カメラ自体のプロパティを表します。

  2. 前の手順と同じチェッカーボードを使用して、カメラを再度キャリブレーションすることにより、カメラの外部パラメーターを推定します。外部パラメーターは、魚眼カメラの取り付け位置を、車両座標系で表します。

  3. 魚眼カメラの内部パラメーターをピンホール カメラの内部パラメーターに変換することにより、イメージの歪みを除去します。これらの内部パラメーターは、歪み補正されたイメージを仮想的に生成できる合成ピンホール カメラを表します。

  4. ピンホール カメラの内部パラメーターと外部パラメーターを使用して、シミュレーション用の単眼カメラ センサーを構成します。その後、このセンサーを使用して、オブジェクトおよび車線境界線を検出できます。

魚眼カメラの内部パラメーターの推定

内部パラメーターを推定するには、カメラのキャリブレーション用のチェッカーボードを使用します。また、結果をより明確に可視化するには、カメラ キャリブレーターアプリを使用します。魚眼カメラの場合は、イメージ内の大きく目立つ歪みを取得するために、チェッカーボードをカメラの近くに配置すると便利です。

 % Gather a set of calibration images.
images = imageDatastore(fullfile(toolboxdir('vision'), 'visiondata', ...
      'calibration', 'gopro'));
imageFileNames = images.Files;
 
% Detect calibration pattern.
[imagePoints, boardSize] = detectCheckerboardPoints(imageFileNames);

% Generate world coordinates of the corners of the squares.
squareSize = 0.029; % Square size in meters
worldPoints = generateCheckerboardPoints(boardSize, squareSize);

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

魚眼カメラの外部パラメーターの推定

外部パラメーターを推定するには、同じチェッカーボードを使用して、カメラの取り付け位置を車両座標系で推定します。次の手順では、1 つのイメージからパラメーターを推定します。複数のチェッカーボード イメージを撮影して複数の推定を取得し、結果を平均することもできます。

% Load a different image of the same checkerboard, where the checkerboard 
% is placed on the flat ground. Its X-axis is pointing to the right of the 
% vehicle, and its Y-axis is pointing to the camera. The image includes 
% noticeable distortion, such as along the wall next to the checkerboard.

imageFileName = fullfile(toolboxdir('driving'), 'drivingdata', 'checkerboard.png');
I = imread(imageFileName);
imshow(I)
title('Distorted Checkerboard Image');

Figure contains an axes object. The axes object with title Distorted Checkerboard Image contains an object of type image.

[imagePoints, boardSize] = detectCheckerboardPoints(I);
 
% Generate coordinates of the corners of the squares.
squareSize = 0.029; % Square size in meters
worldPoints = generateCheckerboardPoints(boardSize, squareSize);
 
% Estimate the parameters for configuring the monoCamera object. 
% Height of the checkerboard is zero here, since the pattern is 
% directly on the ground.
originHeight = 0;
[pitch, yaw, roll, height] = estimateMonoCameraParameters(params.Intrinsics, ...
                               imagePoints, worldPoints, originHeight);
                           

歪み補正されたイメージ用の合成ピンホール カメラの構築

% Undistort the image and extract the synthetic pinhole camera intrinsics.
[J1, camIntrinsics] = undistortFisheyeImage(I, params.Intrinsics, 'Output', 'full');
imshow(J1)
title('Undistorted Image');

Figure contains an axes object. The axes object with title Undistorted Image contains an object of type image.

% Set up monoCamera with the synthetic pinhole camera intrinsics. 
% Note that the synthetic camera has removed the distortion.
sensor = monoCamera(camIntrinsics, height, 'pitch', pitch, 'yaw', yaw, 'roll', roll);

鳥瞰ビューのプロット

これで、鳥瞰ビューをプロットすることによってmonoCameraを検証できます。

% Define bird's-eye-view transformation parameters
distAheadOfSensor = 6; % in meters
spaceToOneSide = 2.5;  % look 2.5 meters to the right and 2.5 meters to the left
bottomOffset = 0.2;  % look 0.2 meters ahead of the sensor
outView = [bottomOffset, distAheadOfSensor, -spaceToOneSide, spaceToOneSide];
outImageSize = [NaN,1000]; % output image width in pixels

birdsEyeConfig = birdsEyeView(sensor, outView, outImageSize);

% Transform input image to bird's-eye-view image and display it
B = transformImage(birdsEyeConfig, J1);

% Place a 2-meter marker ahead of the sensor in bird's-eye view
imagePoint0 = vehicleToImage(birdsEyeConfig, [2, 0]);
offset = 5; % offset marker from text label by 5 pixels
annotatedB = insertMarker(B, imagePoint0 - offset);
annotatedB = insertText(annotatedB, imagePoint0, '2 meters');

figure
imshow(annotatedB)
title('Bird''s-Eye View')

Figure contains an axes object. The axes object with title Bird's-Eye View contains an object of type image.

上記のプロットは、カメラが距離を正確に測定することを示しています。これで、単眼カメラを使用してオブジェクトおよび車線境界線を検出できます。Visual Perception Using Monocular Cameraの例を参照してください。

参考

アプリ

関数

オブジェクト

関連するトピック