Python人臉識(shí)別初探
本文實(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.效果對比
4.參考資料
python使用opencv進(jìn)行人臉識(shí)別
python利用OpenCV2實(shí)現(xiàn)人臉檢測
以上就是本文的全部內(nèi)容,希望對大家的學(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)文章
淺談django2.0 ForeignKey參數(shù)的變化
今天小編就為大家分享一篇淺談django2.0 ForeignKey參數(shù)的變化,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08修改python plot折線圖的坐標(biāo)軸刻度方法
今天小編就為大家分享一篇修改python plot折線圖的坐標(biāo)軸刻度方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12淺析python 內(nèi)置字符串處理函數(shù)的使用方法
這篇文章主要介紹了python 內(nèi)置字符串處理函數(shù)的使用方法,需要的朋友可以參考下2014-06-06利用Python實(shí)現(xiàn)端口掃描器的全過程
這篇文章主要給大家介紹了關(guān)于如何利用Python實(shí)現(xiàn)端口掃描器的相關(guān)資料,用來檢測目標(biāo)服務(wù)器上有哪些端口開放,本文適用于有 Python和計(jì)算機(jī)網(wǎng)絡(luò)語言基礎(chǔ)的用戶,需要的朋友可以參考下2021-08-08Windows下Python2與Python3兩個(gè)版本共存的方法詳解
這篇文章主要介紹了Windows下Python2與Python3兩個(gè)版本共存的方法,文中介紹的很詳細(xì),對大家具有一定的參考價(jià)值,有需要的朋友們下面來一起看看吧。2017-02-02