Coder Social home page Coder Social logo

openvino-for-smartcity's Introduction

OpenVino For SmartCity

1. Foreword

This is a follow-up on the OpenVino’s inference tutorials:

Version 2018 R5.0

Version 2018 R4.0

We will work on and extend this tutorial as a demo app for smart cities, specifically for near misses detection.

2. Introduction

This project consists on showcasing the advantages of the Intel’s OpenVINO toolkit. We will develop a Near Misses case scenario, where we will detect vehicles and pedestrians and estimate a metric of a crossroad’s dangerousness. For that, we will use the OpenVINO toolkit and OpenCV, all written in C++.

As mentioned previously, we will take the step 4 as a starting point, as it provides us with the options to run and stack different models synchronously or asynchronously. Once the proper models for vehicle and pedestrian detection are defined, we proceed to develop a feature to let the user define the different areas of interest (in this case, sidewalks and streets) that will help in identifying dangerous situations later on. Then, we will work on object tracking to recognize the same object across successive frames, giving us the ability to estimate trajectories, speeds and positions of the objects. Finally, we will have to define what are considered dangerous situations and check that the system detects them correctly.

3. Prerequisites

To run the application in this tutorial, the OpenVINO™ toolkit and its dependencies must already be installed and verified using the included demos. Installation instructions may be found at: https://software.intel.com/en-us/articles/OpenVINO-Install-Linux

When needed, the following optional hardware can be used:

  • USB camera - Standard USB Video Class (UVC) camera.

  • Intel® Core™ CPU with integrated graphics.

  • VPU - USB Intel® Movidius™ Neural Compute Stick and what is being referred to as "Myriad"

A summary of what is needed:

3.1. Hardware

Note: While writing this tutorial, an Intel® i7-8550U with Intel® HD graphics 520 GPU was used as both the development and target platform.

  • Optional:

    • Intel® Movidius™ Neural Compute Stick

    • USB UVC camera

    • Intel® Core™ CPU with integrated graphics

3.2. Software

  • OpenVINO™ toolkit supported Linux operating system. This tutorial was run on 64-bit Ubuntu 16.04.1 LTS updated to kernel 4.15.0-43 following the OpenVINO™ toolkit installation instructions.

  • The latest OpenVINO™ toolkit installed and verified. This tutorial was written using version 2018 R4.0. However, version 2018 R5.0 is also supported.

  • Git(git) for downloading from the GitHub repository.

  • BOOST library. To install on Ubuntu, run:

apt-get install libboost-dev
apt-get install libboost-log-dev

3.3. Checks

By now you should have completed the Linux installation guide for the OpenVINO™ toolkit, however before continuing, please ensure:

  • That after installing the OpenVINO™ toolkit you have run the supplied demo samples

  • If you have and intend to use a GPU: You have installed and tested the GPU drivers

  • If you have and intend to use a USB camera: You have connected and tested the USB camera

  • If you have and intend to use a Myriad: You have connected and tested the USB Intel® Movidius™ Neural Compute Stick

  • That your development platform is connected to a network and has Internet access. To download all the files for this tutorial, you will need to access GitHub on the Internet.

4. Build

1. Clone the repository at desired location:

git clone https://github.com/incluit/OpenVino-For-SmartCity.git

2. The first step is to configure the build environment for the OpenCV toolkit by sourcing the "setupvars.sh" script.

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

3. Change to the top git repository:

cd OpenVino-For-SmartCity

4. Create a directory to build the tutorial in and change to it.

mkdir build
cd build

5. Before running each of the following sections, be sure to source the helper script. That will make it easier to use environment variables instead of long names to the models:

source ../scripts/setupenv.sh

6. Compile:

cmake -DCMAKE_BUILD_TYPE=Release ../
make

5. Usage

5.1. Run

5.1.1. Detection

1. First, let us see how it works on a single image file using default synchronous mode.

./intel64/Release/smart_city_tutorial -m_vp $vehicle232 -i ../data/car_1.bmp

2. For video files:

./intel64/Release/smart_city_tutorial -m_vp $vehicle232 -i ../data/video1_640x320.mp4
detection

3. You can also run the command in asynchronous mode using the option "-n_async 2":

./intel64/Release/smart_city_tutorial -m_vp $vehicle232 -i ../data/NewVideo2.mp4 -n_async 2
detection2

4. You can also load the models into the GPU or MYRIAD:

Note: In order to run this section, the GPU and/or MYRIAD are required to be present and correctly configured.

./intel64/Release/smart_city_tutorial -m_vp $vehicle232 -d_vp GPU -i ../data/NewVideo2.mp4
./intel64/Release/smart_city_tutorial -m_vp $vehicle232 -d_vp MYRIAD -i ../data/NewVideo2.mp4

5.1.2. Other models

You can also experiment by using different detection models, being the ones available up to now:

  1. person-vehicle-bike-detection-crossroad-0078

    • -m_vp $vehicle2{16,32}

  2. vehicle-detection-adas-0002 together with person-detection-retail-0013 or pedestrian-detection-adas-0002:

    • -m $mVDR{16,32} and -m_p $person{1,2}{16,32}

  3. frozen_yolo_v3

    • -m_y $yolo16

By default they will be loaded into the CPU, so remember to pass the corresponding argument:

  • -d_vp {CPU,GPU,MYRIAD}

  • -d {CPU,GPU,MYRIAD} and -d_p {CPU,GPU,MYRIAD}

  • -d_y {CPU,GPU,MYRIAD}

The first 2 are included with the OpenVINO toolkit, while the last one is the compiled version of the public yolo general detection model. You can do this yourself by following this Intel’s guide or download our compiled binary and xml. You will need to move these files to the data directory inside your OpenVino-For-SmartCity path.

5.1.3. Tracking

To enable tracking you should run the command with the -tracking argument:

./intel64/Release/smart_city_tutorial -m_vp $vehicle232 -d_vp GPU -i ../data/NewVideo2.mp4 -n_async 16 -tracking
tracking
tracking2

5.1.4. Collisions

To detect collisions you should run the command with the -tracking + -collision arguments:

./intel64/Release/smart_city_tutorial -m_vp $vehicle232 -d_vp GPU -i ../data/video82.mp4 -n_async 16 -tracking -collision
collision
collision2
collision3
5.1.4.1. Short explanation

An in-depth explanation can we found in the wiki.

Once we have the tracking working, we can retrieve for every object its actual and past positions. We average the last 5 frames to filter the noise of the detection models. Once we have the position, we can get the velocity as the difference of two consecutive positions. Again, we calculate the average of the last 5 velocities to avoid abrupt changes that do not match what actually happens in the scene. We also normalize this speed with a factor of 1/y (being y the vertical position of the object in the image). This has to be done because objects moving closer to the camera appear to be moving faster (in terms of pixels/frame) but that it is not true in reality. Once we get the velocities of each tracked object, we can calculate the acceleration analogously.

collisionexample

In the image above, we can assume that the white van goes at constant speed before getting to the intersection, we can see this plotted as a red line in the chart. Then, it tries to break (we can see a small down peak) and then the black car crashes into it, increasing its speed. The yellow line represents the acceleration of the van, we can clearly see that we could define a threshold on the acceleration to define a hard crash like this one.

5.1.4.2. Near misses

We define near misses as an "extension" of collisions, in the way that we can identify thresholds in speed and acceleration and search for other vehicles in the neighborhood of the offender. We could then detect near misses. These situations and other dangerous ones are further explored in the wiki.

5.1.5. Areas of Interest

To draw areas of interest you should run the command with the -show_selection argument.

./intel64/Release/smart_city_tutorial -m_vp $vehicle232 -d_vp GPU -i ../data/video82.mp4 -n_async 16 -show_selection -tracking -collision

One of the main benefits of defining areas of interest is that it will help us to optimize and focus the precision of the detection model into a specific space, reducing the margin of error (false positives, misdetections, etc). With these regions defined we could also trim or mask the original frames to reduce the computing times of the inference and further image processing.

The user can crop the image to a rectangle of their interest and draw on the first frame of the video the areas involved, being streets, sidewalks and crosswalks. In the particular case of a street, the user will have to type its orientation (east, west, north, south). Taking into account these criterias for defining AoIs, we are in a position to define rules for considering dangerous situations scenarios, i.e.: a car going from the street to the sidewalks or cars on a crosswalk while there are pedestrians on it. (In Progress)

areas

Step by step instructions can be found on the wiki.

5.2. Performance analysis

We integrated our program to the Intel® IoT DevCloud platform. This developer tool enabled us to run the inference proccess on different hardware targets. The following is the comparison graph where greater is better:

areas

6. Dashboarding

We notice that in order get a deeper understanding of the near miss identification, it was mandatory to view the progress of the variables metioned above (speed, acceleration). A real-time dashboard of collision and relevant events was develop as available feature as a response to this issue.

areas

Step by step instructions to install and run the dashboard can be found on the wiki.

7. Cloud integration

As we focus on delivered a POC that could be productized in the near future, we unterstood that integrate that a distributed application should have the possibility to compare two different intersection dangerouness. To address this, we developed a metric that weight each type of near miss and took into account the total ammount of detection on each street. This metric is evaluated once every 30 seconds and broadcasted throught MQTT to AWS IoT Core. To learn more about cloud integration using AWS, follow this link to our wiki.

8. To Do

8.1. README

  • ✓ Short README with usage examples

  • ✓ Travis + Sonarcloud

  • [X] Include diagrams and images

  • [X] Elaborate on the wiki

8.2. Development

  • ✓ Try with different models

  • ✓ Detect vehicles and pedestrians

  • ✓ Draw Areas of Interest

  • ✓ Object Tracking

  • ✓ Object Trajectories

  • ✓ Fix labels for the other models

  • ✓ Calculate objects velocities

  • ✓ Calculate objects accelerations

  • ✓ Detect collisions

  • [X] Elaborate on dangerous situations to be detected (near misses)

  • [X] Detect these situations

openvino-for-smartcity's People

Contributors

cabelo avatar mauriff avatar tasuarez avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.