コード例 #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;
        }
コード例 #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;
        }