AbbyyR包中的ocrFile函数出错

时间:2017-07-05 14:15:06

标签: r ocr abbyy

当我使用Abbyy云SDK进行OCR时,当我尝试使用AbbyyR包中的ocrFile函数时,我继续得到以下错误。

" curl_download出错(finishedlist $ resultUrl [res $ id == finishedlist $ id] ,:   论证' url'必须是字符串。 "

当我将文件发送到云并处理它们时,一切正常,但当云返回文件时,下载文件时出现问题。我认为这可能是网络或证书问题,但我无法解决问题。

提前致谢

1 个答案:

答案 0 :(得分:3)

源代码存在问题,需要url的as.character()函数。 我更新了ocrFile函数,如下所示:

    install.packages("curl")
    library(curl)

    new_ocrFile<-function (file_path = "", output_dir = "./", exportFormat = c("txt", 
                                                                  "txtUnstructured", "rtf", "docx", "xlsx", "pptx", "pdfSearchable", 
                                                                  "pdfTextAndImages", "pdfa", "xml", "xmlForCorrectedImage", 
                                                                  "alto"), save_to_file = TRUE) 
    {
      exportFormat <- match.arg(exportFormat)
      res <- processImage(file_path = file_path, exportFormat = exportFormat)
      while (!(any(as.character(res$id) == as.character(listFinishedTasks()$id)))) {
        Sys.sleep(1)
      }
      finishedlist <- listFinishedTasks()
      res$id <- as.character(res$id)
      finishedlist$id <- as.character(finishedlist$id)
      if (identical(save_to_file, FALSE)) {
        res <- curl_fetch_memory(as.character(finishedlist$resultUrl[res$id == 
                                                          finishedlist$id]))
        return(rawToChar(res$content))
      }
      curl_download(as.character(finishedlist$resultUrl[res$id == finishedlist$id]), 
                    destfile = paste0(output_dir, unlist(strsplit(basename(file_path), 
                                                                  "[.]"))[1], ".", exportFormat))
    }

我希望,这有帮助。