Reputation: 49
currently I attached the TangoARScreen script to the Tango camera prefab in Unity, is it possible to retrieve the field of view value in Unity via C# script?
In addition, is it possible to use the front facing camera in Unity?
Upvotes: 0
Views: 717
Reputation: 56
It certainly is possible ddddddddaxing.
Get ready, here is what you need to do:
Let's take a look at retrieving intrinsic parameters from the C API for a general overview of the underpinning logic. The steps are:
TangoService_getCameraIntrinsics
function. Pass it the ID for the camera and the address of the struct.For example, to get the color camera intrinsics:
TangoCameraIntrinsics ccIntrinsics;
TangoService_getCameraIntrinsics(TANGO_CAMERA_COLOR, &ccIntrinsics);
The function populates the struct with intrinsic information.
For C# specifically to use in Unity this should look something like this:
GetIntrinsics
method of the Tango.VideoOverlayProvider
class.The method populates the struct with intrinsic information.
Now you can look at using the Intrinsics to calculate FOV from the Focal length.
All the parameters you need to calculate FOV can be retrieved from the API.
/// Parameter /// Description
/// width /// The width of the image on the image sensor in pixels.
/// height /// The height of the image on the image sensor in pixels.
/// fx /// Focal length, x axis, in pixels.
/// fy /// Focal length, y axis, in pixels.
Note that in most systems, fx = fy.
For Example, lets look at this in C:
TangoCameraIntrinsics ccIntrinsics;
TangoService_getCameraIntrinsics(TANGO_CAMERA_COLOR, &ccIntrinsics);
When you examine the ccIntrinsics
struct, you should something like the following data:
ccIntrinsics.height=720;
ccIntrinsics.fy=1042.0;
Therefore:
Vertical FOV = 2*atan(0.5*720.0/1042.0) = 2*19.0549 deg = 38.1098 deg
The equations for the horizontal and vertical fields of view are:
/// Horizontal FOV = 2 * atan(0.5 * width / Fx)
/// Vertical FOV = 2 * atan(0.5 * height / Fy)
If your rendering engine only supports one FOV value, refer to its documentation to know which FOV to use. If you require the diagonal field of view, the equation is:
/// Diagonal FOV = 2 * arctan(sqrt((width/2Fx)^2 + (height/2Fy)^2))
The lenses in cameras are not perfect and add some amount of distortion. For most use cases the effect is small enough to ignore; however, when a Tango device is calibrated, it examines and stores distortion information and these values are available in the TangoCameraIntrinsics
struct (C and Unity).
If you are using the motion tracking camera (sometimes called the "fisheye" lens), then the "FOV" distortion model is used and the TangoCameraIntrinsics
struct/object will contain the calibration type TANGO_CALIBRATION_EQUIDISTANT
.
If you are using the color camera, then the polynomial distortion model is used and the TangoCameraIntrinsics
struct/object will contain the calibration type TANGO_CALIBRATION_POLYNOMIAL_3_PARAMETERS
.
For some further depth, have a look at the VideoOverlayProvider.cs Script on Git here
SECOND QUESTION-
Accessing the front camera will require you to discard the Tango functionality and disconnect from the TangoCore
service. You can re-enable this mid application by forcing the TangoUx
package and relocalizing, however you will have lost motion tracking and unless your application is using area learning, this might disorient the end user.
If I recall correctly, you can select this via a dropdown list in the Inspector on the TangoMultiCamera
Prefab.
Upvotes: 1