Skip to content

Commit

Permalink
G-API. Face detection MTCNN demo. (#2657)
Browse files Browse the repository at this point in the history
* Apply suggestions from code review

commit suggestions

Co-authored-by: Eduard Zamaliev <eduard.zamaliev@intel.com>

* G-API version aligned with OMZ

* Added last line to README

* add model_keys

Co-authored-by: Eduard Zamaliev <eduard.zamaliev@intel.com>
Co-authored-by: Vladimir Dudnik <vladimir.dudnik@intel.com>
  • Loading branch information
3 people authored Oct 5, 2021
1 parent 5d09d8d commit 1b59d4a
Show file tree
Hide file tree
Showing 17 changed files with 1,072 additions and 28 deletions.
1 change: 1 addition & 0 deletions demos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The Open Model Zoo includes the following demos:
- [Crossroad Camera C++ Demo](./crossroad_camera_demo/cpp/README.md) - Person Detection followed by the Person Attributes Recognition and Person Reidentification Retail, supports images/video and camera inputs.
- [Deblurring Python\* Demo](./deblurring_demo/python/README.md) - Demo for deblurring the input images.
- [Face Detection MTCNN Python\* Demo](./face_detection_mtcnn_demo/python/README.md) - The demo demonstrates how to run MTCNN face detection model to detect faces on images.
- [Face Detection MTCNN C++ G-API\* Demo](./face_detection_mtcnn_demo/cpp_gapi/README.md) - The demo demonstrates how to run MTCNN face detection model to detect faces on images. G-API version.
- [Face Recognition Python\* Demo](./face_recognition_demo/python/README.md) - The interactive face recognition demo.
- [Formula Recognition Python\* Demo](./formula_recognition_demo/python/README.md) - The demo demonstrates how to run Im2latex formula recognition models and recognize latex formulas.
- [Gaze Estimation C++ Demo](./gaze_estimation_demo/cpp/README.md) - Face detection followed by gaze estimation, head pose estimation and facial landmarks regression.
Expand Down
12 changes: 12 additions & 0 deletions demos/face_detection_mtcnn_demo/cpp_gapi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (C) 2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)

add_demo(NAME face_detection_mtcnn_demo_gapi
SOURCES ${SOURCES}
HEADERS ${HEADERS}
INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include"
DEPENDENCIES monitors)
112 changes: 112 additions & 0 deletions demos/face_detection_mtcnn_demo/cpp_gapi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# G-API Face Detection MTCNN Demo

![example](./fdmtcnn.jpg)

This demo demonstrates how to run `mtcnn` model using OpenVINO&trade;.

## How It Works

On startup, the application reads command line parameters and loads the specified networks.
Upon getting a frame from the OpenCV VideoCapture, the application performs inference of Face Detection network and displays the face position and feature points.

> **NOTE**: By default, Open Model Zoo demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the demo application or reconvert your model using the Model Optimizer tool with the `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_convert_model_Converting_Model_General.html).
## Preparing to Run

For demo input image or video files, refer to the section **Media Files Available for Demos** in the [Open Model Zoo Demos Overview](../../README.md).
The list of models supported by the demo is in `<omz_dir>/demos/face_detection_mtcnn_demo/cpp_gapi/models.lst` file.
This file can be used as a parameter for [Model Downloader](../../../tools/model_tools/README.md) and Converter to download and, if necessary, convert models to OpenVINO Inference Engine format (\*.xml + \*.bin).

An example of using the Model Downloader:

```sh
python3 <omz_dir>/tools/model_tools/downloader.py --list models.lst
```

An example of using the Model Converter:

```sh
python3 <omz_dir>/tools/model_tools/converter.py --list models.lst
```

### Supported Models

* mtcnn-o
* mtcnn-p
* mtcnn-r

> **NOTE**: Refer to the tables [Intel's Pre-Trained Models Device Support](../../../models/intel/device_support.md) and [Public Pre-Trained Models Device Support](../../../models/public/device_support.md) for the details on models inference support at different devices.
## Running

Running the application with the `-h` option yields the following usage message:

```
InferenceEngine:
API version ............ <version>
Build .................. <number>
face_detection_mtcnn_demo_gapi [OPTION]
Options:
-h, --help Show this help message and exit.
-i INPUT, --input INPUT
Required. Path to a test image file.
-m_p "<path>", --model_pnet "<path>"
Required. Path to an .xml file with a pnet model.
-m_r "<path>", --model_rnet "<path>"
Required. Path to an .xml file with a rnet model.
-m_o "<path>", --model_onet "<path>"
Required. Path to an .xml file with a onet model.
-th "<num>", --threshold "<num>"
Optional. The threshold to define the face is
recognized or not.
-d_p "<device>", Optional. Target device for MTCNN P network.
The demo will look for a suitable plugin for a specified device.Default value is CPU.
-d_r "<device>", Optional. Target device for MTCNN R network.
The demo will look for a suitable plugin for a specified device.Default value is CPU.
-d_o "<device>", Optional. Target device for MTCNN O network.
The demo will look for a suitable plugin for a specified device.Default value is CPU.
-qc "<num>", Optional. Streaming executor queue capacity. Calculated automaticaly if 0.
-hs, Optional. MTCNN P use half scale pyramid.
--loop Optional. Enable reading the input in a loop.
--no_show Optional. Don't show output
-o OUTPUT, --output OUTPUT
Optional. Name of the output file(s) to save.
-limit OUTPUT_LIMIT, --output_limit OUTPUT_LIMIT
Optional. Number of frames to store in output. If 0 is
set, all frames are stored.
-u UTILIZATION_MONITORS, --utilization_monitors UTILIZATION_MONITORS
Optional. List of monitors to show initially.
```

Running the application with an empty list of options yields an error message.

For example, to do inference on a CPU, run the following command:

```sh
./face_detection_mtcnn_demo_gapi -d_p CPU -i <path_to_video>/input_video.mp4 -m_p mtcnn-p.xml -m_o mtcnn-o.xml -m_r mtcnn-r.xml
```

>**NOTE**: If you provide a single image as an input, the demo processes and renders it quickly, then exits. To continuously visualize inference results on the screen, apply the `-loop` option, which enforces processing a single image in a loop.
You can save processed results to a Motion JPEG AVI file or separate JPEG or PNG files using the `-o` option:

* To save processed results in an AVI file, specify the name of the output file with `avi` extension, for example: `-o output.avi`.
* To save processed results as images, specify the template name of the output image file with `jpg` or `png` extension, for example: `-o output_%03d.jpg`. The actual file names are constructed from the template at runtime by replacing regular expression `%03d` with the frame number, resulting in the following: `output_000.jpg`, `output_001.jpg`, and so on.
To avoid disk space overrun in case of continuous input stream, like camera, you can limit the amount of data stored in the output file(s) with the `limit` option. The default value is 1000. To change it, you can apply the `-limit N` option, where `N` is the number of frames to store.

>**NOTE**: Windows\* systems may not have the Motion JPEG codec installed by default. If this is the case, you can download OpenCV FFMPEG back end using the PowerShell script provided with the OpenVINO &trade; install package and located at `<INSTALL_DIR>/opencv/ffmpeg-download.ps1`. The script should be run with administrative privileges if OpenVINO &trade; is installed in a system protected folder (this is a typical case). Alternatively, you can save results as images.
## Demo Output

The application uses OpenCV to display found faces' boundary and feature points.
The demo reports

* **FPS**: average rate of video frame processing (frames per second).

## See Also

* [Open Model Zoo Demos](../../README.md)
* [Model Optimizer](https://docs.openvinotoolkit.org/latest/_docs_MO_DG_Deep_Learning_Model_Optimizer_DevGuide.html)
* [Model Downloader](../../../tools/model_tools/README.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once

#include <gflags/gflags.h>
#include <utils/default_flags.hpp>

DEFINE_INPUT_FLAGS
DEFINE_OUTPUT_FLAGS

static const char help_message[] = "Print a usage message.";
static const char camera_resolution_message[] = "Optional. Set camera resolution in format WxH.";
static const char mtcnn_p_model_message[] = "Required. Path to an .xml file with a trained OpenVINO MTCNN P (Proposal) detection model.";
static const char mtcnn_r_model_message[] = "Required. Path to an .xml file with a trained OpenVINO MTCNN R (Refinement) detection model.";
static const char mtcnn_o_model_message[] = "Required. Path to an .xml file with a trained OpenVINO MTCNN O (Output) detection model.";
static const char target_device_message_p[] = "Optional. Target device for MTCNN P network. "
"The demo will look for a suitable plugin for a specified device. Default value is \"CPU\".";
static const char target_device_message_r[] = "Optional. Target device for MTCNN R network. "
"The demo will look for a suitable plugin for a specified device. Default value is \"CPU\".";
static const char target_device_message_o[] = "Optional. Target device for MTCNN O network. "
"The demo will look for a suitable plugin for a specified device. Default value is \"CPU\".";
static const char thresh_output_message[] = "Optional. MTCNN confidence threshold. The default value is 0.7.";
static const char queue_capacity_message[] = "Optional. Streaming executor queue capacity. Calculated automaticaly if 0.";
static const char half_scale_message[] = "Optional. MTCNN P use half scale pyramid.";
static const char no_show_message[] = "Optional. Don't show output.";
static const char utilization_monitors_message[] = "Optional. List of monitors to show initially.";

DEFINE_bool(h, false, help_message);
DEFINE_string(res, "1280x720", camera_resolution_message);
DEFINE_string(m_p, "", mtcnn_p_model_message);
DEFINE_string(m_r, "", mtcnn_r_model_message);
DEFINE_string(m_o, "", mtcnn_o_model_message);
DEFINE_string(d_p, "CPU", target_device_message_p);
DEFINE_string(d_r, "CPU", target_device_message_r);
DEFINE_string(d_o, "CPU", target_device_message_o);
DEFINE_uint32(qc, 1, queue_capacity_message);
DEFINE_bool(hs, false, half_scale_message);
DEFINE_double(th, 0.7, thresh_output_message);
DEFINE_bool(no_show, false, no_show_message);
DEFINE_string(u, "", utilization_monitors_message);

/**
* \brief This function shows a help message
*/

#include <iostream>
static void showUsage() {
std::cout << std::endl;
std::cout << "gesture_recognition_demo_gapi [OPTION]" << std::endl;
std::cout << "Options:" << std::endl;
std::cout << std::endl;
std::cout << " -h " << help_message << std::endl;
std::cout << " -i " << input_message << std::endl;
std::cout << " -loop " << loop_message << std::endl;
std::cout << " -o \"<path>\" " << output_message << std::endl;
std::cout << " -limit \"<num>\" " << limit_message << std::endl;
std::cout << " -res \"<WxH>\" " << camera_resolution_message << std::endl;
std::cout << " -m_p \"<path>\" " << mtcnn_p_model_message << std::endl;
std::cout << " -m_r \"<path>\" " << mtcnn_r_model_message << std::endl;
std::cout << " -m_o \"<path>\" " << mtcnn_o_model_message << std::endl;
std::cout << " -d_p \"<device>\" " << target_device_message_p << std::endl;
std::cout << " -d_r \"<device>\" " << target_device_message_r << std::endl;
std::cout << " -d_o \"<device>\" " << target_device_message_o << std::endl;
std::cout << " -qc " << queue_capacity_message << std::endl;
std::cout << " -hs " << half_scale_message << std::endl;
std::cout << " -no_show " << no_show_message << std::endl;
std::cout << " -th " << thresh_output_message << std::endl;
std::cout << " -u " << utilization_monitors_message << std::endl;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1b59d4a

Please sign in to comment.