OpenCV中的摄像头人脸检测

OpenCV中的摄像头人脸检测

代码实现:

import cv2
import os
import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv
from PIL import 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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值