日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

Python基于Dlib的人臉識別系統的實現

瀏覽:29日期:2022-08-06 08:52:16

之前已經介紹過人臉識別的基礎概念,以及基于opencv的實現方式,今天,我們使用dlib來提取128維的人臉嵌入,并使用k臨近值方法來實現人臉識別。

人臉識別系統的實現流程與之前是一樣的,只是這里我們借助了dlib和face_recognition這兩個庫來實現。face_recognition是對dlib庫的包裝,使對dlib的使用更方便。所以首先要安裝這2個庫。

pip3 install dlibpip3 install face_recognition

然后,還要安裝imutils庫

pip3 install imutils

我們看一下項目的目錄結構:

.├── dataset│ ├── alan_grant [22 entries exceeds filelimit, not opening dir]│ ├── claire_dearing [53 entries exceeds filelimit, not opening dir]│ ├── ellie_sattler [31 entries exceeds filelimit, not opening dir]│ ├── ian_malcolm [41 entries exceeds filelimit, not opening dir]│ ├── john_hammond [36 entries exceeds filelimit, not opening dir]│ └── owen_grady [35 entries exceeds filelimit, not opening dir]├── examples│ ├── example_01.png│ ├── example_02.png│ └── example_03.png├── output│ ├── lunch_scene_output.avi│ └── webcam_face_recognition_output.avi├── videos│ └── lunch_scene.mp4├── encode_faces.py├── encodings.pickle├── recognize_faces_image.py├── recognize_faces_video_file.py├── recognize_faces_video.py└── search_bing_api.py 10 directories, 12 files

首先,提取128維的人臉嵌入:

命令如下:

python3 encode_faces.py --dataset dataset --encodings encodings.pickle -d hog

記住:如果你的電腦內存不夠大,請使用hog模型進行人臉檢測,如果內存夠大,可以使用cnn神經網絡進行人臉檢測。

看代碼:

# USAGE# python encode_faces.py --dataset dataset --encodings encodings.pickle # import the necessary packagesfrom imutils import pathsimport face_recognitionimport argparseimport pickleimport cv2import os # construct the argument parser and parse the argumentsap = argparse.ArgumentParser()ap.add_argument('-i', '--dataset', required=True,help='path to input directory of faces + images')ap.add_argument('-e', '--encodings', required=True,help='path to serialized db of facial encodings')ap.add_argument('-d', '--detection-method', type=str, default='hog',help='face detection model to use: either `hog` or `cnn`')args = vars(ap.parse_args()) # grab the paths to the input images in our datasetprint('[INFO] quantifying faces...')imagePaths = list(paths.list_images(args['dataset'])) # initialize the list of known encodings and known namesknownEncodings = []knownNames = [] # loop over the image pathsfor (i, imagePath) in enumerate(imagePaths):# extract the person name from the image pathprint('[INFO] processing image {}/{}'.format(i + 1,len(imagePaths)))name = imagePath.split(os.path.sep)[-2] # load the input image and convert it from RGB (OpenCV ordering)# to dlib ordering (RGB)image = cv2.imread(imagePath)rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # detect the (x, y)-coordinates of the bounding boxes# corresponding to each face in the input imageboxes = face_recognition.face_locations(rgb,model=args['detection_method']) # compute the facial embedding for the faceencodings = face_recognition.face_encodings(rgb, boxes) # loop over the encodingsfor encoding in encodings:# add each encoding + name to our set of known names and# encodingsknownEncodings.append(encoding)knownNames.append(name) # dump the facial encodings + names to diskprint('[INFO] serializing encodings...')data = {'encodings': knownEncodings, 'names': knownNames}f = open(args['encodings'], 'wb')f.write(pickle.dumps(data))f.close()

輸出結果是每張圖片輸出一個人臉的128維的向量和對于的名字,并序列化到硬盤,供后續人臉識別使用。

識別圖像中的人臉:

這里使用KNN方法實現最終的人臉識別,而不是使用SVM進行訓練。

命令如下:

python3 recognize_faces_image.py --encodings encodings.pickle --image examples/example_01.png

看代碼:

# USAGE# python recognize_faces_image.py --encodings encodings.pickle --image examples/example_01.png # import the necessary packagesimport face_recognitionimport argparseimport pickleimport cv2 # construct the argument parser and parse the argumentsap = argparse.ArgumentParser()ap.add_argument('-e', '--encodings', required=True,help='path to serialized db of facial encodings')ap.add_argument('-i', '--image', required=True,help='path to input image')ap.add_argument('-d', '--detection-method', type=str, default='cnn',help='face detection model to use: either `hog` or `cnn`')args = vars(ap.parse_args()) # load the known faces and embeddingsprint('[INFO] loading encodings...')data = pickle.loads(open(args['encodings'], 'rb').read()) # load the input image and convert it from BGR to RGBimage = cv2.imread(args['image'])rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # detect the (x, y)-coordinates of the bounding boxes corresponding# to each face in the input image, then compute the facial embeddings# for each faceprint('[INFO] recognizing faces...')boxes = face_recognition.face_locations(rgb,model=args['detection_method'])encodings = face_recognition.face_encodings(rgb, boxes) # initialize the list of names for each face detectednames = [] # loop over the facial embeddingsfor encoding in encodings:# attempt to match each face in the input image to our known# encodingsmatches = face_recognition.compare_faces(data['encodings'],encoding)name = 'Unknown' # check to see if we have found a matchif True in matches:# find the indexes of all matched faces then initialize a# dictionary to count the total number of times each face# was matchedmatchedIdxs = [i for (i, b) in enumerate(matches) if b]counts = {} # loop over the matched indexes and maintain a count for# each recognized face facefor i in matchedIdxs:name = data['names'][i]counts[name] = counts.get(name, 0) + 1 # determine the recognized face with the largest number of# votes (note: in the event of an unlikely tie Python will# select first entry in the dictionary)name = max(counts, key=counts.get)# update the list of namesnames.append(name) # loop over the recognized facesfor ((top, right, bottom, left), name) in zip(boxes, names):# draw the predicted face name on the imagecv2.rectangle(image, (left, top), (right, bottom), (0, 255, 0), 2)y = top - 15 if top - 15 > 15 else top + 15cv2.putText(image, name, (left, y), cv2.FONT_HERSHEY_SIMPLEX,0.75, (0, 255, 0), 2) # show the output imagecv2.imshow('Image', image)cv2.waitKey(0)

實際效果如下:

Python基于Dlib的人臉識別系統的實現

如果要詳細了解細節,請參考:https://www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-learning/

到此這篇關于Python基于Dlib的人臉識別系統的實現的文章就介紹到這了,更多相關Python Dlib人臉識別內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
麻豆91精品视频| 成人午夜毛片| 日韩免费一区| а√天堂8资源中文在线| 国内精品麻豆美女在线播放视频| 国产精品一级在线观看| 91精品国产自产在线丝袜啪| 日韩精品亚洲专区| 日韩高清国产一区在线| 亚洲精品伊人| 日韩高清在线观看一区二区| 免费观看在线色综合| 中文字幕一区二区精品区| 亚洲一区久久| 日韩网站中文字幕| 日本午夜精品一区二区三区电影| 97久久超碰| 日韩精品a在线观看91| 亚洲18在线| 久久av影视| www.九色在线| 高清在线一区| 97精品国产福利一区二区三区| 欧美国产另类| 国产欧美自拍| 国产精品免费大片| 久久这里只有精品一区二区| 亚洲欧洲高清| 亚洲播播91| 午夜精品免费| 精品欧美激情在线观看| 91精品在线观看国产| 国产尤物精品| 精品一区三区| 五月综合激情| 99国内精品| 亚洲欧美网站| 美女网站久久| 日韩精品一区二区三区中文| 亚洲综合专区| 亚洲精品动态| 日韩av影院| 欧美一区自拍| 国产精品美女午夜爽爽| 国产精品九九| 亚洲精品国产精品粉嫩| 青青草伊人久久| 国产精品xvideos88| 久久精品亚洲一区二区| 精品国产91| 亚洲精品**中文毛片| 亚洲伦乱视频| 中文字幕一区二区三区四区久久 | 久久久久久一区二区| 精品久久久久久久| 亚洲在线免费| 日韩精品亚洲aⅴ在线影院| 日韩精品导航| 亚洲欧美在线综合| 美女福利一区二区三区| 久久99精品久久久野外观看| 久久国产视频网| 亚洲尤物av| 国产精品久久| 日韩免费高清| 亚洲免费成人| 在线天堂资源www在线污| 欧洲av不卡| 欧美日韩中文一区二区| 欧美一区自拍| 精品国产欧美日韩| 日本欧美不卡| 亚洲精品在线国产| 国产精品久久久久毛片大屁完整版| 卡一卡二国产精品| 精品三级久久| 亚洲一级大片| 久久久久久美女精品| 视频一区视频二区中文| 91国内精品| 成人片免费看| 亚洲va中文在线播放免费| 亚洲美洲欧洲综合国产一区| 欧美日韩亚洲三区| 香蕉视频成人在线观看| 国产伦精品一区二区三区视频| av中文字幕在线观看第一页| 午夜久久黄色| 麻豆视频一区| 91精品观看| 美女久久精品| 亚洲精品系列| 亚洲一本视频| 国产精品免费不| 亚洲一区二区三区高清| 欧美日韩视频免费观看| 91成人小视频| 中文字幕高清在线播放| 一区二区国产在线| 久久uomeier| 日本欧美一区二区| 亚洲在线一区| 精品国模一区二区三区| 日韩三级一区| 91日韩在线| 日本一区免费网站| 精品在线播放| 成人精品中文字幕| 国产精品a级| 日韩中文字幕1| 久久久久99| 快she精品国产999| 91精品国产自产在线丝袜啪| 婷婷综合网站| 麻豆91在线播放| 婷婷久久免费视频| 国产精品丝袜xxxxxxx| 国产v综合v| 国产一区二区三区视频在线| 国产精品一区二区三区四区在线观看| 羞羞答答国产精品www一本| 成人在线黄色| 久久这里只有| 在线视频亚洲| 老牛影视一区二区三区| 亚洲一区二区免费看| 激情欧美丁香| 亚洲永久字幕| 欧美色图国产精品| 免费av一区| 国产日韩免费| 麻豆91在线播放| 三级亚洲高清视频| 人人香蕉久久| 色网在线免费观看| 欧美aa在线观看| 红杏一区二区三区| 久久av超碰| 日韩高清电影免费| 在线观看免费一区二区| 高清日韩中文字幕| 91精品二区| 日韩三级一区| 精品久久电影| 久热综合在线亚洲精品| 国产精品不卡| 日韩av资源网| 电影91久久久| 欧美女激情福利| 91嫩草精品| 国产精品激情| 在线观看亚洲精品福利片| 日本不卡免费高清视频在线| 五月天综合网站| 欧美天堂在线| 久久亚洲一区| 成人日韩在线| 国产精品久久久久蜜臀| 国产欧美自拍一区| 久久伊人亚洲| 一区二区三区国产在线| 免费av一区| 99久久精品国产亚洲精品| 精品久久久久中文字幕小说| 亚洲精品激情| 人人精品人人爱| 久久香蕉精品| 亚洲专区欧美专区| 99国产精品自拍| 婷婷亚洲精品| 久久不见久久见免费视频7| 三级久久三级久久久| 日韩三级一区| 一区二区三区国产在线| 国产精品分类| 欧美精品自拍| 成人亚洲一区| 亚洲欧美在线综合| 中文另类视频| 国产一区二区三区久久| 亚洲欧美视频一区二区三区| 久久成人福利| 激情五月色综合国产精品| 国产精品网站在线看| 美女毛片一区二区三区四区| 欧美专区18| 亚洲天堂免费电影| 精品伊人久久| 久久超碰99| 国内自拍视频一区二区三区| 久久这里只有精品一区二区| 亚洲伊人av| 国产在线成人| 中文字幕av亚洲精品一部二部| 蜜芽一区二区三区| 日本精品一区二区三区在线观看视频| 国产精品久久亚洲不卡| 久久gogo国模啪啪裸体| 亚洲精品成人图区| 日产欧产美韩系列久久99|