Realtime Face Detection Application

Hi, I made a real time face detection application based on streamlit and opencv.
here is the code:

import cv2
import streamlit as st
from random import randrange
st.set_page_config(layout="centered", page_title="实时人脸识别")
train_face_data = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
webcam = cv2.VideoCapture(0)
temp = st.empty()
count = st.empty()
while True:
    successful_frame_read, frame = webcam.read()
    gray_style_picture = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    face_coordinate = train_face_data.detectMultiScale(gray_style_picture)
    count.success("检测到"+str(len(face_coordinate))+"个人脸")
    for (x, y, w, h) in face_coordinate:
        cv2.rectangle(frame, (x,y), (x+w, y+h), (randrange(0, 255), randrange(0, 255), randrange(0, 255)), 7)
    temp.image(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB), channels="RGB", use_column_width=True)

Complete details can be visted here:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.