Learn R Programming

recogito (version 0.2.1)

ocv_crop_annotorious: Crop annotations to a bounding box

Description

Crop annotations to a bounding box

Usage

ocv_crop_annotorious(data, bbox)

Value

data where column polygon and the rectangle information in x, y, width, height is limited to the provided bounding box

Arguments

data

an object as returned by read_annotorious

bbox

a vector with elements x, y, xmax, ymax

Examples

Run this code
# \dontshow{
if(require(opencv))
{
# }
library(opencv)
data(openseadragon_areas)
# \dontshow{
  url <- system.file(package = "recogito", "examples",
                     "Cat_and_dog_standoff_(3926784260).jpg")
  attr(openseadragon_areas, "src") <- url
# }
url  <- attr(openseadragon_areas, "src")
img  <- ocv_read(url)
bbox <- ocv_info(img)
bbox <- c(xmin = 0, ymin = 0, xmax = bbox$width - 1, ymax = bbox$height - 1)
x    <- ocv_crop_annotorious(data = openseadragon_areas)
x    <- ocv_crop_annotorious(data = openseadragon_areas, bbox = bbox)

img
area <- x[2, ]
ocv_polygon(img, pts = area$polygon[[1]], crop = TRUE)
area <- x[1, ]
ocv_rectangle(img, x = area$x, y = area$y, width = area$width, height = area$height)
area <- x[3, ]
ocv_rectangle(img, x = area$x, y = area$y, width = area$width, height = area$height)
# \dontshow{
}
# }

Run the code above in your browser using DataLab