The function "estimateW​orldCamera​Pose"retur​ns null values for rotation matrix and the translateur vector

1 view (last 30 days)
Good morning,
I need to use the function "estimateWorldCameraPose" to calculate the rotation matrix and the translation vector.
I am using a picture where the object is a circle.
With a function I designed based on a tutorial, I got the coordinates in 2D of the center of the circle.
I also have the 3D coordinates of the center measured by other software.
My problem is that I have Null values for the rotation matrix and the translation vector and I cannot figure out.
Can you help me please?
Thanks for your help.
The picture used is that one:
The function I used is that one:
function [markers, diameter] = Find_the_center_circle(fullImages)
%% Definition of plotting variables
captionFontSize = 14;
%% Convertion to gray scale
GrayImage = rgb2gray(fullImages);
%% Identification of each blob which are constituted the picture
% Identify individual blobs by seeing which pixels are connected to each other.
% Each group of connected pixels will be given a label, a number, to identify it and distinguish it from the other blobs.
% Do connected components labeling with either bwlabel() or bwconncomp().
% Label each blob so we can make measurements of it.
labeledImage = bwlabel(GrayImage, 8);
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
blobMeasurements = regionprops(labeledImage, GrayImage, 'all');
numberOfBlobs = size(blobMeasurements, 1);
%% Plot the the circle's imprint
imshow(GrayImage);
title('Outlines, from bwboundaries()', 'FontSize', captionFontSize);
% Make sure image is not artificially stretched because of screen's aspect ratio.
axis image;
hold on;
boundaries = bwboundaries(GrayImage);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;
%% Deterination of the centre abd tge size of each circle
% We can get the centroids of ALL the blobs into 2 arrays,
% one for the centroid x values and one for the centroid y values.
allBlobCentroids = [blobMeasurements.Centroid];
centroidsX = allBlobCentroids(1:2:end-1);
centroidsY = allBlobCentroids(2:2:end);
hold on;
% Loop through all blobs.
for k = 1 : numberOfBlobs
plot(centroidsX(k), centroidsY(k), 'bx', 'MarkerSize', 10, 'LineWidth', 2);
end
%% Outputs of the function
markers = [centroidsX, centroidsY];
diameter = blobMeasurements.Perimeter;
end
The following code is what I used:
%Definition of loop counters
% Ncams = length(imRects);
nCams = 1;
Npicture = 1;
%Definition parameters for estimateWorldCameraPose
confidence = 99.9; %Confidence parameter for 'Confidence'
max_error_repro = 1.5; %Reprojecction error for 'MaxReprojectionError'
%Focal length in meters (given by the datasheet of the camera)
Focal_length = 3.04e-3;
%Blender resolution
res_x = 1920;
res_y = 1800;
markerLocations = 1.0e+03 *[0.13689/(pi*2), 2.2718/(pi*2), 0.011503];
%Definition structures
gantryCalib.R = cell(1, nCams);
gantryCalib.T = cell(1, nCams);
markerCamLocalisation = cell(1, nCams);
goodMeasure = cell(1, nCams);
triPositions = cell(1, nCams);
camCsTot = cell(1, nCams);
usedPicture = cell(1, nCams);
%Definition tables
Rs = zeros(3, 3, Npicture);
Ts = zeros(Npicture, 3);
markerLocationsCalculate = zeros(length(markerLocations), 2, Npicture);
measure = false(Npicture, 1);
goodPicture = zeros(Npicture, 1);
camCs(1: Npicture) = CoOrdinateSystem_R_T;
%% Generation intrinsic parameters
%Determination of the size of the picture
fPicture = ['Cam', int2str(1), '_', sprintf('%0.4d', 1)];
imSize = size(CropImage);
%Calculation of the intrinsic matrix K = [f_x, s, o_x; 0, f_y, o_y; 0, 0, 1]
piCam.F = Focal_length; % focal length in meters
piCam.r = [res_x, res_y]; % origional resolution
piCam.p = 1.4e-6 * piCam.r(1)/imSize(1); % pixel size in meters, scaled for the cropped image resolution
piCam.s = 1 /piCam.p; % pixels per metre
piCam.f = piCam.F * piCam.s; % focal length in pixels
piCam.c = imSize([2,1])/2; % principal point in pixels
piCam.I = [piCam.f, 0,0; 0 piCam.f,0;piCam.c,1];
piCam.camParam = cameraParameters('IntrinsicMatrix', piCam.I);
%% Calibration
for i = 1:nCams
camName = ['Camera', int2str(i),'_*.png'];
FlistFull = dir(fullfile(FullFolder, camName));
FlistFull.name;
for j = 1:Npicture
%Load picture
FullImage = imread(fullfile(FullFolder, FlistFull(j).name));
%Detection markers
if(100 < length(CropImage))
[markers, diameter] = Find_the_center_circle(FullImage);
% %Verification place of the markers
f = figure;
imshow(FullImage);
hold on;
plotDots(markers1, 200, 'b', '.');
hold off;
%
else
markers = 0;
fprintf('Error in image %d, camera %d, incorrect number of markets \n', j, i);
end
[s, add] = size(markers);
if(s == 1)
%Calibration
[r, t, inliers, status] = estimateWorldCameraPose(markers, markerLocations, piCam.camParam, ...
'Confidence', confidence, ...
'MaxReprojectionError', max_error_repro);
end
end
end
  5 Comments
Claire Pottier
Claire Pottier on 27 Nov 2020
Hi Matt,
I forgot to give you one function, all my apologies.
Unfortunately, you need to have the whole script to run it.
Here is the script of the missing function:
classdef CoOrdinateSystem_R_T
% The CoOrdinateSystem class is used to store the Origin and xyz unit
% vectors for a co-ordinate system.
%
% obj = CoOrdinateSystem()
% create default co-ordinate system
%
% obj = CoOrdinateSystem(C)
% create unrotated cs with origin at C
%
% obj = CoOrdinateSystem(C,R)
% create rotated cs with unit vectors as the columns of R and
% centered at C
%
% Methods
% R = getRotationMatrix(obj)
% get the columwise rotation matrix from the cs object
properties
O = [0 0 0]; % [ Origin ]
i = [1 0 0]; % [ x axis vector ]
j = [0 1 0]; % [ y axis vector ]
k = [0 0 1]; % [ Z axis vector ]
end
methods
function obj = CoOrdinateSystem_R_T(varargin)
% obj = CoOrdinateSystem()
% create default co-ordinate system
%
% obj = CoOrdinateSystem(C)
% create unrotated cs with origin at C
%
% obj = CoOrdinateSystem(C,R)
% create rotated cs with unit vectors as the columns of R and
% centered at C
switch nargin
case 1
obj.O = varargin{1};
case 2
obj.O = varargin{1};
obj.i = varargin{2}(:,1)';
obj.j = varargin{2}(:,2)';
obj.k = varargin{2}(:,3)';
end
end
function R = getRotationMatrix(obj)
R = [obj.i' , obj.j', obj.k'];
end
end
end
Claire Pottier
Claire Pottier on 1 Dec 2020
Hey everybody
Sorry for my persistence, but do you know where the problem is in my script?
Thank you for your answers

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!