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++;
                }
            }
        }
Exemple #2
0
        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;
            }

            var match = _matchList[index];

            var vobSubOcrNOcrCharacter = new VobSubOcrNOcrCharacter();

            vobSubOcrNOcrCharacter.Initialize(_bitmap, img, new Point(0, 0), false, expandSelectionList.Count > 1, null, null, _vobSubOcr);
            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, null, null, _vobSubOcr);
                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;
            }
        }
        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;
                }
            }
        }