// var PrescriptionImage = ".\prescription.png"; public static string ocrDigit(Bitmap CropedPrescription, int x, int y, int width, int height) { string text; // var PrescriptionImage = CropedPrescription; using (var engine = new TesseractEngine(@"C:\Program Files\Tesseract-OCR\tessdata\", "kor", EngineMode.Default)) { // engine.SetVariable("tessedit_char_whitelist", "0123456789-."); // 숫자와 . - 만 인식하도록 설정 var roi = new Rect(x, y, width, height); // region of interest 좌표를 생성하고 // using (var img = Pix.LoadFromFile(PrescriptionImage)) // { using (var page = engine.Process(CropedPrescription, roi, PageSegMode.Auto)) { text = page.GetText(); text = TextProcess.RemoveWhiteSpace(text); // Console.WriteLine("인식한 문자: \n{0}\n", text); // Console.Read(); } // } } return(text); }
public static string ocrDigitLine(Bitmap source, int x, int y, int width, int height) // 한줄씩 읽어내고 "-" --> "." 으로 치환하고, 공백 제거등, 투약량에 쓰기 좋다. { string text; // var PrescriptionImage = CropedPrescription; using (var engine = new TesseractEngine(@"C:\Program Files\Tesseract-OCR\tessdata\", "kor", EngineMode.Default)) { engine.SetVariable("tessedit_char_whitelist", "0123456789-."); // 숫자와 . - 만 인식하도록 설정 // using (var img = Pix.LoadFromFile(PrescriptionImage)) // { var roi = new Rect(x, y, width, height); // region of interest 좌표를 생성하고 using (var page = engine.Process(source, roi, PageSegMode.SingleLine)) // psm 옵션 설정 { text = page.GetText(); text = TextProcess.RemoveWhiteSpace(text); // text = TextProcess.DotReplace(text); // text = TextProcess.PointInsert(text); // Console.WriteLine("인식한 문자: \n{0}\n", text); // Console.Read(); } // } } return(text); }
public static string ocrTextLine(Bitmap source, int x, int y, int width, int height) // 특정 좌표 지역을 받아서 그 부분만 판독하는 함수 { string htext; // var PrescriptionImage = CropedPrescription; using (var engine = new TesseractEngine(@"C:\Program Files\Tesseract-OCR\tessdata\", "kor", EngineMode.Default)) { // using (var img = Pix.LoadFromFile(PrescriptionImage) // { var roi = new Rect(x, y, width, height); // region of interest 좌표를 생성하고 using (var page = engine.Process(source, roi, PageSegMode.SingleLine)) // PageSegMode 에서 여러 인식형태를 조정한다. { htext = page.GetText(); // System.IO.File.WriteAllText(@"C:\Program Files\PLOCR\textrecognition.html", htext); // 인식한 글자를 html 형식으로 저장한다. // Console.WriteLine(htext); // Console.Read(); htext = TextProcess.RemoveWhiteSpace(htext); // htext = TextProcess.DotReplace(htext); } // } return(htext); } }