Ejemplo n.º 1
0
        private void TrainLetter(ref int numberOfCharactersLeaned, ref int numberOfCharactersSkipped, NOcrDb nOcrD, List <string> charactersLearned, string s, bool bold)
        {
            Bitmap bmp  = GenerateImageFromTextWithStyle(s, bold);
            var    nbmp = new NikseBitmap(bmp);

            nbmp.MakeTwoColor(280);
            var list = NikseBitmapImageSplitter.SplitBitmapToLettersNew(nbmp, 10, false, false, 25);

            if (list.Count == 1)
            {
                NOcrChar match = nOcrD.GetMatch(list[0].NikseBitmap);
                if (match == null)
                {
                    pictureBox1.Image = list[0].NikseBitmap.GetBitmap();
                    this.Refresh();
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(100);

                    NOcrChar nOcrChar = new NOcrChar(s);
                    nOcrChar.Width  = list[0].NikseBitmap.Width;
                    nOcrChar.Height = list[0].NikseBitmap.Height;
                    VobSubOcrNOcrCharacter.GenerateLineSegments((int)numericUpDownSegmentsPerCharacter.Value, checkBoxVeryAccurate.Checked, nOcrChar, list[0].NikseBitmap);
                    nOcrD.Add(nOcrChar);

                    charactersLearned.Add(s);
                    numberOfCharactersLeaned++;
                    labelInfo.Text = string.Format("Now training font '{1}', total characters leaned is {0}, {2} skipped", numberOfCharactersLeaned, _subtitleFontName, numberOfCharactersSkipped);
                    bmp.Dispose();
                }
                else
                {
                    numberOfCharactersSkipped++;
                }
            }
        }
 private void buttonOK_Click(object sender, EventArgs e)
 {
     using (var form = new VobSubOcrNOcrCharacter())
     {
         form.Initialize(_expandItem.NikseBitmap.GetBitmap(), _expandItem, new Point(0, 0), checkBoxItalic.Checked, false, textBoxText.Text);
         var result = form.ShowDialog(this);
         NOcrChar             = form.NOcrChar;
         NOcrChar.ExpandCount = (int)numericUpDownExpandCount.Value;
         DialogResult         = result;
     }
 }
Ejemplo n.º 3
0
        private void addBetterMultiMatchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var form = new AddBetterMultiMatchNOcr())
            {
                var tempImageList = new List <ImageSplitterItem>();
                var idx           = _indexLookup[listBoxInspectItems.SelectedIndex];
                for (int i = idx; i < _imageList.Count; i++)
                {
                    tempImageList.Add(_imageList[i]);
                }

                var tempMatchList = new List <VobSubOcr.CompareMatch>();
                idx = listBoxInspectItems.SelectedIndex;
                for (int i = idx; i < _matchList.Count; i++)
                {
                    tempMatchList.Add(_matchList[i]);
                }

                form.Initialize(_bitmap, 0, tempMatchList, tempImageList);
                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    using (var charForm = new VobSubOcrNOcrCharacter())
                    {
                        charForm.Initialize(_bitmap, form.ExpandItem, new Point(0, 0), form.ExpandItalic, false, false, form.ExpandText);
                        if (charForm.ShowDialog(this) == DialogResult.OK)
                        {
                            charForm.NOcrChar.ExpandCount = form.ExpandCount;
                            var expandList = tempImageList.Take(form.ExpandCount).ToList();
                            charForm.NOcrChar.MarginTop = expandList.First().Top - expandList.Min(p => p.Top);
                            _nOcrDb.Add(charForm.NOcrChar);
                            DialogResult = DialogResult.OK;
                            return;
                        }
                    }
                }

                DialogResult = DialogResult.Cancel;
            }
        }
Ejemplo n.º 4
0
        private void TrainLetter(ref int numberOfCharactersLeaned, ref int numberOfCharactersSkipped, NOcrDb nOcrD, List <string> charactersLearned, string s, bool bold)
        {
            Bitmap bmp  = GenerateImageFromTextWithStyle("H   " + s, bold);
            var    nbmp = new NikseBitmap(bmp);

            nbmp.MakeTwoColor(280);
            nbmp.CropTop(0, Color.FromArgb(0, 0, 0, 0));
            var list = NikseBitmapImageSplitter.SplitBitmapToLettersNew(nbmp, 10, false, false, 25);

            if (list.Count == 3)
            {
                var      item  = list[2];
                NOcrChar match = nOcrD.GetMatch(item.NikseBitmap, item.Top, false, false, 0);
                if (match == null || match.Text != s)
                {
                    labelInfo.Refresh();
                    Application.DoEvents();
                    NOcrChar nOcrChar = new NOcrChar(s)
                    {
                        Width     = item.NikseBitmap.Width,
                        Height    = item.NikseBitmap.Height,
                        MarginTop = item.Top,
                    };
                    VobSubOcrNOcrCharacter.GenerateLineSegments((int)numericUpDownSegmentsPerCharacter.Value, checkBoxVeryAccurate.Checked, nOcrChar, item.NikseBitmap);
                    nOcrD.Add(nOcrChar);

                    charactersLearned.Add(s);
                    numberOfCharactersLeaned++;
                    labelInfo.Text = string.Format("Now training font '{1}', total characters learned is {0:#,###,###}, {2:#,###,###} skipped", numberOfCharactersLeaned, _subtitleFontName, numberOfCharactersSkipped);
                    bmp.Dispose();
                }
                else
                {
                    numberOfCharactersSkipped++;
                }
            }
        }
        private void buttonAddBetterMatch_Click(object sender, EventArgs e)
        {
            var expandSelectionList = new List <ImageSplitterItem>();

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

            int index = listBoxInspectItems.SelectedIndex;
            var img   = _imageList[index];

            if (img.NikseBitmap == null)
            {
                return;
            }

            using (var vobSubOcrNOcrCharacter = new VobSubOcrNOcrCharacter())
            {
                vobSubOcrNOcrCharacter.Initialize(_bitmap, img, new Point(0, 0), false, expandSelectionList.Count > 1);
                DialogResult result          = vobSubOcrNOcrCharacter.ShowDialog(this);
                bool         expandSelection = false;
                bool         shrinkSelection = false;
                if (result == DialogResult.OK && vobSubOcrNOcrCharacter.ExpandSelection)
                {
                    expandSelection = true;
                    expandSelectionList.Add(img);
                }
                while (result == DialogResult.OK && (vobSubOcrNOcrCharacter.ShrinkSelection || vobSubOcrNOcrCharacter.ExpandSelection))
                {
                    if (expandSelection || shrinkSelection)
                    {
                        expandSelection = false;
                        if (shrinkSelection && index > 0)
                        {
                            shrinkSelection = false;
                        }
                        else if (index + 1 < _imageList.Count && _imageList[index + 1].NikseBitmap != null) // only allow expand to EndOfLine or space
                        {
                            index++;
                            expandSelectionList.Add(_imageList[index]);
                        }
                        img = VobSubOcr.GetExpandedSelection(new NikseBitmap(_bitmap), expandSelectionList, false); // true
                    }

                    vobSubOcrNOcrCharacter.Initialize(_bitmap2, img, new Point(0, 0), false, expandSelectionList.Count > 1);
                    result = vobSubOcrNOcrCharacter.ShowDialog(this);

                    if (result == DialogResult.OK && vobSubOcrNOcrCharacter.ShrinkSelection)
                    {
                        shrinkSelection = true;
                        index--;
                        if (expandSelectionList.Count > 0)
                        {
                            expandSelectionList.RemoveAt(expandSelectionList.Count - 1);
                        }
                    }
                    else if (result == DialogResult.OK && vobSubOcrNOcrCharacter.ExpandSelection)
                    {
                        expandSelection = true;
                        index++;
                        expandSelectionList.Add(_imageList[index]);
                    }
                }
                if (result == DialogResult.OK)
                {
                    if (expandSelectionList.Count > 1)
                    {
                        vobSubOcrNOcrCharacter.NOcrChar.ExpandCount = expandSelectionList.Count;
                    }

                    _nocrChars.Add(vobSubOcrNOcrCharacter.NOcrChar);
                    _vobSubOcr.SaveNOcrWithCurrentLanguage();
                    DialogResult = DialogResult.OK;
                }
            }
        }
Ejemplo n.º 6
0
        private void TrainLetter(ref int numberOfCharactersLearned, ref int numberOfCharactersSkipped, NOcrDb nOcrD, string s, bool bold, bool italic, bool doubleLetter)
        {
            var bmp         = GenerateImageFromTextWithStyle("H   " + s, bold, italic);
            var nikseBitmap = new NikseBitmap(bmp);

            nikseBitmap.MakeTwoColor(280);
            nikseBitmap.CropTop(0, Color.FromArgb(0, 0, 0, 0));
            var list = NikseBitmapImageSplitter.SplitBitmapToLettersNew(nikseBitmap, 10, false, false, 25, false);

            if (list.Count == 3)
            {
                var item  = list[2];
                var match = nOcrD.GetMatch(item.NikseBitmap, item.Top, false, 25);
                if (match == null || match.Text != s)
                {
                    labelInfo.Refresh();
                    Application.DoEvents();
                    var nOcrChar = new NOcrChar(s)
                    {
                        Width     = item.NikseBitmap.Width,
                        Height    = item.NikseBitmap.Height,
                        MarginTop = item.Top,
                        Italic    = italic,
                    };
                    VobSubOcrNOcrCharacter.GenerateLineSegments((int)numericUpDownSegmentsPerCharacter.Value + (doubleLetter ? 20 : 0), false, nOcrChar, item.NikseBitmap);
                    nOcrD.Add(nOcrChar);

                    numberOfCharactersLearned++;
                    labelInfo.Text = string.Format(Configuration.Settings.Language.VobSubOcr.NowTraining, numberOfCharactersLearned, _subtitleFontName, numberOfCharactersSkipped);
                    bmp.Dispose();
                }
                else
                {
                    numberOfCharactersSkipped++;
                }
            }
            else if (!doubleLetter)
            {
                if (list.Count == 4 && list[2].NikseBitmap != null && list[3].NikseBitmap != null)
                {
                    // e.g. quote (")
                    var expandItem = VobSubOcr.GetExpandedSelectionNew(nikseBitmap, new List <ImageSplitterItem> {
                        list[2], list[3]
                    });
                    var match = nOcrD.GetMatchExpanded(nikseBitmap, expandItem, 2, list);
                    if (match != null && match.Text == s)
                    {
                        numberOfCharactersSkipped++;
                        return;
                    }

                    var nOcrChar = new NOcrChar(s)
                    {
                        Width       = expandItem.NikseBitmap.Width,
                        Height      = expandItem.NikseBitmap.Height,
                        MarginTop   = expandItem.Top,
                        Italic      = italic,
                        ExpandCount = 2,
                    };
                    VobSubOcrNOcrCharacter.GenerateLineSegments((int)numericUpDownSegmentsPerCharacter.Value + 5, false, nOcrChar, expandItem.NikseBitmap);
                    nOcrD.Add(nOcrChar);
                    return;
                }

                if (list.Count == 5 && list[2].NikseBitmap != null && list[3].NikseBitmap != null && list[4].NikseBitmap != null)
                {
                    // e.g. "%"
                    var expandItem = VobSubOcr.GetExpandedSelectionNew(nikseBitmap, new List <ImageSplitterItem> {
                        list[2], list[3], list[4]
                    });
                    var match = nOcrD.GetMatchExpanded(nikseBitmap, expandItem, 2, list);
                    if (match != null && match.Text == s)
                    {
                        numberOfCharactersSkipped++;
                        return;
                    }

                    var nOcrChar = new NOcrChar(s)
                    {
                        Width       = expandItem.NikseBitmap.Width,
                        Height      = expandItem.NikseBitmap.Height,
                        MarginTop   = expandItem.Top,
                        Italic      = italic,
                        ExpandCount = 3,
                    };
                    nOcrD.Add(nOcrChar);
                    VobSubOcrNOcrCharacter.GenerateLineSegments((int)numericUpDownSegmentsPerCharacter.Value + 10, false, nOcrChar, expandItem.NikseBitmap);
                    return;
                }

                numberOfCharactersSkipped++;
            }
        }
Ejemplo n.º 7
0
        private void buttonAddBetterMatch_Click(object sender, EventArgs e)
        {
            var expandSelectionList = new List <ImageSplitterItem>();

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

            int index = _indexLookup[listBoxInspectItems.SelectedIndex];
            var img   = _imageList[index];

            if (img.NikseBitmap == null)
            {
                return;
            }

            var match = _matchList[listBoxInspectItems.SelectedIndex];

            if (match?.ExpandCount > 1) // expand match
            {
                addBetterMultiMatchToolStripMenuItem_Click(null, null);
                return;
            }

            using (var vobSubOcrNOcrCharacter = new VobSubOcrNOcrCharacter())
            {
                var text = textBoxText.Text;
                vobSubOcrNOcrCharacter.Initialize(_bitmap, img, new Point(-1, -1), checkBoxItalic.Checked, true, expandSelectionList.Count > 1, text);
                DialogResult result          = vobSubOcrNOcrCharacter.ShowDialog(this);
                var          expandSelection = false;
                var          shrinkSelection = false;
                if (result == DialogResult.OK && vobSubOcrNOcrCharacter.ExpandSelection)
                {
                    expandSelection = true;
                    if (img.NikseBitmap != null)
                    {
                        expandSelectionList.Add(img);
                    }
                }
                while (result == DialogResult.OK && (vobSubOcrNOcrCharacter.ShrinkSelection || vobSubOcrNOcrCharacter.ExpandSelection))
                {
                    if (expandSelection || shrinkSelection)
                    {
                        expandSelection = false;
                        if (shrinkSelection && index > 0)
                        {
                            shrinkSelection = false;
                        }
                        else if (index + 1 < _imageList.Count && _imageList[index + 1].NikseBitmap != null) // only allow expand to EndOfLine or space
                        {
                            index++;
                            expandSelectionList.Add(_imageList[index]);
                        }
                        img = VobSubOcr.GetExpandedSelectionNew(new NikseBitmap(_bitmap), expandSelectionList); // true
                    }

                    vobSubOcrNOcrCharacter.Initialize(_bitmap, img, new Point(0, 0), checkBoxItalic.Checked, true, expandSelectionList.Count > 1, string.Empty);
                    result = vobSubOcrNOcrCharacter.ShowDialog(this);

                    if (result == DialogResult.OK && vobSubOcrNOcrCharacter.ShrinkSelection)
                    {
                        shrinkSelection = true;
                        index--;
                        if (expandSelectionList.Count > 0)
                        {
                            expandSelectionList.RemoveAt(expandSelectionList.Count - 1);
                        }
                    }
                    else if (result == DialogResult.OK && vobSubOcrNOcrCharacter.ExpandSelection)
                    {
                        expandSelection = true;
                        if (_imageList[index + 1].NikseBitmap != null)
                        {
                            index++;
                            expandSelectionList.Add(_imageList[index]);
                        }
                    }
                }
                if (result == DialogResult.OK)
                {
                    if (expandSelectionList.Count > 1)
                    {
                        vobSubOcrNOcrCharacter.NOcrChar.ExpandCount = expandSelectionList.Count;
                    }

                    _nOcrChars.Add(vobSubOcrNOcrCharacter.NOcrChar);
                    DialogResult = DialogResult.OK;
                }
            }
        }