Log in or register to post comments

How to pause/freeze the camera?

May 26, 2017 - 10:52am #1

Hello everyone!

 

I'm new Vuforia's user and I'm looking for a way to pause or freeze the camera without affect current AR interaction.

For instance, on mobile, we can :

1. Look at an Image Target

2. View the AR object or animation

3. Press a button to freeze the camera

4. Place our phone on the table while continuing to manipulate AR interaction

 

Can you explain me how to do it please?

Thank you!

How to pause/freeze the camera?

March 13, 2018 - 6:44am #10

Pausing Vuforia Camera using VuforiaRenderer.Instance.Pause(true); in OnApplicationPause(bool true) when app comes back from background on iOS device, but the screen is upside down. It's a landscape app with both left and right landscape ticked and autorotate on using Unity 2017.3.0p2 and Xcode 9.1 running on iPad Pro iOS 11.1.1 (in case it makes a difference)

When I unpause the Vuforia Camera using VuforiaRenderer.Instance.Pause(false); the screen rotates back to normal.

Any way to prevent this upside down screen? I need to make it show a pause menu and having it upside down when the user hasn't changed device orientation at all looks sloppy.



Are there any other ways to pause/freeze the Vuforia Camera?

Thanks in advance!

How to pause/freeze the camera?

March 11, 2018 - 5:18pm #9

using Vuforia;

VuforiaRenderer.Instance.Pause(true);

How to pause/freeze the camera?

July 24, 2017 - 5:59am #8

Hello @ChandanSmartGames !

 

I tried your method, but I get an error saying that Instance in not contain in the namespace Vuforia, any idea where it could have been moved ? :)



Thank you really much !

How to pause/freeze the camera?

June 11, 2017 - 3:27am #7

Hey there!!

First include this line at the very top of your script:

Using Vuforia;

 

And then use this to freeze:

Vuforia.Instance.Pause();

 

Use this line to unfreeze:

Vuforia.Instance.Play();

 

Hope this helps!!

Happy Coding. See you later

How to pause/freeze the camera?

June 8, 2017 - 9:02am #6

Nobody can help me? :/

How to pause/freeze the camera?

May 30, 2017 - 6:23pm #5

Thank you for your help! and sorry for my mistake..

I have a new source code in my GameObject :

using UnityEngine;
using System.Collections;

using Vuforia;

public class CameraImageAccess : MonoBehaviour
{

#region PUBLIC_MEMBERS

public GameObject BackgroundPlane;
public bool freeze = false;

#endregion

#region PRIVATE_MEMBERS

private Image.PIXEL_FORMAT mPixelFormat = Image.PIXEL_FORMAT.UNKNOWN_FORMAT;

private bool mAccessCameraImage = true;
private bool mFormatRegistered = false;

#endregion // PRIVATE_MEMBERS

#region MONOBEHAVIOUR_METHODS

void Start()
{

  #if UNITY_EDITOR
  mPixelFormat = Image.PIXEL_FORMAT.GRAYSCALE; // Need Grayscale for Editor
  #elif
  m_PixelFormat = Image.PIXEL_FORMAT.RGB888; // Use RGB888 for mobile
  #endif

  // Register Vuforia life-cycle callbacks:
  VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
  VuforiaARController.Instance.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated);
  VuforiaARController.Instance.RegisterOnPauseCallback(OnPause);

}

#endregion // MONOBEHAVIOUR_METHODS

#region PRIVATE_METHODS

void OnVuforiaStarted()
{

  // Try register camera image format
  if (CameraDevice.Instance.SetFrameFormat(mPixelFormat, true))
  {
   Debug.Log("Successfully registered pixel format " + mPixelFormat.ToString());

   mFormatRegistered = true;
  }
  else
  {
   Debug.LogError(
    "\nFailed to register pixel format: " + mPixelFormat.ToString() +
    "\nThe format may be unsupported by your device." +
    "\nConsider using a different pixel format.\n");

   mFormatRegistered = false;
  }

}

/// <summary>
/// Called each time the Vuforia state is updated
/// </summary>
void OnTrackablesUpdated()
{
  if (mFormatRegistered)
  {
   if (mAccessCameraImage)
   {
    Vuforia.Image image = CameraDevice.Instance.GetCameraImage(mPixelFormat);

    if (image != null)
    {
     Debug.Log(
      "\nImage Format: " + image.PixelFormat +
      "\nImage Size:   " + image.Width + "x" + image.Height +
      "\nBuffer Size:  " + image.BufferWidth + "x" + image.BufferHeight +
      "\nImage Stride: " + image.Stride + "\n"
     );

     byte[] pixels = image.Pixels;

     if (pixels != null && pixels.Length > 0)
     {
      Debug.Log(
       "\nImage pixels: " +
       pixels[0] + ", " +
       pixels[1] + ", " +
       pixels[2] + ", ...\n"
      );
// I WROTE THE CODE BELOW
      if (freeze) {      
       Texture2D texture = new Texture2D (image.Width, image.Height);
       image.CopyToTexture(texture);
       BackgroundPlane.GetComponent<MeshRenderer>().material.mainTexture = texture;
       freeze = false;
      }
     }
    }
   }
  }
}

/// <summary>
/// Called when app is paused / resumed
/// </summary>
void OnPause(bool paused)
{
  if (paused)
  {
   Debug.Log("App was paused");
   UnregisterFormat();
  }
  else
  {
   Debug.Log("App was resumed");
   RegisterFormat();
  }
}

/// <summary>
/// Register the camera pixel format
/// </summary>
void RegisterFormat()
{
  if (CameraDevice.Instance.SetFrameFormat(mPixelFormat, true))
  {
   Debug.Log("Successfully registered camera pixel format " + mPixelFormat.ToString());
   mFormatRegistered = true;
  }
  else
  {
   Debug.LogError("Failed to register camera pixel format " + mPixelFormat.ToString());
   mFormatRegistered = false;
  }
}

/// <summary>
/// Unregister the camera pixel format (e.g. call this when app is paused)
/// </summary>
void UnregisterFormat()
{
  Debug.Log("Unregistering camera pixel format " + mPixelFormat.ToString());
  CameraDevice.Instance.SetFrameFormat(mPixelFormat, false);
  mFormatRegistered = false;
}

#endregion //PRIVATE_METHODS
}

I replace texture.LoadImage (image.Pixels); by image.CopyToTexture(texture); but now there is a black screen :/

Where am I wrong?

 

Thanks again!

How to pause/freeze the camera?

May 29, 2017 - 7:54am #4

See the article I linked, you need to register a callback with the Vuforia service to set the camera pixel format first. Then also check Image is not null before using it.

How to pause/freeze the camera?

May 28, 2017 - 11:23pm #3

Thanks for your answer

I try to do it with this function :

public void Freeze() {

  Vuforia.Image image = CameraDevice.Instance.GetCameraImage (mPixelFormat);

  Texture2D texture = new Texture2D(image.Width, image.Height);

  texture.LoadImage (image.Pixels);

  BackgroundPlane.GetComponent<MeshRenderer>().material.mainTexture = texture;

}

But it doesn't work (the BackgroundPlane becomes white with red '?')

Can you help me?

 

How to pause/freeze the camera?

May 27, 2017 - 7:27am #2

You can get the current camera image from CameraDevice GetCameraImage (https://library.vuforia.com/articles/Solution/How-To-Access-the-Camera-Image-in-Unity)

Then create a texture2d from the image and use this as the texture for the BackgroundPlane

Log in or register to post comments