Goutham204 commited on
Commit
6f5c2ab
Β·
verified Β·
1 Parent(s): adac516

Upload 2 files

Browse files
Expression prediction(org).ipynb ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "06a8ee32-1492-4023-83e2-8738646f0a74",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "from keras.models import load_model\n",
11
+ "import os\n",
12
+ "import cv2\n",
13
+ "import numpy as np"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 2,
19
+ "id": "06c5f530-7dc8-40b0-94bf-2d3aff5c355e",
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "model=load_model('emotion-059.keras')\n",
24
+ "\n",
25
+ "face_clsf=cv2.CascadeClassifier(r'D:/New download/haarcascade_frontalface_default.xml')\n",
26
+ "\n",
27
+ "source=cv2.VideoCapture(0)\n",
28
+ "\n",
29
+ "labels_dict={0:'Angry',1:'Disgust',2:'Fear',3:'Happy',4:'Neutral',5:'Sad',6:'Surprise'}\n",
30
+ "color_dict={0:(0,0,255),1:(255,0,0),2:(128,128,128),3:(0,225,0),4:(0,255,255),5:(255,255,0),6:(0,215,255)}"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": 3,
36
+ "id": "57beb518-e3d4-4184-9d15-457151591f18",
37
+ "metadata": {},
38
+ "outputs": [
39
+ {
40
+ "name": "stdout",
41
+ "output_type": "stream",
42
+ "text": [
43
+ "\u001b[1m1/1\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 877ms/step\n",
44
+ "\u001b[1m1/1\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 108ms/step\n"
45
+ ]
46
+ },
47
+ {
48
+ "ename": "error",
49
+ "evalue": "OpenCV(4.11.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\highgui\\src\\window.cpp:1301: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'\n",
50
+ "output_type": "error",
51
+ "traceback": [
52
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
53
+ "\u001b[1;31merror\u001b[0m Traceback (most recent call last)",
54
+ "Cell \u001b[1;32mIn[3], line 20\u001b[0m\n\u001b[0;32m 16\u001b[0m cv2\u001b[38;5;241m.\u001b[39mrectangle(img,(x,y\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m50\u001b[39m),(x\u001b[38;5;241m+\u001b[39mw,y),color_dict[label],\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m 17\u001b[0m cv2\u001b[38;5;241m.\u001b[39mputText(img, labels_dict[label], (x\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m5\u001b[39m, y\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m10\u001b[39m),cv2\u001b[38;5;241m.\u001b[39mFONT_HERSHEY_SIMPLEX,\u001b[38;5;241m0.8\u001b[39m,(\u001b[38;5;241m255\u001b[39m,\u001b[38;5;241m255\u001b[39m,\u001b[38;5;241m255\u001b[39m),\u001b[38;5;241m2\u001b[39m)\n\u001b[1;32m---> 20\u001b[0m \u001b[43mcv2\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mimshow\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mFace Emotion Detection\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43mimg\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 21\u001b[0m key\u001b[38;5;241m=\u001b[39mcv2\u001b[38;5;241m.\u001b[39mwaitKey(\u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m 23\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m(key\u001b[38;5;241m==\u001b[39m\u001b[38;5;241m27\u001b[39m):\n",
55
+ "\u001b[1;31merror\u001b[0m: OpenCV(4.11.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\highgui\\src\\window.cpp:1301: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'\n"
56
+ ]
57
+ }
58
+ ],
59
+ "source": [
60
+ "while(True):\n",
61
+ " ret,img=source.read()\n",
62
+ " gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n",
63
+ " faces=face_clsf.detectMultiScale(gray,scaleFactor=1.1,minNeighbors=5)\n",
64
+ "\n",
65
+ " for (x,y,w,h) in faces:\n",
66
+ " face_img=gray[y:y+w,x:x+w]\n",
67
+ " resized=cv2.resize(face_img,(100,100))\n",
68
+ " normalized=resized/255.0\n",
69
+ " reshaped=np.reshape(normalized,(1,100,100,1))\n",
70
+ " result=model.predict(reshaped)\n",
71
+ "\n",
72
+ " label=np.argmax(result,axis=1)[0]\n",
73
+ "\n",
74
+ " cv2.rectangle(img,(x,y),(x+w,y+h),color_dict[label],2)\n",
75
+ " cv2.rectangle(img,(x,y-50),(x+w,y),color_dict[label],-1)\n",
76
+ " cv2.putText(img, labels_dict[label], (x+5, y-10),cv2.FONT_HERSHEY_SIMPLEX,0.8,(255,255,255),2)\n",
77
+ " \n",
78
+ " \n",
79
+ " cv2.imshow('Face Emotion Detection',img)\n",
80
+ " key=cv2.waitKey(1)\n",
81
+ " \n",
82
+ " if(key==27):\n",
83
+ " break\n",
84
+ " \n",
85
+ "cv2.destroyAllWindows()\n",
86
+ "source.release()"
87
+ ]
88
+ }
89
+ ],
90
+ "metadata": {
91
+ "kernelspec": {
92
+ "display_name": "Python 3",
93
+ "language": "python",
94
+ "name": "python3"
95
+ },
96
+ "language_info": {
97
+ "codemirror_mode": {
98
+ "name": "ipython",
99
+ "version": 3
100
+ },
101
+ "file_extension": ".py",
102
+ "mimetype": "text/x-python",
103
+ "name": "python",
104
+ "nbconvert_exporter": "python",
105
+ "pygments_lexer": "ipython3",
106
+ "version": "3.10.0"
107
+ }
108
+ },
109
+ "nbformat": 4,
110
+ "nbformat_minor": 5
111
+ }
Face Emotion Detection(org).ipynb ADDED
The diff for this file is too large to render. See raw diff