Footfall People Counting System

repository·master·Indexed 43 days ago

https://github.com/watershedarts/footfall

A camera-based people counting system built with openFrameworks for Raspberry Pi hardware using a Pi Cam. It features customizable detection via a config.json file, support for HTTP data POSTing, CSV logging, and tools for testing with video files on desktop environments.

Tokens
6.6K
Snippets
29
Records
35
Agent score
56%

What's inside Footfall

  1. Overview of Footfall

    master

    Footfall is a camera-based people counting system designed to run on a Raspberry Pi using a Pi Cam and the openFrameworks framework.

    Note: The provided source code is a barebones implementation. It is not a 'plug-and-play' solution and requires customization for every specific installation. Customization is primarily handled by tweaking variables in a configuration file.

  2. Initialize the Footfall Database

    master

    After setting up your server (Local or Dedicated), you must create a database and the required data table to store event information.

    1. Access phpMyAdmin via http://localhost/phpmyadmin or http://<ServerIP>/phpmyadmin.
    2. Create a new database.
    3. Select the new database and navigate to the SQL panel.
    4. Execute the following statement to create the event data table:
    CREATE TABLE IF NOT EXISTS `data` (
      `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
      `locationID` tinyint(4) NOT NULL,
      `event` tinyint(4) NOT NULL,
      KEY `timestamp` (`timestamp`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  3. Build the Footfall app folder manually

    master

    If you encounter compilation errors with the simple method, follow these steps to generate a fresh project folder and migrate the source files.

    1. Navigate to your openFrameworks/apps/myApps/ directory.
    2. Copy the emptyExample/ folder to a new Footfall/ folder.
    3. Create the necessary bin and bin/data directories inside the new folder.
    4. Edit addons.make using pico and add the following addons on new lines:
      • ofxCv
      • ofxCsv
      • ofxOpenCv
      • ofxJSON
      • ofxHttpUtils
      • ofxCvPiCam
    5. Copy the source files from the original repository into the new src folder.
    6. Compile using make -j3 from the project root.
    7. After successful compilation, copy the config.json file from the original project's data folder into your new bin/data/ folder.
    cd openFrameworks/apps/myApps/
    cp -r emptyExample/ Footfall/
    cd Footfall
    mkdir bin
    mkdir bin/data
    
    # Edit addons.make with pico and add:
    # ofxCv
    # ofxCsv
    # ofxOpenCv
    # ofxJSON
    # ofxHttpUtils
    # ofxCvPiCam
    
    cd src
    cp ../../../../Footfall/Footfall/src/* .
    cd ..
    make -j3
    
    # Move config after build:
    cp ../../../../Footfall/Footfall/bin/data/config.json ./bin/data/
  4. Run Footfall Linux applications

    master

    To run Footfall applications on Linux, use the provided clickToLaunchApp.sh shell script. This script ensures the application can find its required shared object libraries by setting the LD_LIBRARY_PATH environment variable to point to the local libs directory.

    Users are generally only required to have glut installed on their system; all other necessary .so files are included in the libs folder for portability.

    ./clickToLaunchApp.sh
  5. How to customise Footfall

    master

    To customize the system for your specific installation, you must modify the config.json file located inside the bin/data folder of the Footfall App. This file contains all the relevant variables required to tune the system's behavior. For detailed instructions on which variables to change, refer to the Configuration documentation.

    bin/data/config.json
  6. Set up Raspberry Pi for Footfall

    master

    This guide provides steps for preparing a Raspberry Pi (tested on RPI 1, 2, and 3) for use with Footfall.

    1. OS Installation: Download a Noobs Package from the official Raspberry Pi website and install Jessie. Wait for the SD card to be ready and the system to reboot.
    2. Filesystem Expansion: Run sudo raspi-config to open the Raspberry Pi Config screen. Expand the filesystem and reboot.
    3. System Updates: Run the following commands to ensure the system is up to date:
      sudo apt-get update
      sudo apt-get upgrade
      sudo raspi-update
    4. Camera Setup: Enable the camera via sudo raspi-config and reboot. Verify the camera is working by running raspistill -o testimage.jpg and checking the resulting image.
    sudo raspi-config
    # Expand filesystem and reboot
    
    sudo apt-get update
    sudo apt-get upgrade
    sudo raspi-update
    
    # Test camera
    raspistill -o testimage.jpg
  7. Set up a Dedicated Remote Server

    master

    If using a remote dedicated server instead of a Raspberry Pi, follow these steps:

    1. Database Setup: Create a new database via phpMyAdmin and run the following SQL command to create the data table:
    CREATE TABLE IF NOT EXISTS `data` (
      `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
      `locationID` tinyint(4) NOT NULL,
      `event` tinyint(4) NOT NULL,
      KEY `timestamp` (`timestamp`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    1. File Deployment:
      • Create a subfolder named footfall on your server.
      • Use an FTP client (e.g., Transmit or Cyberduck) to upload the contents of the project's public folder into that footfall directory.
  8. Install Footfall dependencies via getrepos.sh

    master

    To build the Footfall application on Raspberry Pi, you must install specific dependencies using the getrepos.sh script within your openFrameworks addons directory.

    1. Prepare the script: Navigate to your openFrameworks addons folder and create a new file named getrepos.sh.
    2. Populate the script: Copy the contents of the getrepos.sh file from the Footfall repository and paste them into this new file.
    3. Execute: Run the script to pull down the required packages.

    Note: This assumes you have already built and compiled openFrameworks (oF) on your Raspberry Pi.

    cd ~/openFrameworks/addons
    touch getrepos.sh && vim getrepos.sh
    # Paste content, save with :wq
    ./getrepos.sh
  9. Set up a Local Server on Raspberry Pi

    master

    To run Footfall on a Raspberry Pi, you must install a LAMP stack (Linux, Apache, MySQL, PHP) and configure phpMyAdmin. This process requires command-line knowledge.

    1. Install System Dependencies

    Update your system and install Apache, PHP, and MySQL:

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install apache2 -y
    sudo apt-get install php5 libapache2-mod-php5 -y
    sudo apt-get install mysql-server php5-mysql -y

    Note: Keep track of the database names and passwords prompted during the MySQL installation.

    2. Install and Configure phpMyAdmin

    Install phpMyAdmin and select apache2 when prompted. Set dbconfig-common to yes.

    To enable the phpMyAdmin interface, add it to your Apache configuration:

    1. Open the config file: sudo nano /etc/apache2/apache2.conf
    2. Add this line near the bottom: Include /etc/phpmyadmin/apache.conf
    3. Save (CTRL+X, then Y) and restart Apache: /etc/init.d/apache2 restart

    3. Deploy Public Files

    Move the contents of the project's Web/ folder to your webroot (typically /var/www/ or /var/www/html):

    cd /var/www/
    sudo cp -r /home/pi/Footfall/Web/* .

    Verify the deployment by visiting http://localhost/events.php (on the Pi) or http://<RaspberryPiIP>/events.php (from another computer).

  10. Launch the Footfall app manually via SSH

    master

    If you are accessing the Raspberry Pi via SSH, you can launch the Footfall application and push it to the background using one of the following commands. Setting DISPLAY=:0 ensures the application renders to the local display connected to the Pi.

    DISPLAY=:0 make run & disown
    # OR
    DISPLAY=:0 bin/Footfall & disown