Changes

Jump to: navigation, search

Orange Pi Zero 3

1,424 bytes added, 17:12, 11 July 2023
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 &gt; '''face_recognition/examples''' directory, and then execute the &gt; 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 &gt; 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 &gt; '''face_recognition/examples''' directory, and then execute the &gt; 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, &gt; 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 &gt; '''face_recognition/examples''' directory, and then execute the &gt; 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. &gt; You can see that the faces in the picture are marked with &gt; 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 &gt; the development board, and then use the '''v4l2-ctl''' ('''<span style="color:#FF0000">note &gt; that l in v4l2 is a lowercase letter l, not the number 1</span>''') &gt; command to check the serial number of the device node of the &gt; 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 &gt; '''face_recognition/examples''' directory, and first modify the &gt; device serial number of the camera used in &gt; '''facerec_from_webcam_faster.py.''' For example, through the &gt; '''v4l2-ctl --list-devices''' command above, you can see that &gt; the USB camera is '''/dev/video1''', then modify the '''0''' in &gt; '''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 &gt; '''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 &gt; camera detects a face, it will frame the detected face with a &gt; square. '''Note that when detecting a face, the image displayed &gt; by the camera will be relatively slow, please do not move too &gt; fast'''</p></li><li><p>You can also open a picture of Obama, and then use the camera to &gt; point at the opened picture. You can see that not only the &gt; face can be marked, but also the name of the detected face can &gt; be displayed correctly. '''Note that when detecting a face, the &gt; image displayed by the camera will be relatively slow, please &gt; 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 &gt; '''face_recognition/examples''' directory, and then execute the &gt; following command ('''<span style="color:#FF0000">if face_recognition is automatically &gt; installed using a script, then there is no need to install &gt; 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 &gt; return the result of image recognition (note that the &gt; execution path of the following command is &gt; '''face_recognition/examples''')</p>{| class="wikitable" style="width:800px;" |-|
<p>orangepi@orangepi:~/face_recognition/examples$ '''curl -XPOST -F \'''</p>
<p>'''&quot;file=@obama2.jpg&quot; http://127.0.0.1:5001'''</p>
<p>'''{'''</p>
:<p>'''&quot;face_found_in_image&quot;: true,'''</p>:<p>'''&quot;is_picture_of_obama&quot;: true'''</p><p>'''}'''</p>|}</li><li><p>We can also copy the picture &gt; '''face_recognition/examples/obama2.jpg''' to other Linux &gt; computers. Of course, we can also prepare a picture named &gt; '''obama2.jpg''' by ourselves, and then use the following &gt; command on the Linux computer to remotely Use the service &gt; running on the development board to recognize faces ('''note &gt; that the IP address in the command needs to be replaced with &gt; the IP address of the development board, and the file name &gt; after file needs to be replaced with the name of the picture &gt; you want to test''').</p>{| class="wikitable" style="width:800px;" |-|
<p>test@test:~$ '''curl -XPOST -F &quot;file=@obama2.jpg&quot; http://192.168.1.79:5001'''</p>
<p>'''{'''</p>
:<p>'''&quot;face_found_in_image&quot;: true,'''</p>:<p>'''&quot;is_picture_of_obama&quot;: 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 &gt; development board: 5001</span>''' in the address bar of &gt; 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 &gt; 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 &gt; 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 &gt; position (output pixel coordinates) in a single picture or a &gt; picture folder. Use '''face_detection --help''' to view the &gt; 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 &quot;use all in</p><p>system&quot;</p>  :<p>--model TEXT Which face detection model to use. Options are &quot;hog&quot; or</p><p>&quot;cnn&quot;.</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 &gt; 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 &gt; check the pictures in the test folder, where '''--cpus &gt; -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 &gt; is in a single picture or a picture folder. Use &gt; '''face_recognition --help''' to view the help information of &gt; 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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; number of CPU cores to use in parallel (can speed</p><p>up processing lots of images). -1 means &quot;use all in</p><p>system&quot;</p>  :<p>--tolerance FLOAT &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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 &nbsp;&nbsp; Output face distance. Useful for tweaking tolerance</p><p>setting.</p>  :<p>--help &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Show this message and exit.</p>|}</li><li><p>First create a new face picture folder '''known_people''' with a &gt; known name, then copy two pictures to '''known_people''', and &gt; then copy '''obama2.jpg''' to '''unknown.jpg''', which is the &gt; 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 &gt; the person in the '''unknown.jpg''' picture, and you can see &gt; 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 &gt; 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 &gt; in it, and then we can use all the CPUs to recognize all the &gt; 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>

Navigation menu