Rend19 commited on
Commit
2b9fb76
·
verified ·
1 Parent(s): fefbd58

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -163,9 +163,8 @@ class ResNetModel():
163
 
164
  faceRecognition = ResNetModel.load("resnet_v2")
165
  def predict(image):
166
-
167
  faceCascade = cv2.CascadeClassifier('Cascades/haarcascade_frontalface_default.xml')
168
- frame = cv2.flip(image, 1)
169
  faces = faceCascade.detectMultiScale(
170
  frame,
171
  scaleFactor=1.2,
@@ -173,21 +172,17 @@ def predict(image):
173
  minSize=(20, 20)
174
  )
175
  for (x,y,w,h) in faces:
176
- cv2.rectangle(frame,(x,y),(x+w,y+h),(0,0,255),2)
177
  roi_color = frame[y:y+h, x:x+w]
178
  roi_color = cv2.flip(roi_color, 1)
179
  label, conf = faceRecognition.predict(roi_color)
180
  label = label[:12] + "..." if len(label) > 10 else label
181
  text = "{label} : {conf:.3f}".format(label = label, conf = conf)
182
 
183
- cv2.putText(frame, text, (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0,0,255), 2)
184
  return frame
185
 
186
- css = """.my-group {max-width: 600px !important; max-height: 600px !important;}
187
- .my-column {display: flex !important; justify-content: center !important; align-items: center !important;}"""
188
- rtc_configuration = {
189
- "frameRate": {"ideal": 10}
190
- }
191
  with gr.Blocks(css=css) as demo:
192
  gr.HTML(
193
  """
@@ -201,13 +196,15 @@ with gr.Blocks(css=css) as demo:
201
  </ul>
202
  """
203
  )
204
- with gr.Column(elem_classes=["my-column"]):
205
- with gr.Group(elem_classes=["my-group"]):
206
- image = WebRTC(label="Stream", rtc_configuration=rtc_configuration)
 
 
207
 
208
- image.stream(
209
- fn=predict, inputs=[image], outputs=[image], time_limit=60
210
  )
211
 
212
  if __name__ == "__main__":
213
- demo.launch(share=True)
 
163
 
164
  faceRecognition = ResNetModel.load("resnet_v2")
165
  def predict(image):
 
166
  faceCascade = cv2.CascadeClassifier('Cascades/haarcascade_frontalface_default.xml')
167
+ frame = np.array(image)
168
  faces = faceCascade.detectMultiScale(
169
  frame,
170
  scaleFactor=1.2,
 
172
  minSize=(20, 20)
173
  )
174
  for (x,y,w,h) in faces:
175
+ cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),3)
176
  roi_color = frame[y:y+h, x:x+w]
177
  roi_color = cv2.flip(roi_color, 1)
178
  label, conf = faceRecognition.predict(roi_color)
179
  label = label[:12] + "..." if len(label) > 10 else label
180
  text = "{label} : {conf:.3f}".format(label = label, conf = conf)
181
 
182
+ cv2.putText(frame, text, (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255,0,0), 3)
183
  return frame
184
 
185
+ css = """.my-column {max-width: 600px;}"""
 
 
 
 
186
  with gr.Blocks(css=css) as demo:
187
  gr.HTML(
188
  """
 
196
  </ul>
197
  """
198
  )
199
+ with gr.Row():
200
+ with gr.Column(elem_classes=["my-column"]):
201
+ input_img = gr.Image(label="Input", sources="webcam")
202
+ with gr.Column(elem_classes=["my-column"]):
203
+ output_img = gr.Image(label="Output")
204
 
205
+ input_img.stream(
206
+ fn=predict, inputs=[input_img], outputs=[output_img], time_limit=1, stream_every=0.1
207
  )
208
 
209
  if __name__ == "__main__":
210
+ demo.launch()