一、開發平台及語言等
操作系統:Ubuntu18.04
Ros版本:ros melodic
編程語言:python
依賴庫:opencv-python
二、face_recognition 環境搭建
1、face_recogition github開源項目:https://github.com/ageitgey/face_recognition
2、face_recognition API在線文檔:https://face-recognition.readthedocs.io/en/latest/readme.html
3、配置face_recognition環境:參考博客:https://blog.csdn.net/view994/article/details/84316318pip install dlib pip install face_recognition
在實際搭建的時候發現dlib依賴包需要下載下來編譯才能使用,因此我的配置步驟是:
(1) 下載dlibgit clone https://github.com/davisking/dlib.git
(2) 編譯dlib
參考博客:https://www.cnblogs.com/whenyd/p/7721989.htmlcd dlib mkdir build; cd build; cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1; cmake --build .
(3)安裝face_recognition
pip install face_recognition
整個過程很漫長,網速一直在10k/s左右,花了大概四個小時。最終出現以下打印表示安裝成功
Successfully installed Click-7.0 face-recognition-1.2.3 face-recognition-models-0.3.0
三、項目簡介
1. 工作空間結構:

2. 各節點相互關系:
節點名 | Kinect_2 | main_node | turty_face_detector | turty_face_recognizer |
---|---|---|---|---|
節點描述 | 模擬kinect采集圖像 | 模擬主節點 | 人臉檢測 | 人臉識別 |
py文件 | kinect_img_publisher.py | main_loop.py | turty_face_detection.py | turty_face_recognition.py |
ros運行指令 | rosrun face detector kinect_img_publisher.py | rosrun face_detector main_loop.py | rosrun face_detector turty_face_detection.py | rosrun face_detector turty_face_recognition.py |
消息訂閱 | 無 | Kinect_2、turty_face_detector、turty_face_recognizer | Kinect_2 | main_node |
消息發布 | 攝像頭圖像 | 已知人臉ROI圖像、待匹配的人名 | 人臉位置、編號 | 人臉位置、編號、姓名 |
消息類型 | Image | face_msgs | face_msgs | face_msgs |
3. 消息類型簡介
(1)Image類
該消息類型為sensor_msgs/Image下的包內已定義消息類型:

其中,std_msgs/Header為圖像幀頭信息,定義為:

(2)face_msgs類
該消息類型為msg/face_msgs下的自定義消息類型:

其中,my_list 子消息類型為人臉標簽(姓名)及人臉區域頂點坐標信息

4. 各節點內容
在各py文件中有較為詳細的介紹,故不做闡述,給出縮略圖:
(1)Kinect_2

(2) main_node

(3)turty_face_detector

(4)turty_face_recognizer

四. 源程序下載
1、本人github鏈接:https://github.com/Beta-y/face_detect_ws
2、各節點調用順序推薦:roscore rosrun face_detector kinect_img_publisher.py rosrun face_detector turty_face_detection.py rosrun face_detector main_loop.py rosrun face_detector turty_face_recognition.py