91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 9.31MB
    文件類(lèi)型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2023-10-22
  • 語(yǔ)言: Python
  • 標(biāo)簽: 表情識(shí)別??

資源簡(jiǎn)介

代碼基于python3和opencv框架,可能需要安裝所需的module; 功能描述 --實(shí)現(xiàn)筆記本攝像頭獲取人臉的面部表情識(shí)別,happy,angry,neural,sad.. --實(shí)現(xiàn)指定路徑下視頻中人臉的識(shí)別.. 驗(yàn)證成功,未做改動(dòng),源自github

資源截圖

代碼片段和文件信息

import?cv2
import?numpy?as?np
from?keras.models?import?load_model
from?statistics?import?mode
from?utils.datasets?import?get_labels
from?utils.inference?import?detect_faces
from?utils.inference?import?draw_text
from?utils.inference?import?draw_bounding_box
from?utils.inference?import?apply_offsets
from?utils.inference?import?load_detection_model
from?utils.preprocessor?import?preprocess_input

USE_WEBCAM?=?True?#?If?false?loads?video?file?source

#?parameters?for?loading?data?and?images
emotion_model_path?=?‘./models/emotion_model.hdf5‘
emotion_labels?=?get_labels(‘fer2013‘)

#?hyper-parameters?for?bounding?boxes?shape
frame_window?=?10
emotion_offsets?=?(20?40)

#?loading?models
face_cascade?=?cv2.CascadeClassifier(‘./models/haarcascade_frontalface_default.xml‘)
emotion_classifier?=?load_model(emotion_model_path)

#?getting?input?model?shapes?for?inference
emotion_target_size?=?emotion_classifier.input_shape[1:3]

#?starting?lists?for?calculating?modes
emotion_window?=?[]

#?starting?video?streaming

cv2.namedWindow(‘window_frame‘)
video_capture?=?cv2.VideoCapture(0)

#?Select?video?or?webcam?feed
cap?=?None
if?(USE_WEBCAM?==?True):
????cap?=?cv2.VideoCapture(0)?#?Webcam?source
else:
????cap?=?cv2.VideoCapture(‘./demo/dinner.mp4‘)?#?Video?file?source

while?cap.isOpened():?#?True:
????ret?bgr_image?=?cap.read()

????#bgr_image?=?video_capture.read()[1]

????gray_image?=?cv2.cvtColor(bgr_image?cv2.COLOR_BGR2GRAY)
????rgb_image?=?cv2.cvtColor(bgr_image?cv2.COLOR_BGR2RGB)

????faces?=?face_cascade.detectMultiScale(gray_image?scaleFactor=1.1?minNeighbors=5
minSize=(30?30)?flags=cv2.CASCADE_SCALE_IMAGE)

????for?face_coordinates?in?faces:

????????x1?x2?y1?y2?=?apply_offsets(face_coordinates?emotion_offsets)
????????gray_face?=?gray_image[y1:y2?x1:x2]
????????try:
????????????gray_face?=?cv2.resize(gray_face?(emotion_target_size))
????????except:
????????????continue

????????gray_face?=?preprocess_input(gray_face?True)
????????gray_face?=?np.expand_dims(gray_face?0)
????????gray_face?=?np.expand_dims(gray_face?-1)
????????emotion_prediction?=?emotion_classifier.predict(gray_face)
????????emotion_probability?=?np.max(emotion_prediction)
????????emotion_label_arg?=?np.argmax(emotion_prediction)
????????emotion_text?=?emotion_labels[emotion_label_arg]
????????emotion_window.append(emotion_text)

????????if?len(emotion_window)?>?frame_window:
????????????emotion_window.pop(0)
????????try:
????????????emotion_mode?=?mode(emotion_window)
????????except:
????????????continue

????????if?emotion_text?==?‘a(chǎn)ngry‘:
????????????color?=?emotion_probability?*?np.asarray((255?0?0))
????????elif?emotion_text?==?‘sad‘:
????????????color?=?emotion_probability?*?np.asarray((0?0?255))
????????elif?emotion_text?==?‘happy‘:
????????????color?=?emotion_probability?*?np.asarray((255?255?0))
????????elif?emotion_text?==?‘surprise‘:
????????????color?=?emotion_probability?*?np.asarray((0?255?255))
????????else:
????????????color?=?emotion_probab

?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????目錄???????????0??2018-01-17?00:38??Emotion-master\
?????文件????????1068??2018-01-17?00:38??Emotion-master\LICENSE
?????文件?????????881??2018-01-17?00:38??Emotion-master\README.md
?????目錄???????????0??2018-01-17?00:38??Emotion-master\demo\
?????文件?????5408300??2018-01-17?00:38??Emotion-master\demo\demo.gif
?????文件?????2613425??2018-01-17?00:38??Emotion-master\demo\dinner.mp4
?????文件??????980831??2018-01-17?00:38??Emotion-master\demo\report.pdf
?????文件????????3458??2018-01-17?00:38??Emotion-master\emotions.py
?????目錄???????????0??2018-01-17?00:38??Emotion-master\models\
?????文件??????872856??2018-01-17?00:38??Emotion-master\models\emotion_model.hdf5
?????文件??????930127??2018-01-17?00:38??Emotion-master\models\haarcascade_frontalface_default.xml
?????目錄???????????0??2018-01-17?00:38??Emotion-master\utils\
?????文件???????????0??2018-01-17?00:38??Emotion-master\utils\__init__.py
?????文件?????????149??2018-01-17?00:38??Emotion-master\utils\__init__.pyc
?????目錄???????????0??2018-01-17?00:38??Emotion-master\utils\__pycache__\
?????文件?????????145??2018-01-17?00:38??Emotion-master\utils\__pycache__\__init__.cpython-36.pyc
?????文件????????5076??2018-01-17?00:38??Emotion-master\utils\__pycache__\datasets.cpython-36.pyc
?????文件????????1778??2018-01-17?00:38??Emotion-master\utils\__pycache__\inference.cpython-36.pyc
?????文件?????????966??2018-01-17?00:38??Emotion-master\utils\__pycache__\preprocessor.cpython-36.pyc
?????文件???????10257??2018-01-17?00:38??Emotion-master\utils\data_augmentation.py
?????文件????????5855??2018-01-17?00:38??Emotion-master\utils\datasets.py
?????文件????????6495??2018-01-17?00:38??Emotion-master\utils\datasets.pyc
?????文件????????6693??2018-01-17?00:38??Emotion-master\utils\grad_cam.py
?????文件????????1368??2018-01-17?00:38??Emotion-master\utils\inference.py
?????文件????????2509??2018-01-17?00:38??Emotion-master\utils\inference.pyc
?????文件?????????642??2018-01-17?00:38??Emotion-master\utils\preprocessor.py
?????文件????????1375??2018-01-17?00:38??Emotion-master\utils\preprocessor.pyc
?????文件????????6368??2018-01-17?00:38??Emotion-master\utils\visualizer.py

評(píng)論

共有 條評(píng)論