cpet-563-01l3-coursework/lab2/lab2.m

22 lines
737 B
Matlab

baseline = 60; %Distance between the cameras in millimeters
focalLength = 6; %Focal length is measured in millimeters
pixelSize = 0.006; %Pixel size is measured in millimeters per pixel
%Define object of interest's centroid's offset from center of frame
xLeftOffset = 15;
yLeftOffset = 4;
xRightOffset = -5;
yRightOffset = 6;
%Disparity: difference (in millimeters) in position in the 2 camera's frames
disparity = (abs(xLeftOffset - xRightOffset)*pixelSize);
%Z= depth coordinate (in millimeters) of the centroid of the object of interest
Z=(baseline*focalLength)/disparity;
%X and Y coordinates (in millimeters) can then be found
X= (Z * xLeftOffset * pixelSize) / focalLength;
Y= (Z * yLeftOffset * pixelSize) / focalLength;