Exemplo n.º 1
0
 /// <summary>
 /// Creates a marker bundle node.
 /// </summary>
 /// <param name="name">Name of this marker bundle node</param>
 /// <param name="tracker">A marker tracker used to track this fiducial marker</param>
 /// <param name="supportingMarkerNodes">A list of marker nodes that will supplement
 /// the base marker array</param>
 /// <param name="markerConfigs">A list of configs that specify the fiducial marker
 /// (can be either an array or a single marker) to look for</param>
 public MarkerBundleNode(String name, IMarkerTracker tracker,
                         List <MarkerNode> supportingMarkerNodes, params object[] markerConfigs)
     : base(name, tracker, markerConfigs)
 {
     supportingMarkers = new List <RelativeMarker>();
     foreach (MarkerNode markerNode in supportingMarkerNodes)
     {
         RelativeMarker marker = new RelativeMarker(markerNode);
         supportingMarkers.Add(marker);
     }
     autoReconfigure = false;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a marker bundle node.
 /// </summary>
 /// <param name="name">Name of this marker bundle node</param>
 /// <param name="tracker">A marker tracker used to track this fiducial marker</param>
 /// <param name="supportingMarkerNodes">A list of marker nodes that will supplement
 /// the base marker array</param>
 /// <param name="markerConfigs">A list of configs that specify the fiducial marker 
 /// (can be either an array or a single marker) to look for</param>
 public MarkerBundleNode(String name, IMarkerTracker tracker, 
     List<MarkerNode> supportingMarkerNodes, params object[] markerConfigs)
     : base(name, tracker, markerConfigs)
 {
     supportingMarkers = new List<RelativeMarker>();
     foreach (MarkerNode markerNode in supportingMarkerNodes)
     {
         RelativeMarker marker = new RelativeMarker(markerNode);
         supportingMarkers.Add(marker);
     }
     autoReconfigure = false;
 }
Exemplo n.º 3
0
        private void SetupMarkerTracking()
        {
            IVideoCapture captureDevice = null;

            if (useStaticImage)
            {
                captureDevice = new NullCapture();
                captureDevice.InitVideoCapture(1, FrameRate._30Hz, Resolution._800x600,
                                               ImageFormat.R8G8B8_24, false);
                ((NullCapture)captureDevice).StaticImageFile = "MarkerImage";
            }
            else
            {
                // Create our video capture device that uses DirectShow library. Note that
                // the combinations of resolution and frame rate that are allowed depend on
                // the particular video capture device. Thus, setting incorrect resolution
                // and frame rate values may cause exceptions or simply be ignored, depending
                // on the device driver.  The values set here will work for a Microsoft VX 6000,
                // and many other webcams.
                captureDevice = new DirectShowCapture2();
                captureDevice.InitVideoCapture(0, FrameRate._30Hz, Resolution._640x480,
                                               ImageFormat.R8G8B8_24, false);
            }

            // Add this video capture device to the scene so that it can be used for
            // the marker tracker
            scene.AddVideoCaptureDevice(captureDevice);

            IMarkerTracker tracker = null;


            // Create an optical marker tracker that uses ALVAR library
            tracker = new ALVARMarkerTracker();
            ((ALVARMarkerTracker)tracker).MaxMarkerError = 0.02f;
            tracker.InitTracker(captureDevice.Width, captureDevice.Height, "calib.xml", 9.0);

            // Set the marker tracker to use for our scene
            scene.MarkerTracker = tracker;

            // Display the camera image in the background. Note that this parameter should
            // be set after adding at least one video capture device to the Scene class.
            scene.ShowCameraImage = true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a node that is tracked by fiducial marker (can be either an array or
        /// a single marker) and updated automatically.
        /// </summary>
        /// <param name="name">Name of this marker node</param>
        /// <param name="tracker">A marker tracker used to track this fiducial marker</param>
        /// <param name="markerConfigs">A list of configs that specify the fiducial marker
        /// (can be either an array or a single marker) to look for</param>
        public MarkerNode(String name, IMarkerTracker tracker, params Object[] markerConfigs)
            : base(name)
        {
            this.tracker = tracker;
            if (tracker != null)
            {
                markerID           = tracker.AssociateMarker(markerConfigs);
                this.markerConfigs = markerConfigs;
            }
            found       = false;
            maxDropouts = 5;
            prevMatrix  = Matrix.Identity;
            dropout     = 0;
            optimize    = false;

            smoother       = null;
            predictor      = null;
            smooth         = false;
            predict        = false;
            predictionTime = 0;

            inverseCameraView = Matrix.Identity;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a marker bundle node.
 /// </summary>
 /// <param name="tracker">A marker tracker used to track this fiducial marker</param>
 /// <param name="supportingMarkerNodes">A list of marker nodes that will supplement
 /// the base marker array</param>
 /// <param name="markerConfigs">A list of configs that specify the fiducial marker
 /// (can be either an array or a single marker) to look for</param>
 public MarkerBundleNode(IMarkerTracker tracker, List <MarkerNode> supportingMarkerNodes,
                         params object[] markerConfigs)
     : this("", tracker, supportingMarkerNodes, markerConfigs)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a marker bundle node.
 /// </summary>
 /// <param name="tracker">A marker tracker used to track this fiducial marker</param>
 /// <param name="supportingMarkerNodes">A list of marker nodes that will supplement
 /// the base marker array</param>
 /// <param name="markerConfigs">A list of configs that specify the fiducial marker 
 /// (can be either an array or a single marker) to look for</param>
 public MarkerBundleNode(IMarkerTracker tracker, List<MarkerNode> supportingMarkerNodes,
     params object[] markerConfigs)
     : this("", tracker, supportingMarkerNodes, markerConfigs)
 {
 }
Exemplo n.º 7
0
        /// <summary>
        /// Updates the current matrix of this marker node
        /// </summary>
        /// <param name="elapsedTime">Elapsed time from last update in milliseconds</param>
        public virtual void Update(float elapsedTime)
        {
            if (tracker == null && scene.MarkerTracker != null)
            {
                tracker  = scene.MarkerTracker;
                markerID = tracker.AssociateMarker(markerConfigs);
            }

            if (tracker != null && tracker.FindMarker(markerID))
            {
                Vector3    p      = new Vector3();
                Quaternion q      = Quaternion.Identity;
                Matrix     rawMat = tracker.GetMarkerTransform();

                if (smooth || predict)
                {
                    Vector3 scale;
                    rawMat.Decompose(out scale, out q, out p);
                }

                if (smooth)
                {
                    smoother.FilterMatrix(ref p, ref q, out worldTransformation);
                }
                else
                {
                    worldTransformation = rawMat;
                }

                if (isInverseViewSet)
                {
                    Matrix.Multiply(ref worldTransformation, ref inverseCameraView, out worldTransformation);
                }

                if (predict)
                {
                    predictionTime = 0;
                    predictor.UpdatePredictor(ref p, ref q);
                }

                prevMatrix = worldTransformation;
                dropout    = 0;
                found      = true;
            }
            else
            {
                if (maxDropouts < 0)
                {
                    worldTransformation = prevMatrix;
                    found = false;
                }
                else
                {
                    if (dropout < maxDropouts)
                    {
                        dropout++;
                        if (predict)
                        {
                            predictionTime += elapsedTime;
                            predictor.GetPrediction(predictionTime, out worldTransformation);
                        }
                        else
                        {
                            worldTransformation = prevMatrix;
                        }
                    }
                    else
                    {
                        found = false;
                        worldTransformation = MatrixHelper.Empty;
                    }
                }

                if (smooth)
                {
                    smoother.ResetHistory();
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a node that is tracked by fiducial marker (can be either an array or a single
 /// marker) and updated automatically.
 /// </summary>
 /// <param name="tracker">A marker tracker used to track this fiducial marker</param>
 /// <param name="markerConfigs">A list of configs that specify the fiducial marker
 /// (can be either an array or a single marker) to look for</param>
 public MarkerNode(IMarkerTracker tracker, params Object[] markerConfigs)
     :
     this("", tracker, markerConfigs)
 {
 }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a node that is tracked by fiducial marker (can be either an array or
        /// a single marker) and updated automatically.
        /// </summary>
        /// <param name="name">Name of this marker node</param>
        /// <param name="tracker">A marker tracker used to track this fiducial marker</param>
        /// <param name="markerConfigs">A list of configs that specify the fiducial marker 
        /// (can be either an array or a single marker) to look for</param>
        public MarkerNode(String name, IMarkerTracker tracker, params Object[] markerConfigs)
            : base(name)
        {
            this.tracker = tracker;
            if (tracker != null)
            {
                markerID = tracker.AssociateMarker(markerConfigs);
                this.markerConfigs = markerConfigs;
            }
            found = false;
            maxDropouts = 5;
            prevMatrix = Matrix.Identity;
            dropout = 0;
            optimize = false;

            smoother = null;
            predictor = null;
            smooth = false;
            predict = false;
            predictionTime = 0;

            inverseCameraView = Matrix.Identity;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Updates the current matrix of this marker node
        /// </summary>
        /// <param name="elapsedTime">Elapsed time from last update in milliseconds</param>
        public virtual void Update(float elapsedTime)
        {
            if (tracker == null && scene.MarkerTracker != null)
            {
                tracker = scene.MarkerTracker;
                markerID = tracker.AssociateMarker(markerConfigs);
            }

            if (tracker != null && tracker.FindMarker(markerID))
            {
                Vector3 p = new Vector3();
                Quaternion q = Quaternion.Identity;
                Matrix rawMat = tracker.GetMarkerTransform();

                if (smooth || predict)
                {
                    Vector3 scale;
                    rawMat.Decompose(out scale, out q, out p);
                }

                if (smooth)
                    smoother.FilterMatrix(ref p, ref q, out worldTransformation);
                else
                    worldTransformation = rawMat;

                if (isInverseViewSet)
                    Matrix.Multiply(ref worldTransformation, ref inverseCameraView, out worldTransformation);

                if (predict)
                {
                    predictionTime = 0;
                    predictor.UpdatePredictor(ref p, ref q);
                }

                prevMatrix = worldTransformation;
                dropout = 0;
                found = true;
            }
            else
            {
                if (maxDropouts < 0)
                {
                    worldTransformation = prevMatrix;
                    found = false;
                }
                else
                {
                    if (dropout < maxDropouts)
                    {
                        dropout++;
                        if (predict)
                        {
                            predictionTime += elapsedTime;
                            predictor.GetPrediction(predictionTime, out worldTransformation);
                        }
                        else
                            worldTransformation = prevMatrix;
                    }
                    else
                    {
                        found = false;
                        worldTransformation = MatrixHelper.Empty;
                    }
                }

                if (smooth)
                    smoother.ResetHistory();
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Creates a node that is tracked by fiducial marker (can be either an array or a single
 /// marker) and updated automatically.
 /// </summary>
 /// <param name="tracker">A marker tracker used to track this fiducial marker</param>
 /// <param name="markerConfigs">A list of configs that specify the fiducial marker 
 /// (can be either an array or a single marker) to look for</param>
 public MarkerNode(IMarkerTracker tracker, params Object[] markerConfigs)
     :
     this("", tracker, markerConfigs) { }