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!