focalLength = [309.4362 344.2161];
principalPoint = [318.9034 257.5352];
camIntrinsics = cameraIntrinsics(focalLength,principalPoint,imageSize);
sensor = monoCamera(camIntrinsics,height,'Pitch',pitch);
outView = [bottomOffset,distAhead,-spaceToOneSide,spaceToOneSide];
outImageSize = [NaN,250];
birdsEye = birdsEyeView(sensor,outView,outImageSize);
BEV = transformImage(birdsEye,I);
worldPts = [outView(1),outView(4);
xLims = outView(2)-outView(1);
yLims = outView(4)-outView(3);
outImageSize = [xLims/yLims*targetImgWidth,targetImgWidth];
monoImgPts = vehicleToImage(birdsEye.Sensor,worldPts);
I = insertMarker(I,monoImgPts);
I = insertText(I,monoImgPts,1:4);
src = insertShape(I,"FilledPolygon",monoImgPts,Opacity=0.3);
tform = fitgeotrans(monoImgPts,fixedPts,"projective");
dstImg = imwarp(src,tform);
title("method1: use imwarp")
[bdsX,bdsY] = meshgrid(1:w,1:h);
[u,v] = transformPointsInverse(tform,bdsX(:),bdsY(:));
mapX = reshape(u,size(bdsX));
mapY = reshape(v,size(bdsY));
birdsEyeImgR = interp2(src(:,:,1),mapX,mapY,"linear",0);
birdsEyeImgG = interp2(src(:,:,2),mapX,mapY,"linear",0);
birdsEyeImgB = interp2(src(:,:,3),mapX,mapY,"linear",0);
birdsEyeImg = cat(3,birdsEyeImgR,birdsEyeImgG,birdsEyeImgB);
figure; imshow(birdsEyeImg)
title("method2: interpolation")
BEV = transformImage(birdsEye,src);
title("method3: use transformImage")