Developing a Low-Cost Raspberry Pi-based Camera Trap for Wildlife Detection



A walk through how we can capture images/videos in the wild non-invasively.


Raspberry pi Operating System

An Operating System (OS) is an interface between a computer user and computer hardware.Your Raspberry Pi needs an operating system to work. It uses Linux, and in particular Raspbian. To install an operating system, you'll need two things: an image file, and a program that will write it to your SD card.


Raspberry Pi OS can be installed using the Raspberry Pi Imager

Raspberry Pi Imager

    Follow the steps below to install Raspberry Pi OS on your Raspberry Pi.
  • Download the Raspberry Pi Imager for your operating system.
  • Connect an SD card reader with the SD card inside.
  • Open the Raspberry Pi Imager and choose the required OS from the list presented.
  • Choose the SD card you wish to write your image to.
  • Review your selections and click 'WRITE' to begin writing data to the SD card.

Headless Connection

A Raspberry Pi is considered headless when you have no monitor or keyboard connected to it. A headless Raspberry Pi can be useful for any situation where you don't want or need access to a monitor and keyboard.


You can use the following to make a headless connection to your Raspberry Pi:
    1. Putty
Putty is a software terminal emulator for Windows and Linux. It provides a text user interface to remote computers running any of its supported protocols, including SSH and Telnet.
Drawing Drawing

    2. VNC viewer
VNC Viewer is a graphical desktop sharing system that allows a user to remotely control the desktop of a remote computer (running VNC Server) from your device, and it transmits the keyboard and mouse or touch events to VNC Server, so that once you are connected, you have control over the computer you've accessed.
drawing drawing

At this point, we should all have connected to our Raspberry pi's headless.


Python

Python is a programming language that lets you work quickly and integrate systems more effectively. It is a powerful tool for prototyping and developing production-ready code.

Simple Python Commands

Type the following commands in the terminal to get started with python.

python3
print("Hello World")


Use the following command to get the ip address of your raspberry pi.

hostname -I

Now we will use a series of commands and learn how to make a directory, change directories, list directories. We will also learn how to create, edit, save and run a python file.

Use the following commands line after line.

This creates a directory called DSAIL
mkdir DSAIL
This changes the directory to DSAIL
cd DSAIL
This lists the files in the directory
ls
This creates a file called hello.py, saves it and exits the editor.
nano hello.py
print("Hello World")
ctrl + s
ctrl + x

This runs the python file
python3 hello.py

Capturing images/videos using the Pi Camera

Now that we have a basic understanding of python, we can now capture images/videos using the raspberry pi camera.

We will use the libcamera command. This command is used to capture images using the raspberry pi camera.

Use the following command on the terminal to capture an image and save it on the desktop.

libcamera-jpeg -o Desktop/test.jpg

Use the following command on the terminal to capture a video and save it on the desktop.

libcamera-vid -t 10000 -o Desktop/test.h264 For more examples, use this guide.
Capturing images/videos using a USB camera

Alternatively, you can use a USB camera to capture the images. Use the following command on the terminal to capture an image and save it on the desktop.

fswebcam -r 1280x720 --no-banner Desktop/image1.jpg For more examples, use this guide.
Exercise:

1. Write a script to capture one image using the USB camera.

2. Write a script to capture several images using the USB camera and save images in a folder.


While out in the field, we cannot do this everytime we need an image or video captured.

So we use python scripts to capture images/videos at a specified time interval.

These Scripts are available in the cloned repository : `ieee-africon-2023` , in the `camera-trap` folder.


Automation

Automation is the technology by which a process or procedure is performed with minimal human assistance.

Scripting

Scripting is a way by which one can alleviate this necessity by automating these command sequences in order to make one’s life at the shell easier and more productive.

Scripts can be used for a variety of purposes, such as to test how well the operating system performs certain tasks, to automate the steps in a software application's installation process, and to add functions to a Web page.

Scripts are usually written in a scripting language, which is a programming language that supports scripts.

For example, scripts can be written with languages such as JavaScript, PHP, Python, Ruby, Perl, and Tcl.

Bash scripts

Bash scripts are used by Systems Administrators, Programmers, Network Engineers, Scientists and just about anyone else who uses a Linux/ Unix system regularly.

As a programmer, you will undoubtedly have to write scripts to automate tasks.


To automate the process of capturing multiple images or videos, you can use Python, Bash scripts, and crontab. For example, you can write a Python script that captures an image every 5 minutes and saves it with a timestamped filename. Then, you can use a Bash script to run this Python script at regular intervals using crontab. Here's an example Bash script that runs the above Python script every 5 minutes to capture an image using a Pi Camera:


#!/bin/bash

# Change to the directory where the Python script is located
cd /home/pi/camera_trap

# Run the Python script to capture an image
python3 capture_image.py

                    
                

Crontab

The crontab is a list of commands that you want to run on a regular schedule, and also the name of the command used to manage that list.

The crontab command opens the crontab for editing, and lets you add, remove, or modify scheduled tasks.

The cron job checks a user's crontab file at regular intervals, which are defined in the cron configuration file, typically /etc/crontab.

Make sure to make this script executable by running chmod +x /path/to/script.sh. Then, you can use crontab to run this script at regular intervals. For example, to run the script every hour, you can add the following line to your crontab if you would like for your script to run at reboot:


@reboot /path/to/script.sh

Power Software for deployed camera traps

The power management software enables the Raspberry Pi to control the DSAIL Power Management Board. The figure below shows the flowchart of the power management software.

Power Control Software Flowchart