Python人臉識(shí)別初探
更新時(shí)間:2017年12月21日 10:16:26 作者:_Rick_
這篇文章主要為大家詳細(xì)介紹了Python人臉識(shí)別初探的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了Python人臉識(shí)別的具體代碼,供大家參考,具體內(nèi)容如下
1.利用opencv庫
sudo apt-get install libopencv-* sudo apt-get install python-opencv sudo apt-get install python-numpy
2 .Python實(shí)現(xiàn)
import os
import os
from PIL import Image,ImageDraw
import cv
def detect_object(image):
grayscale = cv.CreateImage((image.width,image.height),8,1)#創(chuàng)建空的灰度值圖片
cv.CvtColor(image,grayscale,cv.CV_BGR2GRAY)
cascade=cv.Load("/usr/share/opencv/haarcascades/haarcascade_frontalface_alt_tree.xml")#記載特征值庫,此目錄下還有好多庫可以選用
rect=cv.HaarDetectObjects(grayscale,cascade,cv.CreateMemStorage(),1.1,2,cv.CV_HAAR_DO_CANNY_PRUNING,(20,20))
result=[]#標(biāo)記位置
for r in rect:
result.append((r[0][0],r[0][1],r[0][0]+r[0][2],r[0][1]+r[0][3]))
return result
def process(infile):
image = cv.LoadImage(infile)
if image:
faces = detect_object(image)
im = Image.open(infile)
path = os.path.abspath(infile)
save_path = os.path.splitext(path)[0]+"_face"
try:
os.mkdir(save_path)
except:
pass
if faces:
draw = ImageDraw.Draw(im)
count=0
for f in faces:
count+=1
draw.rectangle(f,outline=(255,0,0))
a=im.crop(f)
file_name=os.path.join(save_path,str(count)+".jpg")
a.save(file_name)
drow_save_path = os.path.join(save_path,"out.jpg")
im.save(drow_save_path,"JPEG",quality=80)
else:
print "Error: cannot detect faces on %s" % infile
if __name__ == "__main__":
process("test3.jpg")
3.效果對(duì)比

4.參考資料
python使用opencv進(jìn)行人臉識(shí)別
python利用OpenCV2實(shí)現(xiàn)人臉檢測
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Python opencv實(shí)現(xiàn)人眼/人臉識(shí)別以及實(shí)時(shí)打碼處理
- python利用Opencv實(shí)現(xiàn)人臉識(shí)別功能
- python3人臉識(shí)別的兩種方法
- python dlib人臉識(shí)別代碼實(shí)例
- Python基于OpenCV庫Adaboost實(shí)現(xiàn)人臉識(shí)別功能詳解
- python調(diào)用OpenCV實(shí)現(xiàn)人臉識(shí)別功能
- python opencv3實(shí)現(xiàn)人臉識(shí)別(windows)
- 基于python3 OpenCV3實(shí)現(xiàn)靜態(tài)圖片人臉識(shí)別
- 基于python神經(jīng)卷積網(wǎng)絡(luò)的人臉識(shí)別
- Python3利用Dlib19.7實(shí)現(xiàn)攝像頭人臉識(shí)別的方法
- python3+dlib實(shí)現(xiàn)人臉識(shí)別和情緒分析
- python實(shí)現(xiàn)人臉識(shí)別經(jīng)典算法(一) 特征臉法
- Python3結(jié)合Dlib實(shí)現(xiàn)人臉識(shí)別和剪切
- python+opencv實(shí)現(xiàn)的簡單人臉識(shí)別代碼示例
- python實(shí)現(xiàn)人臉識(shí)別代碼
- 詳解如何用OpenCV + Python 實(shí)現(xiàn)人臉識(shí)別
- python使用opencv進(jìn)行人臉識(shí)別
- Python人臉識(shí)別第三方庫face_recognition接口說明文檔
相關(guān)文章
Python爬蟲使用bs4方法實(shí)現(xiàn)數(shù)據(jù)解析
這篇文章主要介紹了Python爬蟲使用bs4方法實(shí)現(xiàn)數(shù)據(jù)解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08
Django利用Channels+websocket開發(fā)聊天室完整案例
Channels是Django團(tuán)隊(duì)研發(fā)的一個(gè)給Django提供websocket支持的框架,使用它我們可以輕松開發(fā)需要長鏈接的實(shí)時(shí)通訊應(yīng)用,下面這篇文章主要給大家介紹了關(guān)于Django利用Channels+websocket開發(fā)聊天室的相關(guān)資料,需要的朋友可以參考下2023-06-06

