intel-iot-devkit / social-distance

Build a solution that recognizes people within a specific area and measures the distance between them. Get an alert if the distance is less than a specified amount.
https://software.intel.com/content/www/us/en/develop/topics/iot/reference-implementations/retail-pandemic-social-distancing.html
BSD 3-Clause "New" or "Revised" License
12 stars 7 forks source link
computer-vision deep-learning edge edge-ai edge-computing image-recognition inference intel live-demo machine-learning object-detection openvino pretrained-models real-time reference-implementation video

DISCONTINUATION OF PROJECT

This project will no longer be maintained by Intel. This project has been identified as having known security escapes. Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. Intel no longer accepts patches to this project.

Retail Pandemic Reference Implementation - Social Distance

Details
Target OS: Ubuntu* 18.04 LTS
Programming Language: Python* 3.5
Time to Complete: 1 hour

socialdistance

What it does

This reference implementation showcases a retail social distance application that detects people and measures the distance between them. If this distance is less than a value previously provided by the user, then an alert is triggered.

Requirements

Hardware

Software

How It works

The application uses the Inference Engine and Model Downloader included in the Intel® Distribution of OpenVINO Toolkit doing the following steps:

  1. Ingests video from a file, processing it frame by frame.
  2. Detects people in the frame of interest using a DNN model.
  3. Extract features from detected people to track them by using a second DNN model.
  4. Calculates the distance between detected people based on each person’s location, size and perspective, to identify if the minimum social distancing threshold is violated.

The DNN models are optimized for Intel® architecture and are included with Intel Distribution of OpenVINO™ toolkit.

architecture image

Setup

Get the code

Clone the reference implementation:

sudo apt-get update && sudo apt-get install git
git clone github.com:intel-iot-devkit/social-distance.git

Install Python requirements

pip3 install -r requirements.txt

Install Intel® Distribution of OpenVINO™ Toolkit

Refer to https://software.intel.com/en-us/articles/OpenVINO-Install-Linux for more information about how to install and setup the Intel® Distribution of OpenVINO™ toolkit.

Installing the requirements

To install the dependencies of the Reference Implementation, run the following commands:

cd <path-to-social-distance-directory>
pip3 install -r requirements.txt

Which model to use

This application uses the person-detection-retail-0013 and person-reidentification-retail-0300 Intel® pre-trained models, that can be downloaded using the model downloader. The model downloader downloads the .xml and .bin files that is used by the application.

To install the dependencies of the RI and to download the models Intel® model, run the following command:

mkdir models
cd models
python3 /opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py --name person-detection-retail-0013 --precisions FP32
python3 /opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py --name person-reidentification-retail-0300 --precisions FP32

The models will be downloaded inside the following directories:

- models/intel/person-detection-retail-0013/FP32/
- models/intel/person-reidentification-retail-0300/FP32/

The Config File

The config.json contains the path to the videos and models that will be used by the application.

The config.json file is of the form name/value pair.

Example of the config.json file:

{
  "video": "path/to/video/myvideo.mp4",
  "pedestrian_model_weights": "models/intel/person-detection-retail-0013/FP32/person-detection-retail-0013.bin",
  "pedestrian_model_description": "models/intel/person-detection-retail-0013/FP32/person-detection-retail-0013.xml",
  "reidentification_model_weights": "models/intel/person-reidentification-retail-0300/FP32/person-reidentification-retail-0300.bin",
  "reidentification_model_description": "models/intel/person-reidentification-retail-0300/FP32/person-reidentification-retail-0300.xml",
  "coords": [[0, 0], [0, 100], [100, 100], [100, 0]]
}

Which Input video to use

The application works with any input video format supported by OpenCV. Find sample videos here.

Sample videos also may be available on platforms such as https://videos.pexels.com (e.g., https://www.pexels.com/video/black-and-white-video-of-people-853889/), subject to the terms and conditions for use of the applicable platform. Intel does not endorse the use of, or grant any rights to, any particular platform, video, or data.

To use the video, specify the path in config.json file

Setup the environment

You must configure the environment to use the Intel® Distribution of OpenVINO™ toolkit one time per session by running the following command:

source /opt/intel/openvino/bin/setupvars.sh -pyver 3.5

Note: This command needs to be executed only once in the terminal where the application will be executed. If the terminal is closed, the command needs to be executed again.

Run the application

Change the current directory to the project location on your system:

cd <path-to-social-distance-directory>/src

Run the python script.

python3 socialdistance.py