原創(chuàng)|使用教程|編輯:黃竹雯|2018-02-28 14:52:41.000|閱讀 343 次
概述:日常工作和業(yè)務(wù)中會(huì)有一些圖片中的計(jì)算公式等需要計(jì)算,這個(gè)代碼片斷顯示了LEADTOOLS OCR可以用來(lái)檢測(cè)、識(shí)別和執(zhí)行簡(jiǎn)單的數(shù)學(xué)命題,如“2 + 2”。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
static void SimpleOCRCalculator(string filePath) { RasterCodecs codecs = new RasterCodecs(); RasterImage image = codecs.Load(filePath); string[] calculations; using (IOcrEngine engine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false)) { engine.Startup(null, null, null, null); IOcrPage page = engine.CreatePage(image, OcrImageSharingMode.None); page.AutoZone(null); page.Recognize(null); calculations = new string[page.Zones.Count]; for (int i = 0; i < page.Zones.Count; i++) { calculations[i] = page.GetText(i); } engine.Shutdown(); } Dictionary<string, Action<double, double>> operands = new Dictionary<string, Action<double, double>>(); operands.Add("+", new Action<double, double>(delegate(double a, double b) { double ans = a + b; Console.WriteLine("{0} + {1} = {2}", a, b, ans); })); operands.Add("-", new Action<double, double>(delegate(double a, double b) { double ans = a - b; Console.WriteLine("{0} - {1} = {2}", a, b, ans); })); operands.Add("x", new Action<double, double>(delegate(double a, double b) { double ans = a * b; Console.WriteLine("{0} * {1} = {2}", a, b, ans); })); operands.Add("/", new Action<double, double>(delegate(double a, double b) { double ans = a / b; Console.WriteLine("{0} / {1} = {2}", a, b, ans); })); for (int i = 0; i < calculations.Length; i++) { string equation = Regex.Replace(calculations[i], @"\n|\r| ", ""); string[] ops = new string[] { "+", "-", "x", "/" }; for (int j = 0; j < ops.Length; j++) { int index = equation.IndexOf(ops[j]); if (index > 0 && index < equation.Length) { string op1 = equation.Substring(0, index); string op2 = equation.Substring(index + 1); double arg1 = double.Parse(op1); double arg2 = double.Parse(op2); operands[ops[j]](arg1, arg2); break; } } } codecs.Dispose(); image.Dispose(); }
試用、下載、了解更多產(chǎn)品信息請(qǐng)點(diǎn)擊""
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn