【发布时间】:2019-07-24 16:38:46
【问题描述】:
我正在为 OCR 构建一个小应用程序。
根据图像,有时 teseract 需要一些时间来计算。虽然需要时间,但我想添加一个小微调器,说明加载或计算算法。
这是我的代码的简化摘录:
---
title : app demo
author : yeshipants
output :
flexdashboard::flex_dashboard:
orientation: rows
self_contained : TRUE
source_code: embed
runtime: shiny
---
```{r setup}
knitr::opts_chunk$set(cache = FALSE)
```
```{r loadPackages}
setwd("C:/Users/y_bho/Desktop/Training/OCR")
library(magick)
library(tesseract)
```
Column {.sidebar data-width=350}
-------------------------------------
### Input & Parameters
```{r inputImages, cache = TRUE}
selectInput("imagesToChoose",
label = "Choose an image to process",
choices = c("Language example 1",
"Language example 2",
"Jounal example"),
selected = "Language example 1")
```
Row {.tabset}
-------------------------------------
### Image
```{r displayImage, cache = FALSE}
renderImage({
if (input$imagesToChoose == "Language example 1"){
list(src = "images/receipt.png", height = 240, width = 300)
}
else if(input$imagesToChoose == "Language example 2"){
list(src = "images/french.JPG", height = 240, width = 300)
}
else if(input$imagesToChoose == "Jounal example"){
list(src = "images/journal.jpg", height = 240, width = 300)
}
}, deleteFile = FALSE)
```
### OCR
```{r}
# load the dictionary
imageInput <- reactive({
if (input$imagesToChoose == "Language example 1"){
x = "images/receipt.png"
}
else if(input$imagesToChoose == "Language example 2"){
x = "images/french.JPG"
}
else if(input$imagesToChoose == "Jounal example"){
x = "images/journal.jpg"
}
return(x)
})
eng <- tesseract("eng")
text <- reactive({
tesseract::ocr(imageInput(), engine = eng)
})
renderPrint({
cat(text())
})
```
基本上在用户选择不同图像之间,我想显示“正在加载”,直到 tesseract 正在处理代码底部的反应函数。
我在this repo 中看到了繁忙指示器busyIndicator(wait = 1000) 但是,首先,包没有下载,其次,我不知道把它放在哪里,尤其是在 flexdashboard 中。
编辑
同时保留从 cat(text()) 获得的输出。 例子;如果我想在以下收据上执行 OCR:
我需要这个输出(逐行捕获信息):
【问题讨论】:
标签: r shiny tesseract flexdashboard