Exemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            TerminarFuenteDeVideo();

            if (EspacioCamara.Image != null)
            {
                //Save First
                Bitmap varBmp = new Bitmap(EspacioCamara.Image);

                Bitmap newBitmap    = new Bitmap(varBmp);
                string physicalPath = Path.Combine("C:/root/JuntaFiles/", "a.jpg");
                varBmp.Save(physicalPath, ImageFormat.Jpeg);
                //varBmp.Save(@"C:\a.png", ImageFormat.Png);
                //Now Dispose to free the memory
                varBmp.Dispose();
                varBmp = null;
            }
            else
            {
                MessageBox.Show("null exception");
            }


            using (var api = OcrApi.Create())
            {
                api.Init(Languages.English);
                string plainText = api.GetTextFromImage("C:/captura.png");

                lblOcr.Text = plainText;
            }
        }
        /* Auxiliary methods */
        private void TakeImage_btn_Click(object sender, EventArgs e)
        {
            if (_capture != null)
            {
                pictureBox2.Image   = pictureBox1.Image;
                pictureBox1.Visible = false;
                pictureBox2.Visible = true;
                pictureBox2.Image.Save(@"C:\Users\lukaa\Desktop\l.jpg");
            }
            using (var objOcr = OcrApi.Create())
            {
                objOcr.Init(Patagames.Ocr.Enums.Languages.English);
                string x = objOcr.GetTextFromImage(@"C:\Users\lukaa\Desktop\l.jpg");
                x = new string((from c in x
                                where char.IsNumber(c)
                                select c
                                ).ToArray());

                int balance = int.Parse(x);
                if (balance == 206)
                {
                    balance = 200;
                }
                else if (balance == 1005)
                {
                    balance = 1000;
                }
                RegistrationForm rf = (RegistrationForm)Application.OpenForms["RegistrationForm"];
                rf.balance_txt.Text = balance.ToString();
            }
        }
Exemplo n.º 3
0
        private void btnconvert_Click(object sender, EventArgs e)
        {
            txtsubject.Text = "";
            // open file dialog
            OpenFileDialog open = new OpenFileDialog();

            // image filters
            open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.png;*.bmp)|*.jpg; *.jpeg; *.gif; *.png;*.bmp";
            if (open.ShowDialog() == DialogResult.OK)
            {
                string testImagePath = Path.GetFullPath(open.FileName);


                try
                {
                    using (var api = OcrApi.Create())
                    {
                        api.Init(Languages.English);
                        string plainText = api.GetTextFromImage(testImagePath);
                        txtsubject.Text = plainText;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Unexpected Error During Conversion");
                    return;
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 测试识别率。
        /// </summary>
        /// <param name="verificationCodeCategory">验证码类别。</param>
        /// <param name="count">数量。</param>
        /// <param name="action">回调函数。</param>
        /// <returns>结果。成功数+总数。</returns>
        public Tuple <int, int> Test(VerificationCodeCategory verificationCodeCategory, int count, Action <string> action)
        {
            var successCount = 0;

            if (count > 0)
            {
                using (var ocrApi = OcrApi.Create())
                {
                    ocrApi.Init(Languages.English);
                    for (int i = 0; i < count; i++)
                    {
                        var numberChar = Utils.GetRandString(verificationCodeCategory);
                        using (var bitmap = Utils.CreateCaptchaSimpleImage(numberChar))
                        {
                            var text          = ocrApi.GetTextFromImage(bitmap);
                            var resultSuccess = string.Equals(numberChar?.Trim(), text?.Trim(),
                                                              StringComparison.CurrentCultureIgnoreCase);
                            var resultMessage = resultSuccess
                                ? "识别成功"
                                : "识别失败";
                            if (resultSuccess)
                            {
                                successCount++;
                            }

                            var message = $"{i + 1}, 随机数是{numberChar},验证码识别是{text},结果:{resultMessage}。 \r\n";
                            action?.Invoke(message);
                            bitmap.Dispose();
                        }
                    }
                }
            }

            return(new Tuple <int, int>(successCount, count));
        }
Exemplo n.º 5
0
 /// <summary>
 /// 识别字符串。
 /// </summary>
 /// <param name="bitmap">bitmap图片。</param>
 /// <returns>识别结果。</returns>
 public string GetStringFromImage(Bitmap bitmap)
 {
     using (var ocrApi = OcrApi.Create())
     {
         ocrApi.Init(Languages.English);
         return(ocrApi.GetTextFromImage(bitmap));
     }
 }
Exemplo n.º 6
0
 private string RecognizeText(string filename)
 {
     using (var ocrEntity = OcrApi.Create())
     {
         ocrEntity.Init(Patagames.Ocr.Enums.Languages.English);
         string recognizedText = ocrEntity.GetTextFromImage(filename);
         return(recognizedText);
     }
 }
Exemplo n.º 7
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (var api = OcrApi.Create())
     {
         api.Init(Languages.Arabic);
         String Text = api.GetTextFromImage(@"C:\OCR\arabic-1.jpg");
         label1.Text = Text.ToString();
     }
 }
Exemplo n.º 8
0
 static void Main(string[] args)
 {
     using (var api = OcrApi.Create())
     {
         api.Init(Languages.Japanese);
         string plainText = api.GetTextFromImage(filepath);
         Console.WriteLine(plainText);
     }
     Console.ReadLine();
 }
Exemplo n.º 9
0
        public void ConvertImageToText()
        {
            using (var api = OcrApi.Create())
            {
                api.Init(Languages.Lithuanian);
                string plainText = api.GetTextFromImage("C:\\Users\\justas\\source\\repos\\ProjectTesseract\\ProjectTesseract\\Test3.jpg");

                Console.WriteLine(plainText);
                Console.Read();
            }
        }
Exemplo n.º 10
0
 //Poor results :(
 public void ConvertImageToText()
 {
     using (var api = OcrApi.Create())
     {
         api.Init(Languages.English);
         string image     = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "jcaptcha.jpg");
         string plainText = api.GetTextFromImage(image);
         Console.WriteLine(plainText);
         Console.Read();
     }
 }
Exemplo n.º 11
0
        public string GetCaptChaCode(string path)
        {
            string captchaCode = "";

            using (var objOcr = OcrApi.Create())
            {
                objOcr.Init(Patagames.Ocr.Enums.Languages.English);

                captchaCode = objOcr.GetTextFromImage(path);
            }
            return(captchaCode = Regex.Replace(captchaCode, @"\r\n?|\n", ""));
        }
Exemplo n.º 12
0
        private static string ParseData(string imagename)
        {
            using (var api = OcrApi.Create())
            {
                api.Init(Languages.English, null, OcrEngineMode.OEM_TESSERACT_ONLY);

                var plainText = api.GetTextFromImage(imagename);

                var format = plainText.Split('\n')[0];
                return(CleanString(format));
            }
        }
Exemplo n.º 13
0
        public static string ExtractTextFromImage(string path)
        {
            using (var api = OcrApi.Create())
            {
                api.Init(Languages.English);
                using (var bmp = Bitmap.FromFile(path) as Bitmap)
                {
                    string plainText = api.GetTextFromImage(bmp);

                    return(plainText);
                }
            }
        }
Exemplo n.º 14
0
        public static void ConvertImageToText(Bitmap img)
        {
            using (var api = OcrApi.Create())
            {
//        api.Init(dataPath:@"F:\!prog\La2\WpfLa2\WpfLa2\bin\Debug\x64\tesseract.dll",language:Languages.English);
                api.Init(language: Languages.English);

//        string plainText = api.GetTextFromImage(img);
                string plainText = api.GetTextFromImage("screenshot2.png");
                Console.WriteLine(plainText);
                Console.Read();
            }
        }
 private string RecognizeText(string path)
 {
     using (var api = OcrApi.Create())
     {
         api.Init(Languages.English, "./", OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED);
         string plainText = api.GetTextFromImage(path);
         plainText = Regex.Replace(plainText, "[^a-zA-Z0-9]", "").ToUpper();
         if (plainText.Length >= 8)
         {
             plainText = plainText.Remove(2, 1).ToString();
         }
         return(plainText);
     }
 }
Exemplo n.º 16
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var api = OcrApi.Create())
            {
                OpenFileDialog op = new OpenFileDialog();

                api.Init(Languages.English);
                Image test = Image.FromFile(path);


                string plainText = api.GetTextFromImage(ResizeImage(test, 499, 499));
                MessageBox.Show(plainText);
            }
        }
Exemplo n.º 17
0
 public static void ImageText()
 {
     try
     {
         using (var api = OcrApi.Create())
         {
             api.Init(Languages.English);
             string plaintext = api.GetTextFromImage(invoice55);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Unexpected Error: " + e.Message);
     }
 }
Exemplo n.º 18
0
        public static string GetText(Bitmap imgsource)
        {
            string text;

            using (var api = OcrApi.Create())
            {
                api.Init(Languages.English);
                using (var bmp = imgsource)
                {
                    text = api.GetTextFromImage(bmp);
                }
            }

            return(text);
        }
Exemplo n.º 19
0
        private string GetOCR(Bitmap big, Imaging.ImageRange range, bool flag = true)
        {
            Point p      = new Point();
            int   width  = 0;
            int   height = 0;

            p.X    = range.loc.X;
            p.Y    = range.loc.Y;
            width  = range.width;
            height = range.height;

            big = Imaging.CropImage(big, p, width, height);
            big = Imaging.ConvertFormat(big, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
            if (!flag)
            {
                big = Imaging.MakeGrayscale3(big);
            }
            //;
            else
            {
                big = grayscale(big);
            }

            //tessnet2.Tesseract api = new tessnet2.Tesseract();

            //api.Init()
            OcrApi.PathToEngine = Environment.CurrentDirectory + @"\tesseract.dll";
            OcrApi api = OcrApi.Create();

            Languages[] lang = { Languages.English };
            api.Init(lang, null, OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED);
            api.SetVariable("tessedit_char_whitelist", "0123456789");

            string plainText = api.GetTextFromImage(big);

            ////Console.WriteLine(plainText);
            ////this.Invoke(new MethodInvoker(delegate() { txtLog.AppendText(plainText + Environment.NewLine); }));
            api.Dispose();
            api = null;
            System.GC.Collect(0, GCCollectionMode.Forced);
            System.GC.WaitForPendingFinalizers();

            return(plainText);
            //return "";
        }
Exemplo n.º 20
0
        public string GetCaptChaCode()
        {
            string captchaCode = "";

            using (WebClient client = new WebClient())
            {
                client.DownloadFile(new Uri("http://tracuuhoadon.gdt.gov.vn/Captcha.jpg"), "Captcha.jpg");
                //var autoOcr = new AutoOcr();
                //Image img = new Bitmap(Application.StartupPath + "\\Captcha.jpg");
                //captchaCode = autoOcr.Read(img).ToString();
                using (var objOcr = OcrApi.Create())
                {
                    objOcr.Init(Patagames.Ocr.Enums.Languages.English);

                    captchaCode = objOcr.GetTextFromImage(Application.StartupPath + "\\Captcha.jpg");
                }
                return(captchaCode = Regex.Replace(captchaCode, @"\r\n?|\n", ""));
            }
        }
Exemplo n.º 21
0
        public static string ConvertImageToText(string filePath)
        {
            string plainText = "Error 505";

            using (var api = OcrApi.Create())
            {
                api.Init(Languages.Lithuanian, "./");
                //Image<Bgr, byte> imgInput = new Image<Bgr, byte>("..\\..\\Book_test.jpg");
                //Image<Gray, byte> imgGray = imgInput.Convert<Gray, byte>();
                //imgGray.Dilate(1);
                //imgGray.Erode(1);
                //Image<Gray, byte> imgBinarize = new Image<Gray, byte>(imgGray.Width, imgGray.Height, new Gray(0));
                //CvInvoke.Threshold(imgGray, imgBinarize, 90, 255, Emgu.CV.CvEnum.ThresholdType.Binary);
                //plainText = api.GetTextFromImage(imgBinarize.Bitmap);

                plainText = api.GetTextFromImage(filePath);
            }
            return(plainText);
        }
        public string GetText(string path)
        {
            try
            {
                var answer = new AnswerModel();

                using (var api = OcrApi.Create())
                {
                    api.Init(Languages.English, "./");
                    answer.OutText = api.GetTextFromImage(path);
                }

                return(JsonSerializer.Serialize(answer));
            }
            catch (Exception exception)
            {
                _logger.LogError("Ошибка выполнения GetText {exception}", exception);
                return(null);
            }
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            string picPath = @"Pic/Untitled.png";

            if (File.Exists(picPath))
            {
                using (var ocr = OcrApi.Create())
                {
                    ocr.Init(Patagames.Ocr.Enums.Languages.English);

                    string plainText = ocr.GetTextFromImage(picPath);

                    Console.WriteLine(plainText);
                }
            }
            else
            {
                Console.WriteLine($"Couldn't find {picPath}");
            }

            Console.ReadLine();
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            var path    = args[0];
            var targets = Directory.EnumerateFiles(path, "*.png");

            var c = 0;
            var r = new Regex("[0-9]{3,4}");

            using (var api = OcrApi.Create())
            {
                api.Init(Languages.English);
                api.ReadConfigFiles("TessConf.txt");

                foreach (var item in targets.Skip(0))
                {
                    using (var src = new Bitmap(item))
                    {
                        var bmps = GetImages(src);
                        foreach (var tg in bmps)
                        {
                            using (tg)
                            {
                                tg.Save($"test\\test_{c++}.png");
                                var text = api.GetTextFromImage(tg);
                                var m    = r.Match(text);
                                if (!m.Success)
                                {
                                    Console.WriteLine(text + "?");
                                }
                                Console.WriteLine(m.Value);
                            }
                        }
                    }
                }
            }

            Console.ReadLine();
        }
Exemplo n.º 25
0
 string TesseractAPI()
 {
     using (var objOcr = OcrApi.Create())
     {
         objOcr.Init(Patagames.Ocr.Enums.Languages.English);
         objOcr.SetVariable("tessedit_char_whitelist", "0123456789-Model:");
         ICapture          capture = (ICapture)video;
         Mat               img     = capture.QueryFrame();
         int               with    = img.Width;
         int               heigh   = img.Height;
         Image <Hsv, byte> image1  = (Image <Hsv, byte>)null;
         image1 = new Image <Hsv, byte>(img.Bitmap);
         int       width  = integerVariable3 - integerVariable1;
         int       height = integerVariable4 - integerVariable2;
         Rectangle rect   = new Rectangle(integerVariable1, integerVariable2, width, height);
         image1.Draw(rect, new Hsv(0.0, 0.0, (double)byte.MaxValue), 10, Emgu.CV.CvEnum.LineType.AntiAlias, 0);
         image1.Save(@"C:\Images\Labe.jpg");
         image1.Dispose();
         var    _bmp = Bitmap.FromFile(@"C:\Images\Labe.jpg");
         string _OCR = objOcr.GetTextFromImage((Bitmap)_bmp);
         _bmp.Dispose();
         return(_OCR);
     }
 }
Exemplo n.º 26
0
        private void ScanImageButton_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog sudokuBoardImage = new Microsoft.Win32.OpenFileDialog();
            sudokuBoardImage.Filter = "Image files |*.png;*.jpeg;*jpg";
            if (sudokuBoardImage.ShowDialog() == true)
            {
                var api = OcrApi.Create();
                api.Init(Languages.English);
                try
                {
                    string sudokuValuesFromFile = api.GetTextFromImage(sudokuBoardImage.FileName);
                    sudokuValuesFromFile = sudokuValuesFromFile.Replace("\n", "");
                    if (sudokuValuesFromFile.Length != TOTAL_SUDOKU_VALUES)
                    {
                        MessageBox.Show($"{sudokuValuesFromFile.Length} Incompatible board - Empty boxes should be filled in with X's");
                        MessageBox.Show(sudokuValuesFromFile);
                        return;
                    }


                    for (int i = 0; i < TOTAL_SUDOKU_VALUES; i++)
                    {
                        TextBox temp = (TextBox)BoardGrid.Children[i];
                        int     newValue;
                        if (!Int32.TryParse(sudokuValuesFromFile[i].ToString(), out newValue))
                        {
                            continue;
                        }
                        temp.Text = sudokuValuesFromFile[i] == 'X' ? "" : newValue.ToString();
                    }
                } catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Exemplo n.º 27
0
        private string ExtractTextFromImage(string filePath)
        {
            string datapath = Server.MapPath("~");
            List <System.Drawing.Image> cropimages = new List <System.Drawing.Image>();

            System.Drawing.Image img = System.Drawing.Image.FromFile(filePath, true);

            int totalColumns = 0;

            int.TryParse(txtColumns.Text, out totalColumns);
            int totalRows = 0;

            int.TryParse(txtRows.Text, out totalRows);
            cropimages = MultiCrop(filePath, img, totalRows, totalColumns);

            string directorypath = Server.MapPath("~/uploads/") + Path.GetFileNameWithoutExtension(filePath);

            if (!Directory.Exists(directorypath))
            {
                Directory.CreateDirectory(directorypath);
            }

            DataTable dt = new DataTable();

            for (int i = 1; i <= totalColumns; i++)
            {
                dt.Columns.Add("Column" + i);
            }
            List <string> lstdata = new List <string>();

            for (int i = 0; i < cropimages.Count; i++)
            {
                {
                    string temp_crop_file = directorypath + "\\" + i + Path.GetExtension(filePath);
                    {
                        cropimages[i].Save(temp_crop_file);
                    }
                    try
                    {
                        string[] configs = { "config.cfg" };
                        using (var api = OcrApi.Create())
                        {
                            api.Init(Languages.English, datapath, OcrEngineMode.OEM_DEFAULT, configs);
                            using (var bmp = Bitmap.FromFile(temp_crop_file) as Bitmap)
                            {
                                string extracedText = api.GetTextFromImage(bmp);
                                lstdata.Add(extracedText);
                            }
                        }
                    }
                    catch
                    {
                        lstdata.Add("");
                    }
                }
            }

            for (int i = 0; i < lstdata.Count; i++)
            {
                DataRow dr = dt.NewRow();
                for (int j = 0; j < totalColumns; j++)
                {
                    dr[j] = lstdata[i];
                    i++;

                    if (i >= lstdata.Count)
                    {
                        break;
                    }
                }
                i--;
                dt.Rows.Add(dr);
            }

            GenerateReport(dt);
            string extractedText = "";

            //string extractedText = modiImage.Layout.Text;
            //modiDocument.Close();
            return(extractedText);
        }
Exemplo n.º 28
0
        public ActionResult Index(HttpPostedFileBase file)
        {
            List <string> productNames = new List <string>();
            double        max = 0, max2 = 0;
            string        name1 = "", name2 = "";

            var products = from p in db.Products
                           select p.Name;

            foreach (var p in products)
            {
                productNames.Add(p.ToString());
            }
            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    string path = Path.Combine(Server.MapPath("~/Content/Images"),
                                               Path.GetFileName(file.FileName));
                    file.SaveAs(path);
                    ViewBag.Message = "Sikeres feltöltés";
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            }
            else
            {
                ViewBag.Message = "Nem lett fájl kiválasztva";
            }

            if (file != null && file.ContentLength > 0)
            {
                using (var api = OcrApi.Create())
                {
                    api.Init(Languages.English, "C:/Users/Ati/Documents/Visual Studio 2015/Projects/MVCapp/MVCapp");
                    using (var bmp = Bitmap.FromFile(Path.Combine(Server.MapPath("~/Content/Images"),
                                                                  Path.GetFileName(file.FileName))) as Bitmap)
                    {
                        string plainText = api.GetTextFromImage(bmp);
                        plainText = Regex.Replace(plainText, @"\W", "");
                        foreach (var name in productNames)
                        {
                            double temp = Levenshtein.CalculateSimilarity(plainText, name);
                            if (temp > max)
                            {
                                max2  = max;
                                name2 = name1;
                                max   = temp;
                                name1 = name;
                            }
                            else if (temp > max2)
                            {
                                max2  = temp;
                                name2 = name;
                            }
                        }
                    }
                }
            }
            var results = from p in db.Products
                          where p.Name == name1 || p.Name == name2
                          select p;

            return(View(results.ToList()));
        }
Exemplo n.º 29
0
        public static string GetLastSeen()
        {
            string lastonline = "";

            while (true)
            {
                Thread.Sleep(5000);
                IntPtr hwnd = CommonCode.FindWindow("Qt5QWindowOwnDCIcon", null);
                CommonCode.SetWindowPos(hwnd, CommonCode.WndTopMost, 0, 0, 0, 0, CommonCode.SWP_NOSIZE | CommonCode.SWP_SHOWWINDOW);
                Bitmap screen = new Bitmap(167, 14);
                using (Graphics g = Graphics.FromImage(screen))
                {
                    g.CopyFromScreen(375, 113, 0, 0, screen.Size);
                    screen.Save("image1.png");
                    float width  = screen.Width * (float)1.4;
                    float height = screen.Height * (float)1.4;
                    var   brush  = new SolidBrush(Color.White);
                    var   bmp    = new Bitmap((int)width, (int)height);
                    var   graph  = Graphics.FromImage(bmp);
                    graph.InterpolationMode  = InterpolationMode.High;
                    graph.CompositingQuality = CompositingQuality.HighQuality;
                    graph.SmoothingMode      = SmoothingMode.AntiAlias;
                    var scaleWidth  = (int)(width);
                    var scaleHeight = (int)(height);
                    graph.FillRectangle(brush, new RectangleF(0, 0, width, height));
                    graph.DrawImage(screen, ((int)width - scaleWidth) / 2, ((int)height - scaleHeight) / 2, scaleWidth, scaleHeight);
                    for (int x = 0; x < bmp.Width; x++)
                    {
                        for (int y = 0; y < bmp.Height; y++)
                        {
                            var pixel = bmp.GetPixel(x, y);
                            var color = Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B);
                            if (color.R == 255 && color.G == 255 && color.B == 255 || color == Color.White)
                            {
                                continue;
                            }
                            var brightness = color.GetBrightness();
                            if (brightness < 0.83 && x > 0)
                            {
                                bmp.SetPixel(x, y, Color.Black);
                                bmp.SetPixel(x - 1, y, Color.Black);
                            }
                            else if (brightness > 0.83)
                            {
                                bmp.SetPixel(x, y, Color.White);
                            }
                        }
                    }
                    bmp.Save("image.png");
                }
                var api = OcrApi.Create();
                api.Init(Languages.English);
                string text = api.GetTextFromImage("image.png").ToLower();
                screen.Dispose();
                api.Dispose();
                if (text.Contains("mm ago"))
                {
                    text = text.Replace("mm ago", "min ago");
                }
                if (text.Contains("last seen a long"))
                {
                    lastonline = "Last seen a long time ago";
                }
                else
                {
                    lastonline = text.Trim();
                }
                if (lastonline != "")
                {
                    break;
                }
            }
            return(lastonline);
        }
Exemplo n.º 30
0
        public HttpResponseMessage ProcessImageOCR(ImageData data)
        {
            try
            {
                HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
                using (var db = new NotesAppEntities())
                {
                    if (db.Images.Where(s => s.ImageBase64String == data.base64String).Any())
                    {
                        var imagedata = db.Images.Where(s => s.ImageBase64String == data.base64String).FirstOrDefault();
                        if (imagedata != null)
                        {
                            string plainText = imagedata.OCRText;
                            return(Extensions.GetTextFile(plainText));
                        }
                    }
                    if (!string.IsNullOrEmpty(data.base64String))
                    {
                        var ImagePath = Extensions.LoadImage(data.base64String);

                        if (!string.IsNullOrEmpty(ImagePath))
                        {
                            var ext = Path.GetExtension(ImagePath);
                            if (ext == ".jpg" || ext == ".jpeg")
                            {
                                using (var api = OcrApi.Create())
                                {
                                    api.Init(Languages.English, HttpContext.Current.Server.MapPath("~"));
                                    string plainText = api.GetTextFromImage(ImagePath);

                                    db.Images.Add(new Image
                                    {
                                        ImageBase64String = data.base64String,
                                        OCRText           = plainText,
                                        CreatedUTC        = DateTime.UtcNow
                                    });
                                    db.SaveChanges();

                                    return(Extensions.GetTextFile(plainText));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Please give path for jpg or jpeg images only."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Please give path for jpg or jpeg images only."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Please provide jpg image path to process ocr."));
                    }
                }
            }
            catch (Exception ex)
            {
                //throw ex;
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }