一丶截图文字识别导出
1.引入ScreenCapturer
2.引入 tesseract
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tesseract;
using static System.Net.Mime.MediaTypeNames;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
private Bitmap bmp = null;
private ScreenCapturer.ScreenCapturerTool screenCapturer;
private Page page;
public Form1()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.FormClosing += CloseBitmap;
}
private void CloseBitmap(object sender, FormClosingEventArgs e)
{
bmp.Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
System.Threading.Thread.Sleep(200);
screenCapturer = new ScreenCapturer.ScreenCapturerTool();
if (screenCapturer.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
bmp = (Bitmap)screenCapturer.Image;
pictureBox1.Image = bmp;
}
this.Show();
}
private void button2_Click(object sender, EventArgs e)
{
if(bmp != null)
{
TesseractOCR(bmp);
}
else
{
UIMessageBox.ShowAsk("没有图像!!!");
}
}
public void TesseractOCR(Bitmap image)
{
page = new TesseractEngine(AppDomain.CurrentDomain.BaseDirectory + @"\language", "chi_sim", EngineMode.Default).Process(PixConverter.ToPix(image));
image.Dispose();
Console.WriteLine(String.Format("{0:P}", page.GetMeanConfidence()));
string s = page.GetText().Replace("\n", "").Replace(" ", "");
richTextBox1.Clear();
richTextBox1.AppendText(s + "\n");
Label1.Text = "识别度:" + String.Format("{0:P}", page.GetMeanConfidence());
}
}
}