PaddleOCRSharp?是一個(gè)基于百度飛槳(PaddlePaddle)封裝的.NET版本OCR工具類庫,旨在為.NET開發(fā)者提供高效且簡(jiǎn)便的方式來集成OCR功能。PaddleOCRSharp是PaddleOCR的.NET封裝庫,使得.NET開發(fā)者能夠方便地在其項(xiàng)目中調(diào)用PaddleOCR提供的文本識(shí)別功能?。
?private PaddleOCREngine engine;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
if (ofd.ShowDialog() != DialogResult.OK) return;
this.pictureBox1.Image = Image.FromFile(ofd.FileName);
}
private void button2_Click(object sender, EventArgs e)
{
Bitmap imagebyte = new Bitmap(pictureBox1.Image);
OCRModelConfig config = null;
//OCR參數(shù)
OCRParameter oCRParameter = new OCRParameter();
oCRParameter.cpu_math_library_num_threads = 10;//預(yù)測(cè)并發(fā)線程數(shù)
oCRParameter.enable_mkldnn = true;//web部署該值建議設(shè)置為0,否則出錯(cuò),內(nèi)存如果使用很大,建議該值也設(shè)置為0.
oCRParameter.cls = false; //是否執(zhí)行文字方向分類;默認(rèn)false
oCRParameter.det = true;//是否開啟方向檢測(cè),用于檢測(cè)識(shí)別180旋轉(zhuǎn)
oCRParameter.use_angle_cls = false;//是否開啟方向檢測(cè),用于檢測(cè)識(shí)別180旋轉(zhuǎn)
oCRParameter.det_db_score_mode = true;//是否使用多段線,即文字區(qū)域是用多段線還是用矩形,
oCRParameter.max_side_len = 1500;
oCRParameter.rec_img_h = 48;
oCRParameter.rec_img_w = 320;
oCRParameter.det_db_thresh = 0.3f;
oCRParameter.det_db_box_thresh = 0.618f;
//初始化OCR引擎
engine = new PaddleOCREngine(config, oCRParameter);
//模型配置,使用默認(rèn)值
StructureModelConfig structureModelConfig = null;
//表格識(shí)別參數(shù)配置,使用默認(rèn)值
StructureParameter structureParameter = new StructureParameter();
PaddleStructureEngine structengine = new PaddleStructureEngine(structureModelConfig, structureParameter);
OCRResult ocrResult = engine.DetectText(imagebyte);
richTextBox1.AppendText(ocrResult.Text);
}
閱讀原文:原文鏈接
該文章在 2025/2/17 12:27:31 編輯過