[python][mediapipe]摄像头人脸检测
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                [python][mediapipe]摄像头人脸检测
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                
                            
                            
                            import cv2
import mediapipe as mp# 導入BlazeFace模型
mp_face_detection = mp.solutions.face_detection
model = mp_face_detection.FaceDetection(min_detection_confidence=0.5,  # 置信度閾值,過濾掉小于置信度的預測框model_selection=1,  # 選擇模型,0 適用于人臉離攝像頭比較近(2米內),1 適用于比較遠(5米以內)
)
# 導入可視化函數以及可視化樣式
mp_drawing=mp.solutions.drawing_utils
# 關鍵點樣式
keypoint_style=mp_drawing.DrawingSpec(thickness=5,circle_radius=3,color=(0,255,0))
# 人臉預測框樣式
bbox_style=mp_drawing.DrawingSpec(thickness=5,circle_radius=3,color=(255,0,0))
cap = cv2.VideoCapture(0)# 獲取視頻幀速率 FPS
frame_fps = int(cap.get(cv2.CAP_PROP_FPS))
# 獲取視頻幀寬度和高度
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print("video fps={},width={},height={}".format(frame_fps, frame_width, frame_height))
while True:ret, frame = cap.read()if not ret:break# BGR轉RGBimg_RGB = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)# 將RGB輸入模型預測結果results = model.process(img_RGB)# 可視化人臉框和人臉關鍵點for detection in results.detections:mp_drawing.draw_detection(frame,detection,keypoint_drawing_spec=keypoint_style,bbox_drawing_spec=bbox_style)cv2.imshow('frame', frame)if cv2.waitKey(1) & 0xFF == ord('q'):break
cap.release()
cv2.destroyAllWindows()
                            
                        
                        
                        總結
以上是生活随笔為你收集整理的[python][mediapipe]摄像头人脸检测的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 中软国际面试-c开发
 - 下一篇: Java Scanner类的详细介绍(J