国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python人臉識別初探

2020-02-16 11:14:15
字體:
來源:轉載
供稿:網友

本文實例為大家分享了Python人臉識別的具體代碼,供大家參考,具體內容如下

1.利用opencv庫

sudo apt-get install libopencv-*sudo apt-get install python-opencvsudo apt-get install python-numpy

2 .Python實現

import osimport osfrom PIL import Image,ImageDrawimport cvdef detect_object(image):  grayscale = cv.CreateImage((image.width,image.height),8,1)#創建空的灰度值圖片  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=[]#標記位置  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 resultdef 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" % infileif __name__ == "__main__":   process("test3.jpg")

3.效果對比

4.參考資料

python使用opencv進行人臉識別

Python+OpenCV人臉檢測原理及示例詳解

python利用OpenCV2實現人臉檢測

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 婺源县| 巢湖市| 镇雄县| 昭苏县| 科技| 法库县| 芦溪县| 台安县| 乐安县| 孝义市| 饶平县| 襄垣县| 湖口县| 枞阳县| 黄骅市| 应用必备| 新安县| 定安县| 金寨县| 六盘水市| 陆川县| 墨玉县| 蕉岭县| 五台县| 华宁县| 图片| 南昌县| 商洛市| 闽清县| 阳曲县| 蚌埠市| 兰考县| 增城市| 铜川市| 新绛县| 绥宁县| 抚宁县| 凭祥市| 扎囊县| 子洲县| 新和县|