core

Object Detection over Discord using the Raspberry PI

Setup

Required environment variables in .env file

  • PI_HOSTNAME
    • Hostname (IP) to use for raspberry pi server
  • PI_PASSWORD
    • to use capture_and_fetch on pi server
  • DISCORD_ID
    • This is the Discord client ID token
  • DISCORD_TOKEN
    • Discord bot token

Camera and Network

Connect to Pi, take pictures, and save image locally


capture_and_fetch

 capture_and_fetch (username:str='pi',
                    local_path:str='./data/capture.jpg', delay:int=None,
                    cmd='raspistill -t 0 -h 640 -w 640 -o
                    ~/Desktop/capture.jpg')

Requires PI_PASSWORD be set in .env file. Delay is the number of milliseconds before taking picture

Type Default Details
username str pi Username for Raspberry Pi
local_path str ./data/capture.jpg Path to save image
delay int None Delay between command and picture is taken
cmd str raspistill -t 0 -h 640 -w 640 -o ~/Desktop/capture.jpg Raspberry pi camera command

pltimg

 pltimg (img:cv2.Mat)

Plots picture

Model and Prediction

Fetch YOLOv5 model and predict on image


df_from_preds

 df_from_preds (preds:cvu.detector.prediction.Prediction)

Converts annoying object to DataFrame


get_default_model

 get_default_model ()

Retrieves default YOLOv5 model


predict

 predict (model:cvu.detector.yolov5.core.Yolov5, image_path:str)

Runs model on input image and returns predictions and output image

Example use

model = get_default_model()
preds, img = predict(model, '/path/to/img')

Discord Bot

Manage interactions to camera via Discord Bot

Type python scripts/launch_discord_bot.py --help in root directory for more information


run_bot

 run_bot (run_active_cam:bool=True, cam_interval:int=30,
          cam_class:str='cat', cam_channel:str='general',
          pic_keyword:str='pi!', yolo_keyword:str='yolo!',
          pic_dir:str='./pics')

Run Discord bot that communicates with the Raspberry Pi camera

Type Default Details
run_active_cam bool True Runs camera at interval looking for a class to identify
cam_interval int 30 Number of seconds to camera checks for target class
cam_class str cat Object to identify. Run list_classes to see all options
cam_channel str general Disord channel to post active cam pictures to
pic_keyword str pi! Command a user types in a Discord channel to take a picture
yolo_keyword str yolo! Same as above but with the YOLO predictions overlayed
pic_dir str ./pics Intermediate directory for pictures