Skip to main content

detect and classify insects on a raspberry pi

Project description

bugcam - Raspberry Pi Insect Detection

CLI for running insect detection on Raspberry Pi with Hailo AI HAT+.

Hardware Requirements

  • Raspberry Pi 4/5
  • Raspberry Pi Camera Module 3
  • Raspberry Pi AI HAT+ (Hailo8/Hailo8L)
  • Active cooler recommended

Installation

1. System Setup

Update system packages:

sudo apt update && sudo apt upgrade -y

Install Hailo hardware drivers (required for AI HAT+):

sudo apt install hailo-all

Verify camera is detected:

rpicam-hello

If this fails, enable the camera interface in raspi-config:

sudo raspi-config
# Navigate to: Interface Options > Camera > Enable
# Reboot when prompted

2. Install bugcam

Option A: System-wide install (simplest)

pip install bugcam

Option B: Isolated install with pipx (recommended)

# Install pipx
sudo apt install pipx

# Add pipx binaries to PATH
pipx ensurepath

# IMPORTANT: Close and reopen your terminal for PATH changes to take effect
# Then install bugcam
pipx install bugcam

3. Download Detection Model

# Download the small model (11MB, faster)
bugcam models download yolov8s

# OR download the medium model (31MB, more accurate)
bugcam models download yolov8m

# List installed models
bugcam models list

Models are downloaded from S3 and cached in ~/.cache/bugcam/models/.

4. Run Detection

# Preview camera with detection overlay
bugcam preview

# Start continuous detection
bugcam detect start

# Save detections to file
bugcam detect start --output detections.jsonl

# Enable autostart on boot
bugcam autostart enable

CLI Reference

Models

Manage and inspect detection models.

Download a model:

bugcam models download <model_name>

Available models: yolov8s (11MB, faster), yolov8m (31MB, more accurate)

List installed models:

bugcam models list

Show model details:

bugcam models info <model_name>

Preview

Run live camera preview with detection overlay.

# Basic preview
bugcam preview

# Preview with specific model
bugcam preview --model yolov8m

Options:

  • --model <name> - Specify which model to use (default: yolov8m)

Detection

Run continuous detection and save results.

# Start detection
bugcam detect start

# Save detections to file
bugcam detect start --output detections.jsonl

# Run for specific duration (in minutes)
bugcam detect start --duration 30

# Quiet mode (suppress console output)
bugcam detect start --quiet

# Combined options
bugcam detect start --model yolov8s --output results.jsonl --duration 60 --quiet

Options:

  • --model <name> - Specify which model to use (default: yolov8m)
  • --output <file> - Save detections to file (JSONL format)
  • --duration <minutes> - Run for specified minutes (default: run indefinitely)
  • --quiet - Suppress console output

Detection output format (JSONL):

{"timestamp": "2025-12-14T10:30:45", "class": "insect", "confidence": 0.92, "bbox": [100, 200, 150, 250]}

Autostart (systemd)

Manage automatic detection on system boot.

# Enable autostart
bugcam autostart enable

# Disable autostart
bugcam autostart disable

# Check status
bugcam autostart status

# View logs
bugcam autostart logs

# Follow logs in real-time
bugcam autostart logs --follow

Options:

  • --follow / -f - Follow log output in real-time

Hotspot Setup

Configure the Raspberry Pi as a wireless access point for field deployments.

Create hotspot

# Create hotspot connection
sudo nmcli connection add con-name wlan-sg1 type wifi ifname wlan0 autoconnect yes ssid wlan-sg1 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared

# Secure with password (min 8 characters)
sudo nmcli connection modify wlan-sg1 wifi-sec.key-mgmt wpa-psk
sudo nmcli connection modify wlan-sg1 wifi-sec.psk "yourpassword"

# Activate hotspot
sudo nmcli connection up wlan-sg1

Connect to hotspot

Scan for the network SSID (e.g., wlan-sg1) and use the password to connect. Access via SSH:

ssh username@hostname.local

Additional commands

# Stop hotspot
sudo nmcli connection down wlan-sg1

# Enable autostart on boot
sudo nmcli connection modify wlan-sg1 connection.autoconnect yes

Monitoring

Hailo hardware monitoring

# In terminal 1: start Hailo monitor
hailortcli monitor

# In terminal 2: enable monitoring and run detection
export HAILO_MONITOR=1
bugcam detect start

System monitoring

# CPU and memory
top  # or: btop, htop

# Temperature
vcgencmd measure_temp

# Continuous temperature monitoring
watch -n 1 vcgencmd measure_temp

# Service logs
bugcam autostart logs --follow

Performance tips

  • Use yolov8s for faster inference if accuracy allows
  • Use active cooling to prevent thermal throttling
  • Use official Raspberry Pi power supply (5V 5A for Pi 5 + AI HAT+)

Troubleshooting

Command not found after installation

For pip install:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

For pipx install:

pipx ensurepath
# Close and reopen terminal

Camera not detected

# Test camera
rpicam-hello

# If fails, enable in raspi-config
sudo raspi-config
# Interface Options > Camera > Enable
sudo reboot

Hailo driver errors

# Verify Hailo installation
dpkg -l | grep hailo

# Reinstall if needed
sudo apt install --reinstall hailo-all

# Check if Hailo device is available
hailortcli scan

Service not starting

# Check service logs
bugcam autostart logs

# Verify systemd service status
systemctl status bugcam-detect.service

Models not found

# Verify models are downloaded
bugcam models list

# Download if needed
bugcam models download yolov8m

# Check cache directory
ls -lh ~/.cache/bugcam/models/

Development

For contributors who want to modify bugcam:

# Clone the repository
git clone https://github.com/MIT-Senseable-City-Lab/sensing-garden.git
cd sensing-garden

# Install with dev dependencies
poetry install

# Run tests
poetry run pytest tests/ -v

# Run CLI from source
poetry run bugcam --help

Note: Models in resources/ directory are for development only and not included in package installations.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bugcam-0.1.14.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bugcam-0.1.14-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file bugcam-0.1.14.tar.gz.

File metadata

  • Download URL: bugcam-0.1.14.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.7 Darwin/25.1.0

File hashes

Hashes for bugcam-0.1.14.tar.gz
Algorithm Hash digest
SHA256 7d792ffce2f90f4701a39f9a95cd41dabc3b6a664eddce742da02a216a62b407
MD5 fba6b1f3537d6febff1a0ef46bc3df8e
BLAKE2b-256 27b023bcf64116578fe1a3df80b118fdf6da8ec66ca95a94ba29f4c81523299e

See more details on using hashes here.

File details

Details for the file bugcam-0.1.14-py3-none-any.whl.

File metadata

  • Download URL: bugcam-0.1.14-py3-none-any.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.7 Darwin/25.1.0

File hashes

Hashes for bugcam-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 e1b3c061aae1941d90738326c70eba36e1f88535cb43c05c7aaf4fbc017061a2
MD5 cb64a32f1a64ef18b259f5634cb9a047
BLAKE2b-256 572b66e23dad1ecb2925aef6659034a7d1c8a5c073af5a737f16bc5b8cfd4bda

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page