8,460
个编辑
更改
→face_recognition的测试方法
=== face_recognition的测试方法 ===
{| class="wikitable" style="background-color:#ffffdc;width:800px;" |-| <big>'''注意,下面的操作都是在桌面中演示的,所以首先请连接好HDMI显示器,或者使用NoMachine/VNC远程登录Linux桌面来测试。'''</big>|}
<ol style="list-style-type: decimal;">
<ol style="list-style-type: lower-alpha;">
<li><p>GitHub官方的下载地址</p>
{| class="wikitable" style="width:800px;" |-| <p>orangepi@orangepi:~$ '''git clone https://github.com/ageitgey/face_recognition.git'''</p>|}</li>
<li><p>Gitee镜像下载地址</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>face_recognition示例代码的路径如下所示</p>
{| class="wikitable" style="width:800px;" |-| <p>'''face_recognition/examples'''</p>|}</li>
<li><p>face_recognition的中文说明文档链接如下所示,使用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'''用来在图片中定位人脸的位置,测试步骤如下所示</p>
<ol style="list-style-type: lower-alpha;">
<li><p>在桌面中打开一个终端,然后进入'''face_recognition/examples'''目录,再执行下面的命令</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>等待一段时间会弹出下面的图片,这就是在测试图片中定位到的人脸</p>
<p>[[File:media/image201.png|575x311px]]</p></li></ol>
<ol style="list-style-type: lower-alpha;">
<li><p>在桌面中打开一个终端,然后进入'''face_recognition/examples'''目录,再执行下面的命令</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>等待一段时间会弹出下面的图片,可以看到将人脸轮廓都标注出来了</p>
<p>[[File:media/image202.png|575x302px]]</p></li></ol>
<ol style="list-style-type: lower-alpha;">
<li><p>在桌面中打开一个终端,然后进入'''face_recognition/examples'''目录,再执行下面的命令</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>等待一段时间会弹出下面的图片,可以看到将图片中的人脸都使用方框标注出来了,并且正确显示了人物的名字</p>
<p>[[File:media/image203.png|461x250px]]</p></li></ol>
</li>
<li><p>'''face_distance.py'''用来在不同精度上比较两个人脸是否属于一个人,首先打开一个终端,然后进入'''face_recognition/examples'''目录,再执行下面的命令就可以看到测试的输出结果</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'''用来识别未知图片中的人脸是谁。首先打开一个终端,然后进入'''face_recognition/examples'''目录,再执行下面的命令,等待一端时间后就能看到测试结果</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'''用来识别USB摄像头中的人脸,测试步骤如下所示:</p>
<ol style="list-style-type: lower-alpha;">
<li><p>首先请将USB摄像头插入开发板的USB接口中,然后通过'''v4l2-ctl'''('''<span style="color:#FF0000">注意v4l2中的l是小写字母l,不是数字1</span>''')命令查看下USB摄像头的设备节点的序号</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>然后在桌面中打开一个终端,进入'''face_recognition/examples'''目录后,首先修改下'''facerec_from_webcam_faster.py'''中使用的摄像头的设备序号。比如上面通过'''v4l2-ctl > --list-devices'''命令查看到USB摄像头为'''/dev/video1''',那就修改'''cv2.VideoCapture(0)'''中的'''0'''为'''<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>然后执行下面的命令运行'''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>等待一段时间会弹出摄像头的显示画面</p>
<p>[[File:media/image204.png|314x245px]]</p></li>
<li><p>'''web_service_example.py'''是一个非常简单的使用Web服务上传图片运行人脸识别的案例,后端服务器会识别这张图片是不是奥巴马,并把识别结果以json键值对输出,测试步骤如下所示:</p>
<ol style="list-style-type: lower-alpha;">
<li><p>在桌面中打开一个终端,然后进入'''face_recognition/examples'''目录,再执行下面的命令('''<span style="color:#FF0000">如果是使用脚本自动安装的face_recognition,那么就不需要安装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>* Restarting with stat</p>
<p>* Debugger is active!</p>
<p>* Debugger PIN: 500-161-390</p>|}</li>
<li><p>然后另外打开一个终端,再运行下面的命令就可以返回图片识别的结果(注意,下面的命令执行路径为'''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>我们也可以将'''face_recognition/examples/obama2.jpg'''这张图片拷贝到其他的Linux电脑中,当然也可以自己准备一张名为'''obama2.jpg'''的图片,然后在Linux电脑中可以使用下面的命令远程通过开发板运行的服务来识别人脸('''注意命令中的IP地址需要替换为开发板的IP地址,file后的文件名需要替换为想要测试的图片的名字''')</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>使用浏览器测试的方法如下所示:</p>
<ol style="list-style-type: lower-alpha;">
<p>[[File:media/image206.png|575x150px]]</p></li>
<li><p>然后将obama2.jpg复制到桌面</p>
{| class="wikitable" style="width:800px;" |-| <p>orangepi@orangepi:~/face_recognition/examples$ '''cp obama2.jpg /home/orangepi/Desktop/'''</p>|}</li>
<li><p>然后在浏览器中选择刚才复制的图片</p>
<p>[[File:media/image207.png|575x217px]]</p></li>
<ol style="list-style-type: lower-alpha;">
<li><p>face_detection命令行工具可以在单张图片或一个图片文件夹中定位人脸位置(输出像素点坐标)。使用'''face_detection > --help'''可以查看下face_detection命令的帮助信息</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>检测单张图片的示例如下所示:</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>使用多核并行检测多张图片的示例如下所示:</p>
<ol style="list-style-type: lower-alpha;">
<li><p>然后将jpg图片都拷贝到test文件夹中</p></li>
<li><p>然后使用所有的cpu并行运行'''face_detection'''来检查test文件夹中的图片,其中'''--cpus > -1'''表示使用所有的cpu</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>
<ol style="list-style-type: lower-alpha;">
<li><p>'''face_recognition'''命令行工具可以在单张图片或者一个图片文件夹中认出是谁的脸。使用'''face_recognition > --help'''可以查看下face_recognition命令的帮助信息</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>首先新建一个已知名字的人脸图片文件夹'''known_people''',然后复制两张图片到'''known_people'''中,然后将'''obama2.jpg'''复制为'''unkown.jpg''',也就是我们要识别的图片</p>
<p>orangepi@orangepi:~$ '''cd face_recognition/examples'''</p>