How to use wikitude plugin in xamarin forms?

核能气质少年 提交于 2019-12-11 00:42:04

问题


I am using Xamarin to develop cross platform AR application. I am using Wikitude instant tracking.

I am able to start the Wikitude activity and able to run the Instant tracking...Now I want capture the high resolution image while tracking...I am trying to build the plugin to get the frame and then convert it to image stream

Her is my Wikitude activity

 namespace XamarinExample.Droid
    {
        [Activity(Label = "WikitudeActivity")]
        public class WikitudeActivity : Activity, ArchitectView.IArchitectUrlListener
        {
            ArchitectView architectView;
            string worldUrl;

            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);

                SetContentView(Resource.Layout.sample_cam);

                Title = Intent.GetStringExtra("id");

                worldUrl = "Wikitude" + File.Separator + Intent.GetStringExtra("id") + File.Separator + "index.html";

                architectView = FindViewById<ArchitectView>(Resource.Id.architectView);

                ArchitectStartupConfiguration startupConfiguration = new ArchitectStartupConfiguration();
                startupConfiguration.setLicenseKey(Constants.WIKITUDE_SDK_KEY);
                startupConfiguration.setFeatures(ArchitectStartupConfiguration.Features.ImageTracking);
                startupConfiguration.setCameraResolution(CameraSettings.CameraResolution.Auto);



/////////////////////////////// Register  Plugin////////////////////////////////////


                var plugins = new Plugin01("test");
                architectView.RegisterPlugin(plugins);

                architectView.OnCreate(startupConfiguration);
                architectView.RegisterUrlListener(this);
            }

    }

My Plugin code taken from

public class Plugin01 : Com.Wikitude.Common.Plugins.Plugin
 {
    public Plugin01(string p0) : base(p0)
    {

    }    
    Frame currentFrame = null;
    public override void CameraFrameAvailable(Frame p0)
    {
    System.Diagnostics.Debug.WriteLine("AVAILABLE FRAME");
        try
        {
            var data = p0.GetData();
            currentFrame = p0;
        }
        catch (System.Exception ex) { }
    }

    public override void Update(RecognizedTarget[] p0)
    {
            System.Diagnostics.Debug.WriteLine("AVAILABLE FRAME");
        if (p0 != null)
        {
            if (currentFrame != null)
            {
               // ConvertYuvToJpeg(currentFrame, p0[0]);
            }
        }
    }

}

I have registered the plugins but it is not calling
public override void Update(RecognizedTarget[] p0) Method....What am I doing wrong here ?


回答1:


I think the problem is calling "RegisterPlugin" in the wrong method, as you know the cycle of calling activity methods are different.you should call it in "OnPostCreate" method of activity. try below code and let me know the result:

protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        try
        {
            SetContentView(Resource.Layout.Main);
            architectView = FindViewById<ArchitectView>(Resource.Id.architectView);
            var config = new ArchitectStartupConfiguration();
            config.setLicenseKey(WIKITUDE_SDK_KEY);
            architectView.OnCreate(config);
        }
        catch (Exception ex) { Toast.MakeText(this, ex.ToString(), ToastLength.Long); }
    }

protected override void OnPostCreate(Bundle savedInstanceState)
    {
        base.OnPostCreate(savedInstanceState);
        if (architectView != null)
            architectView.OnPostCreate();
        try
        {
            try
            {
                string url = string.Format(@"file:///android_asset/01_ImageRecognition_1_ImageOnTarget/index.html");
                architectView.Load(url);
                Plugin01 cardPlugin = new Plugin01("com.plugin.dpiar");
                architectView.RegisterPlugin(cardPlugin);
            }
            catch (Exception ex) { }
        }
        catch (Exception ex) { Toast.MakeText(this, ex.ToString(), ToastLength.Long); }
    }

consider changing variables name.



来源:https://stackoverflow.com/questions/46707586/how-to-use-wikitude-plugin-in-xamarin-forms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!