OpenCV中的攝像頭人臉檢測

2021-10-19 16:22:22 字數 1484 閱讀 5067

**實現:

import cv2

import os

import numpy as np

import matplotlib.pyplot as plt

import cv2 as cv

from

pilimport image

import pytesseract as test

#攝像頭人臉檢測

def face_detect

(img)

: gray = cv2.

cvtcolor

(img, cv2.

color_bgr2gray

) # 載入分類器

faces_cascade = cv2.

cascadeclassifier

("haarcascade_frontalface_alt_tree.xml"

) eyes_cascade = cv2.

cascadeclassifier

("haarcascade_eye.xml"

) # detectmultiscale

()第三個引數數值越大,檢測錯誤率越低,但需要影象足夠清晰,若不夠清晰可能檢測失敗

faces = faces_cascade.

detectmultiscale

(gray,

1.02,2

) eyes = eyes_cascade.

detectmultiscale

(gray,

1.02,25

)for x, y, w, h in faces:

img = cv2.

rectangle

(img,

(x, y)

,(x + w, y + h),(

255,0,

0),2

)for x, y, w, h in eyes:

img = cv2.

rectangle

(img,

(x, y)

,(x + w, y + h),(

0,255,0)

,2) cv2.

namedwindow

('face'

, cv2.

window_autosize

) cv2.

imshow

('face'

, img)

cv2.

waitkey(10

)capture = cv2.

videocapture(0

)while true:

ret,frame = capture.

read()

frame = cv2.

flip

(frame,1)

face_detect

(frame)

python opencv3 攝像頭人臉檢測

git 1 coding utf823 import cv2456 defdetect 7 建立人臉檢測的物件 8 face cascade cv2.cascadeclassifier data haarcascade frontalface default.xml 9 建立眼睛檢測的物件 10 e...

從攝像頭中檢測人臉

coding cp936 import cv2.cv as cv cv.namedwindow w1 cv.cv window autosize cv.namedwindow w2 cv.cv window autosize cv.movewindow w1 10,10 cv.movewindow ...

借助攝像頭在Python中實現人臉檢測

1 使用opencv中自帶的訓練器和檢測器。如果你想自己訓練乙個分類器來檢測汽車,飛機等的話,可以使用opencv來構建。2 opencv中已經包含了很多已經訓練好的分類器,其中包括 面部,眼睛,微笑等。這些xml檔案儲存在 opencv data haarcascades 檔案中。下面我將使用op...