gurwindersingh commited on
Commit
af0aeb3
·
1 Parent(s): 7e8aa2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -62,9 +62,9 @@ img_file_buffer=st.camera_input("Take a picture")
62
  if img_file_buffer is not None:
63
 
64
  test_image = Image.open(img_file_buffer)
 
65
  st.image(test_image, use_column_width=True)
66
- image = cv2.resize(test_image,(48,48))
67
- image = extract_features(image)
68
 
69
 
70
  #########################
@@ -85,16 +85,22 @@ if img_file_buffer is not None:
85
  y1, x2, y2, x1 = faceLoc
86
  y1, x2, y2, x1 = y1*4,x2*4,y2*4,x1*4
87
  cv2.rectangle(image,(x1,y1),(x2,y2),(0,255,0),2)
88
- st.write("reshape")
89
- pred = model.predict(image)
90
- prediction_label = labels[pred.argmax()]
91
- st.write("predict")
92
  cv2.rectangle(image,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILLED)
93
  cv2.putText(image,name,(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255, 255, 255),2)
94
- st.write("Predicted Output:", prediction_label)
95
- cv2.putText(image, '% s' %(prediction_label), (x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX_SMALL,2, (0,0,255))
96
- st.write("success")
97
-
 
 
 
 
 
 
 
 
 
 
98
  else:
99
  st.write("fail")
100
 
 
62
  if img_file_buffer is not None:
63
 
64
  test_image = Image.open(img_file_buffer)
65
+ image1 = Image.open(img_file_buffer)
66
  st.image(test_image, use_column_width=True)
67
+ image = np.asarray(test_image)
 
68
 
69
 
70
  #########################
 
85
  y1, x2, y2, x1 = faceLoc
86
  y1, x2, y2, x1 = y1*4,x2*4,y2*4,x1*4
87
  cv2.rectangle(image,(x1,y1),(x2,y2),(0,255,0),2)
 
 
 
 
88
  cv2.rectangle(image,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILLED)
89
  cv2.putText(image,name,(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255, 255, 255),2)
90
+
91
+ faces=face_cascade.detectMultiScale(image1,1.3,5)
92
+ try:
93
+ for (p,q,r,s) in faces:
94
+ image = gray[q:q+s,p:p+r]
95
+ cv2.rectangle(image1,(p,q),(p+r,q+s),(255,0,0),2)
96
+ image = cv2.resize(image,(48,48))
97
+ img = extract_features(image)
98
+ pred = model.predict(img)
99
+ prediction_label = labels[pred.argmax()]
100
+ st.write("Predicted Output:", prediction_label)
101
+ # cv2.putText(im,prediction_label)
102
+ img = cv2.putText(image1, '% s' %(prediction_label), (p-10, q-10),cv2.FONT_HERSHEY_COMPLEX_SMALL,2, (0,0,255))
103
+ st.image(img, use_column_width=True)
104
  else:
105
  st.write("fail")
106