示例#1
0
        public void ImageOCR(SubtitleFonts fonts, bool reportUnknownCharacter)
        {
            if (letters == null)
            {
                // We haven't scanned for letters yet, this probably means I'm debugging something as this shouldn't normally happen
                return;
            }

            fonts.debugStrings.Clear();
            // First try to scan all the letters we can
            foreach (SubtitleLetter l in letters)
            {
                if (l.Text == null)
                {
                    // This letter is unknown, try to scan it
                    DateTime t = DateTime.Now;
                    SubtitleLetter l2 = fonts.FindMatch(l, AppOptions.similarityTolerance * 100);
                    Debugger.scanTime += (DateTime.Now - t).TotalMilliseconds;

                    if (l2 != null)
                    {
                        //Debugger.Print("    found letter " + l2.Text);
                        if (AppOptions.replaceHighCommas && l.Height < -10 && l2.Text.Equals(","))
                            l.Text = "'";
                        else if (AppOptions.replaceHighCommas && l.Height > 10 && l2.Text.Equals("'"))
                            l.Text = ",";
                        else
                            l.Text = l2.Text;
                    }
                    // If we should report unknown characters, then throw an exception, otherwise just skip it
                    else if (reportUnknownCharacter)
                        throw new UnknownCharacterException();
                }
            }
        }
示例#2
0
        public MainForm()
        {
            InitializeComponent();

            Debugger.ResetTimes();

            #if !DEBUG
            debugButton.Hide();
            #endif

            bitmapSize = new Size(400, 400);
            bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height, PixelFormat.Format24bppRgb);

            fonts = new SubtitleFonts();

            redPen = new Pen(new SolidBrush(Color.Red));
            yellowPen = new Pen(new SolidBrush(Color.Yellow));
            bluePen = new Pen(new SolidBrush(Color.Blue));
            greenPen = new Pen(new SolidBrush(Color.Green));
            whitePen = new Pen(new SolidBrush(Color.White));

            //SetStyle(ControlStyles.UserPaint, true);
            //SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            //SetStyle(ControlStyles.DoubleBuffer, true);

            subtitlePictureBox.SizeMode = PictureBoxSizeMode.Zoom;
            letterPictureBox.SizeMode = PictureBoxSizeMode.Zoom;

            ToolTip tt = new ToolTip();
            tt.AutoPopDelay = 20000;
            tt.SetToolTip(nextButton, "Moves to the next subtitle image\n\nCtrl+N");
            tt.SetToolTip(previousButton, "Moves to the previous subtitle image\n\nCtrl+P");
            tt.SetToolTip(ocrButton, "Tries to scan the current image, and will prompt the user to identify any unknown character.\n\nCtrl+O");
            tt.SetToolTip(minimumSpaceCharacterWidthTextBox, "Configures how big an empty space between two letters has to be to be counted as a space character.\nIf spaces are inserted where there shouldn't be any, increase this number.\nIf too many spaces are not detected, lower this number.");
            tt.SetToolTip(charSplitTolerance, "Configures how eagerly the OCR function splits characters.\nIf too many characters (especially 'k') get split in the middle, increase this number.\nIf too many double characters get erroneously detected as a single one, lower this number.");
            tt.SetToolTip(similarityTolerance, "Configures how similar two letters have to be so they are seen as equal.\nIf you have to manually enter too many letters, increase this number.\nIf there are some accidentially misidentified letters, lower this number.");
            tt.SetToolTip(contrast, "Sets a contrast correction on the image. Helpful for some subtitles that have large gray zones, but slows down OCR if it is set to any other value than zero.");
            tt.SetToolTip(autoProgress, "Automatically continues with the next subtitle if all characters in this one can be scanned. OCR will stop as soon as an unknown character is encountered.");
            tt.SetToolTip(autoOCRButton, "Automatically scans all subtitles. Unknown characters will simply be skipped.");
            tt.SetToolTip(loadButton, "Load a new subtitle file.");
            tt.SetToolTip(saveButton, "Save the scanned SRT file as you can see it on the left to a file.");
            tt.SetToolTip(convertDoubleApostrophes, "Automatically replaces double-apostrophes with a single quote sign.");
            tt.SetToolTip(replaceHighCommas, "Automatically replaces comma signs that are pretty high up in their line with apostrophes.");
            tt.SetToolTip(forcedOnly, "Only output forced subtitles.");
            tt.SetToolTip(combineSubtitles, "Combines two subsequent subtitles with completely identical text so they only use one line in the SRT.");
            tt.SetToolTip(ptsOffset, "The delay that should be applied to timestamps. For most subtitles it will be zero.");

            nextButton.Enabled = false;
            previousButton.Enabled = false;
            autoOCRButton.Enabled = false;
            ocrButton.Enabled = false;
            letterOKButton.Enabled = false;
            saveButton.Enabled = false;

            // Load the settings from the registry
            initialized = false;
            options = new AppOptions();
            minimumSpaceCharacterWidthTextBox.Text = AppOptions.minimumSpaceCharacterWidth.ToString();
            charSplitTolerance.Text = AppOptions.charSplitTolerance.ToString();
            similarityTolerance.Text = AppOptions.similarityTolerance.ToString();
            contrast.Text = AppOptions.contrast.ToString();
            convertDoubleApostrophes.Checked = AppOptions.convertDoubleApostrophes;
            stripFormatting.Checked = AppOptions.stripFormatting;
            replaceHighCommas.Checked = AppOptions.replaceHighCommas;
            forcedOnly.Checked = AppOptions.forcedOnly;
            preservePositions.Checked = AppOptions.preservePositions;
            combineSubtitles.Checked = AppOptions.combineSubtitles;
            initialized = true;

            try
            {
                Assembly x = Assembly.Load("Interop.MODI");
                AppOptions.modiInstalled = true;
            }
            catch (FileNotFoundException)
            {
                AppOptions.modiInstalled = false;
            }

            System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
            timer1.Enabled = true;
            timer1.Interval = 100;
            timer1.Tick += new System.EventHandler(TimerEvent);

            Text = "SupRip " + version;
        }
示例#3
0
文件: MainForm.cs 项目: Rupan/SupRip
        public MainForm()
        {
            InitializeComponent();

            Debugger.ResetTimes();

#if !DEBUG
            debugButton.Hide();
#endif

            bitmapSize = new Size(400, 400);
            bitmap     = new Bitmap(bitmapSize.Width, bitmapSize.Height, PixelFormat.Format24bppRgb);

            fonts = new SubtitleFonts();

            redPen    = new Pen(new SolidBrush(Color.Red));
            yellowPen = new Pen(new SolidBrush(Color.Yellow));
            bluePen   = new Pen(new SolidBrush(Color.Blue));
            greenPen  = new Pen(new SolidBrush(Color.Green));
            whitePen  = new Pen(new SolidBrush(Color.White));

            //SetStyle(ControlStyles.UserPaint, true);
            //SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            //SetStyle(ControlStyles.DoubleBuffer, true);

            subtitlePictureBox.SizeMode = PictureBoxSizeMode.Zoom;
            letterPictureBox.SizeMode   = PictureBoxSizeMode.Zoom;

            ToolTip tt = new ToolTip();
            tt.AutoPopDelay = 20000;
            tt.SetToolTip(nextButton, "Moves to the next subtitle image\n\nCtrl+N");
            tt.SetToolTip(previousButton, "Moves to the previous subtitle image\n\nCtrl+P");
            tt.SetToolTip(ocrButton, "Tries to scan the current image, and will prompt the user to identify any unknown character.\n\nCtrl+O");
            tt.SetToolTip(minimumSpaceCharacterWidthTextBox, "Configures how big an empty space between two letters has to be to be counted as a space character.\nIf spaces are inserted where there shouldn't be any, increase this number.\nIf too many spaces are not detected, lower this number.");
            tt.SetToolTip(charSplitTolerance, "Configures how eagerly the OCR function splits characters.\nIf too many characters (especially 'k') get split in the middle, increase this number.\nIf too many double characters get erroneously detected as a single one, lower this number.");
            tt.SetToolTip(similarityTolerance, "Configures how similar two letters have to be so they are seen as equal.\nIf you have to manually enter too many letters, increase this number.\nIf there are some accidentially misidentified letters, lower this number.");
            tt.SetToolTip(contrast, "Sets a contrast correction on the image. Helpful for some subtitles that have large gray zones, but slows down OCR if it is set to any other value than zero.");
            tt.SetToolTip(autoProgress, "Automatically continues with the next subtitle if all characters in this one can be scanned. OCR will stop as soon as an unknown character is encountered.");
            tt.SetToolTip(autoOCRButton, "Automatically scans all subtitles. Unknown characters will simply be skipped.");
            tt.SetToolTip(loadButton, "Load a new subtitle file.");
            tt.SetToolTip(saveButton, "Save the scanned SRT file as you can see it on the left to a file.");
            tt.SetToolTip(convertDoubleApostrophes, "Automatically replaces double-apostrophes with a single quote sign.");
            tt.SetToolTip(replaceHighCommas, "Automatically replaces comma signs that are pretty high up in their line with apostrophes.");
            tt.SetToolTip(forcedOnly, "Only output forced subtitles.");
            tt.SetToolTip(combineSubtitles, "Combines two subsequent subtitles with completely identical text so they only use one line in the SRT.");
            tt.SetToolTip(ptsOffset, "The delay that should be applied to timestamps. For most subtitles it will be zero.");

            nextButton.Enabled     = false;
            previousButton.Enabled = false;
            autoOCRButton.Enabled  = false;
            ocrButton.Enabled      = false;
            letterOKButton.Enabled = false;
            saveButton.Enabled     = false;

            // Load the settings from the registry
            initialized = false;
            options     = new AppOptions();
            minimumSpaceCharacterWidthTextBox.Text = AppOptions.minimumSpaceCharacterWidth.ToString();
            charSplitTolerance.Text          = AppOptions.charSplitTolerance.ToString();
            similarityTolerance.Text         = AppOptions.similarityTolerance.ToString();
            contrast.Text                    = AppOptions.contrast.ToString();
            convertDoubleApostrophes.Checked = AppOptions.convertDoubleApostrophes;
            stripFormatting.Checked          = AppOptions.stripFormatting;
            replaceHighCommas.Checked        = AppOptions.replaceHighCommas;
            forcedOnly.Checked               = AppOptions.forcedOnly;
            preservePositions.Checked        = AppOptions.preservePositions;
            combineSubtitles.Checked         = AppOptions.combineSubtitles;
            initialized = true;


            System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
            timer1.Enabled  = true;
            timer1.Interval = 100;
            timer1.Tick    += new System.EventHandler(TimerEvent);

            Text = "SupRip " + version;
        }