mirror of
https://github.com/Yshelgi/face_web.git
synced 2026-05-25 16:00:28 +00:00
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
import cv2
|
|
import numpy as np
|
|
import gradio as gr
|
|
from infer import Face_inference
|
|
|
|
|
|
# 当设置置信度阈值较大时,人脸检测返回值为空,此时直接返回原图
|
|
def inference(image,thresh,model_type):
|
|
global name
|
|
if image is None:
|
|
yield image
|
|
if model_type == "人脸识别":
|
|
if m_model.face_detect(image,thresh,is_show=True) is None:
|
|
yield image
|
|
else:
|
|
name,prob,res_frame = m_model.face_detect(image,thresh,is_show=True)
|
|
yield res_frame
|
|
else:
|
|
if m_model.live_detect(image,name,thresh,is_show=True) is None:
|
|
yield image
|
|
else:
|
|
label,prob,res_frame = m_model.live_detect(image,name,thresh,is_show=True)
|
|
yield res_frame
|
|
|
|
|
|
model_name = gr.Radio(["人脸识别","活体检测"],value="人脸识别",label="Model",info="选择需要的模型")
|
|
threshold = gr.Slider(0.001,1,value=0.1,label="threshold",info="设置置信度阈值")
|
|
inputs_webcam = gr.Image(sources=["webcam"],streaming=True)
|
|
outputs_image = gr.Image(type="numpy",label="结果图片")
|
|
|
|
if __name__ == "__main__":
|
|
m_model = Face_inference()
|
|
name = ""
|
|
demo = gr.Interface(inference,inputs=[inputs_webcam,threshold,model_name],outputs=outputs_image,live=True,title="检测")
|
|
demo.queue().launch(max_threads=8)
|