日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > pytorch >内容正文

pytorch

人工智能之基于face_recognition的人脸检测与识别

發布時間:2023/12/10 pytorch 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 人工智能之基于face_recognition的人脸检测与识别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

不久乘高鐵出行,看見高鐵火車站已經實現了“刷臉進站”,而且效率很高,很感興趣,今天抽時間研究一下,其實沒那么復雜。

我基本上是基于https://github.com/ageitgey/face_recognition上的資料和源碼做一些嘗試和試驗。

首先,需要配置我們的python環境,我懸著的python27(比較穩定),具體過程不多說了。

然后,需要安裝這次的主角face_recognition庫,這個的安裝花了我不少時間,需要注意一下幾點(按照本人的環境):

  1,首先,安裝visual studio 2015,因為vs2015默認只安裝c#相關組件,所以需要安裝c++相關組件。

    ps:vs2015安裝c++相關組件的方法:在vs2015中新建c++項目,出現下面場景

    

    選擇第二項,確定后就會自動安裝。

    為什么需要安裝c++,因為安裝face_recognition時會先安裝dlib,dlib是基于c++的一個庫。

  2,安裝cmake(一個跨平臺編譯工具),然后需要將cmake的安裝路徑加入到系統環境變量path中去。

最后,就可以直接在dos中執行安裝命令了(需要切換到python目錄下的Script目錄下):pip install? face_recognition,命令會自動幫你安裝好需要的dlib庫。 

到此為止,我們完成了face_recognition安裝工作。

?

---------------------------------------------------------------分割線----------------------------------------------------------------------------------

下面給出幾個實例來逐步了解“人臉識別”:

1.一行代碼實現“人臉識別”

?

在Python目錄中新建兩個文件夾:分別表示“已知姓名的人”和“未知姓名的人”,圖片以額、人名命名,如下:

?

?接下來,我們通過“認識的人”來識別“不認識的人”:

結果表明:1.jpg不認識,3.jpg是obama,unkown.jpg中有兩個人,一個是obama,另一個不認識

結果還挺準確的!很給力!!

?

2.識別圖片中所有的人臉,并顯示出來

import Image import face_recognition image = face_recognition.load_image_file('F:/Python27/Scripts/all.jpg') face_locations = face_recognition.face_locations(image)#face_locations =face_recognition.#face_locations(image,number_of_times_to_upsample=0,model='cnn') print('i found {} face(s) in this photograph.'.format(len(face_locations))) for face_location in face_locations:top,right,bottom,left = face_locationprint('A face is located at pixel location Top:{},Left:{},Bottom:{},Right:{}'.format(top,right,bottom,left))face_image = image[top:bottom,left:right]pil_image=Image.fromarray(face_image)pil_image.show() View Code

避坑指南:import Image需要先安裝PIL庫,在pycharm中安裝的時候會報錯(因為pil沒有64位的版本),這時我們安裝Pillow-PIL就好了。

我們的all.jpg如下:

?

?執行以下,看看結果:

沒有錯,總共12個人臉都被識別出來了!!!

?

3.給照片“美顏”

face_recognition可以識別人像的下巴,眼睛,鼻子,嘴唇,眼球等區域,包含以下這些個特征:

  facial_features = [?'chin',?'left_eyebrow',?'right_eyebrow',?'nose_bridge',?'nose_tip',?'left_eye',?'right_eye',?'top_lip',?'bottom_lip' ]

? ? ? ?利用這些特征屬性,可以輕松的給人像“美顏”

from PIL import Image, ImageDraw face_recognition import face_recognitionimage = face_recognition.load_image_file("F:/Python27/Scripts/known_people/obama.jpg")#查找圖像中所有面部的所有面部特征 face_landmarks_list = face_recognition.face_landmarks(image)for face_landmarks in face_landmarks_list:pil_image = Image.fromarray(image)d = ImageDraw.Draw(pil_image, 'RGBA')#讓眉毛變成了一場噩夢d.polygon(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 128))d.polygon(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 128))d.line(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 150), width=5)d.line(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 150), width=5)#光澤的嘴唇d.polygon(face_landmarks['top_lip'], fill=(150, 0, 0, 128))d.polygon(face_landmarks['bottom_lip'], fill=(150, 0, 0, 128))d.line(face_landmarks['top_lip'], fill=(150, 0, 0, 64), width=8)d.line(face_landmarks['bottom_lip'], fill=(150, 0, 0, 64), width=8)#閃耀眼睛d.polygon(face_landmarks['left_eye'], fill=(255, 255, 255, 30))d.polygon(face_landmarks['right_eye'], fill=(255, 255, 255, 30))#涂一些眼線d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]], fill=(0, 0, 0, 110), width=6)d.line(face_landmarks['right_eye'] + [face_landmarks['right_eye'][0]], fill=(0, 0, 0, 110), width=6)pil_image.show() View Code

執行下看看結果:

有點辣眼睛!!!!

?

4.利用筆記本攝像頭識別人像

回到前面說的高鐵站的“刷臉”,其實就是基于攝像頭的“人像識別”。

這里要調用電腦的攝像頭,而且涉及一些計算機視覺系統的計算,所以我們要先安裝opencv庫,

安裝方法:

pip install --upgrade setuptools pip install numpy Matplotlib pip install opencv-python

 ps:如果報錯:EnvironmentError:?[Errno 13]?Permission denied: 在install后加上--user即可

? ? ? ? ?小技巧:可以在python命令行中用?import site; site.getsitepackages()來確定當前的python環境的site-packages目錄的位置

目的:這里我們需要用攝像頭識別自己,那么首先需要有一張自己的照片,我將我的照片命名為mike.jpg,然后使用攝像頭來識別我自己。

?看看代碼:

import face_recognition import cv2# This is a demo of running face recognition on live video from your webcam. It's a little more complicated than the # other example, but it includes some basic performance tweaks to make things run a lot faster: # 1. Process each video frame at 1/4 resolution (though still display it at full resolution) # 2. Only detect faces in every other frame of video.# PLEASE NOTE: This example requires OpenCV (the `cv2` library) to be installed only to read from your webcam. # OpenCV is *not* required to use the face_recognition library. It's only required if you want to run this # specific demo. If you have trouble installing it, try any of the other demos that don't require it instead.# Get a reference to webcam #0 (the default one) video_capture = cv2.VideoCapture(0)# Load a sample picture and learn how to recognize it. obama_image = face_recognition.load_image_file("F:/Python27/Scripts/known_people/obama.jpg") obama_face_encoding = face_recognition.face_encodings(obama_image)[0]# Load a second sample picture and learn how to recognize it. biden_image = face_recognition.load_image_file("F:/Python27/Scripts/known_people/mike.jpg") biden_face_encoding = face_recognition.face_encodings(biden_image)[0]# Create arrays of known face encodings and their names known_face_encodings = [obama_face_encoding,biden_face_encoding ] known_face_names = ["Barack Obama","mike" ]# Initialize some variables face_locations = [] face_encodings = [] face_names = [] process_this_frame = Truewhile True:# Grab a single frame of videoret, frame = video_capture.read()# Resize frame of video to 1/4 size for faster face recognition processingsmall_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)# Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)rgb_small_frame = small_frame[:, :, ::-1]# Only process every other frame of video to save timeif process_this_frame:# Find all the faces and face encodings in the current frame of videoface_locations = face_recognition.face_locations(rgb_small_frame)face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)face_names = []for face_encoding in face_encodings:# See if the face is a match for the known face(s)matches = face_recognition.compare_faces(known_face_encodings, face_encoding)name = "Unknown"# If a match was found in known_face_encodings, just use the first one.if True in matches:first_match_index = matches.index(True)name = known_face_names[first_match_index]face_names.append(name)process_this_frame = not process_this_frame# Display the resultsfor (top, right, bottom, left), name in zip(face_locations, face_names):# Scale back up face locations since the frame we detected in was scaled to 1/4 sizetop *= 4right *= 4bottom *= 4left *= 4# Draw a box around the facecv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)# Draw a label with a name below the facecv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)font = cv2.FONT_HERSHEY_DUPLEXcv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)# Display the resulting imagecv2.imshow('Video', frame)# Hit 'q' on the keyboard to quit!if cv2.waitKey(1) & 0xFF == ord('q'):break# Release handle to the webcam video_capture.release() cv2.destroyAllWindows() View Code

只想看看結果:

?

看來,我被識別成功了。看起來有點小激動呢。

?

?

?

通過上面四個小例子基本了解face_recognition的用法,這只是小試牛刀,具體在現實中的應用要復雜很多,

我們需要大量的人臉數據,會涉及到機器學習和數學算法等等,而且根據應用場景的不同也會出現很多不同的要求。

這里只是一起學習分享,期待后續關于"人工智能"的內容。

?

總結

以上是生活随笔為你收集整理的人工智能之基于face_recognition的人脸检测与识别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 三级视频久久 | 中国字幕一色哟哟 | 全部孕妇毛片 | 北条麻妃一区二区三区 | 黄色三极片 | 日韩 在线 | 欧美做爰爽爽爽爽爽爽 | 欧美一级欧美三级 | 亚洲成人一二三区 | 六月丁香综合 | 亚洲精品2区 | 在线观看欧美视频 | 国产老肥熟 | 一本久道久久 | 爱爱15p| 日本簧片在线观看 | 52av在线| 国产精品久久..4399 | 亚洲狼人社区 | 精品熟女一区二区 | 欧美七区 | 亚洲国产日韩一区 | 久久亚洲一区二区 | 色呦呦免费 | 色av一区二区 | 午夜天堂精品久久久久 | 久久久久久九九 | 欧美区一区 | 合欢视频在线观看 | 色老板精品凹凸在线视频观看 | 日韩一区二区免费视频 | 操操操操操操操操操操 | 无码人妻少妇色欲av一区二区 | 99热首页| 青青操在线观看 | 免费色片网站 | 久久黑人 | 青苹果av| 亚洲精品日日夜夜 | 依人在线视频 | 成人免费公开视频 | 性www| 初尝情欲h名器av | 女人天堂av| 桃花久久| 国产精品人人人人 | 污视频91| 亚洲人成亚洲人成在线观看 | 青青草官网 | 秋霞在线一区二区 | 严厉高冷老师动漫播放 | 少妇高清精品毛片在线视频 | 国产精品国产三级国产普通话对白 | h视频网站在线观看 | 国产精品成人一区二区网站软件 | 免费网站www在线观看 | 久久久久xxxx | 黄色av小说在线观看 | 亚洲精品国产精品乱码不卡 | 日韩在线中文字幕 | www.色播.com| 三级全黄视频 | 五月在线| 午夜激情视频在线 | 老外黄色一级片 | 日韩av专区 | 免费的黄色一级片 | 一级淫片在线观看 | 亚洲a色| a级在线播放 | 成人激情自拍 | 草草视频在线观看 | 色视频网站 | 日本一区免费 | 免费a级片视频 | 色丁香av | 久草色视频 | 亚洲偷偷 | 亚洲老妇色熟女老太 | 精品综合久久久 | 中文字字幕码一二三区 | 天天爽夜夜爽一区二区三区 | 国产日韩欧美一区 | 亚洲色图图片区 | 毛片毛片毛片毛片毛片毛片毛片毛片毛片 | 日韩精品视 | 黄色一级在线视频 | 国产精华一区二区三区 | а√在线中文网新版地址在线 | 欧美69久成人做爰视频 | 成年人天堂 | 操操操综合 | 色综合视频 | 字幕网在线观看 | 国产在线精品一区二区 | 欧美性大战久久久久xxx | jizz国产在线观看 | 扩阴视频 | 亚洲jizzjizz|