This project is read-only.

Which marker is lost in the layout of markers?

Apr 18, 2011 at 5:21 PM

Do we have a way (function/attributes) to know which marker is lost among the layout of markers?

Let say I have 4 markers in the custom marker layout generated from Markerlayout tool, how do I know which marker is lost during the tracking?

Many thanks

Apr 18, 2011 at 9:51 PM

Well, I think i got it from one of ohan's post in this forum at http://goblinxna.codeplex.com/discussions/237183.

Thanks

Truyen

Apr 19, 2011 at 1:02 AM

Each MarkerNode has an IsFound or something like that.

 

Do know which individual marker node is missing (not detected), you'd need to create a markerNode using the IDs (identification numbers) for each marker..so for 4 markers you'd need 4 marker nodes.

 

In your update() method, check the isFound (or found or whatever)

Apr 19, 2011 at 4:14 AM

// Load ALVAR marker IDs from XML file
var alvarMarkerIds = GetDataFromXml(xmlFileName, out scale, out Dimensions);

// Register ALVAR marker IDs with tracker and get tracker IDs
int[] trackerIds = new int[alvarMarkerIds.Length];
for (var i = 0; i < alvarMarkerIds.Length; i++)
   trackerIds[i] = (int)tracker.AssociateMarker(alvarMarkerIds[i]);

// Count found markers using LINQ
var foundMarkerCount = trackerIds.Sum(t => tracker.FindMarker(t) ? 1 : 0);

// Convert to percentage
var multiMarkerFoundPercentage = (float) foundMarkerCount/trackerIds.Length;

// Function to load ALVAR markerIds from an ALVAR XML config file
private static int[] GetDataFromXml(string filename, out float scale, out Vector4 dimensions)
{
    var list = new List<int>();
    var corners = new List<Vector3>();
            
    var reader =
        new XmlTextReader(filename)
        {
            WhitespaceHandling = WhitespaceHandling.Significant
        };

    while (reader.Read())
    {
        if (reader.NodeType != XmlNodeType.Element) continue;

        if (reader.Name.Equals("marker"))
        {
            if (!reader.HasAttributes) continue;

            reader.MoveToFirstAttribute();

            do
            {
                if (!reader.Name.Equals("index")) continue;

                list.Add(int.Parse(reader.Value));
                break;
            }
            while (reader.MoveToNextAttribute());

            reader.MoveToElement();
        }
        else if (reader.Name.Equals("corner"))
        {
            if (!reader.HasAttributes) continue;

            var v = new Vector3();

            reader.MoveToFirstAttribute();

            do
            {
                if (reader.Name.Equals("x"))
                    v.X = float.Parse(reader.Value);
                else if (reader.Name.Equals("y"))
                    v.Y = float.Parse(reader.Value);
                else if (reader.Name.Equals("z"))
                    v.Z = float.Parse(reader.Value);
            }
            while (reader.MoveToNextAttribute());

            corners.Add(v);

            reader.MoveToElement();
        }
    }

    var minX = corners.Min(v => v.X);
    var minY = corners.Min(v => v.Y);
    var maxX = corners.Max(v => v.X);
    var maxY = corners.Max(v => v.Y);
    var width = maxX - minX;
    var height = maxY - minY;

    var singleMarker = corners.GetRange(0, 4);

    scale = singleMarker.Max(v => v.X) - singleMarker.Min(v => v.X);

    dimensions = new Vector4((maxX + minX)/2, (maxY + minY)/2, width, height);

    return list.ToArray();
}