-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Mood & Enhanced Speech Classifications
- Loading branch information
1 parent
3bd1ca5
commit fb53090
Showing
12 changed files
with
189 additions
and
33 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Son Nguyen Hoang | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import cv2 | ||
from deepface import DeepFace | ||
|
||
|
||
def analyze_and_show(image, show_results=True): | ||
try: | ||
analysis = DeepFace.analyze(image, actions=['emotion'], enforce_detection=False) | ||
|
||
text_y = 20 | ||
|
||
for result in analysis: | ||
if 'region' in result: | ||
region = result['region'] | ||
x, y, w, h = region['x'], region['y'], region['w'], region['h'] | ||
cv2.rectangle(image, (x, y), (x + w, y + h), (255, 0, 0), 2) | ||
|
||
if 'emotion' in result: | ||
emotions = result['emotion'] | ||
dominant_emotion = result['dominant_emotion'] | ||
|
||
if show_results: | ||
print(f"Dominant emotion: {dominant_emotion}") | ||
print("See more detailed stats on the popup window.") | ||
|
||
for emotion, prob in emotions.items(): | ||
cv2.putText(image, f"{emotion}: {prob:.2f}%", (10, text_y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, | ||
(0, 255, 0), 2) | ||
text_y += 20 | ||
|
||
cv2.imshow('Mood Detector', image) | ||
|
||
except Exception as e: | ||
print(f"Error in emotion detection: {e}") | ||
|
||
|
||
def process_input(source): | ||
cap = cv2.VideoCapture(0 if source == 'webcam' else source) | ||
|
||
while True: | ||
ret, frame = cap.read() | ||
if not ret: | ||
break | ||
|
||
show_results = True | ||
analyze_and_show(frame, show_results) | ||
|
||
if cv2.waitKey(1) & 0xFF in [27, ord('q')]: | ||
break | ||
|
||
if cv2.getWindowProperty('Mood Detector', cv2.WND_PROP_VISIBLE) < 1: | ||
break | ||
|
||
cap.release() | ||
cv2.destroyAllWindows() | ||
|
||
|
||
if __name__ == "__main__": | ||
choice = input("Enter 'image', 'video', or 'webcam': ").lower() | ||
|
||
if choice == 'image': | ||
image_path = input("Enter the image path: ") | ||
image = cv2.imread(image_path) | ||
analyze_and_show(image) | ||
cv2.waitKey(0) | ||
cv2.destroyAllWindows() | ||
elif choice in ['video', 'webcam']: | ||
source = 'webcam' if choice == 'webcam' else input("Enter the video path: ") | ||
process_input(source) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.