public void ReadsCharactersWithLotsOfWhitespaceAbove() { var ocr = new OCRReader(new OCRSplitter()); var alphabet = new Dictionary <string, byte[, ]> { { ".", new byte[, ] { { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 1 } } } }; var text = new byte[, ] { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 1, 0 } }; Assert.AreEqual(".", ocr.ReadTableRow(text, alphabet)); }
public void ReadsResearchTableInWindow() { var screenshot = new HijackableScreenShotCapturer(); var inputDevice = new ResearchTableInWindowInputDevice(screenshot); var screen = new Screen(new ScreenDataRetriever(Substitute.For <ISleeper>(), screenshot)); var window = new Control(screen, inputDevice, 5, 1000, 5, 1000); var ocr = new OCRReader(new OCRSplitter()); var datagrid = new Datagrid(window, inputDevice, ocr, 521, 568, new[] { 370, 652, 718 }) { LineHeight = 16, TopOfCharactersOffset = 3 }; var table = datagrid.GetTable(); Assert.AreEqual(3, table.Count); Assert.AreEqual("GenomeSequenceResearch", table[0][0]); Assert.AreEqual("TerraformingModule", table[1][0]); Assert.AreEqual("TerraformingRate0.0012atm", table[2][0]); Assert.AreEqual("5000", table[0][1]); Assert.AreEqual("5000", table[1][1]); Assert.AreEqual("3000", table[2][1]); }
public void ReadsActualResearchTableOnLargeScreen() { var windowFinder = Substitute.For <IWindowFinder>(); windowFinder.GetWindowHandle(Arg.Any <string>()).Returns(IntPtr.Zero); windowFinder.GetDimensions(IntPtr.Zero).Returns(new NativeMethods.RECT { Bottom = 1224, Left = 500, Right = 1751, Top = 300 }); var screenshot = new HijackableScreenShotCapturer(); var inputDevice = new ActualResearchTableOnScreenInputDevice(screenshot); var screen = new Screen(new ScreenDataRetriever(Substitute.For <ISleeper>(), screenshot)); var ocr = new OCRReader(new OCRSplitter()); var settings = Substitute.For <ISettingsStore>(); settings.HorizontalWindowOffset.Returns(5); settings.VerticalWindowOffset.Returns(5); var window = new PopulationAndProductionWindow(screen, windowFinder, inputDevice, ocr, settings); var table = window.ResearchTable.GetTable(); Assert.AreEqual(13, table.Count); Assert.AreEqual("GenomeSequenceResearch", table[0][0]); Assert.AreEqual("TerraformingModule", table[1][0]); Assert.AreEqual("TerraformingRate0.0012atm", table[2][0]); Assert.AreEqual("5000", table[0][1]); Assert.AreEqual("5000", table[1][1]); Assert.AreEqual("3000", table[2][1]); }
public void ReadsRealCharactersWithDropCharacters() { var ocr = new OCRReader(new OCRSplitter()); var colors = new[] { new byte[] { 0, 0, 0 } }; Assert.AreEqual("CivilianMiningColonies", ocr.ReadTableRow(Read(Properties.Resources.ocr_CivilianMiningColonies, colors), OCRReader.Alphabet)); Assert.AreEqual("Terraforminglnstallations", ocr.ReadTableRow(Read(Properties.Resources.ocr_TerraformingInstallations, colors), OCRReader.Alphabet)); }
public void ReadsUncomplicatedRealCharacters() { var ocr = new OCRReader(new OCRSplitter()); var colors = new[] { new byte[] { 0, 0, 0 } }; Assert.AreEqual("Demand", ocr.ReadTableRow(Read(Properties.Resources.ocr_Demand, colors), OCRReader.Alphabet)); Assert.AreEqual("MannedMines", ocr.ReadTableRow(Read(Properties.Resources.ocr_MannedMines, colors), OCRReader.Alphabet)); }
public void ReadsRealCharactersWithSideBySideDropCharacters() { var ocr = new OCRReader(new OCRSplitter()); var colors = new[] { new byte[] { 0, 0, 0 } }; Assert.AreEqual("ManageShipyards", ocr.ReadTableRow(Read(Properties.Resources.ocr_ManageShipyards, colors), OCRReader.Alphabet)); Assert.AreEqual("lnstallationType", ocr.ReadTableRow(Read(Properties.Resources.ocr_InstallationType, colors), OCRReader.Alphabet)); }
public void CorrectlyReadsSamplePopulatedSystemsSimpleViewTreeList() { var screenshot = new HijackableScreenShotCapturer(); var inputDevice = new SimpleViewInputDevice(screenshot); var screen = new Screen(new ScreenDataRetriever(Substitute.For <ISleeper>(), screenshot)); var ocrReader = new OCRReader(new OCRSplitter()); var treelist = new TreeList(screen, inputDevice, ocrReader, 0, 707, 0, 340); Assert.AreEqual("+PopulatedSystems\n +Sol(500m)\n +Earth-Human(Capital):500m\n", treelist.Text); }
public void CorrectlyReadsSamplePopulatedSystemsCategoriesViewTreeList() { var screenshot = new HijackableScreenShotCapturer(); var inputDevice = new CategoriesViewInputDevice(screenshot); var screen = new Screen(new ScreenDataRetriever(Substitute.For <ISleeper>(), screenshot)); var ocrReader = new OCRReader(new OCRSplitter()); var treelist = new TreeList(screen, inputDevice, ocrReader, 0, 707, 0, 340); Assert.AreEqual("+PopulatedSystems\n+AutomatedMiningColonies\n+CivilianMiningColonies\n+ListeningPosts\n+ArcheologicalDigs\n+TerraformingSites\n+OtherColonies\n", treelist.Text); }
public void CorrectlyReadsEmptyTreeList() { var screenshot = new HijackableScreenShotCapturer(); var inputDevice = new EmptyViewInputDevice(screenshot); var screen = new Screen(new ScreenDataRetriever(Substitute.For <ISleeper>(), screenshot)); var ocrReader = new OCRReader(new OCRSplitter()); var treelist = new TreeList(screen, inputDevice, ocrReader, 0, 707, 0, 340); Assert.AreEqual("No children.\n", treelist.Text); }
public void ReadsInstallationTypeLabelShrunkWrapToText() { var screenshot = new HijackableScreenShotCapturer(); var inputDevice = new CivilianTabInputDevice(screenshot); var screen = new Screen(new ScreenDataRetriever(Substitute.For <ISleeper>(), screenshot)); var ocrReader = new OCRReader(new OCRSplitter()); var label = new Label(screen, inputDevice, ocrReader, 183, 193, 412, 488); Assert.AreEqual("lnstallationType", label.Text); }
public void ReadsInstallationTypeLabelWithExtraSpaceOnSidesAndBelow() { var screenshot = new HijackableScreenShotCapturer(); var inputDevice = new CivilianTabInputDevice(screenshot); var screen = new Screen(new ScreenDataRetriever(Substitute.For <ISleeper>(), screenshot)); var ocrReader = new OCRReader(new OCRSplitter()); var label = new Label(screen, inputDevice, ocrReader, 183, 200, 406, 495); Assert.AreEqual("lnstallationType", label.Text); }
public void ReadsUncomplicatedCharacters() { var ocr = new OCRReader(new OCRSplitter()); var alphabet = new Dictionary <string, byte[, ]> { { "1", new byte[, ] { { 1, 1, 0 }, { 0, 1, 0 }, { 1, 1, 1 } } } }; var colors = new[] { new byte[] { 0, 0, 0 } }; Assert.AreEqual("", ocr.ReadTableRow(Read(Properties.Resources.ocr_ones, colors), alphabet)); Assert.AreEqual("11111", ocr.ReadTableRow(Read(Properties.Resources.ocr_onesclean, colors), alphabet)); }
public void ReadsTwoOfSameCharacter() { var ocr = new OCRReader(new OCRSplitter()); var alphabet = new Dictionary <string, byte[, ]> { { "1", new byte[, ] { { 1, 1, 0 }, { 0, 1, 0 }, { 1, 1, 1 } } } }; var text = new byte[, ] { { 1, 1, 0, 0, 1, 1, 0, 0 }, { 0, 1, 0, 0, 0, 1, 0, 0 }, { 1, 1, 1, 0, 1, 1, 1, 0 } }; Assert.AreEqual("11", ocr.ReadTableRow(text, alphabet)); }
public void DoesNotReadForcedWhitespace() { var ocr = new OCRReader(new OCRSplitter()); var alphabet = new Dictionary <string, byte[, ]> { { ".", new byte[, ] { { 0, 0, 0 }, { 0, 0, 0 }, { 1, 0, 0 } } } }; var text = new byte[, ] { { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 0, 0, 0, 1, 0, 0, 0, 0 } }; Assert.AreEqual("", ocr.ReadTableRow(text, alphabet)); }
public void ReadsTheWordGenomeWithExtraneousSpaces() { var ocr = new OCRReader(new OCRSplitter()); var pixels = new byte[, ] { { 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 0, 0, 0,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0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; Assert.AreEqual("Genome", ocr.ReadTableRow(pixels, OCRReader.Alphabet)); }
public void ReadsVeryLongLines() { var ocr = new OCRReader(new OCRSplitter()); var alphabet = new Dictionary <string, byte[, ]> { { "_", new byte[, ] { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } } } }; var text = new byte[, ] { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 } }; Assert.AreEqual("_", ocr.ReadTableRow(text, alphabet)); }
private void button1_Click(object sender, EventArgs e) { int[] RGB; if (checkBox1.Checked) { RGB = new[] { 255, 255, 255 }; } else { RGB = new[] { 0, 0, 0 }; } _font = OCRFont.Load(button2.Text); _reader = new OCRReader(_font, Color.FromArgb(RGB[0], RGB[1], RGB[2]), checkBox1.Checked ? true : false); if ((_font == null) || (pictureBox1.Image == null)) { MessageBox.Show("Выберите изображение и шрифт"); return; } var d = DateTime.Now; var img = (Bitmap)pictureBox1.Image; Bitmap s; textBox1.Text = _reader.Recognize(ref img, out s); pictureBox2.Image = _reader.Crop((Bitmap)pictureBox1.Image); pictureBox3.Image = s; var time = DateTime.Now - d; button1.Text = time.TotalMilliseconds.ToString(); }
public void ReadsDifferentDotsWithoutTrailingWhitespaceAtTheEnd() { var ocr = new OCRReader(new OCRSplitter()); var alphabet = new Dictionary <string, byte[, ]> { { ":", new byte[, ] { { 1 }, { 0 }, { 1 } } }, { "-", new byte[, ] { { 0 }, { 1 }, { 0 } } }, { ".", new byte[, ] { { 0 }, { 0 }, { 1 } } } }; var text = new byte[, ] { { 0, 0, 0, 0, 0, 0, 1 }, { 0, 0, 0, 0, 1, 0, 0 }, { 1, 0, 1, 0, 0, 0, 1 } }; Assert.AreEqual("..-:", ocr.ReadTableRow(text, alphabet)); }
public void DifferentiatesBetweenDifferentDots() { var ocr = new OCRReader(new OCRSplitter()); var alphabet = new Dictionary <string, byte[, ]> { { ":", new byte[, ] { { 1 }, { 0 }, { 1 } } }, { "-", new byte[, ] { { 0 }, { 1 }, { 0 } } }, { ".", new byte[, ] { { 0 }, { 0 }, { 1 } } } }; var text = new byte[, ] { { 0, 0, 0, 0, 0, 0, 1, 0 }, { 0, 0, 0, 0, 1, 0, 0, 0 }, { 1, 0, 1, 0, 0, 0, 1, 0 } }; Assert.AreEqual("..-:", ocr.ReadTableRow(text, alphabet)); }
public void ReadsTheLetterG() { var ocr = new OCRReader(new OCRSplitter()); var alphabet = new Dictionary <string, byte[, ]> { { "G", new byte[, ] { { 0, 1, 1, 1, 1, 0 }, { 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0, 0 }, { 1, 0, 0, 1, 1, 1 }, { 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 1, 1 }, { 0, 1, 1, 1, 0, 1 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 } } } }; var pixels = new byte[, ] { { 0, 1, 1, 1, 1, 0, 0 }, { 1, 0, 0, 0, 0, 1, 0 }, { 1, 0, 0, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0, 0, 0 }, { 1, 0, 0, 1, 1, 1, 0 }, { 1, 0, 0, 0, 0, 1, 0 }, { 1, 0, 0, 0, 0, 1, 0 }, { 1, 0, 0, 0, 1, 1, 0 }, { 0, 1, 1, 1, 0, 1, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 } }; Assert.AreEqual("G", ocr.ReadTableRow(pixels, alphabet)); }