首页 > 解决方案 > R中自动一张一张选择图像文件的功能

问题描述

我有一个包含 100 多张图片的文件夹。我想在 R 中对它们中的每一个运行谷歌视觉分析。我不想一次对一张图像运行分析,而是想创建一个函数来逐个访问每个图像并运行分析。

使用以下代码:

getGooglevisionResponse(file.choose(),feature = 'text_detection')

file.choose()习惯一次选择一个文件,但我想创建一个循环,该循环将动态选择每个图像并对其运行分析.. 使用list.files()但低于错误 the following condition has length >1 and only the first element will be used

找到了一篇文章,但那是在 python 中无法在 R 中复制它

https://github.com/andrikosrikos/Google-Cloud-Support/blob/master/Google%20Vision/multiple_features_request_single_API_call.py

标签: rloopsfunctorgoogle-vision

解决方案


在没有看到更多代码的情况下,您只需要使用lapplyand list.files

fil <- list.files("<myImgDir>", full.names = T)
out <- lapply(fil, getGoogleVisionResponse, feature = 'text_detection'))

推荐阅读