Start a new topic
Solved

Image Recognition works on Live Preview, but not on Phone

Hello, 


I've been testing the image recognition on my computer on Unity for the past couple of days now. When I bring up multiple images on my webcam for the live preview, it is being recognized perfectly fine with no errors. But when I try to test it on my Android phone, it doesn't recognize the images at all.


I currently have it set up so that when the image is recognized, it will add the target's name to a list. When 4 images are recognized and added to the list, a message pops up. The text that I have added to the scene that shows the list's count is updating successfully when I test it on my computer, but when I build it to my phone, the text does not update at all. 


Any help would be appreciated. Thank you!


Hi,


Could you please send the following details:


  • Which version of the SDK are you using?
  • What Unity version are you using?
  • What device does this happen with (model details and OS version)?
  • Is this happening with the sample app or in your own app? If it happens with your own app, Does the sample app work on your device?


Thx and greetings

Nicola

Hi Nicola,


  • I am currently using the Wikitude SDK Unity 8.5.0 version.
  • I am using Unity 2019.1.8f1.
  • The device I am testing this on is the Google Pixel 2 with Android version 9.
  • This is currently happening with my own app. I tried running the sample app (Image Tracking - Simple) on my device, and the camera did not work; the screen was just black.

Update:

The error message says "Failed to load requested resource" and "The associated image target collection failed to load". 

Is there a reason why the .wtc file isn't being recognized in my phone? Am I missing a step when I build the project?

Hi, 


The reason there was only a black screen in the sample app was because it was only building the Image Tracking - Simple scene. In newer versions of Unity, the developer is responsible for asking for camera permissions, which in our sample app is done in MenuController.cs in the Awake method. By removing the Main Menu scene from the build, the camera permission is also skipped, leading to a black frame. If possible, please include the menu scene in the build and try again.


However, I'm not sure if this is the same issue as the one you're encountering in your app. Is the wtc file placed in the StreamingAssets folder in the Unity project, or are you specifying it from a custom URL?


Thank you,

Alexandru

The wtc file is placed in a different folder, and I am using the Custom URL option in the image tracker.

Hi, 


Is the wtc file still placed in the project, or somewhere else on the Android device? Do you download it from a separate location? How does the URL look like?


Thank you,

Alexandru

The wtc file is placed in the project, under a folder called Databases. The URL that I'm using is  

file://Assets/Databases/Runes.wtc

 

Hi, 


This will not work, since during the build, Unity will take all the assets that are referenced from the project and bundle them together, not necessarily respecting any file structure. The only file structure that is respected is the StreamingAssets folder, which is why we're using it as well. Additionally, since you're only specifying a path to the file, Unity will not see that the wtc file is referenced from anywhere and it won't even be included in the build. You can read more about this in the Unity documentation regarding StreamingAssets.

If placing them in StreamingAssets is really not an option, they can also be placed on a remote server. The Wikitude SDK can download them automatically every time you run the app, or you can download them manually and cache them.


Best regards,

Alexandru

Hi,


I have tried using the StreamingAssets folder, but whenever I tried to change the TargetCollection path via script, it wouldn't change when I saw it in the inspector. It always defaulted to the last .wtc file in the StreamingAssets folder. Any advice on how to fix this ?

EDIT: sorry, I meant it's always defaulting to the FIRST .wtc file in the StreamingAssets folder. Is there any way to change the Target Collection via script, rather than manually doing it in the inspector?

Hi, 


The reason why it's switching to the first .wtc file is because of a bug in our plugin. This is fixed in the upcoming release, which should be available soon. However, this is only a visual bug in the UI of the inspector and doesn't affect functionality at all.

To switch the Target Collection from a script, simply assign the path relative to the StreamingAssets folder to the TargetPath property of the TargetCollectionResource. Please make sure to do this before the Start method of the ImageTracker is called, otherwise the native tracker will already be initialized and the change won't work. Here's an example where I do the change in Awake:


using UnityEngine;
using Wikitude;

public class ChangeTargetCollection : MonoBehaviour
{
  private void Awake() {
    var imageTracker = FindObjectOfType<ImageTracker>();
    imageTracker.TargetCollectionResource.TargetPath = "Wikitude/dinosaurs.wtc";
  }
}

I've tested this in our sample project by adding this script to a new GameObject in the Image Tracking - Simple scene.


Best regards,

Alexandru


Hello,


That helps immensely, knowing that it is a visual error and nothing else. I guess my calling it in the Start() function is what was messing with the functionality. Thank you for your help!

Login or Signup to post a comment