Log in or register to post comments

Enabling/disabling AR camera

SDK 10.0
September 7, 2021 - 2:29am #1

Hi!

 

We are currently in the process of updating an old unity project from unity 2019.4.13/vuforia  8.5.9 to unity 2020.3.17/vuforia 10.1.4.

Our app has different functions: one of them uses the normal phone front/back cameras, another uses the vuforia AR camera. We used to be able to disable the AR camera by disabling the VuforiaBehaviour:

Vuforia.VuforiaBehaviour.Instance.enabled = false;

Using Vuforia 10 however, does not seem to release the camera like it used to, making it unavailable to us.

We have tried other ways of stopping the camera/vuforia, but none of those methods seems to release the camera:

Vuforia.VuforiaBehaviour.Instance.VideoBackground.StopVideoBackgroundRendering();
Vuforia.VuforiaApplication.Instance.Deinit();

Is there some other way to achieve what we want?

SDK Version: 

Enabling/disabling AR camera

November 11, 2021 - 8:46am #14

I am facing a similar issue. I am working on the HoloLens trying to take pictures with it. I am disabling Vuforia before I take a picture with "VuforiaBehaviour.Instance.enabled = false;" and enabling it when I'm done however Unity (I'm using version 2020.3) is giving me the error: "Failed capturing photo (hr = 0xC00D3704)" unless I delay Vuforia's initialization. However, whenever I do that Vuforia doesn't seem to work in my scene at all. I would love for this to get fixed. Thanks.

Enabling/disabling AR camera

October 30, 2021 - 7:33am #13

Same issue on my side, reproduced from the editor (in Android mode) using a webcam. I can tell the webcam is "active" because it lits up when capturing any video. Before opening the scene containing the AR camera it's off, then when opening the scene it turns on. The issue is when I try to turn if off using a script such as Vuforia.VuforiaBehaviour.Instance.enabled = false; nothing happens, it just stays on...

Enabling/disabling AR camera

October 27, 2021 - 3:04pm #12

Hello @wissej,

Thanks for the feedback. I've confirmed that this is an ARCore supported device.

Assuming you're developing in Unity, are you building with Mono or IL2CPP? It's important the you build with the latter as Mono does not support 64-bit builds. Google recently required ARCore apps to be 64-bit, which was "silently" rolled out in Google Play Services for AR updates.

If you are building with IL2CPP and still seeing a black screen, please send us an ADB log when running your app with Vuforia Engine and we can take a look.

Thanks,

Vuforia Engine Support

Enabling/disabling AR camera

October 26, 2021 - 6:56am #11

Hi @medabit

 

Using GNieraeth's sample I found that the Vuforia camera shows a black screen when I have Google Play-services for AR (ARCore) installed. I am using a Oneplus 7 Pro on Android 11. Unity 2020.3.17, having ARCore set to optional including ARCore libraries. When I remove the AR Play services from the device the camera works as intended.

Enabling/disabling AR camera

October 8, 2021 - 11:26am #10

Hello @GNieraeth,

The team attempted to replicate the issue using the provided code block. Unfortunately, they were unable to do so on an iPad and Galaxy S20.

Can you (or anyone else) provide feedback on the devices where this is observed?

Thanks,

Vuforia Engine Support

Enabling/disabling AR camera

October 8, 2021 - 9:35am #9

Hello,

Just a bit of feedback to the thread that I'm actively working with the team on an RCA.

Thanks,

Vuforia Engine Support

Enabling/disabling AR camera

October 7, 2021 - 5:22am #8

Hi Patrick,

We're facing the same issues. Any updates?

Enabling/disabling AR camera

September 28, 2021 - 5:51am #7

Hi Patrick,

 

Were you able to reproduce the issue using the code I posted earlier?

Enabling/disabling AR camera

September 10, 2021 - 9:27am #6

Hello Patrick,

 

The following script should demonstrate the issue:

using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using Vuforia;

public class CameraSwitcher : MonoBehaviour
{
    [SerializeField]
    private RawImage target;

    private WebCamTexture camTexture;
    private bool ar = true;

    public void SwitchCamera()
    {
        if (ar)
        {
            // turn off vuforia, start webcam texture

            StartCoroutine(EnableSelfieCamera());
        }
        else
        {
            // turn off webcam texture, turn on vuforia

            StartCoroutine(EnableARCamera());
        }
    }

    private IEnumerator EnableSelfieCamera()
    {
        VuforiaBehaviour.Instance.enabled = false;

        // wait 1 frame
        yield return null;

        camTexture = new WebCamTexture(WebCamTexture.devices[0].name, Screen.width, Screen.height);
        target.gameObject.SetActive(true);
        target.texture = camTexture;
        camTexture.Play();

        ar = false;
    }

    private IEnumerator EnableARCamera()
    {
        camTexture.Stop();

        // wait until webcam has stoped before destroying
        yield return new WaitWhile(() => camTexture.isPlaying);
        Destroy(camTexture);
        target.gameObject.SetActive(false);

        // wait 1 frame before starting vuforia
        yield return null;

        VuforiaBehaviour.Instance.enabled = true;

        ar = true;
    }
}

Create a new scene with a vuforia AR camera. Attach this script to a new canvas with a rawimage and a button. Assign the rawimage to the script and assign the SwitchCamera function to the button.

Using Unity 2019 with Vuforia 8.5.9 this will have the expected behaviour: start out with the vuforia AR camera and switch to webcamtexture after the button press.

Using Unity 2020 with Vuforia 10.1.4 this will not work: the ar camera will stop after switching, but the hardware is not released, making it unavailable to webcamtexture. In the end only a black screen is visible after switching

Enabling/disabling AR camera

September 10, 2021 - 12:21am #5

Hey both,

 

Sorry for the small delay. 

So it's my understanding that this should work. Is there a possibility to share with me a project or code which you use to utulize the back camera, seperate from Vuforia Engine? That way I could test and see myself and possibly get R&D involved.

 

Kind regards,

Patrick Scheper

Technical Community Manager

Enabling/disabling AR camera

September 9, 2021 - 7:16am #4

Hello GNieraeth and Pattrick,

I also experienced the same issue, if you find the solution please share.

 

 

 

 

Enabling/disabling AR camera

September 8, 2021 - 2:05am #3

Hello Patrick,

 

Thank you for your response!

I am afraid your suggested change has not fixed our issue, the result is the same.

Is there something else we can try?

Enabling/disabling AR camera

September 7, 2021 - 2:46am #2

Hey there,

 

I'm sorry you're facing difficulties with the new API. Instead of calling Vuforia.VuforiaBehaviour.Instance.enabled = false; you can now use: VuforiaBehaviour.Instance.enabled = false;.

Could you validate if that works? 

 

Kind regards,

Patrick Scheper

Technical Community Manager

Log in or register to post comments