internal void Initialize(Bitmap bitmap, int selectedIndex, List <VobSubOcr.CompareMatch> matches, List <ImageSplitterItem> splitterItems)
        {
            _wholeImage = new NikseBitmap(bitmap);
            _startIndex = selectedIndex;
            for (int i = 0; i < selectedIndex; i++)
            {
                if (matches[i] != null && matches[i].Extra != null && matches[i].Extra.Count > 0)
                {
                    _extraCount += matches[i].Extra.Count - 1;
                }
            }

            _matches       = matches;
            _splitterItems = splitterItems;
            int count = 0;

            for (int i = _startIndex; i < _splitterItems.Count - _extraCount; i++)
            {
                if (i >= _matches.Count)
                {
                    break;
                }

                var item = _splitterItems[i];
                if (item.SpecialCharacter != null)
                {
                    break;
                }

                var m = _matches[i];
                if (m != null && m.Extra?.Count > 0)
                {
                    break;
                }

                if (m == null)
                {
                    m = new VobSubOcr.CompareMatch(string.Empty, false, 0, null);
                }

                count++;
                listBoxInspectItems.Items.Add(m);
                if (count < 3)
                {
                    listBoxInspectItems.SetSelected(listBoxInspectItems.Items.Count - 1, true);
                }
            }
            numericUpDownExpandCount.Maximum = listBoxInspectItems.Items.Count;
            MakeExpandImage();
        }
示例#2
0
        internal void Initialize(Bitmap vobSubImage, ImageSplitterItem character, Point position, bool italicChecked, bool showShrink, VobSubOcr.CompareMatch bestGuess, List <VobSubOcr.ImageCompareAddition> additions, VobSubOcr vobSubForm)
        {
            ShrinkSelection = false;
            ExpandSelection = false;

            textBoxCharacters.Text = string.Empty;
            if (bestGuess != null)
            {
                buttonGuess.Visible = false; // hm... not too useful :(
                buttonGuess.Text    = bestGuess.Text;
            }
            else
            {
                buttonGuess.Visible = false;
            }

            _vobSubForm = vobSubForm;
            _additions  = additions;

            buttonShrinkSelection.Visible = showShrink;

            checkBoxItalic.Checked = italicChecked;
            if (position.X != -1 && position.Y != -1)
            {
                StartPosition = FormStartPosition.Manual;
                Left          = position.X;
                Top           = position.Y;
            }

            pictureBoxSubtitleImage.Image = vobSubImage;
            pictureBoxCharacter.Image     = character.NikseBitmap.GetBitmap();

            if (_additions.Count > 0)
            {
                var last = _additions[_additions.Count - 1];
                buttonLastEdit.Visible = true;
                if (last.Italic)
                {
                    buttonLastEdit.Font = new Font(buttonLastEdit.Font.FontFamily, buttonLastEdit.Font.Size, FontStyle.Italic);
                }
                else
                {
                    buttonLastEdit.Font = new Font(buttonLastEdit.Font.FontFamily, buttonLastEdit.Font.Size);
                }
                pictureBoxLastEdit.Visible = true;
                pictureBoxLastEdit.Image   = last.Image.GetBitmap();
                buttonLastEdit.Text        = string.Format(Configuration.Settings.Language.VobSubOcrCharacter.EditLastX, last.Text);
                pictureBoxLastEdit.Top     = buttonLastEdit.Top - last.Image.Height + buttonLastEdit.Height;
            }
            else
            {
                buttonLastEdit.Visible     = false;
                pictureBoxLastEdit.Visible = false;
            }

            using (var org = (Bitmap)vobSubImage.Clone())
            {
                var bm = new Bitmap(org.Width, org.Height);
                using (var g = Graphics.FromImage(bm))
                {
                    g.DrawImage(org, 0, 0, org.Width, org.Height);
                    g.DrawRectangle(Pens.Red, character.X, character.Y, character.NikseBitmap.Width, character.NikseBitmap.Height - 1);
                }
                pictureBoxSubtitleImage.Image = bm;
            }

            pictureBoxCharacter.Top = labelCharacters.Top + 16;
            pictureBoxLastEdit.Left = buttonLastEdit.Left + buttonLastEdit.Width + 5;
        }
        private void listBoxInspectItems_SelectedIndexChanged(object sender, EventArgs e)
        {
            labelImageInfo.Text   = string.Empty;
            labelExpandCount.Text = string.Empty;

            if (listBoxInspectItems.SelectedIndex < 0)
            {
                return;
            }

            _selectedCompareNode            = null;
            _selectedCompareBinaryOcrBitmap = null;

            pictureBoxInspectItem.Image         = _imageSources[listBoxInspectItems.SelectedIndex];
            pictureBoxCompareBitmap.Image       = null;
            pictureBoxCompareBitmapDouble.Image = null;

            int index = (listBoxInspectItems.SelectedIndex);
            var match = _matches[index];

            _selectedMatch = match;
            if (!string.IsNullOrEmpty(match.Name))
            {
                Bitmap bitmap = new Bitmap(1, 1);

                if (_binOcrDb != null)
                {
                    bool bobFound = false;
                    foreach (BinaryOcrBitmap bob in _binOcrDb.CompareImages)
                    {
                        if (match.Name == bob.Key)
                        {
                            textBoxText.Text                = bob.Text;
                            checkBoxItalic.Checked          = bob.Italic;
                            _selectedCompareBinaryOcrBitmap = bob;

                            bitmap = bob.ToOldBitmap();
                            pictureBoxCompareBitmap.Image        = bitmap;
                            pictureBoxCompareBitmapDouble.Width  = bitmap.Width * 2;
                            pictureBoxCompareBitmapDouble.Height = bitmap.Height * 2;
                            pictureBoxCompareBitmapDouble.Image  = bitmap;

                            var matchBob = new BinaryOcrBitmap(new NikseBitmap(_imageSources[listBoxInspectItems.SelectedIndex]));
                            if (matchBob.Hash == bob.Hash && matchBob.Width == bob.Width && matchBob.Height == bob.Height && matchBob.NumberOfColoredPixels == bob.NumberOfColoredPixels)
                            {
                                buttonAddBetterMatch.Enabled = false; // exact match
                            }
                            else
                            {
                                buttonAddBetterMatch.Enabled = true;
                            }

                            bobFound = true;
                            break;
                        }
                    }
                    if (!bobFound)
                    {
                        foreach (BinaryOcrBitmap bob in _binOcrDb.CompareImagesExpanded)
                        {
                            if (match.Name == bob.Key)
                            {
                                textBoxText.Text                = bob.Text;
                                checkBoxItalic.Checked          = bob.Italic;
                                _selectedCompareBinaryOcrBitmap = bob;

                                bitmap = bob.ToOldBitmap();
                                pictureBoxCompareBitmap.Image        = bitmap;
                                pictureBoxCompareBitmapDouble.Width  = bitmap.Width * 2;
                                pictureBoxCompareBitmapDouble.Height = bitmap.Height * 2;
                                pictureBoxCompareBitmapDouble.Image  = bitmap;
                                buttonAddBetterMatch.Enabled         = false; // exact match
                                labelExpandCount.Text = string.Format("Expand count: {0}", bob.ExpandCount);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    foreach (XmlNode node in ImageCompareDocument.DocumentElement.ChildNodes)
                    {
                        if (node.Attributes["Text"] != null && node.InnerText == match.Name)
                        {
                            string text          = node.Attributes["Text"].InnerText;
                            string imageFileName = node.InnerText;
                            imageFileName          = Path.Combine(_directoryPath, imageFileName);
                            textBoxText.Text       = text;
                            checkBoxItalic.Checked = node.Attributes["Italic"] != null;

                            string databaseName = Path.Combine(_directoryPath, "Images.db");
                            using (var f = new FileStream(databaseName, FileMode.Open))
                            {
                                try
                                {
                                    string name = node.InnerText;
                                    int    pos  = Convert.ToInt32(name);
                                    f.Position = pos;
                                    ManagedBitmap mbmp = new ManagedBitmap(f);
                                    bitmap = mbmp.ToOldBitmap();
                                    pictureBoxCompareBitmap.Image        = bitmap;
                                    pictureBoxCompareBitmapDouble.Width  = bitmap.Width * 2;
                                    pictureBoxCompareBitmapDouble.Height = bitmap.Height * 2;
                                    pictureBoxCompareBitmapDouble.Image  = bitmap;
                                }
                                catch (Exception exception)
                                {
                                    MessageBox.Show(exception.Message);
                                }
                            }

                            try
                            {
                                labelImageInfo.Text = string.Format(Configuration.Settings.Language.VobSubEditCharacters.Image + " - {0}x{1}", bitmap.Width, bitmap.Height);
                            }
                            catch
                            {
                            }

                            _selectedCompareNode = node;
                            break;
                        }
                    }
                }
            }

            if (_selectedCompareNode == null && _selectedCompareBinaryOcrBitmap == null)
            {
                buttonUpdate.Enabled         = false;
                buttonDelete.Enabled         = false;
                buttonAddBetterMatch.Enabled = false;
                textBoxText.Enabled          = false;
                textBoxText.Text             = string.Empty;
                checkBoxItalic.Enabled       = false;
            }
            else
            {
                buttonUpdate.Enabled = true;
                buttonDelete.Enabled = true;
                if (_selectedCompareNode != null)
                {
                    buttonAddBetterMatch.Enabled = true;
                }
                textBoxText.Enabled    = true;
                checkBoxItalic.Enabled = true;
            }
        }
示例#4
0
        internal void Initialize(Bitmap vobSubImage, ImageSplitterItem character, Point position, bool italicChecked, bool showShrink, VobSubOcr.CompareMatch bestGuess, List <VobSubOcr.ImageCompareAddition> additions, VobSubOcr vobSubForm)
        {
            listBoxLinesForeground.Items.Clear();
            listBoxlinesBackground.Items.Clear();
            NikseBitmap nbmp = new NikseBitmap(vobSubImage);

            nbmp.ReplaceTransparentWith(Color.Black);
            vobSubImage = nbmp.GetBitmap();

            radioButtonHot.Checked = true;
            ShrinkSelection        = false;
            ExpandSelection        = false;

            textBoxCharacters.Text = string.Empty;
            _vobSubForm            = vobSubForm;
            _additions             = additions;
            _nocrChar           = new NOcrChar();
            _nocrChar.MarginTop = character.Y - character.ParentY;
            _imageWidth         = character.NikseBitmap.Width;
            _imageHeight        = character.NikseBitmap.Height;
            _drawLineOn         = false;
            _warningNoNotForegroundLinesShown = false;

            buttonShrinkSelection.Visible = showShrink;

            if (position.X != -1 && position.Y != -1)
            {
                StartPosition = FormStartPosition.Manual;
                Left          = position.X;
                Top           = position.Y;
            }

            pictureBoxSubtitleImage.Image = vobSubImage;
            pictureBoxCharacter.Image     = character.NikseBitmap.GetBitmap();

            Bitmap   org = (Bitmap)vobSubImage.Clone();
            Bitmap   bm  = new Bitmap(org.Width, org.Height);
            Graphics g   = Graphics.FromImage(bm);

            g.DrawImage(org, 0, 0, org.Width, org.Height);
            g.DrawRectangle(Pens.Red, character.X, character.Y, character.NikseBitmap.Width, character.NikseBitmap.Height - 1);
            g.Dispose();
            pictureBoxSubtitleImage.Image = bm;

            pictureBoxCharacter.Top = labelCharacters.Top + 16;
            SizePictureBox();
            checkBoxItalic.Checked = italicChecked;

            _history      = new List <NOcrChar>();
            _historyIndex = -1;

            _nocrChar.Width  = _imageWidth;
            _nocrChar.Height = _imageHeight;
            GenerateLineSegments(150, false, _nocrChar, new NikseBitmap(pictureBoxCharacter.Image as Bitmap));
            ShowOcrPoints();
            pictureBoxCharacter.Invalidate();
        }
示例#5
0
        private void listBoxInspectItems_SelectedIndexChanged(object sender, EventArgs e)
        {
            labelImageInfo.Text   = string.Empty;
            labelExpandCount.Text = string.Empty;

            if (listBoxInspectItems.SelectedIndex < 0)
            {
                return;
            }

            _selectedCompareNode            = null;
            _selectedCompareBinaryOcrBitmap = null;

            var img = _imageSources[listBoxInspectItems.SelectedIndex];

            pictureBoxInspectItem.Image = img;
            if (img != null)
            {
                pictureBoxInspectItem.Width  = img.Width + 2;
                pictureBoxInspectItem.Height = img.Height + 2;
            }

            pictureBoxCompareBitmap.Image       = null;
            pictureBoxCompareBitmapDouble.Image = null;

            int index = listBoxInspectItems.SelectedIndex;
            var match = _matches[index];

            _selectedMatch = match;
            if (!string.IsNullOrEmpty(match.Name))
            {
                if (_binOcrDb != null)
                {
                    bool bobFound = false;
                    foreach (BinaryOcrBitmap bob in _binOcrDb.CompareImages)
                    {
                        if (match.Name == bob.Key)
                        {
                            textBoxText.Text                = bob.Text;
                            checkBoxItalic.Checked          = bob.Italic;
                            _selectedCompareBinaryOcrBitmap = bob;
                            SetDbItemView(bob.ToOldBitmap());
                            var matchBob = new BinaryOcrBitmap(new NikseBitmap(_imageSources[listBoxInspectItems.SelectedIndex]));
                            if (matchBob.Hash == bob.Hash && matchBob.Width == bob.Width && matchBob.Height == bob.Height && matchBob.NumberOfColoredPixels == bob.NumberOfColoredPixels)
                            {
                                buttonAddBetterMatch.Enabled = false; // exact match
                            }
                            else
                            {
                                buttonAddBetterMatch.Enabled = true;
                            }
                            bobFound = true;
                            break;
                        }
                    }
                    if (!bobFound)
                    {
                        foreach (BinaryOcrBitmap bob in _binOcrDb.CompareImagesExpanded)
                        {
                            if (match.Name == bob.Key)
                            {
                                textBoxText.Text                = bob.Text;
                                checkBoxItalic.Checked          = bob.Italic;
                                _selectedCompareBinaryOcrBitmap = bob;

                                var oldBitmap = bob.ToOldBitmap();
                                SetDbItemView(oldBitmap);

                                int dif = 1;
                                if (oldBitmap.Width == match.ImageSplitterItem.NikseBitmap.Width && oldBitmap.Height == match.ImageSplitterItem.NikseBitmap.Height)
                                {
                                    dif = NikseBitmapImageSplitter.IsBitmapsAlike(match.ImageSplitterItem.NikseBitmap, oldBitmap);
                                }
                                buttonAddBetterMatch.Enabled = dif > 0; // if exact match then don't allow "Add better match"
                                labelExpandCount.Text        = $"Expand count: {bob.ExpandCount}";
                                break;
                            }
                        }
                    }
                }
                else
                {
                    foreach (XmlNode node in ImageCompareDocument.DocumentElement.ChildNodes)
                    {
                        if (node.Attributes["Text"] != null && node.InnerText == match.Name)
                        {
                            string text = node.Attributes["Text"].InnerText;
                            textBoxText.Text       = text;
                            checkBoxItalic.Checked = node.Attributes["Italic"] != null;
                            string databaseName = Path.Combine(_directoryPath, "Images.db");
                            using (var f = new FileStream(databaseName, FileMode.Open))
                            {
                                try
                                {
                                    string name = node.InnerText;
                                    int    pos  = Convert.ToInt32(name);
                                    f.Position = pos;
                                    var mbmp   = new ManagedBitmap(f);
                                    var bitmap = mbmp.ToOldBitmap();
                                    SetDbItemView(mbmp.ToOldBitmap());
                                    labelImageInfo.Text = string.Format(Configuration.Settings.Language.VobSubEditCharacters.Image + " - {0}x{1}", bitmap.Width, bitmap.Height);
                                }
                                catch (Exception exception)
                                {
                                    labelImageInfo.Text = Configuration.Settings.Language.VobSubEditCharacters.Image;
                                    MessageBox.Show(exception.Message);
                                }
                            }

                            _selectedCompareNode = node;
                            break;
                        }
                    }
                }
            }

            buttonAddBetterMatch.Text = Configuration.Settings.Language.VobSubOcrCharacterInspect.AddBetterMatch;
            if (_selectedMatch.Text == Configuration.Settings.Language.VobSubOcr.NoMatch)
            {
                buttonUpdate.Enabled                  = false;
                buttonDelete.Enabled                  = false;
                buttonAddBetterMatch.Enabled          = true;
                buttonAddBetterMatch.Text             = Configuration.Settings.Language.VobSubOcrCharacterInspect.Add;
                textBoxText.Enabled                   = true;
                textBoxText.Text                      = string.Empty;
                checkBoxItalic.Enabled                = true;
                pictureBoxCompareBitmap.Visible       = true;
                pictureBoxCompareBitmapDouble.Visible = true;
                labelDoubleSize.Visible               = true;
            }
            else if (_selectedCompareNode == null && _selectedCompareBinaryOcrBitmap == null)
            {
                buttonUpdate.Enabled                  = false;
                buttonDelete.Enabled                  = false;
                buttonAddBetterMatch.Enabled          = true;
                textBoxText.Enabled                   = true;
                textBoxText.Text                      = string.Empty;
                checkBoxItalic.Enabled                = false;
                pictureBoxCompareBitmap.Visible       = false;
                pictureBoxCompareBitmapDouble.Visible = false;
                labelDoubleSize.Visible               = false;
                if (img == null)
                {
                    buttonAddBetterMatch.Enabled = false;
                }
            }
            else
            {
                buttonUpdate.Enabled = true;
                buttonDelete.Enabled = true;
                if (_selectedCompareNode != null)
                {
                    buttonAddBetterMatch.Enabled = true;
                }
                textBoxText.Enabled                   = true;
                checkBoxItalic.Enabled                = true;
                pictureBoxCompareBitmap.Visible       = true;
                pictureBoxCompareBitmapDouble.Visible = true;
                labelDoubleSize.Visible               = true;
            }
        }