User Manual Orange Pi Zero 3

  Features   |  Use   |    Linux     |  Linux SDK   |  Android   |  Android SRC   |

RU          EN  

Chapt 3. Instructions for use of Debian/Ubuntu Server and Xfce desktop system
Страница:   25    26    27    28    29    30    31    32    33    34    35    36    37    38    39    40    41    42    43    44    45    46    47    48    49    50    51    52    53    54    55    56    57    58    59    60    61    62    63    64    65    66    67    68    69    70    71    72    73    74    75    76    77    78    79    80    81    82    83    84    85    86    87    88    89    90    91    92    93    94    95    96    97    98    99    100    101    102    103    104    105    106    107    108    109    110    111    112    113    114    115    116    117    118    119    120    121    122  


3.27.3. The test method of face_recognition

Note that the following operations are demonstrated on the desktop, so please connect the HDMI monitor first, or use NoMachine/VNC to remotely log in to the Linux desktop to test

  • 1) There are some sample codes in the source code of face_recognition, which we can use directly for testing. The download address of the source code of face_recognition is as follows

    a. GitHub official download address

    orangepi@orangepi:~$ git clone https://github.com/ageitgey/face_recognition.git

    b. Gitee image download address

    orangepi@orangepi:~$ git clone https://gitee.com/leeboby/face_recognition.git

  • 2) The path to the face_recognition sample code is as follows face_recognition/examples

  • 3) The Chinese description document link of face_recognition is as follows, please read it carefully before using face_recognition

    https://github.com/ageitgey/face_recognition/blob/master/README_Simplified_Chinese.md

  • 4) find_faces in picture.py is used to locate the position of the face in the picture, the test steps are as follows

    a. Open a terminal on the desktop, then enter the face_recognition/examples directory, and then execute the following command

    orangepi@orangepi:~$ cd face_recognition/examples
    orangepi@orangepi:~/face_recognition/examples$ python3 find_faces in picture.py
    I found 1 face(s) in this photograph.
    A face is located at pixel location Top: 241, Left: 419, Bottom: 562, Right: 740

    b. Wait for a while and the following picture will pop up, which is the face located in the test picture



    Img 3.181

  • 5) find_facial_features in picture.py is used to identify the key points of the face in a single picture, and the test steps are as follows

    a. Open a terminal on the desktop, then enter the face_recognition/examples directory, and then execute the following command

    orangepi@orangepi:~$ cd face_recognition/examples
    orangepi@orangepi:~/face_recognition/examples$ python3 find_facial_features in picture.py

    b. After waiting for a while, the following picture will pop up, and you can see that the outline of the face is marked



    Img 3.182

  • 6) identify_and_draw_boxes_on_faces.py is used to identify faces and mark them with boxes. The test steps are as follows

    a. Open a terminal on the desktop, then enter the face_recognition/examples directory, and then execute the following command

    orangepi@orangepi:~$ cd face_recognition/examples
    orangepi@orangepi:~/face_recognition/examples$ python3 identify_and_draw_boxes_on_faces.py

    b. After waiting for a while, the following picture will pop up. You can see that the faces in the picture are marked with boxes, and the names of the characters are displayed correctly



    Img 3.183

  • 7) face_distance.py is used to compare whether two faces belong to the same person at different precisions. First open a terminal, then enter the face_recognition/examples directory, and then execute the following command to see the output of the test

    orangepi@orangepi:~$ cd face_recognition/examples
    orangepi@orangepi:~/face_recognition/examples$ python3 face_distance.py
    The test image has a distance of 0.35 from known image #0
    - With a normal cutoff of 0.6, would the test image match the known image? True
    - With a very strict cutoff of 0.5, would the test image match the known image? True
    The test image has a distance of 0.82 from known image #1
    - With a normal cutoff of 0.6, would the test image match the known image? False
    - With a very strict cutoff of 0.5, would the test image match the known image?
    False

  • 8) recognize_faces in pictures.py is used to identify who the face in the unknown picture is. First open a terminal, then enter the face_recognition/examples directory, and then execute the following command, and you can see the test results after waiting for a while

    orangepi@orangepi:~$ cd face_recognition/examples
    orangepi@orangepi:~/face_recognition/examples$ python3 recognize_faces in pictures.py
    Is the unknown face a picture of Biden False
    Is the unknown face a picture of Obama True
    Is the unknown face a new person that we've never seen before False

  • 9) facerec_from_webcam_faster.py is used to recognize the face in the USB camera, the test steps are as follows

    a. First, please insert the USB camera into the USB interface of the development board, and then use the v4l2-ctl (note that l in v4l2 is a lowercase letter l, not the number 1) command to check the serial number of the device node of the USB camera

    orangepi@orangepi:~$ sudo apt update
    orangepi@orangepi:~$ sudo apt install -y v4l-utils
    orangepi@orangepi:~$ v4l2-ctl --list-devices
    cedrus (platform:cedrus):
    /dev/video0

    USB2.0 UVC PC Camera: USB2.0 UV (usb-5311000.usb- 1): /dev/video1 /dev/video2

    b. Then open a terminal on the desktop, enter the face_recognition/examples directory, and first modify the device serial number of the camera used in facerec_from_webcam_faster.py. For example, through the v4l2-ctl --list-devices command above, you can see that the USB camera is /dev/video1, then modify the 0 in cv2.VideoCapture(0) to 1

    orangepi@orangepi:~$ cd face_recognition/examples
    orangepi@orangepi:~/face_recognition/examples$ vim facerec_from_webcam_faster.py
    video_capture = cv2.VideoCapture(1)

    c. Then execute the following command to run facerec_from_webcam_faster.py

    orangepi@orangepi:~/face_recognition/examples$ python3 facerec_from_webcam_faster.py

    d. Wait for a while and the camera display screen will pop up



    Img 3.184

    e. At this point, you can point the camera at yourself. When the camera detects a face, it will frame the detected face with a square.

    Note that when detecting a face, the image displayed by the camera will be relatively slow, please do not move too fast

    f. You can also open a picture of Obama, and then use the camera to point at the opened picture. You can see that not only the face can be marked, but also the name of the detected face can be displayed correctly.

    Note that when detecting a face, the image displayed by the camera will be relatively slow, please do not move too fast



    Img 3.185

  • 10) web_service_example.py is a very simple case of using a web service to upload a picture to run face recognition. The backend server will identify whether the picture is Obama, and output the recognition result as a json key-value pair. The test steps are as follows

    a. Open a terminal on the desktop, then enter the face_recognition/examples directory, and then execute the following command (if face_recognition is automatically installed using a script, then there is no need to install flask)

    orangepi@orangepi:~$ python3 -m pip install flask
    orangepi@orangepi:~$ cd face_recognition/examples
    root@orangepi:~/face_recognition/examples$ python3 web_service_example.py
    * Serving Flask app 'web_service_example' (lazy loading)
    * Environment: production
    WARNING: This is a development server.
    Do not use it in a production deployment. Use a production WSGI server instead.
    * Debug mode: on
    * Running on all addresses (0.0.0.0)
    WARNING: This is a development server. Do not use it in a production deployment.
    * Running on http://127.0.0. 1:5001
    * Running on http://192.168.1.79:5001 (Press CTRL+C to quit)
    * Restarting with stat
    * Debugger is active!
    * Debugger PIN: 500- 161-390

    b. Then open another terminal and run the following command to return the result of image recognition (note that the execution path of the following command is face_recognition/examples)

    orangepi@orangepi:~/face_recognition/examples$ curl -XPOST -F \
    "file=@obama2.jpg" http://127.0.0.1:5001
    {
    "face_found_in_image": true,
    "is_picture_of_obama": true
    }

    c. We can also copy the picture face_recognition/examples/obama2.jpg to other Linux computers. Of course, we can also prepare a picture named obama2.jpg by ourselves, and then use the following command on the Linux computer to remotely Use the service running on the development board to recognize faces/

    Note that the IP address in the command needs to be replaced with the IP address of the development board, and the file name after file needs to be replaced with the name of the picture you want to test.

    test@test:~$ curl -XPOST -F "file=@obama2.jpg" http://192.168.1.79:5001
    {
    "face_found_in_image": true,
    "is_picture_of_obama": true
    }

    d. The method to test using the browser is as follows a) First open the browser, then enter the IP address of thedevelopmentboard:

  • 5001 in the address bar of the browser, and then you can see the following page


    Img 3.186

    b) Then copy obama2.jpg to the desktop

    orangepi@orangepi:~/face_recognition/examples$ cp obama2.jpg \
    /home/orangepi/Desktop/

    c) Then select the picture you just copied in your browser



    Img 3.187

    d) Then click Upload to upload the picture you just selected for face recognition



    Img 3.188

    e) After waiting for a while, the detection result will be displayed



    Img 3.189

  • 11) face_detection command test example

    a. The face_detection command-line tool can locate the face position (output pixel coordinates) in a single picture or a picture folder. Use face_detection --help to view the help information of the face_detection command

    orangepi@orangepi:~$ face_detection --help
    Usage: face_detection [OPTIONS] IMAGE_TO_CHECK
    Options:
    --cpus INTEGER number of CPU cores to use in parallel. -1 means "use all in
    system"
    --model TEXT Which face detection model to use. Options are "hog" or
    "cnn".
    --help Show this message and exit

    b. An example of detecting a single image is shown below

    orangepi@orangepi:~$ cd face_recognition/examples
    orangepi@orangepi:~/face_recognition/examples$ face_detection \
    obama2.jpg obama2.jpg,302,474,611, 164

    c. An example of using multiple cores to detect multiple images in parallel is shown below

      a) First enter the face_recognition/examples folder b) Then create a new test folder c) Then copy the jpg images to the test folder d) Then use all cpus to run face_detection in parallel to check the pictures in the test folder, where --cpus -1 means to use all cpus

    orangepi@orangepi:~$ cd face_recognition/examples
    orangepi@orangepi:~/face_recognition/examples$ mkdir test
    orangepi@orangepi:~/face_recognition/examples$ cp *.jpg test
    orangepi@orangepi:~/face_recognition/examples$ face_detection --cpus -1 test
    test/obama-240p.jpg,29,261, 101, 189
    test/obama_small.jpg,65,215, 169, 112
    test/obama2.jpg,302,474,611, 164
    test/two_people.jpg,62,394,211,244
    test/two_people.jpg,95,941,244,792
    test/obama.jpg, 136,624,394,366
    test/obama-480p.jpg,65,507, 189,383
    test/obama-720p.jpg,94,751,273,572
    test/obama- 1080p.jpg, 136, 1140,394,882
    test/biden.jpg,233,749,542,439

  • 12) face_recognition command test example

    a. face_recognition command-line tool can recognize whose face is in a single picture or a picture folder. Use face_recognition --help to view the help information of the face_recognition command

    orangepi@orangepi:~$ face_recognition --help
    Usage: face_recognition [OPTIONS] KNOWN_PEOPLE_FOLDER
    IMAGE_TO_CHECK
    Options:
    --cpus INTEGER
    --tolerance FLOAT

    number of CPU cores to use in parallel (can speed up processing lots of images). - 1 means "use all in system" Tolerance for face comparisons. Default is 0.6. Lower this ifyou get multiple matches for the same person. --show-distance BOOLEAN Output face distance. Useful for tweaking tolerance setting.

    --help Show this message and exit.

    b. First create a new face picture folder known_people with a known name, then copy two pictures to known_people, and then copy obama2.jpg to unknown.jpg, which is the picture we want to identify

    orangepi@orangepi:~$ cd face_recognition/examples
    orangepi@orangepi:~/face_recognition/examples$ mkdir known_people
    orangepi@orangepi:~/face_recognition/examples$ cp biden.jpg obama.jpg known_people
    orangepi@orangepi:~/face_recognition/examples$ cp obama2.jpg unkown.jpg
    

    c. Then you can use the following command to identify the name of the person in the unknown.jpg picture, and you can see that the unknown.jpg picture is recognized as obama

    orangepi@orangepi:~/face_recognition/examples$ face_recognition known_people \
    unkown.jpg
    unkown.jpg,obama

    d. If we identify an irrelevant image, unknown_person will be displayed

    root@orangepi:~/face_recognition/examples$ face_recognition known_people \
    alex-lacamoire.png
    alex-lacamoire.png,unknown_person

    test/biden.jpg,biden test/obama- 1080p.jpg,obama


     <         > 


  • Страница:   25    26    27    28    29    30    31    32    33    34    35    36    37    38    39    40    41    42    43    44    45    46    47    48    49    50    51    52    53    54    55    56    57    58    59    60    61    62    63    64    65    66    67    68    69    70    71    72    73    74    75    76    77    78    79    80    81    82    83    84    85    86    87    88    89    90    91    92    93    94    95    96    97    98    99    100    101    102    103    104    105    106    107    108    109    110    111    112    113    114    115    116    117    118    119    120    121    122