應映老師該死的關鍵字要求(OCR)
找了一圈發現簡單的基礎範例
花了一天一夜才發現最方便的就是這個emgu啊阿啊
原來他那麼好用(滿足
這個也是我跟估狗大神請教的喔
找了一圈發現簡單的基礎範例
花了一天一夜才發現最方便的就是這個emgu啊阿啊
原來他那麼好用(滿足
這個也是我跟估狗大神請教的喔
不是我自己的
環境:
NET framework 4.5.2
重要步驟 :
安裝套件:myEmguCV.Net
設計頁面:
程式碼:
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 Emgu.CV;
using Emgu.Util;
using Emgu.CV.OCR;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.CV.CvEnum;
namespace _01
{
public partial class Form1 : Form
{
public Boolean btnFirstTimeInResizeEvent = true;
public int intOrigFromWidth;
public int intOrigFromHeight;
public int intOrigTableLayoutPanelWidth;
public int intOrigTableLayoutPanelHeight;
public Image<Bgr, Byte> imgImage;
public Image<Bgr, Byte> imgBlank;
public Tesseract tess;
public Form1()
{
InitializeComponent();
intOrigFromHeight = this.Height;
intOrigFromWidth = this.Width;
intOrigTableLayoutPanelHeight = tblTextBoxAndImageBox.Height;
intOrigTableLayoutPanelWidth = tblTextBoxAndImageBox.Width;
try
{
tess = new Tesseract("tessdata","eng", Tesseract.OcrEngineMode.OEM_DEFAULT);
}
catch (Exception e)
{
this.Text = "Error Instantiating Tesseract Object";
txtOCR.Text = "Error Instantiating Tesseract Object";
System.Console.WriteLine(e.ToString());
txtFile.Enabled = false;
btnFile.Enabled = false;
}
}
private void frmOCR_Resize(object sender, EventArgs e)
{
if (btnFirstTimeInResizeEvent)
{
btnFirstTimeInResizeEvent = false;
}
else
{
tblTextBoxAndImageBox.Width = this.Width - (intOrigFromWidth - intOrigTableLayoutPanelWidth);
tblTextBoxAndImageBox.Height = this.Height - (intOrigFromHeight - intOrigTableLayoutPanelHeight);
}
}
private void btnFile_Click(object sender, EventArgs e)
{
DialogResult result = oldFile.ShowDialog();
if (result == DialogResult.OK)
{
txtFile.Text = oldFile.FileName;
}
}
private void txtFile_TextChanged(object sender, EventArgs e)
{
txtFile.SelectionStart = txtFile.Text.Length;
if (string.IsNullOrWhiteSpace(txtFile.Text))
{
// Message box
}
else
{
processImageUpdateGUI();
}
}
private void processImageUpdateGUI()
{
try
{
imgImage = new Image<Bgr, byte>(txtFile.Text);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
if (imgImage == null)
{
Console.WriteLine("No image is found");
}
pbImage.Image = imgImage.ToBitmap();
Application.DoEvents();
tess.Recognize(imgImage);
txtOCR.Text = tess.GetText();
}
}
}
結果:
沒有留言:
張貼留言