Social Distancing for Retail Settings Reference Implementation

Version: 1   Published: 03/16/2021

Edge Software Hub   /   Social Distancing for Retail Settings  /  Documentation

Overview

This reference implementation showcases a retail capacity limit application, line monitoring application, one-way monitoring application and social distancing application.

  • Retail capacity limit application showcases where a people counter keeps track of how many people are in the store based on the detected people entering and exiting the store. Single virtual line is configured for both entrance and exit areas to indicate the limits of entering and exiting the area of interest.  
  • One-way retail application monitors if people are walking in the correct direction in a one-way direction store aisle and reports the people walking in the wrong direction.  
  • Line monitoring retail application counts people standing in, waiting line at a retail store. The application estimates how many people are waiting in a line by doing an intersection between the people detected and a virtual line. 
  • Social distancing application gives count of people who do not maintain social distance.

Select Configure & Download to download the reference implementation and the software listed below.  

Configure & Download



Time to Complete

Programming
Language

Available Software

20 - 30 minutes

Python* 3


Intel® Distribution of OpenVINO™
toolkit Release


Recommended Hardware
The below hardware is recommended for use with this reference implementation. See the Recommended Hardware page for other suggestions. 


Target System Requirements

  • Ubuntu* 18.04.3 LTS
  • 6th to 11th Generation Intel® Core™ processors with Intel® Iris® Plus Graphics or Intel® HD Graphics
  • USB webcam (optional)

How It Works

Figure 1: Multiple Analytics on Multiple Channels

 

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 frame by frame. 
  2. Detects people in the frame using a pre-trained DNN model. 
  3. Extracts features from people detected using a second pre-trained DNN in order to do a tracking of the people. 
  4. If analytics field is socialdistancing in the camera_config.json file, then the application computes Euclidean distance between all the people and checks to see whether any people are violating N pixels apart.
  5. If analytics field is capacitylimit in the camera_config.json file, then the application checks if people cross the predefined virtual gates based on the coordinates and identify in which direction the virtual gate was closed to determine if it is an entry or exit event. 
  6. The people counter is updated based on the entry and exit data. 
  7. If analytics field is capacitylimit in the camera_config.json file, then the application checks if any of the tracked persons are not going in the predefined allowed direction. 
  8. The oneway counter is updated based on the people violating the specified direction. 
  9. If analytics field is linemonitoring in the camera_config.json file, then the application checks for the count of people in the line area. The queue line area is defined by a virtual line in the configuration file. The result of the amount of people in line are showcased in the screen. 
  10. Store total violations count of social distancing data in InfluxDB*. 
  11. Visualize the stored data of InfluxDB on Grafana* dashboard. 

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

Figure 2: Architecture Diagram

 


Get Started

Step 1: Install the Reference Implementation 

Select Configure & Download to download the reference implementation and then follow the steps below to install it.  

Configure & Download

  1. Open a new terminal, go to the downloaded folder and unzip the downloaded RI package:  
    unzip social_distancing_for_retail_settings.zip

     

  2.  Go to social_distancing_for_retail_settings/ directory:
    cd social_distancing_for_retail_settings
      
  3. Change permission of the executable edgesoftware file: 
    chmod 755 edgesoftware
     
  4. Run the command below to install the Reference Implementation: 
    ./edgesoftware install

     

  5. During the installation, you will be prompted for the Product Key. The Product Key is contained in the email you received from Intel confirming your download. 
    Figure 3: Product Key

     

  6. When the installation is complete, you see the message “Installation of package complete” and the installation status for each module. 
    Figure 4: Install Success

     
  7. Go to the working directory: 
    cd  Social_Distancing_for_Retail_Settings_<version>/Social_Distancing_for_Retail_Settings/retail-settings

     

    NOTE: In the command above, <version> is the Intel® Distribution of OpenVINO™ toolkit version. 

Step 2: Build the Docker Images  

NOTE: Run the commands mentioned below from the working directory, unless specified otherwise.

Build the Docker images with the command:

sudo -E docker-compose build

Run the Application

NOTE: The steps below use sample videos included with the Reference Implementation. For instructions on how to run the application with feed from a camera or how to use other videos, see Optional Steps section. 

  1. Set the HOST_IP environment variable with the command: 
    export HOST_IP=$(hostname -I | cut -d' ' -f1)

     

  2. Start the application with the command: 
    sudo -E docker-compose up -d

     

  3. Check if the containers are running properly with the command: 
    sudo -E docker-compose ps

     

  4. Check retailpandemic container logs with the command:  
    sudo docker logs -f retailpandemic

    Example output: 
     
    Figure 5: Status of Containers

     

Visualize the Data on Grafana

1. Open an Internet Browser and go to http://localhost:3000.

NOTE: If accessing remotely, go to http://:3000. Get host system IP address using: hostname -I | cut -d' ' -f1

2. Log in with user as admin and password as admin.

3. Click Home and Select the RPS to open the main dashboard. 

Figure 6: Grafana* Home Screen

 

Figure 7: Grafana Dashboard List

 

Dashboards

Below are the dashboards for different analytics, which are mentioned in the camera_config.json

Figure 8: Dashboard of an Individual Camera Feed for the Analytics – Oneway Monitoring

 

Figure 9: Dashboard of an Individual Camera Feed for the Analytics – Line Monitoring  

 

Figure 10: Dashboard of an Individual Camera Feed for the Analytics – Capacity Limit Monitoring 

 

Figure 11: Dashboard for the Analytics – Line Monitoring, Oneway Monitoring, Capacitylimit Monitoring, Social Distance Monitoring 

 

To open the Grafana Dashboard for a particular camera with the detection results and other data metrics, click on the camera feed on the small window, as shown in the figure below. 

NOTE: To close the small window with camera feed, click the close button (X) on the top left corner of the window. 

To view the detection results of all the configured camera feeds, click on View All Streams from top right corner from the main Grafana Dashboard, i.e., RPS (refer to Figure 7: Grafana Main Dashboard – RPS) 

NOTE: To open combined streams in full tab go to http://localhost:5000/get_all_streams. 

Optional Steps 

Configure the Input  

The camera_config.json file on the working directory contains all the necessary configurations including the path to default input video. If you wish to change the input, edit camera_config.json file and add the required information. The role of elements in the camera_config.json file are: 

  • analytics: Name of the application such as socialdistance, linemonitoring, onewaymonitoring and capacitylimit. 
  • capacity_coords: Coordinates of the door/line segment. 
  • capacity_limit: Total capacity of people in retail. 
  • oneway_coords: Coordinates of the door/line segment. 
  • oneway_area: Buffer area of interest around the coordinates to find oneway violation. 
  • oneway_direction: Direction of violation such as “Up”, “Down”, “Right” or “Left”. 
  • linemonitoring_coords: Coordinates of the door/line segment. 
  • device: Hardware Device to be used for inferencing.  (e.g.: CPU)  

NOTE: Supported hardware devices are CPU, HDDL and MYRIAD. You can also use a combination of these using MULTI (e.g.: MULTI:CPU,HDDL) 

  • path: path to the input video.

NOTE: Input videos should always be placed in the /resources folder. To use camera stream instead of video, replace the video file name with /dev/video0. To use RTSP stream instead of video, replace the video file name with the RTSP link.

NOTE: If any of the device value in camera_config.json has MYRIAD, add the following line to smartcity service in docker-compose.yml file: 

privileged: true

Validate the configuration file after changes (optional) with the command: 

cd app/ && python3 validate_config.py && cd ../

Restart the container: 

sudo docker restart retailpandemic

Stop the application 

Stop all the containers using the command: 

sudo docker-compose down

Summary and Next Steps

This application successfully leverages Intel® Distribution of OpenVINO™ toolkit plugins for detecting and measuring distance between the people and storing data to InfluxDB*.


Learn More

To continue learning, see the following guides and software resources:


Known Issues

Limitation in Distance between Individual Cameras 

The distance between individual cameras, which is configured using their geographic coordinates, should not exceed to the range of hundreds of kilometers. If the distance exceeds the limit, all the Map drop pins may not be displayed on the home screen. 

Issue with Running the Application on GPU Device 

You might face an issue running the application on GPU device. 


Troubleshooting

Address already in use  

If running the application results in Error starting userland proxy: listen tcp4 0.0.0.0:3000: bind: address already in use, use the following command to check and force stop the process: 

sudo kill $(pgrep grafana)

NOTE: If the issue persists, it may be possible that Grafana is running in a Docker container. In that case, stop the container using:

sudo docker stop $(sudo docker ps -q --filter expose=3000)

Support Forum 

If you're unable to resolve your issues, contact the Support Forum.  

Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.