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.5.tar.gz (18.6 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.5-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bugcam-0.1.5.tar.gz
  • Upload date:
  • Size: 18.6 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.5.tar.gz
Algorithm Hash digest
SHA256 36e60313e5b79f7976a030977172ae006c17e47f9f6ead824a6e6b33ce604946
MD5 a1a50c38ef864a77548da0a226586e74
BLAKE2b-256 af2230c186cf305a5c087d1724eaa3c0f92873ee3cbf26dcaacfd3e066af9b11

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bugcam-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 22.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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8a1c46ca60449832da587b2a21fc3d61ab0601ec2d7f6fcec2cc55cc6f86bd49
MD5 c88c53a14b8f9ea75cd39a1befcc577d
BLAKE2b-256 4a3eeb344e360d28fa817a2d9d39668cc0dc6c0a461e586ca89a7427524499bd

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