| Type: | Package | 
| Title: | An Interface for Image Recognition | 
| Version: | 0.1.4 | 
| Date: | 2024-06-21 | 
| URL: | https://github.com/cschwem2er/imgrec | 
| BugReports: | https://github.com/cschwem2er/imgrec/issues | 
| Description: | Provides an interface for image recognition using the 'Google Vision API' https://cloud.google.com/vision/ . Converts API data for features such as object detection and optical character recognition to data frames. The package also includes functions for analyzing image annotations. | 
| License: | MIT + file LICENSE | 
| Encoding: | UTF-8 | 
| RoxygenNote: | 7.2.3 | 
| Imports: | knitr (≥ 1.4.7), base64enc (≥ 0.1-0), dplyr (≥ 1.1.0), httr (≥ 1.4.0), jsonlite (≥ 1.8.0), rlang (≥ 1.1.0), methods | 
| Suggests: | magick (≥ 2.8.0), ggplot2 (≥ 3.5.0), usethis (≥ 2.2.0), pillar (≥ 1.6.0), rmarkdown (≥ 2.2) | 
| VignetteBuilder: | knitr | 
| NeedsCompilation: | no | 
| Packaged: | 2024-06-21 12:04:06 UTC; kasus | 
| Author: | Carsten Schwemmer | 
| Maintainer: | Carsten Schwemmer <c.schwem2er@gmail.com> | 
| Repository: | CRAN | 
| Date/Publication: | 2024-06-21 12:20:05 UTC | 
get image annotations
Description
Calls the 'Google Vision' API to return annotations. The function automatically creates batches
Usage
get_annotations(images, features, max_res, mode)
Arguments
| images | A character vector for images to be annotated. Can either be url strings or local images, as specified with  | 
| features | A character vector for the features to be returned. Accepts  | 
| max_res | An integer specifying the maximum number of results to be returned for each feature. | 
| mode | Accepts  | 
Value
An response object of class 'gvision_annotations'.
See Also
Google Vision features and quotas.
Examples
## Not run: 
 gvision_init()
 # one image url
 sw_image <- 'https://upload.wikimedia.org/wikipedia/en/4/40/Star_Wars_Phantom_Menace_poster.jpg'
 results <- get_annotations(images = sw_image, # image character vector
                           features = 'all', # request all available features
                           max_res = 10, # maximum number of results per feature
                           mode = 'url')  # maximum number of results per feature
 # multiple image urls
 finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png'
 padme_image <- 'https://upload.wikimedia.org/wikipedia/en/e/ee/Amidala.png'
 input_imgs <- c(sw_image, finn_image, padme_image)
 results <- get_annotations(images = input_imgs,
            features = c('label', 'face'), max_res = 5, mode = 'url')
            
 # one local image
 temp_img_path <- tempfile(fileext = '.png')
 download.file(finn_image, temp_img_path, mode = 'wb', quiet = TRUE)
 results <- get_annotations(images = temp_img_path,
            features = c('label', 'face'), max_res = 5, mode = 'local')
 
## End(Not run)
authorization for Google Vision
Description
Initializes the authorization credentials for the 'Google Vision' API.
Needs to be called before using any other functions of imgrec and requires gvision_key as environment variable.
Usage
gvision_init()
Value
nothing.
Examples
## Not run: 
Sys.setenv(gvision_key = "Your Google Vision API key")
gvision_init()
## End(Not run)
parse image annotations
Description
Parses the annotations and converts most of the features to data frames. Also stores the corresponding image identifiers for each feature as 'img_id'
Usage
parse_annotations(annotations)
Arguments
| annotations | An annotation object created with  | 
Value
A list containing data frames for each feature:
- labels
- label annotations 
- web_labels
- web label annotations 
- web_similar
- similar web images 
- web_match_partial
- partial matching web images 
- web_match_full
- full matching web images 
- web_match_pages
- matching web pages 
- faces
- face annotations 
- objects
- object annotations 
- logos
- logo annotations 
- landmarks
- landmark annotations 
- full_text
- full text annotation 
- safe_serarch
- safe search annotation 
- colors
- dominant color annotations 
- crop_hints
- crop hints for ratios 0.8/1.0/1.2 
Examples
## Not run: 
# initialize api credentials
gvision_init()
# annotate images
finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png'
sw_image <- 'https://upload.wikimedia.org/wikipedia/en/8/82/Leiadeathstar.jpg'
padme_image <- 'https://upload.wikimedia.org/wikipedia/en/e/ee/Amidala.png'
results <- get_annotations(images = c(finn_image, sw_image, padme_image),
                           features = 'all', max_res = 10, mode = 'url')
# parse annotations
img_data <- parse_annotations(results)
# available feature data frames
names(img_data)
  
## End(Not run)
  
save annotation data as JSON
Description
Writes raw JSON data as returned by the Google Vision API to a UTF-8 encoded local file.
Usage
save_json(annotations, file)
Arguments
| annotations | An annotation object created with  | 
| file | Local path where the JSON data should be stored. | 
Value
nothing.
Examples
## Not run: 
 gvision_init()
 finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png'
 results <- get_annotations(images = finn_image, features = 'all',
                            max_res = 10, mode = 'url')
 temp_file_path <- tempfile(fileext = '.json')
 save_json(results, temp_file_path)
  
## End(Not run)