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

Disabling face recognition until a condition is met #14

Open rsingh2083 opened 3 years ago

rsingh2083 commented 3 years ago

Sir, Let's say I want to disable face detection and recognition until a certain condition is true( decided by another external code). How can I achieve this. At exactly what line do I need to put a boolean condition : if true : execute Face detection and recognition ,else: do nothing.

Qengineering commented 3 years ago

I would place my if(){ at line 324 at main.cpp. Just before ScaleX = ((float) frame.cols) / RetinaWidth;. This way your camera is still piping images. The end bracket } goes at line 500, still showing the images.

    while(1){
        cap >> frame;
        if (frame.empty()) {
            cerr << "End of movie" << endl;
            break;
        }
        if( my_condition ) {
             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);
             .........................................................
             DrawObjects(frame, Faces);

              //calculate frame rate
              f = chrono::duration_cast <chrono::milliseconds> (Tend - Tbegin).count();
              if(f>0.0) FPS[((Fcnt++)&0x0F)]=1000.0/f;
              for(f=0.0, i=0;i<16;i++){ f+=FPS[i]; }
              cv::putText(frame, cv::format("FPS %0.2f", f/16),cv::Point(10,20),cv::FONT_HERSHEY_SIMPLEX,0.6, cv::Scalar(180, 180, 0));
         } //end my_condition

        //show output
        cv::imshow("Jetson Nano - 2014.5 MHz", frame);
        char esc = cv::waitKey(5);
        if(esc == 27) break;
    }

To let another program start/stop the recognition, you have to signal from that program to this main.cpp. By far the easiest way is using a little file. Main.cpp reads the file and sees if the my_condition flag is set/reset. The other program can write to the same file. Tip: locate the file at /dev/shm directory. This directory is redirected to RAM instead of the SD-card. This way the wear out of your SD-card will reduced.