Skip to content

Quickly detect and classify different species of harmful algae within natural water in real-time with AI and a camera (i.e., ESP32-CAM, smartphone, or webcam).

License

lynkos/algae-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using AI and Low-Cost Camera to Detect Harmful Algae

Python C++ HTML Shell C
Ultralytics YOLOv8 OpenCV Roboflow PyTorch Espressif Arduino
Conda PlatformIO Colab

Try YOLOv8 model on Roboflow Open in Colab

Overview

This project aims to provide a practical, convenient, and efficient tool to monitor water quality and mitigate / prevent harmful algal blooms in real-time by:

  • Fine-tuning pre-trained AI models to detect harmful algae
  • Leveraging the portability of smartphones and low-cost cameras
    • Tested with ESP32-CAM AI Thinker and ESP32-S3-EYE, but compatible with many others
    • See 'Boards' section in appendix.md for full list of compatible cameras

Since it's designed to be user-friendly and cost-effective, it's also suitable for educational and research purposes.

Project Demo
Program demo
Detected algae are annotated with a bounding box, predicted class/category, and the AI model's confidence in its prediction(s). Trackbars allow user to configure the AI model's attributes — Confidence, IoU (i.e., Intersection over Union), and Max Detections — in real time.
custom_yolov8n.pt (i.e., custom AI model) validation results
Predict Correct
custom_yolov8n's inference results Actual labels

Though it may appear so, these aren't duplicates! The left image shows what the model detected, while the right image shows the correct labels. The original images are from one of the batches in the model's validation dataset.

Nikon microscope with ESP32-CAM AI Thinker and illuminator
Nikon microscope equipped with ESP32-CAM AI Thinker and illuminator
ESP32-CAM AI Thinker inside a custom 3D printed lens attachment atop the microscope's eyepiece.

Requirements

Note

Conda is technically the only hard requirement, though by itself provides a barebones experience and doesn't show the program's full functionality.

Refer to Customization in appendix.md if you don't want to or can't use a(n) ESP32-CAM and/or microscope.

Tip

If you have trouble deciding between Anaconda and Miniconda, please refer to the table below:

Anaconda Miniconda
New to conda and/or Python Familiar with conda and/or Python
Not familiar with using terminal and prefer GUI Comfortable using terminal
Like the convenience of having Python and 1,500+ scientific packages automatically installed at once Want fast access to Python and the conda commands and plan to sort out the other programs later
Have the time and space (a few minutes and 3 GB) Don't have the time or space to install 1,500+ packages
Don't want to individually install each package Don't mind individually installing each package

Convenient Conda shortcut commands available in conda_shortcuts.sh!

Installation

  1. Verify that conda is installed

    conda --version
    
  2. Ensure conda is up to date

    conda update conda
    
  3. Enter the directory you want algae-detection to be cloned in

    • POSIX
      cd ~/path/to/directory
    • Windows
      cd C:\Users\user\path\to\directory
  4. Clone and enter algae-detection

    git clone https://github.com/lynkos/algae-detection.git && cd algae-detection
  5. Create virtual environment from environment.yml

    conda env create -f environment.yml

Quick Start

  1. Activate algae_env (i.e., virtual environment)
    conda activate algae_env
  2. Confirm algae_env is active
    • algae_env should be in parentheses () or brackets [] before your command prompt, e.g.
      (algae_env) $
    • See which virtual environments are available and/or currently active (active environment denoted with asterisk (*))
      conda info --envs
      OR
      conda env list
  3. Run camera.py

Note

Automatically uses computer's default camera (i.e., webcam). To use different cameras:

User Interface
User Interface
Users can view live footage from the camera. Detected algae are annotated with a bounding box, predicted class/category, and the model's confidence. Trackbars allow user to configure detection model attributes in real time.
  • POSIX
    python src/detection/camera.py
  • Windows
    python src\detection\camera.py

  1. Press the 'Escape' key on your keyboard to terminate

Important

See manual.md and/or appendix.md for further details!

Credits

Special thanks to: