The megadetector package provides an R wrapper for the MegaDetector model, allowing users to detect animals, people, and vehicles in camera trap images using Python’s MegaDetector v5+ from within R.

Installation

You can install the package from GitHub:

# install.packages("remotes")
remotes::install_github("boettiger-lab/megadetector")

Setup

The package requires a Python environment. It can clean-install the necessary megadetector python package for you:

library(megadetector)

# Installs megadetector python package if not present
install_megadetector()

Usage

library(megadetector)

# 1. Load the Model
# Automatically downloads the default model (MDV5A) to the user cache if not present
model <- load_model()

# 2. Get some test images
# (Bundled with the package for demonstration)
image_file <- system.file("img", "Caltech_Animal.jpg", package = "megadetector")

# 3. Detect and Classify
detections <- detect_image(model, image_file)
class_label <- get_classification(detections)

cli::cli_alert_info("Image class: {.strong {class_label}}")

if (length(detections) > 0) {
  print(detections[[1]])
}

License

MIT