exponenta event banner

Настройка монокулярной камеры Fisheye

В этом примере показано, как преобразовать модель камеры рыбьего глаза в модель микроотверстия и построить соответствующее моделирование датчика монокулярной камеры. В этом примере показано, как откалибровать камеру рыбьего глаза и настроить monoCamera объект.

Обзор

Для имитации датчика монокулярной камеры, установленного в транспортном средстве, выполните следующие действия:

  1. Оцените собственные параметры камеры, откалибровав камеру с помощью шашки. Внутренние параметры описывают свойства самой камеры рыбьего глаза.

  2. Оцените параметры внешней камеры, снова откалибровав камеру с помощью той же шахматной доски, что и на предыдущем шаге. Внешние параметры описывают положение установки камеры «рыбий глаз» в системе координат транспортного средства.

  3. Устраните искажение изображения путем преобразования свойств камеры «рыбий глаз» в свойства камеры «микроотверстие». Эти характеристики описывают синтетическую микроотверстную камеру, которая может гипотетически генерировать неискаженные изображения.

  4. Для настройки датчика монокулярной камеры для моделирования используются параметры внутренней камеры и внешние параметры. Затем этот датчик можно использовать для обнаружения объектов и границ полос движения.

Оценка параметров камеры Fisheye

Для оценки собственных параметров используйте шашку для калибровки камеры. В качестве альтернативы, чтобы лучше визуализировать результаты, используйте приложение Camera Calibrator. Для камеры «рыбий глаз» полезно разместить шашку рядом с камерой, чтобы зафиксировать большое заметное искажение изображения.

 % 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);

Оценить внешний вид камеры Fisheye

Для оценки внешних параметров используйте ту же самую шашку для оценки положения камеры в системе координат транспортного средства. На следующем шаге производится оценка параметров по одному изображению. Для получения нескольких оценок и усреднения результатов можно также использовать несколько изображений на шахматной доске.

% 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. The axes 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. The axes 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. The axes with title Bird's-Eye View contains an object of type image.

На графике выше показано, что камера точно измеряет расстояния. Теперь можно использовать монокулярную камеру для обнаружения границ объектов и полос движения. См. пример «Визуальное восприятие с помощью монокулярной камеры».

См. также

Приложения

Функции

Объекты

Связанные темы