ImageTargetOnFly not working on Android.

0 votes
asked Feb 19, 2020 by bigbaak (720 points)
edited Feb 19, 2020 by bigbaak

Unity 3D 2019.2.11f

Easy AR 4.0 Free

I use example sample ImageTargetOnFly. I run my code on Unity Editor and it's working very well and image targets is successfully tracking. But, not working on the Android device.  Has anyone solved this problem?

I use file path:"/data/user/0/com.app.package/files"  and all images save into this folder.

All files save like this:

  •  "/data/user/0/com.app.package/files/photo0.jpg"
  •  "/data/user/0/com.app.package/files/photo0.jpg"
  • also i tested with Application.persistentDataPath

```
    public IEnumerator LoadTarget()
    {
        yield return new WaitForSeconds(2);
        Debug.Log("Run LoadTarget");
        int count = 0;
        var imageTargetName = filesManager.GetImageFiles();
        
        foreach (var obj in imageTargetName.Where(obj => !imageTargetDic.ContainsKey(obj.Key)))
        {
            count++;
            GameObject imageTarget = new GameObject(obj.Key);
            Debug.LogFormat("Android Path= {0}{1}.jpg", "/data/user/0/com.app.package/files/",obj.Key);
            var controller = imageTarget.AddComponent<ImageTargetController>();
            controller.SourceType = ImageTargetController.DataSource.ImageFile;
            controller.ImageFileSource.PathType = PathType.Absolute;
            controller.ImageFileSource.Path =  "/data/user/0/com.app.package/files/" + obj.Key + ".jpg";
            controller.ImageFileSource.Name = obj.Key;
            controller.ImageFileSource.Scale = 1f;
            controller.Tracker = Tracker;
            imageTargetDic.Add(obj.Key, controller);
            var cube = Instantiate(cube3d);
            cube.transform.parent = imageTarget.transform;
            initImageTargetFunction(controller);
        }
        Debug.Log("Loaded target =" + count);
    }

 private void AddTargetControllerEvents(ImageTargetController controller)
    {
        if (!controller)
        {
            return;
        }

        // ----------- all function not fired on Unity Editor,Android.

        controller.TargetFound += () =>
        {
       
            Debug.LogFormat("Found target {{id = {0}, name = {1}}}", controller.Target.runtimeID(), controller.Target.name());
        };
        controller.TargetLost += () =>
        {
            Debug.LogFormat("Lost target {{id = {0}, name = {1}}}", controller.Target.runtimeID(), controller.Target.name());
        };
        controller.TargetLoad += (Target target, bool status) =>
        {
            Debug.LogFormat("Load target {{id = {0}, name = {1}, size = {2}}} into {3} => {4}", target.runtimeID(), target.name(), controller.Size, controller.Tracker.name, status);
        };
        controller.TargetUnload += (Target target, bool status) =>
        {
            Debug.LogFormat("Unload target {{id = {0}, name = {1}}} => {2}", target.runtimeID(), target.name(), status);
        };
    }

```

By Android logcat i saw the image target is successfully loading and creates into the  Unity scene, but not tracking.

Devices:

  • OnePlus 6 Android 10
  • Xiaomi MiPad 4 - Android 8

Also, I found a strange log entry when running the application:

Curl error 7: Failed to connect to localhost port 80: Connection refused
(Filename: ./Modules/UnityWebRequest/Implementations/TransportCurl.cpp Line: 734)
02-19 16:51:36.214 15494 15531 E Unity   : Curl error 7: Failed to connect to localhost port 80: Connection refused
 (Filename: ./Modules/UnityWebRequest/Implementations/TransportCurl.cpp Line: 734)

1 Answer

0 votes
answered Feb 19, 2020 by bigbaak (720 points)
edited Feb 24, 2020 by bigbaak

I solved.

Just added "file://" on the start file path. 

controller.ImageFileSource.Path =  "file:///data/user/0/com.app.package/files/" + obj.Key + ".jpg";

commented Apr 15, 2021 by creartivity (210 points)
edited Apr 15, 2021 by creartivity
Hello!
I got the same problem, i added as well file://, tried both with data/user[...] and with persistent datapath.
The problem is that the target works when the app is installed, but as i exit the app and re-open it the target gets created but does not work with recognition, and never works again, even delething the file and downloading it again in the above path.
Do you have any idea of what could have caused it (the file is alwais present in the above path).
Thanks if you can help  me ;)
Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...