public void Add(TextItem item, bool isLetter = false) { int index = -1; if (item.Position >= 0 && item.Position <= 18) index = 0; if (item.Position >= 14 && item.Position <= 32 && isLetter) index = 1; if (item.Position >= 27 && item.Position <= 43) index = 2; if (item.Position >= 55 && item.Position <= 64) index = 3; if (item.Position >= 70 && item.Position <= 77) // 86 index = 4; if (item.Position >= 82 && item.Position <= 91) index = 5; if (item.Position >= 96 && item.Position <= 116) index = 6; if (index >= 0 && ((isLetter && (index == 1 || index == 2)) || !isLetter)) { if (_text[index] != null) { if (item.Accuracy >= _text[index].Accuracy) { _text[index] = item; } } else { _text[index] = item; } } }
public List<TextItem> DetectText(Bitmap image, int shift = 3, bool onlyLetters = false) { List<TextItem> detectedContent = new List<TextItem>(); int x = 0; TextItem item; while (x + _windowWidth < image.Width) { Rectangle rectangle = new Rectangle(x, 0, _windowWidth, _windowHeight); Bitmap cut = image.Clone(rectangle, System.Drawing.Imaging.PixelFormat.DontCare); Bitmap newImage = new Bitmap(_windowWidth, _windowHeight); using (var graphics = Graphics.FromImage(newImage)) { graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.DrawImage(cut, new Rectangle(0, 0, _windowWidth, _windowHeight)); } x += shift; double[] input = ImageArray.FromBitmap(newImage, true); double[] result = (!onlyLetters) ? _net.Compute(input) : _netLetters.Compute(input); double max = double.MinValue; int index = 0; int maxIndex = 0; foreach (double val in result) { if (val > max) { max = val; maxIndex = index; } index++; } if (max >= 0.3) { item = new TextItem(); item.Position = x; item.PositionEnd = x + _windowHeight; item.Text = !onlyLetters ? maxIndex.ToString()[0] : this.numberToChar(maxIndex); item.Accuracy = max; detectedContent.Add(item); if (saveImages) { newImage.Save("test3/imgb" + x + "f" + maxIndex.ToString() + "----" + Math.Round(max, 3).ToString() + ".png"); } } } return detectedContent; }