国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

.NET中兩種OCR方式對比

2019-11-11 06:26:09
字體:
供稿:網(wǎng)友
1.使用 Tesseract Install-Package Tesseract2.從這里下載實例項目(為了獲得訓(xùn)練數(shù)據(jù))tessdata目錄下的就是訓(xùn)練數(shù)據(jù),等下初始化Tesseract引擎對象會使用。測試代碼:  
PRivate static void TesseractSample()        {            var testImagePath = "phototest.tif";            try            {                using (var engine = new TesseractEngine(@"../../tessdata", "eng", EngineMode.Default))                {                    using (var img = Pix.LoadFromFile(testImagePath))                    {                        using (var page = engine.Process(img))                        {                            var text = page.GetText();                            Console.WriteLine("Mean confidence: {0}", page.GetMeanConfidence());                            Console.WriteLine("Text (GetText): /r/n{0}", text);                            Console.WriteLine("Text (iterator):");                            using (var iter = page.GetIterator())                            {                                iter.Begin();                                do                                {                                    do                                    {                                        do                                        {                                            do                                            {                                                if (iter.IsAtBeginningOf(PageIteratorLevel.Block))                                                {                                                    Console.WriteLine("<BLOCK>");                                                }                                                Console.Write(iter.GetText(PageIteratorLevel.Word));                                                Console.Write(" ");                                                if (iter.IsAtFinalOf(PageIteratorLevel.TextLine, PageIteratorLevel.Word))                                                {                                                    Console.WriteLine();                                                }                                            } while (iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word));                                            if (iter.IsAtFinalOf(PageIteratorLevel.Para, PageIteratorLevel.TextLine))                                            {                                                Console.WriteLine();                                            }                                        } while (iter.Next(PageIteratorLevel.Para, PageIteratorLevel.TextLine));                                    } while (iter.Next(PageIteratorLevel.Block, PageIteratorLevel.Para));                                } while (iter.Next(PageIteratorLevel.Block));                            }                        }                    }                }            }            catch (Exception e)            {                Console.WriteLine("Unexpected Error: " + e.Message);                Console.WriteLine("Details: ");                Console.WriteLine(e.ToString());            }            Console.WriteLine("Press anykey to end");            Console.ReadKey();        }使用MS cognitive做OCR1. 有一個Cognitive 的賬號。2. 準備一個測試圖片

3. 測試代碼:

... MS_OCRApi("phototest.tif");...    static async void MS_OCRApi(string pathOfImage)        {                        var client = new HttpClient();            var queryString = HttpUtility.ParseQueryString(string.Empty);            const string API_KEY = "{your key}";            // Request headers            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", API_KEY);            // Request parameters            queryString["language"] = "unk";            queryString["detectOrientation "] = "true";            var uri = "https://westus.api.cognitive.microsoft.com/vision/v1.0/ocr?" + queryString;            HttpResponseMessage response;            // Request body            byte[] byteData = File.ReadAllBytes(pathOfImage);            using (var content = new ByteArrayContent(byteData))            {                content.Headers.ContentType =                    new MediaTypeHeaderValue("application/octet-stream");                response = await client.PostAsync(uri, content);                var s = new MemoryStream();                await response.Content.CopyToAsync(s);                var str = Encoding.UTF8.GetString(s.ToArray());                var results = JsonConvert.DeserializeObject<MsOCRResult>(str);                Console.WriteLine("Results :");                var lines = results.regions.SelectMany(x => x.lines);                foreach (var ocrLine in lines)                {                    Console.WriteLine(ocrLine);                }                Console.ReadKey();            }        }

對比兩種OCR:1. MS Cognitive Service是RESTful api based,支持多種客戶端而且不用關(guān)心機器學(xué)習(xí)過程,但是收費(每月5000個call,1分鐘20個call免費)。不過可考慮使用緩存來降低成本。2. Tesseract是dll based。因此需要不斷更新訓(xùn)練數(shù)據(jù),如果需要支持多客戶端,需要自己wrap一個RESTful。好處就是免費。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 泰安市| 平邑县| 兴安盟| 望江县| 江川县| 仙游县| 苍梧县| 永吉县| 英吉沙县| 旺苍县| 平泉县| 边坝县| 松阳县| 江北区| 鹰潭市| 商丘市| 连山| 政和县| 珠海市| 上饶县| 大同县| 康马县| 景泰县| 萨嘎县| 县级市| 镇平县| 云阳县| 海盐县| 苏尼特右旗| 杂多县| 淮安市| 汉源县| 泽库县| 元阳县| 特克斯县| 朔州市| 梁河县| 阿城市| 噶尔县| 峡江县| 陕西省|