生活随笔
收集整理的這篇文章主要介紹了
人脸识别(三) 摄像头中的人脸识别+LFW数据集测试
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
實現(xiàn)功能: 載入LFW數(shù)據(jù)集的每張圖片,作為比對數(shù)據(jù)庫。采集攝像頭中的人臉進行比對,計算出與你最像的人
LFW (LFW(Labeled Faces in the Wild Home) lfw數(shù)據(jù)集是為了研究 非限制環(huán)境下的人臉識別問題而建立。LFW 數(shù)據(jù)庫主要是從互聯(lián)網(wǎng)上搜集圖像,而不是實驗室,一共含有13000 多張人臉圖像,每張圖像都被標(biāo)識出對應(yīng)的人的名字。 LFW數(shù)據(jù)集主要測試人臉識別的準(zhǔn)確率,該數(shù)據(jù)庫從中隨機選擇了6000對人臉組成了人臉辨識圖片對,其中3000對屬于同一個人2張人臉照片,3000對屬于不同的人每人1張人臉照片。測試過程LFW給出一對照片,詢問測試中的系統(tǒng)兩張照片是不是同一個人,系統(tǒng)給出“是”或“否”的答案。通過6000對人臉測試結(jié)果的系統(tǒng)答案與真實答案的比值可以得到人臉識別準(zhǔn)確率。 這個集合被廣泛應(yīng)用于評價 face verification算法的性能。
代碼實現(xiàn)
import face_recognition
import cv2
import os
import numpy
as np
def face ( path
) : known_names
= [ ] known_encodings
= [ ] cnt
= 0 cnt_error
= 0 for image_name
in os
. listdir
( path
) : for real_image
in os
. listdir
( path
+ image_name
) : cnt
= cnt
+ 1 load_image
= face_recognition
. load_image_file
( path
+ image_name
+ '/' + real_image
) if not len ( face_recognition
. face_encodings
( load_image
) ) : cnt_error
= cnt_error
+ 1 print ( cnt_error
, "pictures can't be recognized" ) else : image_face_encoding
= face_recognition
. face_encodings
( load_image
) [ 0 ] known_names
. append
( image_name
) known_encodings
. append
( image_face_encoding
) if cnt
% 10 == 0 : print ( cnt
, 'pictures loaded' ) print ( cnt
, 'pictures succesfully loaded.' ) video_capture
= cv2
. VideoCapture
( 0 ) process_this_frame
= True while True : ret
, frame
= video_capture
. read
( ) rgb_frame
= frame
[ : , : , : : - 1 ] if process_this_frame
: face_locations
= face_recognition
. face_locations
( rgb_frame
) face_encodings
= face_recognition
. face_encodings
( rgb_frame
, face_locations
) face_names
= [ ] for face_encoding
in face_encodings
: distance_list
= face_recognition
. face_distance
( known_encodings
, face_encoding
) idx
= np
. argmin
( distance_list
) name
= known_names
[ idx
] face_names
. append
( name
) process_this_frame
= not process_this_frame
for ( top
, right
, bottom
, left
) , name
in zip ( face_locations
, face_names
) : cv2
. rectangle
( frame
, ( left
, top
) , ( right
, bottom
) , ( 0 , 0 , 255 ) , 2 ) cv2
. rectangle
( frame
, ( left
, bottom
- 35 ) , ( right
, bottom
) , ( 0 , 0 , 255 ) , cv2
. FILLED
) font
= cv2
. FONT_HERSHEY_DUPLEX cv2
. putText
( frame
, name
, ( left
+ 6 , bottom
- 6 ) , font
, 1.0 , ( 255 , 255 , 255 ) , 1 ) cv2
. imshow
( 'frame' , frame
) if cv2
. waitKey
( 1 ) & 0xFF == ord ( 'q' ) : break video_capture
. release
( ) cv2
. destroyAllWindows
( ) if __name__
== '__main__' : face
( "F:/traindata/lfw/" )
結(jié)果與分析
(1) face_recognition對IFW數(shù)據(jù)集的人臉識別情況 LFW數(shù)據(jù)集包含5749個人物,每個人物有多張圖片,共有13233張圖片 從結(jié)果來看,57張人物不能識別到人臉,face_recognition對LFW數(shù)據(jù)集的人臉識別率99.57%(不是識別準(zhǔn)確率)
(2)攝像頭中的我和誰最像 識別到我和Zaini_Abdullah最像,再使用我的文章人臉識別(二)中的人臉比對程序看一下,相似度達到79%
討論 (1)最大的問題是,加載1萬多張圖片時間長達數(shù)小時,然而IFW還是一個較小的數(shù)據(jù)集
后續(xù)可考慮將人臉編碼的128維特征值存入數(shù)據(jù)庫,直接讀出人臉數(shù)據(jù),應(yīng)該會快一些
(2)科研與工業(yè)中的人臉識別不同,準(zhǔn)確率基本上難以做到100%,而目前應(yīng)用的人臉識別應(yīng)用只是起到一個篩選的作用,常常需要配合其他方式進行雙重或多重認(rèn)證 ,或者局限于某些場景中較少的人多環(huán)境(不同的光線、角度等)的識別,工業(yè)應(yīng)用更加注重快速落地
總結(jié)
以上是生活随笔 為你收集整理的人脸识别(三) 摄像头中的人脸识别+LFW数据集测试 的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔 推薦給好友。