树莓派人脸识别python_树莓派 python OpenCV人脸识别

使用Python和OpenCV库,在树莓派上实现人脸识别。通过读取摄像头视频流,利用预先训练的Haar级联分类器检测人脸,并在检测到人脸时在框中显示。代码包括视频读取、帧处理、人脸检测和结果展示。
摘要由CSDN通过智能技术生成

# import the necessary packages

import argparse

import datetime

import imutils

import time

import cv2

# construct the argument parser and parse the arguments

ap = argparse.ArgumentParser()

ap.add_argument("-v", "--video", help="path to the video file")

ap.add_argument("-a", "--min-area", type=int, default=500, help="minimum area size")

args = vars(ap.parse_args())

# if the video argument is None, then we are reading from webcam

if args.get("video", None) is None:

camera = cv2.VideoCapture(0)

time.sleep(0.25)

# otherwise, we are reading from a video file

else:

camera = cv2.VideoCapture(args["video"])

cascade = cv2.CascadeClassifier("/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml")

# loop over the frames of the video

while True:

(grabbed, frame) = camera.read()

if not grabbed:

break

frame = imutils.resize(frame, width=200)

rects = cascade.detectMultiScale(frame)

for (x, y, w, h) in rects:

cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)

cv2.putText(frame, datetime.datetime.now().strftime("%A %d %B %Y %I:%M:%S%p"),

(10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1)

# show the frame and record if the user presses a key

cv2.imshow("Security Feed", frame)

key = cv2.waitKey(1) & 0xFF

# cleanup the camera and close any open windows

camera.release()

cv2.destroyAllWindows()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值