robotics专项课程Perception Assignment 1:Dolly Zoom(滑动变焦)




function [ f ] = compute_focal_length( d_ref, f_ref, pos )
%% Compute camera focal length with given camera position. 
%
% In this function, multiple camera positions will be given. The camera is
% placed on z axis and thus only z axis for the camera position is given.
% We'll need to compute corresponding focal length to achieve Dolly Zoom
% effect for each camera position.
%
% Input:
% - d_ref: 1 by 1 double, distance of the object whose size remains constant
% - f_ref: 1 by 1 double, previous camera focal length
% - pos: 1 by n, each element represents camera center position on the z axis.
% Output:
% - f: 1 by n, camera focal length, each element corresponds to an element
% in pos, i.e., f(i) is the focal length for Dolly Zoom effect when the camera is placed at pos(i)

n = length(pos);
f = zeros(n);
for i = 1:n
f = f_ref*(d_ref - pos(n))/d_ref;
end
end

function [ f, pos ] = compute_f_pos( d1_ref, d2_ref, H1, H2, ratio, f_ref )
%% Compute camera focal length and camera position to achieve centain ratio between objects
%
% In this function, we focus on two objects: object A with height H1 and
% d1_ref as distance to camera in 3D world, object B with height H2 and
% d2_ref as distance to camera in 3D world.
% We will keep the size of object A in image the same as before while
% adjusting the size of object B in image.
%
% Input:
% - d1_ref: distance of the first object
% - d2_ref: distance of the second object
% - H1: height of the first object in physical world
% - H2: height of the second object in physical world
% - ratio: ratio between two objects in image coordinate (h1/h2)
% - f_ref: 1 by 1 double, previous camera focal length
% Output:
% - f: 1 by 1, camera focal length
% - pos: 1 by 1, camera position on z axis

temp = f_ref * H1 / d1_ref ;
pos = (d1_ref * H2 * ratio - d2_ref * H1)/(H2 * ratio - H1);
f = temp *(d1_ref - pos) / H1;
end

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

robotics专项课程Perception Assignment 1:Dolly Zoom(滑动变焦)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭