turn image coordinates into world coordinates??

조회 수: 19 (최근 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

카테고리

Help CenterFile Exchange에서 Point Cloud Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by