// 工具栏 “识别” 按钮单击事件 private void Button_Click(object sender, RoutedEventArgs e) { TesseractEngine ocr; string path = AppDomain.CurrentDomain.BaseDirectory; string rootPath = path.Substring(0, path.LastIndexOf("bin")); string tessdataPath = string.Concat(rootPath, "tessdata"); // TODO: 修改为资源->打包后可用 ocr = new TesseractEngine(tessdataPath, "eng", EngineMode.Default); //设置语言 英文 var img = Pix.LoadFromFile(imgPath); //bit = PreprocesImage(bit);//进行图像处理,如果识别率低可试试 Tesseract.Page page = ocr.Process(img); string str = "识别结果:\n\n"; str += page.GetText();//识别后的内容 page.Dispose(); //string str = ImageToText(imgPath); tessTextBlock.Text = str; // 识别结果显示到界面 // TODO: 识别失败的处理 }
public Boolean Classification(int[,] AddedAreaPoints, string ImageID) { // Bitmap DestinationImage = new Bitmap(28, 28); /// To see Result of Scaling Bitmap DestinationImage = new Bitmap(AddedAreaPoints.Rows(), AddedAreaPoints.Columns()); int[,] DestinationPoints = new int[28, 28]; /// To see Result of Scaling double XConvertor = (double)(AddedAreaPoints.Rows()) / (double)(28); double YConvertor = (double)(AddedAreaPoints.Columns()) / (double)(28); double[] input = new double[784]; for (int i = 0; i < 28; i++) { for (int j = 0; j < 28; j++) { double XInSourceImage = (double)(XConvertor * i); double YInSourceImage = (double)(YConvertor * j); int X = (int)(Math.Floor(XInSourceImage)); int Y = (int)(Math.Floor(YInSourceImage)); input[i * 28 + j] = AddedAreaPoints[X, Y]; DestinationPoints[i, j] = AddedAreaPoints[X, Y]; } } // for (int i = 0; i < 28; i++) for (int i = 0; i < AddedAreaPoints.Rows(); i++) { // for (int j = 0; j < 28; j++) for (int j = 0; j < AddedAreaPoints.Columns(); j++) { // if (DestinationPoints[i, j] == 1) if (AddedAreaPoints[i, j] == 1) DestinationImage.SetPixel(i, j, Color.Black); else DestinationImage.SetPixel(i, j, Color.White); } } DestinationImage.Save(@"C:\Users\nhonarva\Documents\ResultsOfScaling\scaling" + ImageID + ".png"); var image = Pix.LoadFromFile(@"C:\Users\nhonarva\Documents\ResultsOfScaling\scaling" + ImageID + ".png"); // Page page; page=_engine.Process(image, PageSegMode.SingleBlock); string text = page.GetText(); double confidence = page.GetMeanConfidence(); page.Dispose(); int actual = (int)ksvm.Compute(input); if (actual == 1) return true; else return false; }
public void Dispose() { page.Dispose(); }