Skip to contents

Detects arbitrary objects described in natural language without any model retraining, powered by YOLO-World (v8s) and Ultralytics.

Usage

image_detect_world(
  img,
  classes = c("object"),
  conf_threshold = 0.25,
  iou_threshold = 0.45,
  model = "yolov8s-world",
  rainbow = TRUE,
  col = NULL,
  lwd = 2,
  cex = 1,
  pad = 0,
  bbox = TRUE,
  badge_pad = 1,
  show_text = TRUE,
  show_conf = TRUE,
  show_class = TRUE,
  show_id = FALSE,
  show_point = FALSE,
  show_box = NULL,
  point_size = 1,
  point_pch = 16,
  point_col = NULL,
  badge = TRUE,
  return_features = FALSE,
  feature_model = c("yolo", "clip-vit-b32", "dinov2"),
  plot_features = FALSE,
  plot = TRUE,
  auto_install = TRUE,
  verbose = TRUE,
  dir = pliman_model_dir(),
  ...
)

Arguments

img

An Image object, a 2D/3D numeric array, a path to an image file, or a list of images.

classes

A character vector of object classes or a comma-separated string (e.g. c("dog", "frisbee")).

conf_threshold

Minimum confidence threshold (default 0.25).

iou_threshold

IoU threshold for NMS (default 0.45).

model

Model name or weights path (default "yolov8s-world").

rainbow

Logical. If TRUE, gives each detected object instance a distinct, vibrant color. If FALSE (default), objects of the same class share the exact same color.

col

Optional color or palette for bounding boxes.

lwd

Bounding box line width (default 2).

cex

Size factor for bounding box label text (default 1.0).

pad

Padding multiplier controlling the box padding around label text (default 0).

bbox

Logical. Whether to draw bounding boxes around detected objects (default TRUE).

badge_pad

Padding multiplier controlling the background badge size around label text (default 1.0).

show_text

Logical. Whether to display text labels on bounding boxes (default TRUE).

show_conf

Logical. Whether to display confidence scores in labels (default TRUE).

show_class

Logical. Whether to display class names in labels (default TRUE).

show_id

Logical. Whether to display object IDs (#1, #2, ...) in labels (default FALSE).

show_point

Logical. Whether to show a point at the centroid of each detected object. Defaults to FALSE.

show_box

Logical. Whether to draw bounding boxes. Defaults to NULL (TRUE unless show_point = TRUE and all text displays are FALSE).

point_size

Numeric. Size (cex) of the centroid point when show_point = TRUE. Defaults to 1.

point_pch

Integer. Plotting symbol (pch) for the centroid point. Defaults to 16 (filled circle).

point_col

Character. Color of the centroid point. Defaults to NULL (matches the object color / rainbow).

badge

Logical. Whether to draw a solid background badge behind label text (default TRUE). If FALSE, only the text is drawn directly.

return_features

Logical. If TRUE, extracts deep feature representations for detected bounding boxes and the global image. Attaches "features" (an \(N \times D\) matrix of per-object deep embeddings, 512-D for CLIP or 384-D for DINOv2) and "feature_map" (dense spatial 3-component PCA false-color Image) as attributes to the returned object. Defaults to FALSE.

feature_model

Foundation model used for feature representation when return_features = TRUE. Options are "clip-vit-b32" (default, OpenAI CLIP ViT-B/32 producing 512-D semantic embeddings) or "dinov2" (Meta DINOv2-S ViT producing 384-D self-supervised patch embeddings).

plot_features

Logical. If TRUE and return_features = TRUE, visualizes the dense spatial PCA feature map. Defaults to FALSE.

plot

Logical. If TRUE (default), displays the image with annotated bounding boxes.

auto_install

Logical. If TRUE, sets up required Python libraries if not already available.

verbose

Logical. Whether to display progress messages.

dir

Directory where models are stored (default pliman_model_dir()).

...

Additional plotting parameters.

Value

A data frame containing detected bounding boxes (id, xmin, ymin, xmax, ymax, class, score). If return_features = TRUE, features (an \(N \times D\) matrix) and feature_map (dense spatial PCA Image) are attached as attributes.

Examples

if (FALSE) { # interactive()
  library(pliman)
  img <- image_import("field.jpg")
  dets <- image_detect_world(img, classes = c("corn plant", "weed", "soil"), rainbow = TRUE)
}