python學習--第三天 粗略介紹人臉識別
阿新 • • 發佈:2018-06-09
窗體 比對 tro all style 介紹 sca ase 機會
首先安裝opencv
在安裝opencv過程中遇到一些錯誤(百度解決)
直接貼代碼吧,講師略講了一下,體會不深,以後有機會深入學習,再詳細介紹解釋吧
人臉識別訓練集應該可以網上下載吧,都是開源的
import cv2 cap=cv2.VideoCapture(0) #打開筆記本攝像頭 #創建窗體 cv2.namedWindow(‘mywindow‘) #自動生成變量 mywindow #引入人臉識別訓練集 face_xml=cv2.CascadeClassifier(‘haarcascade_frontalface_alt.xml‘) while(1): #讀取攝像頭數據 ret,frame=cap.read()#將提取的圖片幀放入窗體 (‘窗口名’,圖片幀) # cv2.imshow(‘mywindow‘,frame) #監測比對是否是人臉 result=face_xml.detectMultiScale(frame) print(result) #判斷是否是人臉,是人臉在人臉部分加上邊框 if result!=(): cv2.rectangle(frame,(result[0][0],result[0][1]),(result[0][0]+result[0][2],result[0][1]+result[0][3]),(255,255,0),10) cv2.imshow(‘mywindow‘,frame) #按下q鍵關閉窗口 if(cv2.waitKey(1) & 0xFF==ord(‘q‘)): break #釋放 cv2.release() cv2.destroyAllWindows()
python學習--第三天 粗略介紹人臉識別