Esempio n. 1
0
        /// <summary>
        /// Initialize the EasyAR component graph.
        /// See https://help.easyar.com/EasyAR%20Sense/v3/Getting%20Started/Getting-Started-with-EasyAR.html
        /// </summary>
        void CreateEasyAr()
        {
            camera          = CameraDeviceSelector.createCameraDevice(CameraDevicePreference.PreferObjectSensing);
            throttler       = InputFrameThrottler.create();
            inputFrameFork  = InputFrameFork.create(2);
            join            = OutputFrameJoin.create(2);
            oFrameBuffer    = OutputFrameBuffer.create();
            i2OAdapter      = InputFrameToOutputFrameAdapter.create();
            i2FAdapter      = InputFrameToFeedbackFrameAdapter.create();
            outputFrameFork = OutputFrameFork.create(2);

            bool status = camera.openWithPreferredType(CameraDeviceType.Back);

            camera.setSize(new Vec2I(1280, 720));
            camera.setFocusMode(CameraDeviceFocusMode.Continousauto);
            camera.setBufferCapacity(5 + 7);
            if (!status)
            {
                return;
            }
            ImageTracker tracker = ImageTracker.create();

            LoadFromImage(tracker, "almondblossoms.jpg", "almondblossoms");
            LoadFromImage(tracker, "irises.jpg", "irises");
            LoadFromImage(tracker, "starrynight.jpg", "starrynight");
            tracker.setSimultaneousNum(6);
            trackers.Add(tracker);

            feedbackFrameFork = FeedbackFrameFork.create(trackers.Count);

            camera.inputFrameSource().connect(throttler.input());
            throttler.output().connect(inputFrameFork.input());
            inputFrameFork.output(0).connect(i2OAdapter.input());
            i2OAdapter.output().connect(join.input(0));

            inputFrameFork.output(1).connect(i2FAdapter.input());
            i2FAdapter.output().connect(feedbackFrameFork.input());
            int k = 0;

            foreach (ImageTracker _tracker in trackers)
            {
                feedbackFrameFork.output(k).connect(_tracker.feedbackFrameSink());
                _tracker.outputFrameSource().connect(join.input(k + 1));
                k++;
            }

            join.output().connect(outputFrameFork.input());
            outputFrameFork.output(0).connect(oFrameBuffer.input());
            outputFrameFork.output(1).connect(i2FAdapter.sideInput());
            oFrameBuffer.signalOutput().connect(throttler.signalInput());

            arComponent = fgScene.CreateComponent <EasyARComponent>();
            arComponent.ARFrameUpdated   += OnARFrameUpdated;
            arComponent.OutputFrameBuffer = oFrameBuffer;
        }
Esempio n. 2
0
        private void Assemble()
        {
            // throttler
            iFrameThrottler = InputFrameThrottler.create();

            // fork input
            iFrameFork = InputFrameFork.create(2 + GetFrameFilterCount <FrameFilter.IInputFrameSink>());
            iFrameThrottler.output().connect(iFrameFork.input());
            var iFrameForkIndex = 0;

            i2OAdapter = InputFrameToOutputFrameAdapter.create();
            iFrameFork.output(iFrameForkIndex).connect(i2OAdapter.input());
            iFrameForkIndex++;
            i2FAdapter = InputFrameToFeedbackFrameAdapter.create();
            iFrameFork.output(iFrameForkIndex).connect(i2FAdapter.input());
            iFrameForkIndex++;
            foreach (var filter in FrameFilters)
            {
                if (filter is FrameFilter.IInputFrameSink)
                {
                    FrameFilter.IInputFrameSink unit = filter as FrameFilter.IInputFrameSink;
                    var sink = unit.InputFrameSink();
                    if (sink != null)
                    {
                        iFrameFork.output(iFrameForkIndex).connect(unit.InputFrameSink());
                    }
                    if (filter is FrameFilter.IInputFrameSinkDelayConnect)
                    {
                        var delayUnit = filter as FrameFilter.IInputFrameSinkDelayConnect;
                        delayUnit.ConnectedTo(iFrameFork.output(iFrameForkIndex), ResetBufferCapacity);
                    }
                    iFrameForkIndex++;
                }
            }

            // feedback
            fbFrameFork = FeedbackFrameFork.create(GetFrameFilterCount <FrameFilter.IFeedbackFrameSink>());
            i2FAdapter.output().connect(fbFrameFork.input());
            var fbFrameForkIndex = 0;

            foreach (var filter in FrameFilters)
            {
                if (filter is FrameFilter.IFeedbackFrameSink)
                {
                    FrameFilter.IFeedbackFrameSink unit = filter as FrameFilter.IFeedbackFrameSink;
                    fbFrameFork.output(fbFrameForkIndex).connect(unit.FeedbackFrameSink());
                    fbFrameForkIndex++;
                }
            }

            // join
            oFrameJoin = OutputFrameJoin.create(1 + GetFrameFilterCount <FrameFilter.IOutputFrameSource>());
            var joinIndex = 0;

            foreach (var filter in FrameFilters)
            {
                if (filter is FrameFilter.IOutputFrameSource)
                {
                    FrameFilter.IOutputFrameSource unit = filter as FrameFilter.IOutputFrameSource;
                    unit.OutputFrameSource().connect(oFrameJoin.input(joinIndex));
                    joinIndex++;
                }
            }
            i2OAdapter.output().connect(oFrameJoin.input(joinIndex));

            // fork output for feedback
            oFrameFork = OutputFrameFork.create(2);
            oFrameJoin.output().connect(oFrameFork.input());
            oFrameBuffer = OutputFrameBuffer.create();
            oFrameFork.output(0).connect(oFrameBuffer.input());
            oFrameFork.output(1).connect(i2FAdapter.sideInput());

            // signal throttler
            oFrameBuffer.signalOutput().connect(iFrameThrottler.signalInput());

            // connect source
            if (FrameSource != null)
            {
                FrameSource.Connect(iFrameThrottler.input());
            }

            // set BufferCapacity
            ResetBufferCapacity();

            if (FrameSource.HasSpatialInformation)
            {
                RequireWorldCenter = true;
            }
            foreach (var filter in FrameFilters)
            {
                if (filter is SurfaceTrackerFrameFilter)
                {
                    if (RequireWorldCenter)
                    {
                        throw new InvalidOperationException(typeof(SurfaceTracker) + " + VIOCameraDevice is not supported");
                    }
                    RequireWorldCenter = true;
                }
            }

            Ready = true;
        }
Esempio n. 3
0
        void Init()
        {
            initialized = true;

            iFrameThrottler = InputFrameThrottler.create();
            oFrameBuffer    = OutputFrameBuffer.create();
            i2fAdapter      = InputFrameToFeedbackFrameAdapter.create();
            inputFrameFork  = InputFrameFork.create(ForkOutputNum);
            i2OAdapter      = InputFrameToOutputFrameAdapter.create();
            oFrameJoin      = OutputFrameJoin.create(JoinNum);

            if (FrameSourceType == FrameSource.easyar)
            {
                if (CameraDevice.isAvailable())
                {
                    Debug.Log("[EasyAR] use ezar camera device");
                    easyarCamera = CameraDeviceSelector.createCameraDevice(EasyarCameraPrefer);
                    var openResult = false;
                    if (UseSecondCamera)
                    {
                        openResult = easyarCamera.openWithIndex(1);
                    }
                    else
                    {
                        openResult = easyarCamera.openWithType(CameraDeviceType.Default);
                    }
                    easyarCamera.setFocusMode(CameraFocusMode);

                    if (!openResult)
                    {
                        Debug.Log("[EasyAR] open camera failed");
                        initialized = false;
                        return;
                    }
                    easyarCamera.setSize(new Vec2I((int)CameraSize.x, (int)CameraSize.y));
                    easyarCamera.inputFrameSource().connect(iFrameThrottler.input());
                    easyarCamera.start();
                }
                else
                {
                    initialized = false;
                    Debug.Log("[EasyAR] ezar camera device can not work");
                    return;
                }
            }

            iFrameThrottler.output().connect(inputFrameFork.input());
            inputFrameFork.output(0).connect(i2OAdapter.input());
            i2OAdapter.output().connect(oFrameJoin.input(0));
            outputFrameFork = OutputFrameFork.create(1);

            int index = 0;

            if (ImgTracker != null)
            {
                index++;
                outputFrameFork = OutputFrameFork.create(2);
                inputFrameFork.output(index).connect(i2fAdapter.input());
                i2fAdapter.output().connect(ImgTracker.Input());
                ImgTracker.Output().connect(oFrameJoin.input(index));
                outputFrameFork.output(1).connect(i2fAdapter.sideInput());
            }

            if (SfTracker != null)
            {
                index++;
                inputFrameFork.output(index).connect(SfTracker.Input());
                SfTracker.Output().connect(oFrameJoin.input(index));
            }

            if (CloudImageRecognizer != null)
            {
                index++;
                inputFrameFork.output(index).connect(CloudImageRecognizer.Input());
            }

            oFrameJoin.output().connect(outputFrameFork.input());
            outputFrameFork.output(0).connect(oFrameBuffer.input());
            oFrameBuffer.signalOutput().connect(iFrameThrottler.signalInput());

            args = new ARSessionUpdateEventArgs();
        }