Qengineering / Face-Recognition-with-Mask-Jetson-Nano

Recognize 2000+ faces on your Jetson Nano with additional mask detection, auto-fill and anti-spoofing
https://qengineering.eu/deep-learning-examples-on-raspberry-32-64-os.html
BSD 3-Clause "New" or "Revised" License
35 stars 6 forks source link

How to enable only recognition of larger faces/when someone is near the camera #12

Closed rsingh2083 closed 3 years ago

rsingh2083 commented 3 years ago

Hi Sir, I want the face recognition to start working only when someone is lets say less than 2 feet near to the camera. I dont want to recognize distant people. Can you tell me which like to tweak , ill change as per my requirement.

Qengineering commented 3 years ago

That's easy this time. At line 41 in main.cpp you will find const int MinHeightFace = 90; preventing small faces to be analyzed. You can always alter this number. You have to recompile the code afterwards.

rsingh2083 commented 3 years ago

I changed it to 500 but still its not working sir.

Qengineering commented 3 years ago

Strange. Looking at line 432 and 457 if(Faces[i].rect.height < MinHeightFace){ it should work. If you have altered the code, this is the condition to use in your part.

rsingh2083 commented 3 years ago

Strange. Looking at line 432 and 457 if(Faces[i].rect.height < MinHeightFace){ it should work. If you have altered the code, this is the condition to use in your part.

Sir can you please check again, I tried all values but it doesnt seem to work. If MinHeightFace is actual parameter to change or do I need to change something in header files of arcface etc ?

Qengineering commented 3 years ago

It should work as follows: Faces smaller than MinHeightFace are labelled "too tiny", Faces larger than MinHeightFace are send to the next recognition stage. I though it works well if you have 'too tiny' as label, or, am I missing something here?

rsingh2083 commented 3 years ago

I though it works well if you have 'too tiny' as label, or, am I missing something here?

Actually I want only very very close faces to be recognized. Hence I set MinHeightFace = 500, but its no different than MinHeightFace=90. The bahaviour of code/recognition is same

Qengineering commented 3 years ago

At line 352 main.cpp you see the output of the face detection

            for(i=0;i<Faces.size();i++){
                float x1 = Faces[i].rect.x;
                float y1 = Faces[i].rect.y;
                float x2 = Faces[i].rect.width+x1;
                float y2 = Faces[i].rect.height+y1;

The variable Faces[i].rect.width or Faces[i].rect.height gives you a direct information about the size of the face.

Please note, the input image has been cropped from the original size (say 640x480) to (320x240) = RetinaWidth x RetinaHeight at Line 324 main.cpp

        ScaleX = ((float) frame.cols) / RetinaWidth;
        ScaleY = ((float) frame.rows) / RetinaHeight;

Your face will be max 240 pixel of height.