Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于从png文件提取文本的R中的For循环_R_Regex_Ocr_Tesseract - Fatal编程技术网

用于从png文件提取文本的R中的For循环

用于从png文件提取文本的R中的For循环,r,regex,ocr,tesseract,R,Regex,Ocr,Tesseract,我在文件夹中有一些.png文件,我需要逐个读取它们,并将所有文件生成的文本连接到一个变量中。我正在使用以下代码: filenames <- list.files(path = "C:/Users/tmpxk9/Documents", pattern="*.png") for (i in seq_along(filenames)) { xx <- magick::image_read("filenames[i]") xx %>% magick::image_re

我在文件夹中有一些.png文件,我需要逐个读取它们,并将所有文件生成的文本连接到一个变量中。我正在使用以下代码:

filenames <- list.files(path = "C:/Users/tmpxk9/Documents", pattern="*.png")

for (i in seq_along(filenames)) {
  xx <- magick::image_read("filenames[i]")
  xx %>%
    magick::image_resize("2000x") %>%
    magick::image_convert(type = 'Grayscale') %>%
    tesseract::ocr() %>%
    cat()
}

我确信for循环存在一些问题,我正在处理它,但无法确定检索文件名的方式,它们不包括存储在其中的文件夹。为了使用
list.files()
获取完整路径,必须包含参数
full.names=TRUE

,如果没有可复制的示例,很难进一步探究,但对于初学者来说,“filenames[i]”不应该是引号中的字符串。应该是:
xx引号是问题所在。现在它可以正常工作了
Error in magick_image_readpath(enc2native(path), density, depth, strip) : 
  rsession.exe: UnableToOpenBlob `C:\Users\tmpxk9\Documents\filenames[i]': No such file or directory @ error/blob.c/OpenBlob/2701