How to calculate the focal length from an image

조회 수: 17 (최근 30일)
neenu jose
neenu jose 2011년 12월 20일
How do I get the focal length of an image taken using MATLAB (getsnapshot)

채택된 답변

neenu jose
neenu jose 2012년 1월 10일
if the camera is of fixed focal length,using the camera caliberation toolbox,we can find the focal length as well as the extrinsic parameters.for that,use a chekerboard,take different photos of it at different angles and store them with a common basename..eg:image1, image2 etc..and add this folder to the current directory of matlab.then use the caliberation tool box.
but i dont know the case if the camera is autofocus..

추가 답변 (2개)

Bjorn Gustavsson
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
neenu jose 2012년 1월 5일
wot is tis opt cal
Walter Roberson
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
Image Analyst 2011년 12월 20일
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by