Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions R/googleVision-LIB.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ imageToText <- function(imagePath) {
#' @description a utility to extract features from the API response
#'
#' @param pp an API response object
#' @param feature the name of the feature to return
#' @param feature the name of the feature to return
#' @return a data frame
#'
extractResponse <- function(pp, feature){
Expand All @@ -51,6 +51,9 @@ extractResponse <- function(pp, feature){
if (feature == "LANDMARK_DETECTION") {
return(pp$content$responses$landmarkAnnotations[[1]])
}
if (feature == "SAFE_SEARCH_DETECTION") {
return(pp$content$responses$safeSearchAnnotation)
}
}


Expand All @@ -63,7 +66,7 @@ extractResponse <- function(pp, feature){
#' @param numResults the number of results to return.
#' @export
#' @return a data frame with results
#' @examples
#' @examples
#' f <- system.file("exampleImages", "brandlogos.png", package = "RoogleVision")
#' getGoogleVisionResponse(imagePath = f, feature = "LOGO_DETECTION")
#' @import googleAuthR
Expand All @@ -73,7 +76,7 @@ getGoogleVisionResponse <- function(imagePath, feature = "LABEL_DETECTION", numR
#################################
txt <- imageToText(imagePath)
### create Request, following the API Docs.
if (is.numeric(numResults)) {
if (is.numeric(numResults)) {
body <- paste0('{ "requests": [ { "image": { "content": "',txt,'" }, "features": [ { "type": "',feature,'", "maxResults": ',numResults,'} ], } ],}')
} else {
body <- paste0('{ "requests": [ { "image": { "content": "',txt,'" }, "features": [ { "type": "',feature,'" } ], } ],}')
Expand All @@ -82,7 +85,7 @@ getGoogleVisionResponse <- function(imagePath, feature = "LABEL_DETECTION", numR
simpleCall <- gar_api_generator(baseURI = "https://vision.googleapis.com/v1/images:annotate", http_header = "POST")
## set the request!
pp <- simpleCall(the_body = body)

if (ncol(pp$content$responses) >0) {
## obtain results.
res <- extractResponse(pp, feature)
Expand Down