日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CV:基于keras利用cv2自带两步检测法对《跑男第六季第五期》之如花片段(或调用摄像头)进行实时性别脸部表情检测

發(fā)布時間:2025/3/21 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CV:基于keras利用cv2自带两步检测法对《跑男第六季第五期》之如花片段(或调用摄像头)进行实时性别脸部表情检测 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

CV:基于keras利用cv2自帶兩步檢測法對《跑男第六季第五期》之如花片段(或調(diào)用攝像頭)進行實時性別&臉部表情檢測

?

?

目錄

輸出結(jié)果

設(shè)計思路

核心代碼


?

?

?

?

輸出結(jié)果

?

?

設(shè)計思路

?

?

核心代碼

from statistics import modeimport cv2 from keras.models import load_model import numpy as npdetection_model_path = '../trained_models/detection_models/haarcascade_frontalface_default.xml'emotion_model_path = '../trained_models/emotion_models/fer2013_mini_XCEPTION.102-0.66.hdf5' gender_model_path = '../trained_models/gender_models/simple_CNN.81-0.96.hdf5' emotion_labels = get_labels('fer2013') gender_labels = get_labels('imdb') font = cv2.FONT_HERSHEY_SIMPLEXframe_window = 10 gender_offsets = (30, 60) emotion_offsets = (20, 40)face_detection = load_detection_model(detection_model_path) emotion_classifier = load_model(emotion_model_path, compile=False) gender_classifier = load_model(gender_model_path, compile=False)emotion_target_size = emotion_classifier.input_shape[1:3] gender_target_size = gender_classifier.input_shape[1:3]gender_window = [] emotion_window = []cv2.namedWindow('window_frame_by_Jason_Niu') # video_capture = cv2.VideoCapture(0) video_capture = cv2.VideoCapture("F:\File_Python\Python_example\YOLOv3_use_TF\RunMan5.mp4") while True:bgr_image = video_capture.read()[1]gray_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2GRAY) #分別將讀取的圖像進行灰化、RGB化處理rgb_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB)faces = detect_faces(face_detection, gray_image) for face_coordinates in faces:x1, x2, y1, y2 = apply_offsets(face_coordinates, gender_offsets) rgb_face = rgb_image[y1:y2, x1:x2] x1, x2, y1, y2 = apply_offsets(face_coordinates, emotion_offsets)gray_face = gray_image[y1:y2, x1:x2]try:rgb_face = cv2.resize(rgb_face, (gender_target_size))gray_face = cv2.resize(gray_face, (emotion_target_size))except:continuegray_face = preprocess_input(gray_face, False) gray_face = np.expand_dims(gray_face, 0) gray_face = np.expand_dims(gray_face, -1)emotion_label_arg = np.argmax(emotion_classifier.predict(gray_face)) emotion_text = emotion_labels[emotion_label_arg] emotion_window.append(emotion_text) rgb_face = np.expand_dims(rgb_face, 0)rgb_face = preprocess_input(rgb_face, False)gender_prediction = gender_classifier.predict(rgb_face) gender_label_arg = np.argmax(gender_prediction)gender_text = gender_labels[gender_label_arg]gender_window.append(gender_text)if len(gender_window) > frame_window: emotion_window.pop(0) gender_window.pop(0)try:emotion_mode = mode(emotion_window)gender_mode = mode(gender_window)except:continueif gender_text == gender_labels[0]:color = (0, 0, 255)else:color = (255, 0, 0)draw_bounding_box(face_coordinates, rgb_image, color) draw_text(face_coordinates, rgb_image, gender_mode, color, 0, -20, 1, 4)draw_text(face_coordinates, rgb_image, emotion_mode,color, 0, -45, 1, 4)bgr_image = cv2.cvtColor(rgb_image, cv2.COLOR_RGB2BGR) cv2.namedWindow("window_frame_by_Jason_Niu",0);cv2.resizeWindow("window_frame_by_Jason_Niu", 640, 380);cv2.imshow('window_frame_by_Jason_Niu', bgr_image)if cv2.waitKey(1) & 0xFF == ord('q'):break

總結(jié)

以上是生活随笔為你收集整理的CV:基于keras利用cv2自带两步检测法对《跑男第六季第五期》之如花片段(或调用摄像头)进行实时性别脸部表情检测的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。