public FindDisplay() { // create glyph database for 5x5 glyphs var glyphDatabase = new GlyphDatabase(5); try { using (var stream = new StreamReader("Resources/TagDefinitions.txt")) { String line; do { line = stream.ReadLine(); if (line != null) { var tokens = line.Split(' '); var tagId = tokens[0]; var code = tokens[1]; var matrix = new byte[5, 5]; var i = 0; for (var y = 0; y < 5; y++) { for (var x = 0; x < 5; x++) { matrix[y, x] = byte.Parse(code.Substring(i++, 1)); } } glyphDatabase.Add(new Glyph(tagId, matrix)); } } while (line != null); } _glyphRecognizer = new GlyphRecognizer(glyphDatabase) { MaxNumberOfGlyphsToSearch = 1 }; _glyphTable = new GlyphMetadata[glyphDatabase.Count]; PropertyChanged += (s, e) => { switch (e.PropertyName) { case MinFramesPropertyName: _glyphTable = new GlyphMetadata[glyphDatabase.Count]; break; } }; } catch (Exception e) { LogFormat(e + e.Message + e.StackTrace); } }
public GlyphDecoder() { // create glyph database for 5x5 glyphs GlyphDatabase glyphDatabase = new GlyphDatabase(5); try { using (StreamReader sr = new StreamReader("Resources/TagDefinitions.txt")) { String line; do { line = sr.ReadLine(); if (line != null) { var tokens = line.Split(' '); var tagID = tokens[0]; var code = tokens[1]; var matrix = new byte[5, 5]; int i = 0; for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) { matrix[y, x] = byte.Parse(code.Substring(i++, 1)); } } glyphDatabase.Add(new Glyph(tagID, matrix)); } } while (line != null); } _glyphRecognizer = new GlyphRecognizer(glyphDatabase); _glyphRecognizer.MaxNumberOfGlyphsToSearch = GLYPHSTOSEARCHFOR; PropertyChanged += (s, e) => { switch (e.PropertyName) { case MinFramesPropertyName: _glyphTable = new GlyphMetadata[GLYPHCOUNT]; break; } }; } catch (Exception e) { LogFormat(e + e.Message + e.StackTrace); } }
public MainWindow() { InitializeComponent(); GlyphDatabase glyphDatabase = new GlyphDatabase(5); glyphDatabase.Add(new Glyph("Glider", new byte[, ] { { 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 0 }, { 0, 1, 1, 0, 0 }, { 0, 0, 1, 1, 0 }, { 0, 0, 0, 0, 0 }, })); _glyphRecognizer = new GlyphRecognizer(5); _glyphRecognizer.GlyphDatabase = glyphDatabase; InitializeCapturer(); InitializeComboBox_Webcams(); if (ComboBox_Webcams.Items.Count > 0) { ComboBox_Webcams.SelectedIndex = 0; } }
// Used to create the glyphs and the GRATF glyph recognizer private void CreateGlyphRecognizer() { GlyphDatabase glyphDatabase = new GlyphDatabase(5); // Create glyph database for 5x5 glyphs. Ones represent white squares, 0 black. // Note that the ID needs to match the name of the robot glyphDatabase.Add(new Glyph("0", new byte[5, 5] { { 0, 0, 0, 0, 0 }, { 0, 1, 0, 1, 0 }, { 0, 0, 1, 0, 0 }, { 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 0 } })); glyphDatabase.Add(new Glyph("1", new byte[5, 5] { { 0, 0, 0, 0, 0 }, { 0, 1, 1, 0, 0 }, { 0, 0, 1, 1, 0 }, { 0, 1, 1, 0, 0 }, { 0, 0, 0, 0, 0 } })); glyphDatabase.Add(new Glyph("2", new byte[5, 5] { { 0, 0, 0, 0, 0 }, { 0, 1, 1, 0, 0 }, { 0, 0, 1, 0, 0 }, { 0, 1, 0, 1, 0 }, { 0, 0, 0, 0, 0 } })); glyphDatabase.Add(new Glyph("3", new byte[5, 5] { { 0, 0, 0, 0, 0 }, { 0, 1, 1, 0, 0 }, { 0, 0, 1, 1, 0 }, { 0, 0, 1, 0, 0 }, { 0, 0, 0, 0, 0 } })); glyphDatabase.Add(new Glyph("4", new byte[5, 5] { { 0, 0, 0, 0, 0 }, { 0, 1, 1, 1, 0 }, { 0, 0, 1, 0, 0 }, { 0, 1, 0, 1, 0 }, { 0, 0, 0, 0, 0 } })); glyphDatabase.Add(new Glyph("5", new byte[5, 5] { { 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 0 }, { 0, 1, 1, 1, 0 }, { 0, 0, 1, 1, 0 }, { 0, 0, 0, 0, 0 } })); glyphDatabase.Add(new Glyph("6", new byte[5, 5] { { 0, 0, 0, 0, 0 }, { 0, 1, 1, 0, 0 }, { 0, 1, 0, 1, 0 }, { 0, 0, 1, 0, 0 }, { 0, 0, 0, 0, 0 } })); glyphDatabase.Add(new Glyph("7", new byte[5, 5] { { 0, 0, 0, 0, 0 }, { 0, 0, 1, 1, 0 }, { 0, 1, 1, 0, 0 }, { 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 0 } })); glyphDatabase.Add(new Glyph("8", new byte[5, 5] { { 0, 0, 0, 0, 0 }, { 0, 1, 1, 1, 0 }, { 0, 1, 0, 0, 0 }, { 0, 1, 0, 1, 0 }, { 0, 0, 0, 0, 0 } })); glyphDatabase.Add(new Glyph("9", new byte[5, 5] { { 0, 0, 0, 0, 0 }, { 0, 1, 0, 0, 0 }, { 0, 0, 0, 1, 0 }, { 0, 0, 1, 0, 0 }, { 0, 0, 0, 0, 0 } })); recognizer = new GlyphRecognizer(glyphDatabase); recognizer.MaxNumberOfGlyphsToSearch = glyphDatabase.Count; }
public GlyphImageProcessor(GlyphDatabase database) { _recognizer = new GlyphRecognizer(database); }
public GlyphImageProcessor(int size) { recognizer = new GlyphRecognizer(size); GlyphVisualizationData visualizationData; byte[,] data; GlyphDatabase gDB = new GlyphDatabase(5); if (size == 5) { #region Monitors //Monitor 1 data = new byte[5, 5]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 1; data[1, 3] = 0; data[1, 4] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 1; data[2, 3] = 0; data[2, 4] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 0; data[3, 3] = 1; data[3, 4] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; Glyph S1 = new Glyph("Monitor1", data); visualizationData = new GlyphVisualizationData(Color.Red); S1.UserData = visualizationData; //Monitor 2 data = new byte[5, 5]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 0; data[1, 3] = 1; data[1, 4] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 1; data[2, 3] = 0; data[2, 4] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 0; data[3, 3] = 1; data[3, 4] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; Glyph S2 = new Glyph("Monitor2", data); visualizationData = new GlyphVisualizationData(Color.Red); S2.UserData = visualizationData; //Monitor 3 data = new byte[5, 5]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 0; data[1, 3] = 0; data[1, 4] = 0; data[2, 0] = 0; data[2, 1] = 1; data[2, 2] = 1; data[2, 3] = 0; data[2, 4] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 0; data[3, 3] = 1; data[3, 4] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; Glyph S3 = new Glyph("Monitor3", data); visualizationData = new GlyphVisualizationData(Color.Red); S3.UserData = visualizationData; //Monitor 4 data = new byte[5, 5]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 1; data[1, 3] = 1; data[1, 4] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 1; data[2, 3] = 0; data[2, 4] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 0; data[3, 3] = 1; data[3, 4] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; Glyph S4 = new Glyph("Monitor4", data); visualizationData = new GlyphVisualizationData(Color.Red); S4.UserData = visualizationData; //Monitor 5 data = new byte[5, 5]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 0; data[1, 3] = 1; data[1, 4] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 1; data[2, 3] = 1; data[2, 4] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 0; data[3, 3] = 1; data[3, 4] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; Glyph S5 = new Glyph("Monitor5", data); visualizationData = new GlyphVisualizationData(Color.Red); S5.UserData = visualizationData; //Monitor 6 data = new byte[5, 5]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 0; data[1, 3] = 1; data[1, 4] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 1; data[2, 3] = 1; data[2, 4] = 0; data[3, 0] = 0; data[3, 1] = 1; data[3, 2] = 0; data[3, 3] = 1; data[3, 4] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; Glyph S6 = new Glyph("Monitor6", data); visualizationData = new GlyphVisualizationData(Color.Red); S6.UserData = visualizationData; //Monitor 7 data = new byte[5, 5]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 0; data[1, 3] = 1; data[1, 4] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 1; data[2, 3] = 0; data[2, 4] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 0; data[3, 3] = 1; data[3, 4] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; Glyph S7 = new Glyph("Monitor7", data); visualizationData = new GlyphVisualizationData(Color.Red); S7.UserData = visualizationData; //Monitor 8 data = new byte[5, 5]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 1; data[1, 3] = 1; data[1, 4] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 0; data[2, 3] = 1; data[2, 4] = 0; data[3, 0] = 0; data[3, 1] = 1; data[3, 2] = 1; data[3, 3] = 1; data[3, 4] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; Glyph S8 = new Glyph("Monitor8", data); visualizationData = new GlyphVisualizationData(Color.Red); S8.UserData = visualizationData; //Monitor 9 data = new byte[5, 5]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[1, 0] = 0; data[1, 1] = 0; data[1, 2] = 1; data[1, 3] = 0; data[1, 4] = 0; data[2, 0] = 0; data[2, 1] = 1; data[2, 2] = 0; data[2, 3] = 1; data[2, 4] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 1; data[3, 3] = 1; data[3, 4] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; Glyph S9 = new Glyph("Monitor9", data); visualizationData = new GlyphVisualizationData(Color.Red); S9.UserData = visualizationData; //Monitor 10 data = new byte[5, 5]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 1; data[1, 3] = 1; data[1, 4] = 0; data[2, 0] = 0; data[2, 1] = 1; data[2, 2] = 0; data[2, 3] = 0; data[2, 4] = 0; data[3, 0] = 0; data[3, 1] = 1; data[3, 2] = 0; data[3, 3] = 1; data[3, 4] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; Glyph S10 = new Glyph("Monitor10", data); visualizationData = new GlyphVisualizationData(Color.Red); S10.UserData = visualizationData; #endregion Monitors #region Roomba glyph //Roomba data = new byte[5, 5]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 0; data[1, 3] = 1; data[1, 4] = 0; data[2, 0] = 0; data[2, 1] = 1; data[2, 2] = 1; data[2, 3] = 1; data[2, 4] = 0; data[3, 0] = 0; data[3, 1] = 1; data[3, 2] = 1; data[3, 3] = 1; data[3, 4] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; Glyph roomba = new Glyph("Roomba", data); visualizationData = new GlyphVisualizationData(Color.Yellow); roomba.UserData = visualizationData; #endregion Roomba glyph gDB = new GlyphDatabase(5); gDB.Add(S1); gDB.Add(S2); gDB.Add(S3); gDB.Add(S4); gDB.Add(S5); gDB.Add(S6); gDB.Add(S7); gDB.Add(S8); gDB.Add(S9); gDB.Add(S10); gDB.Add(roomba); } else if (size == 6) { Color MarkerColor = Color.GreenYellow; #region Objects 6*6 glype data = new byte[6, 6]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[0, 5] = 0; data[1, 0] = 0; data[1, 1] = 0; data[1, 2] = 1; data[1, 3] = 0; data[1, 4] = 1; data[1, 5] = 0; data[2, 0] = 0; data[2, 1] = 1; data[2, 2] = 0; data[2, 3] = 1; data[2, 4] = 0; data[2, 5] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 1; data[3, 3] = 0; data[3, 4] = 1; data[3, 5] = 0; data[4, 0] = 0; data[4, 1] = 1; data[4, 2] = 0; data[4, 3] = 1; data[4, 4] = 1; data[4, 5] = 0; data[5, 0] = 0; data[5, 1] = 0; data[5, 2] = 0; data[5, 3] = 0; data[5, 4] = 0; data[5, 5] = 0; Glyph o1 = new Glyph("Marker_6_1", data); visualizationData = new GlyphVisualizationData(MarkerColor); o1.UserData = visualizationData; data = new byte[6, 6]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[0, 5] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 0; data[1, 3] = 0; data[1, 4] = 1; data[1, 5] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 0; data[2, 3] = 1; data[2, 4] = 0; data[2, 5] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 1; data[3, 3] = 0; data[3, 4] = 1; data[3, 5] = 0; data[4, 0] = 0; data[4, 1] = 1; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 1; data[4, 5] = 0; data[5, 0] = 0; data[5, 1] = 0; data[5, 2] = 0; data[5, 3] = 0; data[5, 4] = 0; data[5, 5] = 0; Glyph o2 = new Glyph("Marker_6_2", data); visualizationData = new GlyphVisualizationData(MarkerColor); o2.UserData = visualizationData; data = new byte[6, 6]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[0, 5] = 0; data[1, 0] = 0; data[1, 1] = 0; data[1, 2] = 1; data[1, 3] = 1; data[1, 4] = 0; data[1, 5] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 1; data[2, 3] = 0; data[2, 4] = 1; data[2, 5] = 0; data[3, 0] = 0; data[3, 1] = 1; data[3, 2] = 0; data[3, 3] = 0; data[3, 4] = 0; data[3, 5] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 1; data[4, 3] = 1; data[4, 4] = 0; data[4, 5] = 0; data[5, 0] = 0; data[5, 1] = 0; data[5, 2] = 0; data[5, 3] = 0; data[5, 4] = 0; data[5, 5] = 0; Glyph o3 = new Glyph("Marker_6_3", data); visualizationData = new GlyphVisualizationData(MarkerColor); o3.UserData = visualizationData; data = new byte[6, 6]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[0, 5] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 0; data[1, 3] = 1; data[1, 4] = 0; data[1, 5] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 1; data[2, 3] = 1; data[2, 4] = 0; data[2, 5] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 1; data[3, 3] = 1; data[3, 4] = 0; data[3, 5] = 0; data[4, 0] = 0; data[4, 1] = 1; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 1; data[4, 5] = 0; data[5, 0] = 0; data[5, 1] = 0; data[5, 2] = 0; data[5, 3] = 0; data[5, 4] = 0; data[5, 5] = 0; Glyph o4 = new Glyph("Marker_6_4", data); visualizationData = new GlyphVisualizationData(MarkerColor); o4.UserData = visualizationData; data = new byte[6, 6]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[0, 5] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 0; data[1, 3] = 0; data[1, 4] = 1; data[1, 5] = 0; data[2, 0] = 0; data[2, 1] = 1; data[2, 2] = 1; data[2, 3] = 0; data[2, 4] = 1; data[2, 5] = 0; data[3, 0] = 0; data[3, 1] = 1; data[3, 2] = 0; data[3, 3] = 1; data[3, 4] = 0; data[3, 5] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 1; data[4, 5] = 0; data[5, 0] = 0; data[5, 1] = 0; data[5, 2] = 0; data[5, 3] = 0; data[5, 4] = 0; data[5, 5] = 0; Glyph o5 = new Glyph("Marker_6_5", data); visualizationData = new GlyphVisualizationData(MarkerColor); o5.UserData = visualizationData; data = new byte[6, 6]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[0, 5] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 0; data[1, 3] = 0; data[1, 4] = 1; data[1, 5] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 0; data[2, 3] = 1; data[2, 4] = 1; data[2, 5] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 1; data[3, 3] = 0; data[3, 4] = 1; data[3, 5] = 0; data[4, 0] = 0; data[4, 1] = 1; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; data[4, 5] = 0; data[5, 0] = 0; data[5, 1] = 0; data[5, 2] = 0; data[5, 3] = 0; data[5, 4] = 0; data[5, 5] = 0; Glyph o6 = new Glyph("Marker_6_6", data); visualizationData = new GlyphVisualizationData(MarkerColor); o6.UserData = visualizationData; data = new byte[6, 6]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[0, 5] = 0; data[1, 0] = 0; data[1, 1] = 0; data[1, 2] = 1; data[1, 3] = 0; data[1, 4] = 0; data[1, 5] = 0; data[2, 0] = 0; data[2, 1] = 1; data[2, 2] = 1; data[2, 3] = 1; data[2, 4] = 0; data[2, 5] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 0; data[3, 3] = 1; data[3, 4] = 1; data[3, 5] = 0; data[4, 0] = 0; data[4, 1] = 1; data[4, 2] = 0; data[4, 3] = 0; data[4, 4] = 0; data[4, 5] = 0; data[5, 0] = 0; data[5, 1] = 0; data[5, 2] = 0; data[5, 3] = 0; data[5, 4] = 0; data[5, 5] = 0; Glyph o7 = new Glyph("Marker_6_7", data); visualizationData = new GlyphVisualizationData(MarkerColor); o7.UserData = visualizationData; data = new byte[6, 6]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[0, 5] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 1; data[1, 3] = 0; data[1, 4] = 0; data[1, 5] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 1; data[2, 3] = 0; data[2, 4] = 0; data[2, 5] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 1; data[3, 3] = 1; data[3, 4] = 1; data[3, 5] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 1; data[4, 3] = 0; data[4, 4] = 0; data[4, 5] = 0; data[5, 0] = 0; data[5, 1] = 0; data[5, 2] = 0; data[5, 3] = 0; data[5, 4] = 0; data[5, 5] = 0; Glyph o8 = new Glyph("Marker_6_8", data); visualizationData = new GlyphVisualizationData(MarkerColor); o8.UserData = visualizationData; data = new byte[6, 6]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[0, 5] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 0; data[1, 3] = 0; data[1, 4] = 1; data[1, 5] = 0; data[2, 0] = 0; data[2, 1] = 0; data[2, 2] = 1; data[2, 3] = 1; data[2, 4] = 0; data[2, 5] = 0; data[3, 0] = 0; data[3, 1] = 1; data[3, 2] = 0; data[3, 3] = 1; data[3, 4] = 0; data[3, 5] = 0; data[4, 0] = 0; data[4, 1] = 0; data[4, 2] = 1; data[4, 3] = 0; data[4, 4] = 1; data[4, 5] = 0; data[5, 0] = 0; data[5, 1] = 0; data[5, 2] = 0; data[5, 3] = 0; data[5, 4] = 0; data[5, 5] = 0; Glyph o9 = new Glyph("Marker_6_9", data); visualizationData = new GlyphVisualizationData(MarkerColor); o9.UserData = visualizationData; data = new byte[6, 6]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[0, 5] = 0; data[1, 0] = 0; data[1, 1] = 0; data[1, 2] = 1; data[1, 3] = 0; data[1, 4] = 1; data[1, 5] = 0; data[2, 0] = 0; data[2, 1] = 1; data[2, 2] = 1; data[2, 3] = 1; data[2, 4] = 1; data[2, 5] = 0; data[3, 0] = 0; data[3, 1] = 0; data[3, 2] = 1; data[3, 3] = 1; data[3, 4] = 0; data[3, 5] = 0; data[4, 0] = 0; data[4, 1] = 1; data[4, 2] = 0; data[4, 3] = 1; data[4, 4] = 1; data[4, 5] = 0; data[5, 0] = 0; data[5, 1] = 0; data[5, 2] = 0; data[5, 3] = 0; data[5, 4] = 0; data[5, 5] = 0; Glyph o10 = new Glyph("Marker_6_10", data); visualizationData = new GlyphVisualizationData(MarkerColor); o10.UserData = visualizationData; data = new byte[6, 6]; data[0, 0] = 0; data[0, 1] = 0; data[0, 2] = 0; data[0, 3] = 0; data[0, 4] = 0; data[0, 5] = 0; data[1, 0] = 0; data[1, 1] = 1; data[1, 2] = 0; data[1, 3] = 0; data[1, 4] = 1; data[1, 5] = 0; data[2, 0] = 0; data[2, 1] = 1; data[2, 2] = 0; data[2, 3] = 0; data[2, 4] = 1; data[2, 5] = 0; data[3, 0] = 0; data[3, 1] = 1; data[3, 2] = 0; data[3, 3] = 0; data[3, 4] = 1; data[3, 5] = 0; data[4, 0] = 0; data[4, 1] = 1; data[4, 2] = 1; data[4, 3] = 1; data[4, 4] = 1; data[4, 5] = 0; data[5, 0] = 0; data[5, 1] = 0; data[5, 2] = 0; data[5, 3] = 0; data[5, 4] = 0; data[5, 5] = 0; Glyph o11 = new Glyph("Marker_6_11", data); visualizationData = new GlyphVisualizationData(MarkerColor); o11.UserData = visualizationData; #endregion objects 6*6 glyph gDB = new GlyphDatabase(6); gDB.Add(o1); gDB.Add(o2); gDB.Add(o3); gDB.Add(o4); gDB.Add(o5); gDB.Add(o6); gDB.Add(o7); gDB.Add(o8); gDB.Add(o9); gDB.Add(o10); gDB.Add(o11); } GlyphDatabase = gDB; }
void camera_NewFrame(object sender, NewFrameEventArgs eventArgs) { float sizeHalf = 113.0f / 2; Vector3[] glyphModel = new Vector3[] { new Vector3(-sizeHalf, 0, sizeHalf), new Vector3(sizeHalf, 0, sizeHalf), new Vector3(sizeHalf, 0, -sizeHalf), new Vector3(-sizeHalf, 0, -sizeHalf), }; try { GlyphRecognizer gr = new GlyphRecognizer(glyphDatabase); List <ExtractedGlyphData> glyphs = gr.FindGlyphs(eventArgs.Frame); System.Drawing.Image img = (Bitmap)eventArgs.Frame.Clone(); double x = 0; double y = 0; String glyphName = String.Empty; AForge.Point[] glyphPoints = new AForge.Point[4]; foreach (var glyph in glyphs) { if (glyph.RecognizedGlyph != null) { glyphName = glyph.RecognizedGlyph.Name; x = (glyph.Quadrilateral[0].X + glyph.Quadrilateral[2].X) / 2; y = (glyph.Quadrilateral[0].Y + glyph.Quadrilateral[2].Y) / 2; for (int i = 0; i < 4; i++) { glyphPoints[i] = new AForge.Point( (int)(glyph.RecognizedQuadrilateral[i].X - x), (int)y - glyph.RecognizedQuadrilateral[i].Y); } break; } } MemoryStream ms = new MemoryStream(); img.Save(ms, ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); bi.Freeze(); Dispatcher.BeginInvoke(new ThreadStart(delegate { //Canvas.SetLeft(pictureGlyph, x-60); //Canvas.SetTop(pictureGlyph, y-60); image1.Source = bi; Title = "Found glyphs " + glyphs.Count + " " + glyphName; if (glyphName != "") { Dispatcher.BeginInvoke(new ThreadStart(delegate { Console.WriteLine(MODEL_PATH); MODEL_PATH = CurrentGallery.UrlPrefix + "\\" + glyphName + ".3ds"; float yaw, pitch, roll; CoplanarPosit posit = new CoplanarPosit(glyphModel, 1); Matrix3x3 positRotation; Vector3 positTranslation; posit.EstimatePose(glyphPoints, out positRotation, out positTranslation); positRotation.ExtractYawPitchRoll(out yaw, out pitch, out roll); visualisation3Dmodel(MODEL_PATH, yaw, pitch, roll, new Vector3D(positTranslation.X, positTranslation.Y, positTranslation.Z)); })); } })); } catch (Exception ex) { MessageBox.Show(ex.Message); } }