How to calculate the focal length from an image
显示 更早的评论
How do I get the focal length of an image taken using MATLAB (getsnapshot)
采纳的回答
更多回答(2 个)
Bjorn Gustavsson
2011-12-20
From an image you need to know the direction (phi,theta, or their proper position [x,y,z]) to a number of identifiable objects in your image. From there onwards it is just to get going!
With the camera at [0,0,0] for slight simplicity, this should be the function to minimize
function err = opt_cal(pars,imsiz,r_objs,im_pos)
err = 0;
rot1 = pars(1);
rot2 = pars(2);
rot3 = pars(3);
f = pars(4);
dudv = pars(5:6);
x = r_objs(:,1);
y = r_objs(:,2);
z = r_objs(:,3);
R = rotation_matrix(rot1,rot2,rot3);
for i1 = 1:length(z),
e_i = R*[x;y;z]/norm([x;y;z]);
theta_i = acos(e_i(3));
phi_i = atan2(e_i(2),e_i(1));
[u_par,v_par] = f*[cos(phi_i),sin(phi_i)]*tan(theta) + imsiz/2+dudv;
err = err + (u_obj-u_par)^2 + (v_obj-v_par)^2;
end
I think that should do it. Come to think about it: What have you done to solve your problem?
HTH
2 个评论
neenu jose
2012-1-5
Walter Roberson
2012-1-5
opt_cal is the function name that Bjorn gave to the code. A line that starts with "function" defines a new function.
Image Analyst
2011-12-20
0 个投票
I think you'd have to have some objects of known distance from the camera. Because you can get a scene that looks pretty much the same by being up close with a short focal length lens, or far away with a long focal length lens. But if you're looking at something with different distances they'd look different. Think of how an array of pegs would look with different focal lengths. But just a flat scene (say a picture on a wall) wouldn't look much different. I think you need to study up on your geometrical optics first and then come back here, maybe after trying in the sci.optics newsgroup.
类别
在 帮助中心 和 File Exchange 中查找有关 Image Preview and Device Configuration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!