图像的校准以获得位于同一平面上的点的顶视图 [英] Calibration of images to obtain a top-view for points that lie on a same plane

查看:878
本文介绍了图像的校准以获得位于同一平面上的点的顶视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

校准



我已在Matlab中使用此视觉工具箱校准了相机。我使用棋盘图像这样做。校准后我得到cameraParams
其中包含:

 相机Extrinsics 
RotationMatrices:[3x3x18 double]
TranslationVectors:[18x3 double]


$ b b

  Camera Intrinsics 
IntrinsicMatrix:[3x3 double]
FocalLength:[1.0446e + 03 1.0428e + 03]
PrincipalPoint:[604.1474 359.7477 ]
Skew:3.5436

目标:
我使用这台摄像机记录了一些运动物体的轨迹。每个对象对应于帧中的单个点。现在,我想投影点,使我得到一个顶视图。


  1. 请注意,我想转换的所有这些点都在同一个平面上。



    例如:[xcor_i,ycor_i]

      -101.7000 -77.4040 
    -102.4200 -77.4040


  2. KEYPOINT :此平面垂直于用于校准的棋盘图像之一。对于那个图像(下面),我知道从地面(193.040厘米)的棋盘的原点的高度。

,并通过@Dima下面的答案):

  function generate_homographic_matrix()
%%校准摄像机
%定义要处理的图像
path = ['。'filesep'Images'filesep];
list_imgs = dir([path'* .jpg']);
list_imgs_path = strcat(path,{list_imgs.name});

%检测图像中的棋盘图像
[imagePoints,boardSize,imagesUsed] = detectCheckerboardPoints(list_imgs_path);
imageFileNames = list_imgs_path(ImagesUsed);

%生成正方形角的世界坐标
squareSize = 27; %以'mm'为单位
worldPoints = generateCheckerboardPoints(boardSize,squareSize);

%校准摄像机
[cameraParams,imagesUsed,estimateErrors] = estimateCameraParameters(imagePoints,worldPoints,...
'EstimateSkew',true,'EstimateTangentialDistortion',true,。 ..
'NumRadialDistortionCoefficients',3,'WorldUnits','mm');
%%计算垂直平面到棋盘的单应性
%检测棋盘
im = imread(['。'filesep'Images'filesep'exp_19.jpg']); %exp_19.jpg是与地板正交的棋盘
[imagePoints,boardSize] = detectCheckerboardPoints(im);

%计算摄像机的旋转和平移。
[Rc,Tc] = extrinsics(imagePoints,worldPoints,cameraParams);

%Rc(校准视图旋转相机)= [xyz])
%那么地板具有旋转Rf = [zx -y](地板的法线向量
Rf = [Rc(:,3),Rc(:,1),Rc(:,2)* - 1]

%翻译到地板
H = 452;%距离btw原点和楼层
Fc = Rc * [0; H; 0];
Tc = Tc + Fc';

%将旋转和平移合并为一个矩阵:
Rf(3,:) = Tc;

%计算棋盘和图像平面之间的单应性:
H = Rf * cameraParams.IntrinsicMatrix;

save('homographic_matrix.mat','H')
end


$ b b




  %%转换点
函数[x_transf,y_transf] = transform_points(xcor_i,ycor_i)
%创建一个projective2D对象,然后将点向前转换为
%get a top-view
%xcor_i和ycor_i是包含轨迹的x坐标和
%y坐标的1d向量。
data = load('homographic_matrix.mat');
homo_matrix = data.H;
tform = projective2d(inv(homo_matrix));
[x_transf,y_transf] = transformPointsForward(tform,xcor_i,ycor_i);
end






引用OReilly Learning OpenCV Pg 412:
一旦我们设置了单应性矩阵和高度参数设置,我们可以
然后删除棋盘和驱动车,使鸟瞰视频$ b $

解决方案

Abhishek,



我不完全明白你在做什么。



如果是这样,那么你需要知道外星人,R和t ,描述该平面和相机之间的关系。获得R和t的一种方法是在飞机上放置棋盘,然后使用 extrinsics 函数。



之后,您可以按照你引用的问题来获得单应性。一旦你有了单应性,你可以创建一个 projective2D 对象,并使用 transformPointsForward 方法来转换你的点。 / p>

Calibration:

I have calibrated the camera using this vision toolbox in Matlab. I used checkerboard images to do so. After calibration I get the cameraParams which contains:

Camera Extrinsics
RotationMatrices: [3x3x18 double]
TranslationVectors: [18x3 double]

and

 Camera Intrinsics
 IntrinsicMatrix: [3x3 double]
 FocalLength: [1.0446e+03 1.0428e+03]
 PrincipalPoint: [604.1474 359.7477]
 Skew: 3.5436

Aim: I have recorded trajectories of some objects in motion using this camera. Each object corresponds to a single point in a frame. Now, I want to project the points such that I get a top-view.

  1. Note all these points I wish to transform are are the on the same plane.

    ex: [xcor_i,ycor_i ]

    -101.7000  -77.4040
    -102.4200  -77.4040
    

  2. KEYPOINT: This plane is perpendicular to one of images of checkerboard used for calibration. For that image(below), I know the height of origin of the checkerboard of from ground(193.040 cm). And the plane to project the points on is parallel to the ground and perpendicular to this image.

Code (Ref:http://stackoverflow.com/a/27260492/3646408 and answer by @Dima below):

function generate_homographic_matrix()
%% Calibrate camera
% Define images to process
path=['.' filesep 'Images' filesep];
list_imgs=dir([path '*.jpg']);
list_imgs_path=strcat(path,{list_imgs.name});

% Detect checkerboards in images
[imagePoints, boardSize, imagesUsed] = detectCheckerboardPoints(list_imgs_path);
imageFileNames = list_imgs_path(imagesUsed);

% Generate world coordinates of the corners of the squares
squareSize = 27;  % in units of 'mm'
worldPoints = generateCheckerboardPoints(boardSize, squareSize);

% Calibrate the camera
[cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ...
    'EstimateSkew', true, 'EstimateTangentialDistortion', true, ...
    'NumRadialDistortionCoefficients', 3, 'WorldUnits', 'mm');
%% Compute homography for peripendicular plane to checkerboard
% Detect the checkerboard 
im=imread(['.' filesep 'Images' filesep 'exp_19.jpg']); %exp_19.jpg is the checkerboard orthogonal to the floor
[imagePoints, boardSize] = detectCheckerboardPoints(im);

% Compute rotation and translation of the camera.
[Rc, Tc] = extrinsics(imagePoints, worldPoints, cameraParams);

% Rc(rotation of the calibration view w.r.t the camera) = [x y z])
%then the floor has rotation Rf = [z x -y].(Normal vector of the floor goes up.)
Rf=[Rc(:,3),Rc(:,1),Rc(:,2)*-1];

% Translate it to the floor
H=452;%distance btw origin and floor
Fc = Rc * [0; H; 0];
Tc = Tc + Fc';

% Combine rotation and translation into one matrix:
Rf(3, :) = Tc;

% Compute the homography between the checkerboard and the image plane:
H = Rf * cameraParams.IntrinsicMatrix;

save('homographic_matrix.mat','H')
end


%% Transform points
function [x_transf,y_transf] =transform_points(xcor_i,ycor_i)
% creates a projective2D object and then transforms the points forward to
% get a top-view
% xcor_i and ycor_i are 1d vectors comprising of the x-coordinates and
% y-coordinates of trajectories. 
data=load('homographic_matrix.mat');
homo_matrix=data.H;
tform=projective2d(inv(homo_matrix));
[x_transf,y_transf] = transformPointsForward(tform,xcor_i,ycor_i);
end


Quoting text from OReilly Learning OpenCV Pg 412: "Once we have the homography matrix and the height parameter set as we wish, we could then remove the chessboard and drive the cart around, making a bird’s-eye view video of the path..." This what I essentially wish to achieve.

解决方案

Abhishek,

I don't entirely understand what you are trying to do. Are your points on a plane, and are you trying to create a bird's eye view of that plane?

If so, then you need to know the extrinsics, R and t, describing the relationship between that plane and the camera. One way to get R and t is to place a checkerboard on the plane, and then use the extrinsics function.

After that, you can follow the directions in the question you cited to get the homography. Once you have the homography, you can create a projective2D object, and use its transformPointsForward method to transform your points.

这篇关于图像的校准以获得位于同一平面上的点的顶视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆