How To Get X And Y Of Camera Size In Unity
Working with the Camera
- Camera Focus Modes
- How To Obtain HD Camera Frames
- How To Access the Photographic camera Image in Unity
- How To Access the Camera Image in Native
- How To Use the Photographic camera Projection Matrix
- How To Access Camera Parameters
- How To Determine Camera Pose
- How To Determine Target Distance
Camera Focus Modes
Continuous Autofocus and Other Focus Modes
This article describes the different focus modes available in Vuforia Engine (since v1.v and above).
The behavior of the focus modes in Vuforia Engine (since v1.5) is described below:
Focus mode | Beliefs |
FOCUS_MODE_NORMAL | Sets the camera into the default mode as defined past the camera driver. |
FOCUS_MODE_TRIGGERAUTO | Triggers a single autofocus operation. |
FOCUS_MODE_CONTINUOUSAUTO | Lets yous plough on driver-level continuous autofocus for cameras. This mode is optimal for AR applications. This mode yields the all-time tracking results because it guarantees that the camera is focused on the target. (starts in Android 2.3 and iOS devices) |
FOCUS_MODE_INFINITY | Sets the camera to infinity, as provided by the photographic camera commuter implementation. (not supported on iOS) |
FOCUS_MODE_MACRO | Sets the camera to macro manner, as provided past the photographic camera driver implementation. This mode provides a abrupt camera image for distances of closeups (approximately 15 cm), rarely used in AR setups. (not supported on iOS) |
We encourage usingFOCUS_MODE_CONTINUOUSAUTO
in your applications whenever it is bachelor on the device. When setting this mode, if the return value of setFocusMode() is TRUE your awarding will provide precipitous camera images for both superior rendering, likewise equally for robust tracking performance.
If theFOCUS_MODE_CONTINUOUSAUTO
is not available, the side by side best option is to implement a 'bear on to focus' beliefs in your app. To do this,trigger setFocusMode()
withFOCUS_MODE_TRIGGERAUTO
value each time the user touches the screen. The disadvantage of this behavior is that most photographic camera drivers option a random direction to focus (most or far), so yous have a l% adventure that the image will defocus and and then focus on the target. Nether certain weather due this focus logic the tracking can be lost for a moment until a sharp image is provided over again by the camera.
FOCUS_MODE_INFINITY
andFOCUS_MODE_MACRO
are usable in certain awarding scenarios, as described to a higher place.
FOCUS_MODE_NORMAL
sets the photographic camera into the default fashion as defined by the photographic camera driver.
C++
bool focusModeSet = Vuforia::CameraDevice::getInstance().setFocusMode( Vuforia::CameraDevice::FOCUS_MODE_CONTINUOUSAUTO); if (!focusModeSet) { LOG("Failed to set focus mode (unsupported mode)."); }
Java
void Start () { var vuforia = VuforiaARController.Instance; vuforia.RegisterVuforiaStartedCallback(OnVuforiaStarted); vuforia.RegisterOnPauseCallback(OnPaused); } private void OnVuforiaStarted() { CameraDevice.Example.SetFocusMode( CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO); } private void OnPaused(bool paused) { if (!paused) // resumed { // Set over again autofocus mode when app is resumed CameraDevice.Instance.SetFocusMode( CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO); } }
Unity
bool focusModeSet = CameraDevice.Instance.SetFocusMode( CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO); if (!focusModeSet) { Debug.Log("Failed to set focus manner (unsupported mode)."); }
Yous can configure autofocus when Vuforia Engine initializes by calculation the following code to a script that inherits fromMonobehaviour
. This registers a callback with theVuforiaBehaviour
that volition prepare a focus fashion when the Vuforia Engine process has started.
void Starting time () { var vuforia = VuforiaARController.Case; vuforia.RegisterVuforiaStartedCallback(OnVuforiaStarted); vuforia.RegisterOnPauseCallback(OnPaused); } private void OnVuforiaStarted() { CameraDevice.Instance.SetFocusMode( CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO); } individual void OnPaused(bool paused) { if (!paused) // resumed { // Set again autofocus mode when app is resumed CameraDevice.Example.SetFocusMode( CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO); } }
How To Obtain HD Camera Frames
Hard disk camera view enables apps to asking photographic camera preview frames in Hard disk. Apps tin can offering features such as recording and sharing of images and videos in HD. Hard disk drive fashion is enabled past default on supported devices and there is null specific that an app must practice. Supported devices include those that have a Hd camera and screen, and quad core processors.
How To Access the Camera Image in Unity
This article describes 2 approaches for obtaining the photographic camera image (without augmentation) in Unity:
- Use the
Vuforia.Image
course - Utilize the paradigm every bit an OpenGL texture
Use theVuforia.Prototype
class
Using theVuforia.Image
class works much like the native version.
Register for the desired image format using theCameraDevice.SetFrameFormat()
method:
CameraDevice.Example.SetFrameFormat(PIXEL_FORMAT.RGB888, true);
Note: The Vuforia Namespace Reference folio lists the available pixel formats.
Call this method afterwards Vuforia Engine has been initialized and started; to this aim, it is recommended to register anOnVuforiaStarted
callback in theStart()
method of yourMonoBehaviour
script, eastward.grand.:
void First() { VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted); } private void OnVuforiaStarted() { // Vuforia has started, now register camera prototype format if (CameraDevice.Instance.SetFrameFormat(mPixelFormat, true)) { Debug.Log("Successfully registered pixel format " + mPixelFormat.ToString()); mFormatRegistered = truthful; } else { Debug.LogError( "Failed to register pixel format " + mPixelFormat.ToString() + "\n the format may be unsupported by your device;" + "\northward consider using a different pixel format."); mFormatRegistered = false; } }
Recollect the camera image using theCameraDevice.GetCameraImage()
method.
- Take this action from the
OnTrackablesUpdated()
callback. That manner you can ensure that you retrieve the latest camera image that matches the current frame. - Always make certain that the photographic camera image isnon null, since information technology can take a few frames for the image to become available later registering for an image format.
- Make sure tounregister the camera image format whenever the application ispaused, and toannals itagain when the application isresumed.
Instructions: Attach this script to a GameObject in your AR scene and cheque the logs in the Console to come across the captured Prototype information:
using UnityEngine; using System.Collections; using Vuforia; public grade CameraImageAccess : MonoBehaviour { #region PRIVATE_MEMBERS private PIXEL_FORMAT mPixelFormat = PIXEL_FORMAT.UNKNOWN_FORMAT; private bool mAccessCameraImage = truthful; individual bool mFormatRegistered = false;
0 Response to "How To Get X And Y Of Camera Size In Unity"
Post a Comment