after i look at undistortFisheyPoints internal implementation and expermient, it turns out the following implementation.
function [undistortedPoints,camIntrinsics] = undistortFisheyePointsFcn(points,...
fisheyeIntrinsicsP,scaleFactor)
% Brief: Removal of image distortion points from the principle by Scaramuzza fisheye camera model
% Details:
% None
%
% Syntax:
% [undistortedPoints,camIntrinsics] = undistortFisheyePointsFcn(points,fisheyeIntrinsicsP,scaleFactor)
%
% Inputs:
% points - [m,n] size,[double] type,Description
% fisheyeIntrinsicsP - [m,n] size,[double] type,Description
% scaleFactor - [m,n] size,[double] type,Description
%
% Outputs:
% undistortedPoints - [m,n] size,[double] type,Description
% camIntrinsics - [m,n] size,[double] type,Description
%
% Example:
% None
%
% See also: None
% Author: cuixingxing
% Email: cuixingxing150@gmail.com
% Created: 03-Aug-2022 08:41:36
% Version history revision notes:
% None
% Implementation In Matlab R2022a
%
arguments
points (:,2) % distort fisheye image points
fisheyeIntrinsicsP (1,1) fisheyeIntrinsics
scaleFactor (1,2) double = [1,1]
end
% Scaramuzza fisheye model
uv = fisheyeIntrinsicsP.StretchMatrix\(points-fisheyeIntrinsicsP.DistortionCenter)';% Fisheye Camera Model, camera model proposed by Scaramuzza
rho = vecnorm(uv,2,1);
D = fisheyeIntrinsicsP.MappingCoefficients;
Zc = D(1)+D(2)*rho.^2+D(3)*rho.^3+D(4)*rho.^4;
Xc = uv(1,:);Yc = uv(2,:);
worldPoints = [Xc;Yc;Zc];
nw = vecnorm(worldPoints,2,1); % lambda
nw(nw == 0) = eps;
uvz = worldPoints ./ [nw;nw;nw];
uvNormal = uvz./uvz(3,:);
% Default to the middle of the original image, which is the same as for
% undistortFisheyeImage. That way, they'll match at least for the 'same'
% output view. It's a more intuitive result.
imageSize = fisheyeIntrinsicsP.ImageSize;
principalPoint = imageSize([2 1]) / 2 + 0.5 ;
f = min(imageSize) / 2;
focalLength = f .* scaleFactor(:)';
camIntrinsics = cameraIntrinsics(focalLength, principalPoint, imageSize);
% camera coordinates to image pixel coordinates
undistortedPoints = camIntrinsics.IntrinsicMatrix'*uvNormal;
undistortedPoints = undistortedPoints(1:2,:)';
end