knitr::opts_chunk$set(echo = TRUE) library(knitr)
# devtools::install_github("mgahan/WanderingEye") library(WanderingEye)
In order to test the package, it is good to have a set of sample files. Feel free to use your own, but here some sample files that I uploaded to Google Cloud
# Download file downloadURL <- "https://storage.googleapis.com/mike-public-data/SampleAnimalPhotos.zip" destFile <- "SampleAnimalPhotos.zip" if (!file.exists(destFile)) { download.file(url=downloadURL, destfile = destFile) } # Unzip file destDir <- gsub(".zip","",destFile) if (!dir.exists(destDir)) { unzip(zipfile=destFile) }
We can first check out how many files we have available to us.
FileListDat <- data.table(Filename=list.files(path=destDir, recursive = TRUE, full.names = TRUE)) kable(head(FileListDat))
We can now forge ahead and attempt to detect labels of the image using Google Cloud Vision. If you have not gone through the process of extracting the Google Cloud Vision API keys, please do this before moving onto this next step.
SampleImage <- FileListDat[35, Filename]
GoogleOutput <- googleCloudVision( imagePath=SampleImage, feature = "LABEL_DETECTION", numResults = 10, API_KEY = Sys.getenv("GCLOUD_VISION_API_KEY")) kable(GoogleOutput[])
MicrosoftOutput <- microsoftComputerVision( imagePath=SampleImage, feature = "analyze", MICROSOFT_API_ENDPOINT = Sys.getenv("MICROSOFT_API_ENDPOINT"), MICROSOFT_API_KEY1 = Sys.getenv("MICROSOFT_API_KEY1")) kable(MicrosoftOutput$Tags[]) kable(MicrosoftOutput$Descriptions[]) kable(MicrosoftOutput$Meta[])
AWSOutput <- awsRekognition( imagePath=SampleImage, targetPath = NULL, feature = "detect-labels", AWS_ACCESS_KEY_ID = Sys.getenv("AWS_ACCESS_KEY_ID"), AWS_SECRET_ACCESS_KEY = Sys.getenv("AWS_SECRET_ACCESS_KEY"), AWS_BUCKET = Sys.getenv("AWS_BUCKET"), AWS_DEFAULT_REGION = Sys.getenv("AWS_DEFAULT_REGION")) kable(AWSOutput[])
IBMOutput <-IBMWatsonVision( imagePath=SampleImage, IBM_WATSON_API = Sys.getenv("IBM_WATSON_API"), IBM_WATSON_VERSION = Sys.getenv("IBM_WATSON_VERSION")) kable(IBMOutput[])
ClarifaiOutput <- clarifaiPredict( imagePath=SampleImage, CLARIFAI_API_KEY = Sys.getenv("CLARIFAI_API_KEY")) kable(ClarifaiOutput[])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.