8,367
edits
Changes
→The test method of face_recognition
=== The test method of face_recognition ===
{| class="wikitable" style="background-color:#ffffdc;width:800px;" |-| <big>'''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.'''</big>|}
<ol style="list-style-type: decimal;">
<ol style="list-style-type: lower-alpha;">
<li><p>GitHub official download address</p>
{| class="wikitable" style="width:800px;" |-| <p>orangepi@orangepi:~$ '''git clone https://github.com/ageitgey/face_recognition.git'''</p>|}</li>
<li><p>Gitee image download address</p>
{| class="wikitable" style="width:800px;" |-| <p>orangepi@orangepi:~$ '''git clone [https://github.com/ageitgey/face_recognition https://gitee.com/leeboby/face_recognition.git]'''</p>|}</li></ol>
</li>
<li><p>The path to the face_recognition sample code is as follows</p>
{| class="wikitable" style="width:800px;" |-| <p>'''face_recognition/examples'''</p>|}</li>
<li><p>The Chinese description document link of face_recognition is as follows, please read it carefully before using face_recognition</p>
{| class="wikitable" style="width:800px;" |-| <p>[https://github.com/ageitgey/face_recognition/blob/master/README_Simplified_Chinese.md '''https://github.com/ageitgey/face_recognition/blob/master/README_Simplified_Chinese.md''']</p>|}</li>
<li><p>'''find_faces_in_picture.py''' is used to locate the position of the face in the picture, the test steps are as follows</p>
<ol style="list-style-type: lower-alpha;">
<li><p>Open a terminal on the desktop, then enter the > '''face_recognition/examples''' directory, and then execute the > following command</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~$ '''cd face_recognition/examples'''</p>
<p>orangepi@orangepi:~/face_recognition/examples$ '''python3 find_faces_in_picture.py'''</p>
<p>'''I found 1 face(s) in this photograph.'''</p>
<p>'''A face is located at pixel location Top: 241, Left: 419, Bottom: 562, Right: 740'''</p>|}</li><li><p>Wait for a while and the following picture will pop up, which is > the face located in the test picture</p>
<p>[[File:media/image201.png|575x311px]]</p></li></ol>
</li>
<li><p>'''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</p>
<ol style="list-style-type: lower-alpha;">
<li><p>Open a terminal on the desktop, then enter the > '''face_recognition/examples''' directory, and then execute the > following command</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~$ '''cd face_recognition/examples'''</p>
<p>orangepi@orangepi:~/face_recognition/examples$ '''python3 find_facial_features_in_picture.py'''</p>|}</li><li><p>After waiting for a while, the following picture will pop up, > and you can see that the outline of the face is marked</p>
<p>[[File:media/image202.png|575x302px]]</p></li></ol>
</li>
<li><p>'''identify_and_draw_boxes_on_faces.py''' is used to identify faces and mark them with boxes. The test steps are as follows</p>
<ol style="list-style-type: lower-alpha;">
<li><p>Open a terminal on the desktop, then enter the > '''face_recognition/examples''' directory, and then execute the > following command</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~$ '''cd face_recognition/examples'''</p>
<p>orangepi@orangepi:~/face_recognition/examples$ '''python3 identify_and_draw_boxes_on_faces.py'''</p>|}</li><li><p>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</p>
<p>[[File:media/image203.png|461x250px]]</p></li></ol>
</li>
<li><p>'''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</p>
{| class="wikitable" style="width:800px;"
|-
|
<p>orangepi@orangepi:~$ '''cd face_recognition/examples'''</p>
<p>orangepi@orangepi:~/face_recognition/examples$ '''python3 face_distance.py'''</p>
<p>'''- With a normal cutoff of 0.6, would the test image match the known image? True'''</p>
<p>'''- With a very strict cutoff of 0.5, would the test image match the known image? True'''</p>
<p>'''The test image has a distance of 0.82 from known image #1'''</p>
<p>'''- With a normal cutoff of 0.6, would the test image match the known image? False'''</p>
<p>'''- With a very strict cutoff of 0.5, would the test image match the known image? False'''</p>|}</li>
<li><p>'''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</p>
{| class="wikitable" style="width:800px;"
|-
|
<p>orangepi@orangepi:~$ '''cd face_recognition/examples'''</p>
<p>orangepi@orangepi:~/face_recognition/examples$ '''python3 recognize_faces_in_pictures.py'''</p>
<p>'''Is the unknown face a picture of Biden? False'''</p>
<p>'''Is the unknown face a picture of Obama? True'''</p>
<p>'''Is the unknown face a new person that we've never seen before? False'''</p>|}</li>
<li><p>'''facerec_from_webcam_faster.py''' is used to recognize the face in the USB camera, the test steps are as follows:</p>
<ol style="list-style-type: lower-alpha;">
<li><p>First, please insert the USB camera into the USB interface of > the development board, and then use the '''v4l2-ctl''' ('''<span style="color:#FF0000">note > that l in v4l2 is a lowercase letter l, not the number 1</span>''') > command to check the serial number of the device node of the > USB camera</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~$ '''sudo apt update'''</p>
<p>orangepi@orangepi:~$ '''sudo apt install -y v4l-utils'''</p>
<p>orangepi@orangepi:~$ '''v4l2-ctl --list-devices'''</p>
<p>cedrus (platform:cedrus):</p>
::<p>/dev/video0</p>
<p>USB2.0 UVC PC Camera: USB2.0 UV (usb-5311000.usb-1):</p>
::<p>'''<span style="color:#FF0000">/dev/video1</span>'''</p>::<p>/dev/video2</p>|}</li><li><p>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 '''<span style="color:#FF0000">1</span>'''</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~$ '''cd face_recognition/examples'''</p>
<p>orangepi@orangepi:~/face_recognition/examples$ '''vim facerec_from_webcam_faster.py'''</p>
<p>'''video_capture = cv2.VideoCapture(<span style="color:#FF0000">1</span>)'''</p>|}</li><li><p>Then execute the following command to run > '''facerec_from_webcam_faster.py'''</p>{| class="wikitable" style="width:800px;" |-| <p>orangepi@orangepi:~/face_recognition/examples$ '''python3 facerec_from_webcam_faster.py'''</p>|}</li>
<li><p>Wait for a while and the camera display screen will pop up</p>
<p>[[File:media/image204.png|314x245px]]</p></li>
<li><p>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'''</p></li><li><p>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'''</p>
<p>[[File:media/image205.png|358x284px]]</p></li></ol>
</li>
<li><p>'''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:</p>
<ol style="list-style-type: lower-alpha;">
<li><p>Open a terminal on the desktop, then enter the > '''face_recognition/examples''' directory, and then execute the > following command ('''<span style="color:#FF0000">if face_recognition is automatically > installed using a script, then there is no need to install > flask</span>''')</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~$ '''python3 -m pip install flask'''</p>
<p>orangepi@orangepi:~$ '''cd face_recognition/examples'''</p>
<p>* Serving Flask app 'web_service_example' (lazy loading)</p>
<p>* Environment: production</p>
:<p>WARNING: This is a development server. Do not use it in a production deployment.</p>:<p>Use a production WSGI server instead.</p>
<p>* Debug mode: on</p>
<p>* Running on all addresses (0.0.0.0)</p>
:<p>WARNING: This is a development server. Do not use it in a production deployment.</p>
<p>* Running on http://127.0.0.1:5001</p>
<p>* Running on http://192.168.1.79:5001 (Press CTRL+C to quit)</p>
<p>* Restarting with stat</p>
<p>* Debugger is active!</p>
<p>* Debugger PIN: 500-161-390</p>|}</li><li><p>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''')</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~/face_recognition/examples$ '''curl -XPOST -F \'''</p>
<p>'''"file=@obama2.jpg" http://127.0.0.1:5001'''</p>
<p>'''{'''</p>
:<p>'''"face_found_in_image": true,'''</p>:<p>'''"is_picture_of_obama": true'''</p><p>'''}'''</p>|}</li><li><p>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''').</p>{| class="wikitable" style="width:800px;" |-|
<p>test@test:~$ '''curl -XPOST -F "file=@obama2.jpg" http://192.168.1.79:5001'''</p>
<p>'''{'''</p>
:<p>'''"face_found_in_image": true,'''</p>:<p>'''"is_picture_of_obama": true'''</p><p>'''}'''</p>|}</li>
<li><p>The method to test using the browser is as follows:</p>
<ol style="list-style-type: lower-alphanone;"><li><p>a) First open the browser, then enter the '''<span class="mark">IP address of the > development board: 5001</span>''' in the address bar of > the browser, and then you can see the following page</p>
<p>[[File:media/image206.png|575x150px]]</p></li>
<li><p>b) Then copy obama2.jpg to the desktop</p>{| class="wikitable" style="width:800px;" |-| <p>orangepi@orangepi:~/face_recognition/examples$ '''cp obama2.jpg /home/orangepi/Desktop/'''</p>|}</li><li><p>c) Then select the picture you just copied in your browser</p>
<p>[[File:media/image207.png|575x217px]]</p></li>
<li><p>d) Then click '''Upload''' to upload the picture you just > selected for face recognition</p>
<p>[[File:media/image208.png|575x145px]]</p></li>
<li><p>e) After waiting for a while, the detection result will be > displayed</p>
<p>[[File:media/image209.png|314x149px]]</p></li></ol>
</li></ol>
<li><p>'''face_detection''' command test example</p>
<ol style="list-style-type: lower-alpha;">
<li><p>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</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~$ '''face_detection --help'''</p>
<p>Usage: face_detection [OPTIONS] IMAGE_TO_CHECK</p>
<p>Options:</p>
:<p>--cpus INTEGER number of CPU cores to use in parallel. -1 means "use all in</p><p>system"</p> :<p>--model TEXT Which face detection model to use. Options are "hog" or</p><p>"cnn".</p> :<p>--help Show this message and exit.</p>|}</li>
<li><p>An example of detecting a single image is shown below:</p>
{| class="wikitable" style="width:800px;"
|-
|
<p>orangepi@orangepi:~$ '''cd face_recognition/examples'''</p>
<p>orangepi@orangepi:~/face_recognition/examples$ '''face_detection obama2.jpg'''</p>
<p>obama2.jpg,302,474,611,164</p>|}</li><li><p>An example of using multiple cores to detect multiple images in > parallel is shown below:</p><ol style="list-style-type: lower-alphanone;"><li><p>a) First enter the '''face_recognition/examples''' folder</p></li><li><p>b) Then create a new test folder</p></li><li><p>c) Then copy the jpg images to the test folder</p></li><li><p>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</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~$ '''cd face_recognition/examples'''</p>
<p>orangepi@orangepi:~/face_recognition/examples$ '''mkdir test'''</p>
<p>test/obama-720p.jpg,94,751,273,572</p>
<p>test/obama-1080p.jpg,136,1140,394,882</p>
<p>test/biden.jpg,233,749,542,439</p>|}</li></ol>
</li></ol>
</li>
<li><p>'''face_recognition''' command test example</p>
<ol style="list-style-type: lower-alpha;">
<li><p>'''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</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~$ '''face_recognition --help'''</p>
<p>Usage: face_recognition [OPTIONS] KNOWN_PEOPLE_FOLDER IMAGE_TO_CHECK</p>
<p>Options:</p>
:<p>--cpus INTEGER number of CPU cores to use in parallel (can speed</p><p>up processing lots of images). -1 means "use all in</p><p>system"</p> :<p>--tolerance FLOAT Tolerance for face comparisons. Default is 0.6.</p><p>Lower this if you get multiple matches for the same</p><p>person.</p> :<p>--show-distance BOOLEAN Output face distance. Useful for tweaking tolerance</p><p>setting.</p> :<p>--help Show this message and exit.</p>|}</li><li><p>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</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~$ '''cd face_recognition/examples'''</p>
<p>orangepi@orangepi:~/face_recognition/examples$ '''mkdir known_people'''</p>
<p>orangepi@orangepi:~/face_recognition/examples$ '''cp biden.jpg obama.jpg known_people'''</p>
<p>orangepi@orangepi:~/face_recognition/examples$ '''cp obama2.jpg unkown.jpg'''</p>|}</li><li><p>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</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~/face_recognition/examples$ '''face_recognition known_people \'''</p>
<p>'''unkown.jpg'''</p>
<p>unkown.jpg,obama</p>|}</li><li><p>If we identify an irrelevant image, unknown_person will be > displayed</p>{| class="wikitable" style="width:800px;" |-|
<p>root@orangepi:~/face_recognition/examples$ '''face_recognition known_people \'''</p>
<p>'''alex-lacamoire.png'''</p>
<p>alex-lacamoire.png,unknown_person</p>|}</li><li><p>We can also create a new test folder and put multiple pictures > in it, and then we can use all the CPUs to recognize all the > pictures in parallel</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~/face_recognition/examples$ '''mkdir test'''</p>
<p>orangepi@orangepi:~/face_recognition/examples$ '''cp *.jpg *.png test'''</p>
<p>test/obama-480p.jpg,obama</p>
<p>test/biden.jpg,biden</p>
<p>test/obama-1080p.jpg,obama</p>|}</li></ol>
</li></ol>