使用Python的OpenCV進行圖片人臉辨識

文章推薦指數: 80 %
投票人數:10人

使用Python的OpenCV進行圖片人臉辨識. GitHub Gist: instantly share code, notes, and snippets. Skiptocontent Allgists BacktoGitHub Signin Signup Sign in Sign up {{message}} Instantlysharecode,notes,andsnippets. e96031413/opencv-image.py LastactiveOct21,2019 Star 0 Fork 0 Star Code Revisions 2 Embed Whatwouldyouliketodo? Embed Embedthisgistinyourwebsite. Share Copysharablelinkforthisgist. Clonevia HTTPS ClonewithGitorcheckoutwithSVNusingtherepository’swebaddress. LearnmoreaboutcloneURLs DownloadZIP 使用Python的OpenCV進行圖片人臉辨識 Raw opencv-image.py ThisfilecontainsbidirectionalUnicodetextthatmaybeinterpretedorcompileddifferentlythanwhatappearsbelow.Toreview,openthefileinaneditorthatrevealshiddenUnicodecharacters. LearnmoreaboutbidirectionalUnicodecharacters Showhiddencharacters importcv2 #載入分類器 face_cascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml') #讀取圖片 img=cv2.imread('a.jpg') #轉成灰階圖片 gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #偵測臉部 faces=face_cascade.detectMultiScale( gray, scaleFactor=1.08, minNeighbors=5, minSize=(32,32)) #繪製人臉部份的方框 for(x,y,w,h)infaces: cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2) #(0,255,0)欄位可以變更方框顏色(Blue,Green,Red) #計算找到幾張臉 print("找到了{0}張臉.".format(len(faces))) #顯示成果 cv2.namedWindow('img',cv2.WINDOW_NORMAL)#正常視窗大小 cv2.imshow('img',img)#秀出圖片 cv2.imwrite("result.jpg",img)#保存圖片 cv2.waitKey(0)#等待按下任一按鍵 cv2.destroyAllWindows()#關閉視窗 Signupforfree tojointhisconversationonGitHub. Alreadyhaveanaccount? Signintocomment Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.



請為這篇文章評分?