gurwindersingh commited on
Commit
133c7e7
·
1 Parent(s): 24a86cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -18
app.py CHANGED
@@ -72,24 +72,27 @@ if img_file_buffer is not None:
72
  faces = face_cascade.detectMultiScale(
73
  image=img_gray, scaleFactor=1.3, minNeighbors=5)
74
  st.write("gray")
75
- for (x, y, w, h) in faces:
76
- cv2.rectangle(img=img, pt1=(x, y), pt2=(
77
- x + w, y + h), color=(255, 0, 0), thickness=2)
78
- roi_gray = img_gray[y:y + h, x:x + w]
79
- roi_gray = cv2.resize(roi_gray, (48, 48), interpolation=cv2.INTER_AREA)
80
- if np.sum([roi_gray]) != 0:
81
- roi = roi_gray.astype('float') / 255.0
82
- roi = img_to_array(roi)
83
- roi = np.expand_dims(roi, axis=0)
84
- prediction = classifier.predict(roi)[0]
85
- maxindex = int(np.argmax(prediction))
86
- finalout = emotion_dict[maxindex]
87
- output = str(finalout)
88
- st.write(output)
89
- label_position = (x, y)
90
- img = cv2.putText(img, output, label_position, cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
91
- st.image(img, use_column_width=True)
92
- st.write("emotion done")
 
 
 
93
 
94
  #########################
95
  imgS = cv2.resize(image,(0,0),None,0.25,0.25)
 
72
  faces = face_cascade.detectMultiScale(
73
  image=img_gray, scaleFactor=1.3, minNeighbors=5)
74
  st.write("gray")
75
+ try:
76
+ for (x, y, w, h) in faces:
77
+ cv2.rectangle(img=img, pt1=(x, y), pt2=(
78
+ x + w, y + h), color=(255, 0, 0), thickness=2)
79
+ roi_gray = img_gray[y:y + h, x:x + w]
80
+ roi_gray = cv2.resize(roi_gray, (48, 48), interpolation=cv2.INTER_AREA)
81
+ if np.sum([roi_gray]) != 0:
82
+ roi = roi_gray.astype('float') / 255.0
83
+ roi = img_to_array(roi)
84
+ roi = np.expand_dims(roi, axis=0)
85
+ prediction = classifier.predict(roi)[0]
86
+ maxindex = int(np.argmax(prediction))
87
+ finalout = emotion_dict[maxindex]
88
+ output = str(finalout)
89
+ st.write(output)
90
+ label_position = (x, y)
91
+ img = cv2.putText(img, output, label_position, cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
92
+ st.image(img, use_column_width=True)
93
+ st.write("emotion done")
94
+ except:
95
+ st.write("face is not clear")
96
 
97
  #########################
98
  imgS = cv2.resize(image,(0,0),None,0.25,0.25)