Skip to content
Snippets Groups Projects
Commit 7c7f8ae9 authored by Amel Abdic's avatar Amel Abdic :8ball:
Browse files

fix

parent c968bed9
No related branches found
No related tags found
No related merge requests found
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv/python_stuff" />
</content>
<orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N802" />
<option value="N801" />
<option value="N806" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Mood Meter.iml" filepath="$PROJECT_DIR$/.idea/Mood Meter.iml" />
</modules>
</component>
</project>
\ No newline at end of file
main.py 0 → 100644
#model.h5 is best model
import cv2
import warnings
warnings.filterwarnings("ignore")
from keras.models import load_model
import numpy as np
import time
class Main:
def main(self):
face_classifier = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
classifier = load_model(r'model.h5')
# Angepasste emotion_labels Liste ohne 'Angry', 'Disgust', 'Fear'
emotion_labels = ['Happy', 'Neutral', 'Sad', 'Surprise']
cap = cv2.VideoCapture(0)
start_time = time.time()
emotion_history = []
while True:
_, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_classifier.detectMultiScale(gray)
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 255), 2)
roi_gray = gray[y:y + h, x:x + w]
roi_gray = cv2.resize(roi_gray, (48, 48), interpolation=cv2.INTER_AREA)
if np.sum([roi_gray]) != 0:
roi = roi_gray.astype('float') / 255.0
roi = np.expand_dims(roi, axis=0)
prediction = classifier.predict(roi)[0]
adjusted_prediction = np.delete(prediction, [0, 1, 2])
max_index = np.argmax(adjusted_prediction)
current_emotion = emotion_labels[max_index]
label_position = (x, y)
cv2.putText(frame, current_emotion, label_position, cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
emotion_history.append(current_emotion)
# Überprüfen, ob 3 Sekunden vergangen sind diese wird dann für die chat gpt api genutzt
if time.time() - start_time >= 3:
if emotion_history.count(current_emotion) == len(emotion_history):
print(f"Konstante Emotion für 3 Sekunden: {current_emotion}")
start_time = time.time()
emotion_history.clear()
cv2.imshow('Emotion Detector', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
main_instance = Main()
main_instance.main()
model.h5 0 → 100644
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment