3

I need to get the camera's horizontal and vertical viewing angles for an app I am writing. I used the approach in the second (not the accepted) answer on this question, which was working fine. I do:

Camera.Parameters p = Camera.open().getParameters();

and can then call

Math.toRadians(p.getVerticalViewAngle());

or the equivalent horizontal method to get the viewing angles.

This worked on my Nexus 4 and on a Samsung tablet, but I decided to try the app on my Nexus 7 and both the horizontal and vertical angles are being returned as pi. Obviously this is a ridiculous value for these attributes. Any idea why I am getting these values for this device?

Also, on a perhaps related note, android.hardware.Camera has been deprecated and replaced by android.hardware.Camera2. I have been unable to find a way of achieving the same goal with Camera2 though, but would welcome any suggestions on how to do this.

Community
  • 1
  • 1
rbennett485
  • 1,907
  • 15
  • 24

1 Answers1

2

The p.getVerticalViewAngle() is probably returning the maximum value for any possible camera.

The answer of pi implies that it has 360° of vision which is improbably but possible and would be the theoretical maximum that a camera could take.

Therefore I would recommend trying to open using the ID:

Camera.Parameters p = Camera.open(/**cameraNumber**/).getParameters();

and checking that the cameraDevice isn't null.

As to the other question, there isn't any way using the camera2 api to get the vertical and horizontal viewing angles, but using the original camera API it does work (at least it's worked for me)

Cjen1
  • 1,826
  • 3
  • 17
  • 47
  • I'm afraid this is wrong and wrong - the Nexus 4 has two cameras also, and `open()` with no arguments opens the first back facing camera on the device, not the only camera (see [docs](http://developer.android.com/reference/android/hardware/Camera.html#open())) – rbennett485 Aug 10 '15 at 14:44