Esempio n. 1
0
        /// <summary>
        /// Click run button to start the OCR function
        /// </summary>
        /// <param name="currentImg">Is image we are processing it</param>
        /// <returns></returns>
        private string runningOCR(ImageClass currentImg)
        {
            try
            {
                if (currentImg == null)
                {
                    //return "please open at least one image";
                    MessageBox.Show("Please open at least one image");
                    return(null);
                }

                // Check the language if it be selected or not
                if (!IsSelectedLanguage)
                {
                    MessageBox.Show("Please select language for recognizing");
                    return("Waiting for Select language");
                }
                else
                {
                    Stopwatch stopW = Stopwatch.StartNew();
                    Debug.WriteLine("USING XISOM OCR LIB: processOCR");

                    //Convert Grayscale using method 3
                    taskViewModel.xisomOCR.Grayscale       = true;
                    taskViewModel.xisomOCR.GrayscaleMethod = 3;

                    var ocrData = taskViewModel.xisomOCR.ProcessOCRwithBoxs(ImageConverter.BitmapImage2Bitmap(currentImg.Image));
                    ocrDetectedRegion = new Dictionary <SolidColorBrush, List <Rectangle> >();
                    ocrDetectedRegion.Add(new SolidColorBrush(Colors.Violet), ocrData.charBoxs.ToList());
                    ocrDetectedRegion.Add(new SolidColorBrush(Colors.Yellow), ocrData.wordBoxs.ToList());
                    ocrDetectedRegion.Add(new SolidColorBrush(Colors.Green), ocrData.lineBoxs.ToList());
                    ocrDetectedRegion.Add(new SolidColorBrush(Colors.Red), ocrData.paraBoxs.ToList());

                    stopW.Stop();
                    var time_dur = stopW.Elapsed.TotalMilliseconds.ToString();
                    this.executedTime = time_dur;
                    return(ocrData.outOCR);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// This is used to automatically find skewAngle and skew
        /// </summary>
        /// <param name="source"></param>
        /// <param name="rect"></param>
        /// <param name="HighQuality"></param>
        /// <returns></returns>
        public static Bitmap CropRotationRect2(Bitmap source, Rectangle rect, bool HighQuality)
        {
            int addition = (int)Math.Sqrt(rect.Width * rect.Width + rect.Height * rect.Height) - rect.Width;

            rect = new Rectangle(rect.X - (int)addition / 2, rect.Y, (int)Math.Sqrt(rect.Width * rect.Width + rect.Height * rect.Height), rect.Height);
            //Crop function first
            Image img = CropImage.Crop(source, rect);

            //Get skewAngle first time
            double imageSkewAngle_temp = 100;   //initial skew angle
            double imageSkewAngle      = 0;     //not skew
            int    iter = 0;                    //iteration

            while (Math.Abs(imageSkewAngle_temp) > 0.1 && iter < 5)
            {
                var skew = new gmseDeskew(ImageConverter.BitmapImage2Bitmap(ImageConverter.Image2BitmapImage(img)));
                imageSkewAngle_temp = skew.GetSkewAngle();
                imageSkewAngle      = imageSkewAngle + imageSkewAngle_temp;
                img  = gmseDeskew.DeskewImage(img);
                iter = iter + 1;
            }


            Debug.WriteLine("Goc skew tich luy sau loop: " + imageSkewAngle.ToString());


            Bitmap result = new Bitmap(rect.Width, rect.Height);

            using (Graphics g = Graphics.FromImage(result))
            {
                g.InterpolationMode = HighQuality ? InterpolationMode.HighQualityBicubic : InterpolationMode.Default;
                using (Matrix mat = new Matrix())
                {
                    mat.Translate(-rect.X, -rect.Y);
                    mat.RotateAt(-(float)imageSkewAngle, new Point(rect.X + (int)rect.Width / 2, rect.Y + (int)rect.Height / 2));
                    g.Transform = mat;
                    g.DrawImage(source, new Point(0, 0));
                }
            }
            return(result);
        }
Esempio n. 3
0
        //perform use skew angle from Deskew algorithm
        /// <summary>
        /// This method is used to find skewAngle with specificed time and skew
        /// </summary>
        /// <param name="source"></param>
        /// <param name="rect"></param>
        /// <param name="HighQuality"></param>
        /// <returns></returns>
        public static Bitmap CropRotationRect(Bitmap source, Rectangle rect, bool HighQuality)
        {
            //Crop function first
            Image img = CropImage.Crop(source, rect);

            //Get skewAngle first time
            gmseDeskew skew           = new gmseDeskew(ImageConverter.BitmapImage2Bitmap(ImageConverter.Image2BitmapImage(img)));
            double     imageSkewAngle = skew.GetSkewAngle();

            //Accumulate skewAngle second time
            Bitmap img2 = gmseDeskew.DeskewImage(ImageConverter.BitmapImage2Bitmap(ImageConverter.Image2BitmapImage(img)));

            skew           = new gmseDeskew(img2);
            imageSkewAngle = imageSkewAngle + skew.GetSkewAngle();

            //Accumulate skewAngle third time
            //Bitmap img3 = gmseDeskew.DeskewImage(img2);
            //gmseDeskew skew3 = new gmseDeskew(img3);
            //imageSkewAngle = imageSkewAngle + skew3.GetSkewAngle();


            Debug.WriteLine("Goc skew sau 2 lan tim: " + imageSkewAngle.ToString());


            Bitmap result = new Bitmap(rect.Width, rect.Height);

            using (Graphics g = Graphics.FromImage(result))
            {
                g.InterpolationMode = HighQuality ? InterpolationMode.HighQualityBicubic : InterpolationMode.Default;
                using (Matrix mat = new Matrix())
                {
                    mat.Translate(-rect.X, -rect.Y);
                    mat.RotateAt(-(float)imageSkewAngle, new Point(rect.X + (int)rect.Width / 2, rect.Y + (int)rect.Height / 2));
                    g.Transform = mat;
                    g.DrawImage(source, new Point(0, 0));
                }
            }
            return(result);
        }
Esempio n. 4
0
 private void LoadResourceImage()
 {
     backgroundImage = new BitmapImage(new Uri("Resources/bg_1920.jpeg", UriKind.Relative));
     bgImg           = new Image <Bgr, byte>(imageConverter.BitmapImage2Bitmap(backgroundImage));
 }