このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
単眼魚眼カメラの設定
この例は、魚眼カメラ モデルをピンホール モデルに変換し、対応する単眼カメラ センサー シミュレーションを構築する方法を示しています。この例では、魚眼カメラをキャリブレーションし、monoCamera
(Automated Driving Toolbox)オブジェクトを設定する方法を学びます。
概要
車両に取り付けられた単眼カメラ センサーをシミュレートするには、次の手順に従います。
チェッカーボードを使用してカメラをキャリブレーションすることにより、内部カメラ パラメーターを推定します。内部パラメーターは、魚眼カメラ自体のプロパティを表します。
前の手順と同じチェッカーボードを使用して、カメラを再度キャリブレーションすることにより、外部カメラ パラメーターを推定します。外部パラメーターは、車両座標系での魚眼カメラの取り付け位置を表します。
魚眼カメラの内部パラメーターをピンホール カメラの内部パラメーターに変換することにより、イメージの歪みを取り除きます。これらの内部パラメーターは、歪み補正されたイメージを仮想的に生成できる合成ピンホール カメラを表しています。
ピンホール カメラの内部パラメーターと外部パラメーターを使用して、シミュレーション用の単眼カメラ センサーを設定します。その後、このセンサーを使用して、オブジェクトと車線境界線を検出できます。
魚眼カメラの内部パラメーターの推定
内部パラメーターを推定するには、カメラのキャリブレーションにチェッカーボードを使用します。あるいは、結果を詳細に可視化するために、カメラ キャリブレーターアプリを使用します。魚眼カメラの場合、イメージの大きく目立つ歪みを取得するために、チェッカーボードをカメラの近くに配置すると便利です。
% 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');
[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');
% 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
(Automated Driving Toolbox)を検証できます。
% 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')
上のプロットは、カメラが距離を正確に測定していることを示しています。これで、単眼カメラを使用してオブジェクトと車線境界線を検出できます。Visual Perception Using Monocular Camera (Automated Driving Toolbox)の例を参照してください。