Beispiel #1
0
        public void TestNOcrSaveLoad()
        {
            string tempFileName = System.IO.Path.GetTempFileName();
            var db = new NOcrDb(tempFileName);

            var nOcrChar = new NOcrChar("t");
            nOcrChar.ExpandCount = 0;
            nOcrChar.Italic = false;
            nOcrChar.MarginTop = 2;
            nOcrChar.Width = 10;
            nOcrChar.Height = 10;
            nOcrChar.LinesForeground.Add(new NOcrPoint(new Point(1,1), new Point(2,2)));
            nOcrChar.LinesBackground.Add(new NOcrPoint(new Point(3,4), new Point(5,6)));
            db.Add(nOcrChar);

            var nOcrChar2 = new NOcrChar("u");
            nOcrChar2.ExpandCount = 0;
            nOcrChar2.Italic = false;
            nOcrChar2.MarginTop = 3;
            nOcrChar2.Width = 12;
            nOcrChar2.Height = 12;
            nOcrChar2.LinesForeground.Add(new NOcrPoint(new Point(1, 1), new Point(2, 2)));
            nOcrChar2.LinesBackground.Add(new NOcrPoint(new Point(3, 4), new Point(5, 6)));
            db.Add(nOcrChar2);
            db.Save();

            db = new NOcrDb(tempFileName);
            Assert.IsTrue(db.OcrCharacters.Count == 2);

            Assert.IsTrue(db.OcrCharacters[0].Text == nOcrChar2.Text);
            Assert.IsTrue(db.OcrCharacters[0].Italic == nOcrChar2.Italic);
            Assert.IsTrue(db.OcrCharacters[0].MarginTop == nOcrChar2.MarginTop);
            Assert.IsTrue(db.OcrCharacters[0].LinesForeground.Count == nOcrChar2.LinesForeground.Count);
            Assert.IsTrue(db.OcrCharacters[0].LinesForeground[0].Start.X == nOcrChar2.LinesForeground[0].Start.X);
            Assert.IsTrue(db.OcrCharacters[0].LinesForeground[0].Start.Y == nOcrChar2.LinesForeground[0].Start.Y);
            Assert.IsTrue(db.OcrCharacters[0].LinesBackground.Count == nOcrChar2.LinesBackground.Count);
            Assert.IsTrue(db.OcrCharacters[0].LinesBackground[0].Start.X == nOcrChar2.LinesBackground[0].Start.X);
            Assert.IsTrue(db.OcrCharacters[0].LinesBackground[0].Start.Y == nOcrChar2.LinesBackground[0].Start.Y);

            Assert.IsTrue(db.OcrCharacters[1].Text == nOcrChar.Text);

            try
            {
                System.IO.File.Delete(tempFileName);
            }
            catch
            {
            }
        }
        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(210, 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++;
                }
            }
        }