Pycharm open CV learning 9

Eddie Chen
Jun 3, 2021

重頭戲登場啦

開始要人臉辨識啦!請注意下面流程

  1. 下載需求演算法(haarcascade_frontalface_default.xml)沒有這個不會動

下載網址https://reurl.cc/lLvWdl

2.放在對的資料夾中(我是放在resources中)

3.寫程式碼:

import cv2

faceCascade = cv2.CascadeClassifier("resources/haarcascade_frontalface_default.xml")
img=cv2.imread('resources/6.PNG')
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = faceCascade.detectMultiScale( imgGray,1.1,4)

for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)

cv2.imshow("Kevin img", img)

cv2.waitKey(0)
cv2.destroyAllWindows()

--

--