banner



How To Check If Something Is Out Of Camera's Range Unity

Working with the Camera

  • Camera Focus Modes
  • How To Obtain HD Camera Frames
  • How To Access the Camera Image in Unity
  • How To Access the Photographic camera Image in Native
  • How To Use the Camera Project Matrix
  • How To Access Photographic camera Parameters
  • How To Determine Camera Pose
  • How To Make up one's mind Target Distance

Photographic camera Focus Modes

Continuous Autofocus and Other Focus Modes

This commodity describes the unlike focus modes bachelor in Vuforia Engine (since v1.5 and higher up).

The behavior of the focus modes in Vuforia Engine (since v1.v) is described below:

Focus mode Behavior
FOCUS_MODE_NORMAL Sets the camera into the default mode as defined by the camera driver.
FOCUS_MODE_TRIGGERAUTO Triggers a single autofocus operation.
FOCUS_MODE_CONTINUOUSAUTO Lets you plow on driver-level continuous autofocus for cameras. This mode is optimal for AR applications. This style yields the best 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 photographic camera to infinity, as provided by the camera driver implementation. (not supported on iOS)
FOCUS_MODE_MACRO Sets the camera to macro mode, as provided by the camera driver implementation. This fashion provides a sharp 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 information technology is available on the device. When setting this mode, if the return value of setFocusMode() is TRUE your awarding volition provide precipitous camera images for both superior rendering, every bit well every bit for robust tracking performance.

If theFOCUS_MODE_CONTINUOUSAUTO is not available, the next best option is to implement a 'bear upon to focus' behavior in your app. To exercise this,trigger setFocusMode() withFOCUS_MODE_TRIGGERAUTO value each time the user touches the screen. The disadvantage of this behavior is that most camera drivers pick a random direction to focus (near or far), so you have a 50% chance that the image volition defocus then focus on the target. Under certain conditions due this focus logic the tracking can be lost for a moment until a sharp image is provided again past the camera.

FOCUS_MODE_INFINITY andFOCUS_MODE_MACRO are usable in sure application scenarios, every bit described above.

FOCUS_MODE_NORMAL sets the camera into the default mode as defined by the camera driver.

C++

                                          bool     focusModeSet = Vuforia::CameraDevice::getInstance().setFocusMode(       Vuforia::CameraDevice::FOCUS_MODE_CONTINUOUSAUTO);     if (!focusModeSet) {       LOG("Failed to fix focus manner (unsupported manner).");      }                  

Java

                                          void Showtime ()     {         var vuforia = VuforiaARController.Case;         vuforia.RegisterVuforiaStartedCallback(OnVuforiaStarted);         vuforia.RegisterOnPauseCallback(OnPaused);     }           individual void OnVuforiaStarted()     {         CameraDevice.Instance.SetFocusMode(             CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);     }           individual void OnPaused(bool paused)     {         if (!paused) // resumed         {             // Ready 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 gear up focus mode           (unsupported mode).");         }                  

Yous can configure autofocus when Vuforia Engine initializes past adding the following code to a script that inherits fromMonobehaviour. This registers a callback with theVuforiaBehaviour that will set a focus mode when the Vuforia Engine procedure has started.

                                          void Start ()     {         var vuforia = VuforiaARController.Case;         vuforia.RegisterVuforiaStartedCallback(OnVuforiaStarted);         vuforia.RegisterOnPauseCallback(OnPaused);     }           individual void OnVuforiaStarted()     {         CameraDevice.Instance.SetFocusMode(             CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);     }           private 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

HD photographic camera view enables apps to request camera preview frames in Hard disk drive.  Apps can offer features such every bit recording and sharing of images and videos in HD. HD mode is enabled past default on supported devices and at that place is nothing specific that an app must do. Supported devices include those that have a HD camera and screen, and quad cadre processors.

How To Admission the Camera Epitome in Unity

This article describes 2 approaches for obtaining the camera image (without augmentation) in Unity:

  • Use theVuforia.Prototype class
  • Employ the image as an OpenGL texture

Use theVuforia.Image class

Using theVuforia.Image class works much like the native version.

Register for the desired epitome format using theCameraDevice.SetFrameFormat() method:

                                          CameraDevice.Instance.SetFrameFormat(PIXEL_FORMAT.RGB888, truthful);                  

Note: The Vuforia Namespace Reference page lists the available pixel formats.

Call this method afterwards Vuforia Engine has been initialized and started; to this aim, information technology is recommended to register anOnVuforiaStarted callback in theStart() method of yourMonoBehaviour script, eastward.thousand.:

                                          void Showtime()     {       VuforiaARController.Example.RegisterVuforiaStartedCallback(OnVuforiaStarted);     }        private void OnVuforiaStarted()     {       // Vuforia has started, at present annals photographic camera image format         if (CameraDevice.Instance.SetFrameFormat(mPixelFormat, truthful))       {         Debug.Log("Successfully registered pixel format " + mPixelFormat.ToString());         mFormatRegistered = true;       }         else       {         Debug.LogError(           "Failed to register pixel format " + mPixelFormat.ToString() +           "\n the format may be unsupported by your device;" +           "\due north consider using a different pixel format.");                   mFormatRegistered = simulated;         }     }                  

Retrieve the photographic camera image using theCameraDevice.GetCameraImage() method.

  • Accept this action from theOnTrackablesUpdated() callback. That manner you lot can ensure that you retrieve the latest photographic camera image that matches the current frame.
  • Always brand sure that the camera image isnot nothing, since it can accept a few frames for the prototype to become bachelor after registering for an image format.
  • Make sure tounregister the photographic camera epitome format whenever the application ispaused, and toannals itonce more when the application isresumed.

Instructions: Attach this script to a GameObject in your AR scene and check the logs in the Console to see the captured Image information:

                                          using UnityEngine;   using Organization.Collections;   using Vuforia;    public course 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 Check If Something Is Out Of Camera's Range Unity"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel