turn image coordinates into world coordinates??

9 ビュー (過去 30 日間)
yoram ifraimov
yoram ifraimov 2022 年 5 月 18 日
回答済み: Sai Pavan 2023 年 11 月 29 日
I have a problem and I do not understand how to turn image coordinates into world coordinates. I would really love to help.
Thanks .
this is my code...
% Initialization steps.
clc;
clearvars;
close all;
workspace;
fontSize = 16;
objects = imaqfind; %find video input objects in memory % מחפש את כל קלטי הוידאו שבזכרון
delete(objects) %delete a video input object from memory %מאפס את כל קלטי הוידאו
load('cameraParams1.mat')% נתונים מהקליברציה
focalLength = [cameraParams.FocalLength(1), cameraParams.FocalLength(2)]; % [fx, fy] in pixel units
principalPoint = [cameraParams.PrincipalPoint(1), cameraParams.PrincipalPoint(2)]; % [cx, cy] optical center in pixel coordinates
imageSize = cameraParams.ImageSize; % [nrows, mcols] 480x640
camIntrinsics = cameraIntrinsics(focalLength, principalPoint, imageSize); %מאחסן את הפרמטרים של המצלמה
videoName = 'test3.mp4';
videoReader = VideoReader(videoName);
timeStamp = 0.06667; % time from the beginning of the video
videoReader.CurrentTime = timeStamp; % point to the chosen frame
frame = readFrame(videoReader); % read frame at timeStamp seconds
imshow(frame) % display frame
% fullFileName = 'https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/988570/road.png';
grayImage = rgb2gray(frame);
figure
imshow(grayImage)
grayImage(grayImage<170)=0;
figure
imshow(grayImage, []);
%impixelinfo;
mask = logical(grayImage > 140 & grayImage < 255);
mask = bwareafilt(mask, 2);
mask = bwskel(mask);
mask2 = imopen(mask, strel('line', 3, 0));
mask(mask2) = 0;
mask = logical(mask);
figure
imshow(mask);
% make center line
[r,c] = find(mask);
rs = sort(unique(r));
cens = [];
for i = 1 : length(rs)
mi = mask(rs(i),:);
[~,ci] = find(mi);
if max(ci) - min(ci) < 1e1
continue;
end
cens = [cens; mean([max(ci) min(ci)]) rs(i)];
end
% make line
p = polyfit(cens(:,2), cens(:,1), 2);
yt = linspace(min(rs), max(rs), 1e3);
xt = polyval(p, yt);
hold on; plot(xt, yt, 'g-', 'LineWidth',3)
figure; imshow(frame);
hold on; plot(xt, yt, 'g-', 'LineWidth',3)
image3D = cat(3, slice1, slice2, slice3, slice4, slice5);
for slice = 1 : totalNumberOfSlices
thisSlice = GetSlice(mask); % Whatever you have to do to get one 2D image.
if slice == 1
image3D = thisSlice;
else
image3D = cat(3, image3D, thisSlice);
end
end

回答 (1 件)

Sai Pavan
Sai Pavan 2023 年 11 月 29 日
Hi Yoram,
I understand that you want to convert the image coordinates into world coordinates. The 'img2world2d' function can help you with the conversion as the translation and rotation variables are available in the 'PatternExtrinsics' variable of 'cameraParams1.mat' file as rigidtform3d objects. The 'Instrinsics' variable in the 'cameraParams1.mat' can be used along with the rigid transformations to make this conversion as shown in the code snippet shown below:
worldPoints = img2world2d(imagePoints,tform,intrinsics)
Please refer to the below documentation to learn more about 'img2world2d' function: https://www.mathworks.com/help/vision/ref/img2world2d.html
Hope it helps.
Regards,
Sai Pavan

Community Treasure Hunt

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

Start Hunting!

Translated by