public Controller() { InitializeComponent(); string dataPath = @"C:/Users/Administrator/Documents/Visual Studio 2015/Projects/JustDrag/JustDrag/tessdata/"; string language = @"kor"; using (var api = new Tesseract.TessBaseAPI(dataPath, language)) { api.Process("C:/Users/Administrator/Documents/Visual Studio 2015/Projects/JustDrag/JustDrag/multiple_numbers.png", true); string text = api.GetUTF8Text(); Console.WriteLine(text); } }
// POST: api/Ocr public IHttpActionResult Post([FromBody] ImageModel image) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); if (image != null) { try { var localImage = createLocalImage(image); lock (syncLock) { tessBaseApi.Process(localImage); stopWatch.Stop(); File.Delete(localImage); var response = new OcrResponseModel() { Id = Guid.NewGuid(), RequestDuration = stopWatch.Elapsed, Text = tessBaseApi.GetUTF8Text() }; return(Ok(response)); } } catch { } } stopWatch.Stop(); var exception = new ExceptionModel() { DateCreated = DateTime.Now, ExceptionMessage = "Image object could not be deserialised or ocr process failed.", RequestDuration = stopWatch.Elapsed }; return(BadRequest(exception.ToString())); }