Giter VIP home page Giter VIP logo

qengineering / face-recognition-raspberry-pi-64-bits Goto Github PK

View Code? Open in Web Editor NEW
68.0 68.0 18.0 20.01 MB

Recognize 2000+ faces on your Raspberry Pi 4 with database auto-fill and anti-spoofing

Home Page: https://qengineering.eu/deep-learning-examples-on-raspberry-32-64-os.html

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

C++ 98.74% CMake 1.26%
aarch64 anti-spoofing arcface armv8 blur-filter deep-learning face-detection face-recognition high-fps mtcnn-face-detection ncnn ncnn-framework raspberry-pi-4 retinaface ubuntu

face-recognition-raspberry-pi-64-bits's Introduction

output image


output image output image
A Raspberry Pi 4, 3 or Zero 2, with stand-alone AI object recognition, browser-based live streaming, email, cloud storage, GPIO and URL event triggers.

output image output image
A Raspberry Pi 4 or 5, with stand-alone AI, supports multiple IP surveillance cameras.


Table of Contents

output image Raspberry Pi 4 Bullseye 64-bit OS with several frameworks and deep-learning examples

output image Raspberry Pi 4 Buster 64-bit OS with several frameworks and deep-learning examples

output image Raspberry Pi Zero 2 W 64-bit OS image with OpenCV, TensorFlow Lite and ncnn

output image Banana Pi M2 Zero image with OV5640 camera and OpenCV

output image Rock 5 with OpenCV, TNN, ncnn and NPU

output image Rock 5 with Ubuntu 22.04, OpenCV, ncnn and NPU

output image Radxa Zero 3 with Ubuntu 22.04, OpenCV, ncnn and NPU

output image A Jetson Nano image with OpenCV, TensorFlow and PyTorch

output image A Jetson Nano - Ubuntu 20.04 image with OpenCV, TensorFlow and PyTorch

  • Applications

output image RPi z2, 3 or 4 motion surveillance camera with email notification and gdrive storage

output image YoloCam, the cheapest AI-powered camera with email notification, gdrive storage and GPIO output

output image YoloIP, the cheapest AI-powered machine, supports multiple IP surveillance cameras

Qengineering's github stats

Visitor count


paypal

face-recognition-raspberry-pi-64-bits's People

Contributors

qengineering avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

face-recognition-raspberry-pi-64-bits's Issues

Compile with cmake

Hello,

Nice!! Thanks for sharing the source code.

You provided in #10 one example of how to compile with g++, but how can i create a CMakeLists.txt to compile using cmake?

Rgrds,
Camilla

Cannot find net.h

image
Failed to compile because of this error. TMtCNN.h:8:10: fatal error: net.h: No such file or directory

Not working with bullsye

Hi Sir,
There are two problems
1.] Your 64bit_Rpi4 image isnt updating due to this error

E: Repository 'http://raspbian.raspberrypi.org/raspbian buster InRelease' changed its 'Suite' value from 'testing' to 'stable'
2.] After updating to bullseye, the face recog code doesnt work (brief snippet of error)

bnll.cpp:(.text+0xf0): undefined reference to `__expf_finite'
/usr/bin/ld: bnll.cpp:(.text+0xf8): undefined reference to `__logf_finite'
/usr/bin/ld: bnll.cpp:(.text+0x13c): undefined reference to `__expf_finite'
/usr/bin/ld: bnll.cpp:(.text+0x144): undefined reference to `__logf_finite'
/usr/bin/ld: /usr/local/lib/ncnn/libncnn.a(convolution.cpp.o): in function `ncnn::Convolution::forward(ncnn::Mat const&, ncnn::Mat&, ncnn::Option const&) const [clone ._omp_fn.0]':
convolution.cpp:(.text+0x560): undefined reference to `__expf_finite'
/usr/bin/ld: convolution.cpp:(.text+0x57c): undefined reference to `__expf_finite'
/usr/bin/ld: convolution.cpp:(.text+0x5a4): undefined reference to `__logf_finite'

Can you please update the code to work with bullseye. And maybe fix the issue with Rpi4 image not getting updated/upgraded also

running from terminal

Good day,

im wondering... Is it possible tu run FaceRecognition.cbp from terminal? ./FaceRecognition seems not to work

Thanks

Vulkan

Hi,

I installed ncnn with vulkan on the raspberry pi 4B 8Gb correctly and I'm running the ncnn examples successfully on vulkan. But I'm not knowing how to correctly configure my CMakeLists.txt file to reference the glslang library.

Error:

/usr/bin/ld: /usr/local/lib/ncnn/libncnn.a(gpu.cpp.o): in function `ncnn::destroy_gpu_instance()':
gpu.cpp:(.text+0xcb4): undefined reference to `glslang::FinalizeProcess()'
/usr/bin/ld: /usr/local/lib/ncnn/libncnn.a(gpu.cpp.o): in function `ncnn::create_gpu_instance()':
gpu.cpp:(.text+0x3dc8): undefined reference to `glslang::InitializeProcess()'
/usr/bin/ld: /usr/local/lib/ncnn/libncnn.a(gpu.cpp.o): in function `ncnn::compile_spirv_module(char const*, int, ncnn::Option const&, std::vector<unsigned int, std::allocator<unsigned int> >&)':
gpu.cpp:(.text+0x7ba0): undefined reference to `glslang::TShader::TShader(EShLanguage)'
/usr/bin/ld: gpu.cpp:(.text+0x7bb8): undefined reference to `glslang::TShader::setStringsWithLengths(char const* const*, int const*, int)'
/usr/bin/ld: gpu.cpp:(.text+0x7bcc): undefined reference to `glslang::TShader::addProcesses(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)'
/usr/bin/ld: gpu.cpp:(.text+0x7bdc): undefined reference to `glslang::TShader::setEntryPoint(char const*)'
/usr/bin/ld: gpu.cpp:(.text+0x7be8): undefined reference to `glslang::TShader::setSourceEntryPoint(char const*)'
/usr/bin/ld: gpu.cpp:(.text+0x7d3c): undefined reference to `glslang::TShader::parse(TBuiltInResource const*, int, EProfile, bool, bool, EShMessages, glslang::TShader::Includer&)'
/usr/bin/ld: gpu.cpp:(.text+0x7d84): undefined reference to `glslang::TShader::getInfoLog()'
/usr/bin/ld: gpu.cpp:(.text+0x7dac): undefined reference to `glslang::TShader::getInfoDebugLog()'
/usr/bin/ld: gpu.cpp:(.text+0x7dd0): undefined reference to `glslang::TShader::~TShader()'
/usr/bin/ld: gpu.cpp:(.text+0x84b0): undefined reference to `glslang::GlslangToSpv(glslang::TIntermediate const&, std::vector<unsigned int, std::allocator<unsigned int> >&, glslang::SpvOptions*)'
/usr/bin/ld: gpu.cpp:(.text+0x84bc): undefined reference to `glslang::TShader::~TShader()'
/usr/bin/ld: gpu.cpp:(.text+0xa474): undefined reference to `glslang::TShader::~TShader()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/test.dir/build.make:285: ../test] Error 1
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/test.dir/all] Error 2

CMakeLists.txt:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

project(test)

macro(use_cxx11)
  if (CMAKE_VERSION VERSION_LESS "3.1")
    if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
      set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
    endif ()
  else ()
    set (CMAKE_CXX_STANDARD 17)
  endif ()
endmacro(use_cxx11)

find_package(OpenCV REQUIRED)
find_package(aws-crt-cpp REQUIRED)
find_package(AWSSDK REQUIRED COMPONENTS s3 transfer)

set(SOURCES src/main.cpp src/TDetection.cpp)
set(
  EXTRA_LIBS ${OpenCV_LIBS} 
  /usr/local/lib/ncnn/libncnn.a
  /usr/lib/aarch64-linux-gnu/libvulkan.so  
)
set(EXECUTABLE_OUTPUT_PATH "../")

include_directories(include ${OpenCV_INCLUDE_DIRS} /usr/local/include/ncnn )
add_link_options(-fopenmp -s -ldl -lpthread )

add_executable(test ${SOURCES})

target_link_libraries(test ${EXTRA_LIBS})
target_link_libraries(test AWS::aws-crt-cpp)
target_link_libraries(test ${AWSSDK_LINK_LIBRARIES})

find_library(WIRINGPI_LIBRARIES NAMES wiringPi)
target_link_libraries(test ${WIRINGPI_LIBRARIES})

Obs: Everything runs perfect with Ncnn without Vulkan

Regards,
Kevin

arcFace ncnn version accuracy and comparing to onnx

Hi,

Is there any accuracy % for this ncnn recognition model ?

I would like to learn your opinion about the onnx and nccn differences between accuracy (sacrifice if any) and speed for arm & intel cpus ?

ie mobile 0.25 insightface model vs nccn this one ?

Best

Add own picture

Can I add my own picture to the database? I realize that when I add my own picture it got a segmentation error. Do I need to crop the picture?

Regarding ANPR

Hi Sir,

Do you know how to implement Automatic number plate recognition on RPI4 ?
The problem statement looks similar to face recognition.
As in one has to first find the license plate in image, once its found we have to then read the characters.
Can you please help which libraries (C++ based) to use for this ?

Compile with g++

Hi,

First of all, nice work. Thanks for sharing.

I don't have much experience with c++, so sorry for the dumb question.

How can i compile and run the script outside of codeblocks using g++?

I moved all .hpp and .cpp files to the same folder and i run this command on raspberry PI console:

g++ main.cpp -o run -I/usr/local/include/opencv4 -I/usr/local/include/ncnn `pkg-config --cflags --libs opencv4`

I got this error:

pi@raspberrypi:~/teste_retinaface $ g++ main.cpp -o run -I/usr/local/include/opencv4 -I/usr/local/include/ncnn `pkg-config --cflags --libs opencv4`
/usr/bin/ld: /tmp/ccbcfqqm.o: in function `main':
main.cpp:(.text+0x34): undefined reference to `TRetina::TRetina(int, int, bool)'
/usr/bin/ld: main.cpp:(.text+0x198): undefined reference to `TRetina::detect_retinaface(cv::Mat const&, std::vector<FaceObject, std::allocator<FaceObject> >&)'
/usr/bin/ld: main.cpp:(.text+0x328): undefined reference to `TRetina::~TRetina()'
/usr/bin/ld: main.cpp:(.text+0x37c): undefined reference to `TRetina::~TRetina()'
collect2: error: ld returned 1 exit status

Obs: I'm testing only the retinaface. The following code runs perfectly in codeblocks with the project that you provide.

Files in folder:

pi@raspberrypi:~/teste_retinaface $ ls -al
total 32
drwxr-xr-x  2 pi pi  4096 Mar 11 16:33 .
drwxr-xr-x 18 pi pi  4096 Mar 11 16:14 ..
-rw-r--r--  1 pi pi  1561 Mar 11 16:26 main.cpp
-rw-r--r--  1 pi pi 12519 Mar 11 16:14 TRetina.cpp
-rw-r--r--  1 pi pi  1022 Mar 11 16:14 TRetina.h

main.cpp

#include <iostream>
#include <opencv2/opencv.hpp>
#include "TRetina.h"

#define RETINA

//----------------------------------------------------------------------------------------
//
// Created by markson zhang
//
// Edited by Xinghao Chen 2020/7/27
//
// Modified by Q-engineering 2020/12/28
//
//----------------------------------------------------------------------------------------
// Build defines
// comment them to turn a function off
//----------------------------------------------------------------------------------------

const int   RetinaWidth      = 320;
const int   RetinaHeight     = 240;

using namespace std;
using namespace cv;

int main(){

    float ScaleX, ScaleY;
    cv::Mat frame;
    cv::Mat result_cnn;
    std::vector<FaceObject> Faces;

    TRetina Rtn(RetinaWidth, RetinaHeight, false);

    cv::VideoCapture cap(0);             //RaspiCam
    //cv::VideoCapture cap("Norton_A.mp4");   //Movie
    if (!cap.isOpened()) {
        cerr << "ERROR: Unable to open the camera" << endl;
        return 0;
    }
    cout << "Start grabbing, press ESC on TLive window to terminate" << endl;

    while(1){
        cap >> frame;
        if (frame.empty()) {
            cerr << "End of movie" << endl;
            break;
        }
        ScaleX = ((float) frame.cols) / RetinaWidth;
        ScaleY = ((float) frame.rows) / RetinaHeight;

        // copy/resize image to result_cnn as input tensor
        cv::resize(frame, result_cnn, Size(RetinaWidth,RetinaHeight),INTER_LINEAR);

        Rtn.detect_retinaface(result_cnn,Faces);

        for(size_t i=0; i < Faces.size(); i++){
            FaceObject& obj = Faces[i];
            obj.rect.x *= ScaleX;
            obj.rect.y *= ScaleY;
            obj.rect.width *= ScaleX;
            obj.rect.height*= ScaleY;

            for(int u=0;u<5;u++){
                obj.landmark[u].x*=ScaleX;
                obj.landmark[u].y*=ScaleY;
            }

        }

        cout << "Faces:" << Faces.size() << endl;
    }

    return 0;
}

windows 10

Hi,

Is this FaceRecog could work on the windows 10 ?

I am a Unix/Linux guy and microsoft makes me crazy. Different compilers and not accepting the compiled libraries.

Is it possible to run on micro-soft win-dows?

RetinaFace crashes at release mode.

Hi, @Qengineering

The system:
Raspi 4 4GB
ubuntu 20.04 64 bit
gcc 10
opencv 4.5
ncnc latest

Progrmam working at Debug mode, but crashing at Release mode with SIGILL

any idea?

NOTE: When I analyze with Valgring it says invalid read 8 :

Screen Shot 2021-02-09 at 21 07 33

How to send the data to any cloud

Can you please let me know if its possible to send the attendance data from raspberry to any cloud database ?
My question is more specific towards relay from C++ code to Cloud. Im new to cloud hence just need your guidance not much.

Android

Hi ,

I love your work and appreciated. Learn a lot.

Do you have android (JNI) version of this project or planning ?

Thx

aligning the face

Hi, @Qengineering

what I noticed that you are aligning the face in TWrap:


 cv::warpPerspective(SmallFrame, aligned, m, cv::Size(96, 112), cv::INTER_LINEAR);
  resize(aligned, aligned, cv::Size(112, 112), 0, 0, cv::INTER_LINEAR);

I saw from ncnn repo:
[
cv::warpAffine(img_src.clone(), *face_aligned, transfer_mat, cv::Size(112, 112), 1, 0, 0);)

is this make a huge diference ? you are usingb (cv::Size(96, 112)) after that resing , below one ise directly 112,112

would you mind to look at it ?

Error when build with CMake

Hi,
I want to build this source with CMake in ubuntu 18.04, and build error, do you have any suggestions for this error? thanks

cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
    message(STATUS "No build type selected, default to Release")
    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (default Debug)" FORCE)
endif()
project(Face recognition)
find_package(OpenCV REQUIRED)
find_package(ncnn REQUIRED)
include_directories(
    ${OpenCV_INCLUDE_DIRS}
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}
)
add_executable(main src/main.cpp src/TArcface.cpp src/TBlur.cpp TFace.cpp TLive.cpp TMtCNN.cpp TRetina.cpp TWarp.cpp )
target_link_libraries(main ncnn -fopenmp -ldl -lpthread -lvulkan ${OpenCV_LIBS})

and log error:

Scanning dependencies of target main
[ 11%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[ 22%] Building CXX object CMakeFiles/main.dir/TWarp.cpp.o
[ 33%] Building CXX object CMakeFiles/main.dir/TRetina.cpp.o
[ 44%] Building CXX object CMakeFiles/main.dir/TMtCNN.cpp.o
[ 55%] Building CXX object CMakeFiles/main.dir/TLive.cpp.o
[ 66%] Building CXX object CMakeFiles/main.dir/TBlur.cpp.o
[ 77%] Building CXX object CMakeFiles/main.dir/TArcface.cpp.o
[ 88%] Building CXX object CMakeFiles/main.dir/TFace.cpp.o
In file included from /home/admin/Face-Recognition-Cmake/TFace.cpp:1:0:
/home/admin/Face-Recognition-Cmake/TFace.h:12:47: error: expected ‘;’ at end of member declaration
     void Process(std::vector<FaceObject> Faces)
                                               ^
/home/admin/Face-Recognition-Cmake/TFace.cpp: In member function ‘void TFace::Process(std::vector<FaceObject>)’:
/home/admin/Face-Recognition-Cmake/TFace.cpp:18:36: error: ‘class cv::Rect_<float>’ has no member named ‘x1’; did you mean ‘x’?
         float x_  =  Faces[i].rect.x1;
                                    ^~
                                    x
/home/admin/Face-Recognition-Cmake/TFace.cpp:19:36: error: ‘class cv::Rect_<float>’ has no member named ‘y1’; did you mean ‘y’?
         float y_  =  Faces[i].rect.y1;
                                    ^~
                                    y
/home/admin/Face-Recognition-Cmake/TFace.cpp:20:22: error: ‘faceInfo’ was not declared in this scope
         float x2_ =  faceInfo[i].x2;
                      ^~~~~~~~
/home/admin/Face-Recognition-Cmake/TFace.cpp:20:22: note: suggested alternative: ‘fileno’
         float x2_ =  faceInfo[i].x2;
                      ^~~~~~~~
                      fileno
/home/admin/Face-Recognition-Cmake/TFace.cpp:26:30: error: variable ‘TFace::Process(std::vector<FaceObject>)::TLiveFaceBox live_box’ has initializer but incomplete type
         struct TLiveFaceBox  live_box={x_,y_,x2_,y2_} ;
                              ^~~~~~~~
/home/admin/Face-Recognition-Cmake/TFace.cpp:28:13: error: ‘rectangle’ is not a member of ‘cv’
         cv::rectangle(result_cnn, Point(x*ratio_x, y*ratio_y), Point(x2*ratio_x,y2*ratio_y), cv::Scalar(0, 0, 255), 2);
             ^~~~~~~~~
/home/admin/Face-Recognition-Cmake/TFace.cpp:28:13: note: suggested alternative: ‘checkRange’
         cv::rectangle(result_cnn, Point(x*ratio_x, y*ratio_y), Point(x2*ratio_x,y2*ratio_y), cv::Scalar(0, 0, 255), 2);
             ^~~~~~~~~
             checkRange
/home/admin/Face-Recognition-Cmake/TFace.cpp:28:23: error: ‘result_cnn’ was not declared in this scope
         cv::rectangle(result_cnn, Point(x*ratio_x, y*ratio_y), Point(x2*ratio_x,y2*ratio_y), cv::Scalar(0, 0, 255), 2);
                       ^~~~~~~~~~
/home/admin/Face-Recognition-Cmake/TFace.cpp:28:43: error: ‘ratio_x’ was not declared in this scope
         cv::rectangle(result_cnn, Point(x*ratio_x, y*ratio_y), Point(x2*ratio_x,y2*ratio_y), cv::Scalar(0, 0, 255), 2);
                                           ^~~~~~~

Saving the recognized person name

Hi Sir,

I wanted to save person name on console and just after line number 113 of you main.cpp, I inserted small code to print person name and then save person name. Its printing the person name but it not saving person name. Can you please help. Where shall I insert these 4 lines to save recognized person name ?

main.cpp

.....  //LINE 108, main.cpp 
switch(obj.NameIndex){     
            case -1: Str="Stranger"; break;
            case -2: Str="too tiny"; break;
            case -3: Str="Fake !";   break;
            default: Str=NameFaces[obj.NameIndex];
        }    // LINE 113 main.cpp

//MY CODE : PRINT PERSON NAME        
cout << "NAME DETECTED AS = " << Str << std::endl;
//END PRINT NAME

//SAVE NAME
 std::string nam= Str.c_str();
 std::cout << "SAVED NAME IN NAME = ", nam;
//END SAVE NAME
......

As you can see in output, its printing the person name but not saving it in the string name
====OUTPUT====

NAME DETECTED AS  = PERSON1  
SAVED NAME IN NAME = 

===============

CMake Questions

#12

Is it possible to run ./FaceRecognition without having the models folder? In other words, somehow the models files be compiled with cmake.

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.