shuiniu86 / safety-gear-detector-cpp

Observe workers as they pass in front of a camera to determine if they have adequate safety protection.

Home Page:https://software.intel.com/content/www/us/en/develop/topics/iot/reference-implementations/safety-gear-detector.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Safety Gear Detector

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

safety-gear-detector

What It Does

This reference implementation is capable of detecting people passing in front of a camera and detecting if the people are wearing safety-jackets and hard-hats. The application counts the number of people who are violating the safety gear standards and the total number of people detected.

Requirements

Hardware

  • 6th to 8th Generation Intel® Core™ processors with Iris® Pro graphics or Intel® HD Graphics

Software

  • Ubuntu* 18.04 LTS
    Note: We recommend using a 4.14+ Linux* kernel with this software. Run the following command to determine the kernel version:

    uname -a
    
  • OpenCL™ Runtime Package

  • Intel® Distribution of OpenVINO™ toolkit 2020 R3 Release

How It Works

The application uses the Inference Engine included in the Intel® Distribution of OpenVINO™ toolkit.

Firstly, a trained neural network detects people in the frame and displays a green colored bounding box over them. For each person detected, the application determines if they are wearing a safety-jacket and hard-hat. If they are not, an alert is registered with the system.

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/safety-gear-detector-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 person-detection-retail-0013 Intel® model, that can be downloaded using the model downloader. The model downloader downloads the .xml and .bin files that will be used by the application.

The application also uses the worker_safety_mobilenet model, whose Caffe* model file are provided in the resources/worker-safety-mobilenet directory. 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.

To download the models and install the dependencies of the application, run the below command in the safety-gear-detector-cpp-with-worker-safety-model directory:

./setup.sh

The Config File

The resources/config.json contains the path of video that will be used by the application as input.

For example:

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

The path/to/video is the path to an input video file.

Which Input Video to use

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

For first-use, we recommend using the Safety_Full_Hat_and_Vest.mp4 video which is present in the resources/ directory.

For example:

{
    "inputs": [
       {
           "video":"sample-videos/Safety_Full_Hat_and_Vest.mp4"
       },
       {
           "video":"sample-videos/Safety_Full_Hat_and_Vest.mp4"
       }
    ]
}

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"
        }
     ]
   }

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 safety-gear-detector-cpp-with-worker-safety-model and run the following commands:

mkdir -p build && cd build
cmake ..
make

Run the Application

To see a list of the various options:

./safety-gear-detector -h

A user can specify what target device to run on by using the device command-line argument -d. 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

To run the application on CPU, use the following command:

./safety-gear-detector -d=CPU -m=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/person-detection-retail-0013/FP32/person-detection-retail-0013.xml -mh=../resources/worker-safety-mobilenet/FP32/worker_safety_mobilenet.xml

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

  • To run the application on the integrated Intel® GPU with floating point precision 32 (FP32) model:

    ./safety-gear-detector -d=GPU -m=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/person-detection-retail-0013/FP32/person-detection-retail-0013.xml -mh=../resources/worker-safety-mobilenet/FP32/worker_safety_mobilenet.xml
    

    FP32: FP32 is single-precision floating-point arithmetic uses 32 bits to represent numbers. 8 bits for the magnitude and 23 bits for the precision. For more information, click here

  • To run on the integrated Intel® GPU with floating point precision 16 (FP16) model:

    ./safety-gear-detector -d=GPU -m=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/person-detection-retail-0013/FP16/person-detection-retail-0013.xml -mh=../resources/worker-safety-mobilenet/FP16/worker_safety_mobilenet.xml
    

    FP16: FP16 is half-precision floating-point arithmetic uses 16 bits. 5 bits for the magnitude and 10 bits for the precision. For more information, click here

Run on the Intel® Neural Compute Stick

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

./safety-gear-detector -d=MYRIAD -m=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/person-detection-retail-0013/FP16/person-detection-retail-0013.xml -mh=../resources/worker-safety-mobilenet/FP16/worker_safety_mobilenet.xml

Running on the Intel® Movidius™ VPU

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

./safety-gear-detector -d=HDDL -m=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/person-detection-retail-0013/FP16/person-detection-retail-0013.xml -mh=../resources/worker-safety-mobilenet/FP16/worker_safety_mobilenet.xml

Note: The Intel® Movidius™ VPU 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:

./safety-gear-detector -lp=true -d=CPU -m=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/person-detection-retail-0013/FP32/person-detection-retail-0013.xml -mh=../resources/worker-safety-mobilenet/FP32/worker_safety_mobilenet.xml

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

About

Observe workers as they pass in front of a camera to determine if they have adequate safety protection.

https://software.intel.com/content/www/us/en/develop/topics/iot/reference-implementations/safety-gear-detector.html

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:C++ 90.9%Language:CMake 4.8%Language:Shell 4.2%