Beispiel #1
0
 private void nudCutoffValue_ValueChanged(object sender, EventArgs e)
 {
     Cursor          = Cursors.WaitCursor;
     pbPicture.Image = RNGraphics.PreprocessScreenshot(_TestBitmap, 1, (int)(nudCutoffValue.Value));
     setMagnifier();
     Cursor = Cursors.Default;
 }
Beispiel #2
0
    private void FilterTest_Load(object sender, EventArgs e)
    {
        Cursor            = Cursors.WaitCursor;
        this.DialogResult = System.Windows.Forms.DialogResult.None;

        nudCutoffValue.Value = CutoffLevel;

        pbPicture.Image = RNGraphics.PreprocessScreenshot(_TestBitmap, 1, (int)(nudCutoffValue.Value));

        pbPicture.Size = pbPicture.Image.Size;
        Cursor         = Cursors.Default;
    }
Beispiel #3
0
        private void ProcessNewScreenshot(string screenshot)
        {
            CurrentScreenshot         = screenshot;
            CurrentScreenshotDateTime = File.GetCreationTime(CurrentScreenshot);

            if (_bOriginal != null)
            {
                _bOriginal.Dispose();
            }
            if (_bOriginalClone != null)
            {
                _bOriginalClone.Dispose();
            }
            if (_bTrimmed_4_View != null)
            {
                _bTrimmed_4_View.Dispose();
            }
            if (_bTrimmed_4_OCR != null)
            {
                _bTrimmed_4_OCR.Dispose();
            }
            if (_bTrimmedHeader != null)
            {
                _bTrimmedHeader.Dispose();
            }

            // Well, we can get the bitmap without locking its file, like this... maybe it will help
            using (Stream s = File.OpenRead(CurrentScreenshot))
                _bOriginal = (Bitmap)Bitmap.FromStream(s);

            using (Stream s = File.OpenRead(CurrentScreenshot))
                _bOriginalClone = (Bitmap)Bitmap.FromStream(s);

            Bitmap _bAnotherClone = null;

            // I apologise for what comes next.
            try
            {
                if (_bOriginal != null)
                {
                    _bAnotherClone = (Bitmap)(_bOriginal.Clone());
                }
            }
            catch (Exception ex)
            {
                _logger.Log("Ignoring _bOriginal.Clone() error...\r\n" + ex);
            }
            _calibrationPoints = _callingForm.cOcrCaptureAndCorrect.UpdateOriginalImage(_bAnotherClone);

            // get the area of the commodity data
            var trim_4_CommodityArea = new Rectangle(_calibrationPoints[2].X, _calibrationPoints[2].Y,
                                                     _calibrationPoints[10].X - _calibrationPoints[2].X,
                                                     _calibrationPoints[11].Y - _calibrationPoints[2].Y);

            // RNGraphics.Crop image to the commodity area
            _bTrimmed_4_OCR = RNGraphics.Crop(_bOriginalClone, trim_4_CommodityArea);

            // save the still colored area for viewing reasons
            _bTrimmed_4_View = (Bitmap)(_bTrimmed_4_OCR.Clone());

            // set all dark colors to black - this removes all crap
            _bTrimmed_4_OCR = RNGraphics.changeColour(_bTrimmed_4_OCR, Color.Black, Color.Black, Program.DBCon.getIniValue <Int32>(IBE.IBESettingsView.DB_GROUPNAME, "GUIColorCutoffLevel"), RNGraphics.enPixelCompare.pc_RGB_all);

            // find automatically the textlines in the commodity area
            var textRowLocations = new List <Tuple <int, int> >();
            var nextLine         = 0;

            while (nextLine < _bTrimmed_4_OCR.Height - 1)
            {
                int startLine = -1, endLine = -1;
                for (int i = nextLine; i < _bTrimmed_4_OCR.Height - 1; i++)
                {
                    nextLine = i + 1;
                    bool hasOrangePixel;
                    using (Bitmap singlePixelRow = RNGraphics.Crop(_bTrimmed_4_OCR, new Rectangle(0, i, _bTrimmed_4_OCR.Width, 1)))
                    {
                        hasOrangePixel = RNGraphics.hasGUIColoredPixel(singlePixelRow);
                    }
                    //Debug.WriteLine(i + " of " + bTrimmed.Height + ": " + hasOrangePixel);
                    if (endLine == -1 && !hasOrangePixel)
                    {
                        startLine = i;
                    }
                    else
                    if (hasOrangePixel)
                    {
                        endLine = i + 1;
                    }
                    else
                    {
                        break;
                    }
                }
                if (startLine != -1 && endLine != -1)
                {
                    textRowLocations.Add(new Tuple <int, int>(startLine, endLine));
                }
            }

            // get the area of the header
            var trim_4_Header = new Rectangle(_calibrationPoints[0].X, _calibrationPoints[0].Y,
                                              _calibrationPoints[10].X - _calibrationPoints[0].X,
                                              _calibrationPoints[1].Y - _calibrationPoints[0].Y);

            // RNGraphics.Crop image to the header area and preprocess for OCR
            _bTrimmedHeader = RNGraphics.PreprocessScreenshot(RNGraphics.Crop(_bOriginalClone, trim_4_Header), 1, Program.DBCon.getIniValue <Int32>(IBE.IBESettingsView.DB_GROUPNAME, "GUIColorCutoffLevel"));

            // now process screenshot for OCR and Elitebrainerous
            _bTrimmed_4_OCR = RNGraphics.PreprocessScreenshot(_bTrimmed_4_OCR, 1, Program.DBCon.getIniValue <Int32>(IBE.IBESettingsView.DB_GROUPNAME, "GUIColorCutoffLevel"));

            // show preprocessed parts on the GUI
            _callingForm.cOcrCaptureAndCorrect.UpdateTrimmedImage(_bTrimmed_4_OCR, _bTrimmedHeader);

            int min = 100, max = 0;

            if (textRowLocations.Count > 0)
            {
                // check if the last line is complete or RNGraphics.Cropped -> if it's RNGraphics.Cropped we delete it
                var finalRowLocation = textRowLocations[textRowLocations.Count - 1];

                foreach (var x in textRowLocations)
                {
                    if (x.Item1 != finalRowLocation.Item1)
                    {
                        if (min > x.Item2 - x.Item1)
                        {
                            min = x.Item2 - x.Item1;
                        }

                        if (max < x.Item2 - x.Item1)
                        {
                            max = x.Item2 - x.Item1;
                        }
                    }
                }

                if (finalRowLocation.Item2 - finalRowLocation.Item1 < (min - 2))
                {
                    textRowLocations.RemoveAt(textRowLocations.Count - 1);
                }
            }

            Debug.Print("process screenshot " + screenshot);
            PerformOcr(textRowLocations);
        }