1

As this question has been asked already, i didnt get any clear idea in it. So i am asking this question again.I am struggling with it for two days. I want to calculate the distance between camera of my devices with that of the object that are infront of camera. I tried to use sensor managers as it was suggested in the following link but i am getting wrong results in it.

I have used two sensors accelerometer and magnetic field.

I calculate the distance based on orientation of the device as suggested in the above link.

onSensorChanged Callback in Sensor listener

@Override
    public void onSensorChanged(SensorEvent event) {

        if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
            gravity = event.values.clone();

        if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
            geoMagnetic = event.values.clone();

        if (gravity != null && geoMagnetic != null) {
            float R[] = new float[9];
            float I[] = new float[9];
            boolean success = SensorManager.getRotationMatrix(R, I, gravity,
                    geoMagnetic);
            if (success) {
                float orientation[] = new float[3];
                SensorManager.getOrientation(R, orientation);
                azimuth = 57.29578F * orientation[0];
                pitch = 57.29578F * orientation[1];
                roll = 57.29578F * orientation[2];

            }
        }


    }

Portrait:

double dist = Math.abs((float) (1.4f * Math.tan(roll * Math.PI / 180)));

Landscape:

double dist = Math.abs((float) (1.4f * Math.tan(pitch* Math.PI / 180)));

Please provide information about how to calculate the distance. Any ideas and suggestion are appreciable, Thanks in advance.

Community
  • 1
  • 1
Suresh
  • 11
  • 2
  • visit http://stackoverflow.com/questions/17738177/measuring-the-area-of-the-object-using-camera-and-known-distance-between-the-cam hope it will help u!! – Jitesh Upadhyay Apr 21 '14 at 10:05
  • @JiteshUpadhyay Thanks for your reply. Actually I need to calculate the distance between object and camera. I dont need to find the width and height of the object. – Suresh Apr 21 '14 at 10:07

0 Answers0