how to get object distance from camera android?
How can i calculate the distance of object from camera in autofocus mode? I have tried using the Camera.Parameters.getFocusDistances(float[]) method, but it always returns the values .15, 1.2, and Infinity on my Galaxy S2. Any help will be appreciated. Here is the code i am using:-
..........
cam=Camera.open();
Camera.Parameters pa=cam.getParameters();
pa.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
cam.setParameters(pa);
cam.startPreview();
cam.autoFocus(this);
..........
@Override
public void onAutoFocus(boolean arg0, Camera arg1) {
// TODO Auto-generated method stub
float f[]=new float[3];
arg1.getParameters().getFocusDistances(f);
text.setText(""+f[1]); //Always returns 1.2
t开发者_运维问答2.setText(""+f[0]); //Always returns .15
t3.setText(""+f[2]); //Always returns Infinity
}
Is there any other way to accomplish this?
Nope :( Check out this other stackoverflow answer. "Nope. The camera can only give you image data and an image alone doesn't give you enough information to give you depth information. If you had multiple images that you had location information for or even video you could then process it to triangulate the distance, but a single image alone would not be enough to give you a distance"
Maybe there is a solution by using the formula 1/f=1/v+1/u, in which f is the focal length, v is the distance of CCD/CMOS from the lens, u is the distance of object from camera. The problem is, can we get the value of v ?
精彩评论