intel-iot-devkit / store-traffic-monitor-cpp

Monitor three different streams of video that count people inside and outside of a facility. This application also counts product inventory.
https://software.intel.com/content/www/us/en/develop/topics/iot/reference-implementations/store-traffic-monitor.html
BSD 3-Clause "New" or "Revised" License
10 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. 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.

Store Traffic Monitor

Details
Target OS: Ubuntu* 18.04 LTS
Programming Language: C++
Time to Complete: 50-70min

store-traffic-monitor

What It Does

The store traffic monitor reference implementation gives the total number of people currently present and total number of people visited the facility. It also counts the product inventory. The application is capable of processing the inputs from multiple cameras and video files.

Requirements

Hardware

Software

How It Works

The application uses the Inference Engine included in the Intel® Distribution of OpenVINO™ toolkit. A trained neural network detects objects by displaying a green bounding box over them. This reference implementation identifies multiple objects entering the frame and records the class of each object, the count, and the time the object entered the frame. Architectural Diagram

Figure 2: Architectural Diagram.

Setup

Get the code

Clone the reference implementation

sudo apt-get update && sudo apt-get install git
git clone https://github.com/intel-iot-devkit/store-traffic-monitor-cpp.git

Install OpenVINO

Refer to Install Intel® Distribution of OpenVINO™ toolkit for Linux* to learn how to install and configure the toolkit.

Install the OpenCL™ Runtime Package to run inference on the GPU, as shown in the instructions below. It is not mandatory for CPU inference.

Other Dependencies

**FFmpeg***
FFmpeg is a free and open-source project capable of recording, converting and streaming digital audio and video in various formats. It can be used to do most of our multimedia tasks quickly and easily say, audio compression, audio/video format conversion, extract images from a video and a lot more.

Which Model to Use

This application uses the mobilenet-ssd model, that can be accessed using the model downloader. The model downloader downloads the model as Caffe* model files. These need to be passed through the model optimizer to generate the IR (the .xml and .bin files) that will be used by the application.

The application also works with any object-detection model, provided it has the same input and output format of the SSD model. The model can be any object detection model:

To download the models and install the dependencies of the application, run the below command in the store-traffic-monitor-cpp directory:

./setup.sh

The Labels File

The application requires a labels file associated with the model used for detection.

All detection models work with integer labels, not string labels (e.g., For the ssd300 and mobilenet-ssd models, the number 15 represents the class "person".). Each model must have a labels file, which associates an integer, the label the algorithm detects, with a string denoting the human-readable label.

The labels file is a text file containing all the classes/labels that the model can recognize, in the order that it was trained to recognize them, one class per line.

For mobilenet-ssd model, labels.txt file is provided in the resources directory.

The Config File

The resources/config.json contains the path of videos and label that will be used by the application as input. Each block represents one video file and its corresponding label for detection.

For example:

   {
       "inputs": [
          {
              "video":"path_to_video/video1.mp4",
              "label":"person"
          }
       ]
   }

The path/to/video is the path to an input video file and the label of the class (e.g., person, bottle) to be detected on that video. The labels used in the config.json file must coincide with the labels from the labels file.

The application can use any number of videos for detection (i.e., the config.json file can have any number of blocks), but the more videos the application uses in parallel, the more the frame rate of each video scales down. This can be solved by adding more computation power to the machine on which the application is running.

Which Input Video to use

The application works with any input video. Sample videos are provided here.

For first-use, we recommend using the people-detection, one-by-one-person-detection, bottle-detection videos. For example:

{
   "inputs":[
      {
         "video":"sample-videos/people-detection.mp4",
         "label":"person"
      },
      {
         "video":"sample-videos/one-by-one-person-detection.mp4",
         "label":"person"
      },
      {
         "video":"sample-videos/bottle-detection.mp4",
         "label":"bottle"
      }
   ]
}

If the user wants to use any other video, it can be used by providing the path in the config.json file.

Using the Camera Stream instead of video

Replace path/to/video with the camera ID in the config.json file, where the ID is taken from the video device (the number X in /dev/videoX).

On Ubuntu, to list all available video devices use the following command:

ls /dev/video*

For example, if the output of above command is /dev/video0, then config.json would be:

  {
     "inputs": [
        {
           "video":"0",
           "label":"person"
        }
     ]
   }

Setup the Environment

Configure the environment to use the Intel® Distribution of OpenVINO™ toolkit by exporting environment variables:

source /opt/intel/openvino/bin/setupvars.sh

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.

Build the Application

To build, go to the store-traffic-monitor-cpp and run the following commands:

mkdir -p build && cd build
cmake -DUI_OUTPUT=OFF ..
make

Run the Application

To see a list of the various options:

./store-traffic-monitor -h

A user can specify what target device to run on by using the device command-line argument -d followed by one of the devices CPU, GPU, HDDL or MYRIAD. If no target device is specified the application will run on the CPU by default. To run with multiple devices use -d MULTI:device1,device2. For example: -d MULTI:CPU,GPU,MYRIAD

Run on the CPU

Although the application runs on the CPU by default, this can also be explicitly specified through the -d CPU command-line argument:

./store-traffic-monitor -d CPU -m ../resources/FP32/mobilenet-ssd.xml -l ../resources/labels.txt

Note: By default, the application runs on async mode. To run the application on sync mode, use -f sync as command-line argument.

Run on the Integrated GPU

Run on the Intel® Neural Compute Stick

To run on the Intel® Neural Compute Stick, use the -d MYRIAD command-line argument.

./store-traffic-monitor -d MYRIAD -m ../resources/FP16/mobilenet-ssd.xml -l ../resources/labels.txt

Note: The Intel® Neural Compute Stick can only run FP16 models. The model that is passed to the application, through the -m <path_to_model> command-line argument, must be of data type FP16.

Run on the Intel® Movidius™ VPU

To run on the Intel® Movidius™ VPU, use the -d HDDL command-line argument:

./store-traffic-monitor -d HDDL -m ../resources/FP16/mobilenet-ssd.xml -l ../resources/labels.txt

Note: The HDDL-R can only run FP16 models. The model that is passed to the application, through the -m <path_to_model> command-line argument, must be of data type FP16.

Loop the Input Video

By default, the application reads the input videos only once and ends when the videos end.

The reference implementation provides an option to loop the video so that the input videos and application run continuously.

To loop the sample video, run the application with the -lp true command-line argument:

./store-traffic-monitor -lp true -d CPU -m ../resources/FP32/mobilenet-ssd.xml -l ../resources/labels.txt

This looping does not affect live camera streams, as camera video streams are continuous and do not end.

Use the Browser UI

The default application uses a simple user interface created with OpenCV. A web based UI with more features is also provided with this application.

For the application to work with the browser UI, the output format must be slightly changed. This is done by compiling the application with UI_OUTPUT variable set:

cmake -DUI_OUTPUT=ON ..
make

Follow the readme provided here to run the web based UI.