Code Monkey home page Code Monkey logo

face-mask-detection-jetson-nano's Introduction

Face-Mask-Detection-Jetson-Nano

output image

A fast face mask recognition running at 44-5 FPS on a Jetson Nano.

License

This is a fast C++ implementation of two deep learning models found in the public domain.

The first is face detector of Linzaer running on a ncnn framework.
https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB.

The second is the Paddle Lite mask detection which classifies the found faces.
https://github.com/PaddlePaddle/Paddle-Lite/tree/develop/lite/demo/cxx/mask_detection.

The frame rate depends on the number of detected faces and can be calculated as follows:
FPS = 1.0/(0.022 + 0.008 x #Faces) when overclocked to 2014 MHz.

Paper: https://arxiv.org/abs/1905.00641.pdf
Size: 320x320

Special made for a Jetson Nano see Q-engineering deep learning examples

New version 2.0.

A new and superior version with only TensorFlow Lite for a Jetson Nano see GitHub

Dependencies.

April 4 2021: Adapted for ncnn version 20210322 or later

To run the application, you have to:

  • The Paddle Lite framework installed. Install Paddle
  • The Tencent ncnn framework installed. Install ncnn
  • Code::Blocks installed. ($ sudo apt-get install codeblocks)

Running the app.

To extract and run the network in Code::Blocks
$ mkdir MyDir
$ cd MyDir
$ wget https://github.com/Qengineering/Face-Mask-Detection-Jetson-Nano/archive/refs/heads/main.zip
$ unzip -j master.zip
Remove master.zip and README.md as they are no longer needed.
$ rm master.zip
$ rm README.md

Your MyDir folder must now look like this:
Face_1.jpg
Face_2.jpg
Face_3.jpg
Face_Mask_Video.mp4
mask_detector_opt2.nb
MaskUltra.cpb
mask_ultra.cpp
UltraFace.cpp
UltraFace.hpp
RFB-320.bin
RFB-320.param
slim_320.bin
slim_320.param

Notes.

The directories in the Code::Blocks project file will probably need to be adapted to the naming convention you are using.
The camera input used is a simple OpenCV webcam. The GStreamer is not used in this example for symplicity reasons.

The RFB-320 model recognizes slightly more faces than slim_320 at the expense of a little bit of speed. It is up to you.
Note that the compilation of the Paddle Lite framework in your application may take a while.

See the Raspberry Pi video at https://youtu.be/LDPXgJv3wAk

face-mask-detection-jetson-nano's People

Contributors

qengineering avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

face-mask-detection-jetson-nano's Issues

JTOP showing different opencv version

I compiled opencv with cuda support but while python3 is showing opencv version as 3.3.1,
JTOP is showing opencv as
Opencv : 4.1.2 compiled CUDA : YES

Any explanation as to what could be happening ? I was able to run the mask detection with average FPS of 25 for single face on webcam. But just puzzled about mismatch between jtop and python's opencv verions.

Lots of undefined errors while building

Hi,
Im getting lots of undefined errors while building this :-
g++ -Wall -fexceptions -pthread -O3 -I/usr/include/opencv4 -I/usr/local/include/paddle-lite -I/usr/local/include/ncnn -c /home/ns/Face-Mask-Detection-Jetson-Nano/mask_ultra.cpp -o obj/Release/mask_ultra.o
...........

g++ -L/usr/local/lib/ -L/usr/lib/ -o bin/Release/MaskUltra obj/Release/mask_ultra.o obj/Release/UltraFace.o   -pthread -fopenmp -s  /usr/local/lib/paddle-lite/libpaddle_api_light_bundled.a /usr/local/lib/ncnn/libncnn.a /usr/lib/aarch64-linux-gnu/libvulkan.so /usr/local/lib/ncnn/libglslang.a /usr/local/lib/ncnn/libOGLCompiler.a /usr/local/lib/ncnn/libOSDependent.a /usr/local/lib/ncnn/libSPIRV.a

obj/Release/mask_ultra.o: In function `cv::Mat::~Mat()':
mask_ultra.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x84): undefined reference to `cv::fastFree(void*)'
mask_ultra.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x94): undefined reference to `cv::Mat::deallocate()'
obj/Release/mask_ultra.o: In function `main':
mask_ultra.cpp:(.text.startup+0x10b8): undefined reference to `cv::String::allocate(unsigned long)'
mask_ultra.cpp:(.text.startup+0x10e8): undefined reference to `cv::VideoCapture::VideoCapture(cv::String const&)'
mask_ultra.cpp:(.text.startup+0x10f0): undefined reference to `cv::String::deallocate()'
mask_ultra.cpp:(.text.startup+0x10f8): undefined reference to `cv::VideoCapture::isOpened() const'
mask_ultra.cpp:(.text.startup+0x1128): undefined reference to `cv::VideoCapture::~VideoCapture()'
mask_ultra.cpp:(.text.startup+0x1200): undefined reference to `cv::VideoCapture::operator>>(cv::Mat&)'
mask_ultra.cpp:(.text.startup+0x1274): undefined reference to `cv::destroyAllWindows()'
mask_ultra.cpp:(.text.startup+0x1494): undefined reference to `cv::fastFree(void*)'
mask_ultra.cpp:(.text.startup+0x15ac): undefined reference to `cv::format(char const*, ...)'
mask_ultra.cpp:(.text.startup+0x15fc): undefined reference to `cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
mask_ultra.cpp:(.text.startup+0x1604): undefined reference to `cv::String::deallocate()'
mask_ultra.cpp:(.text.startup+0x1614): undefined reference to `cv::String::allocate(unsigned long)'
mask_ultra.cpp:(.text.startup+0x1658): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
mask_ultra.cpp:(.text.startup+0x1660): undefined reference to `cv::String::deallocate()'
mask_ultra.cpp:(.text.startup+0x1668): undefined reference to `cv::waitKey(int)'
mask_ultra.cpp:(.text.startup+0x16cc): undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)'
mask_ultra.cpp:(.text.startup+0x1714): undefined reference to `cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)'
mask_ultra.cpp:(.text.startup+0x1744): undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
mask_ultra.cpp:(.text.startup+0x1800): undefined reference to `cv::rectangle(cv::Mat&, cv::Rect_<int>, cv::Scalar_<double> const&, int, int, int)'
mask_ultra.cpp:(.text.startup+0x1874): undefined reference to `cv::fastFree(void*)'
mask_ultra.cpp:(.text.startup+0x18e8): undefined reference to `cv::fastFree(void*)'
mask_ultra.cpp:(.text.startup+0x1904): undefined reference to `cv::Mat::deallocate()'
mask_ultra.cpp:(.text.startup+0x1910): undefined reference to `cv::Mat::deallocate()'
mask_ultra.cpp:(.text.startup+0x1998): undefined reference to `cv::Mat::deallocate()'
mask_ultra.cpp:(.text.startup+0x19f4): undefined reference to `cv::String::deallocate()'
mask_ultra.cpp:(.text.startup+0x1a10): undefined reference to `cv::VideoCapture::~VideoCapture()'
mask_ultra.cpp:(.text.startup+0x1a98): undefined reference to `cv::String::deallocate()'
mask_ultra.cpp:(.text.startup+0x1ac0): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 11 second(s))
31 error(s), 2 warning(s) (0 minute(s), 11 second(s))


JTOP showing different opencv version

I compiled opencv with cuda support but while python3 is showing opencv version as 4.9.0,
JTOP is showing opencv as
Opencv : 4.5.4 compiled CUDA : NO

How can I change opencv version of JTOP to 4.9.0?

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.