Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,8 @@ import cv2
|
|
| 3 |
from utils.detect import create_mtcnn_net, MtcnnDetector
|
| 4 |
from utils.vision import vis_face
|
| 5 |
import argparse
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
MIN_FACE_SIZE = 3
|
| 9 |
|
|
@@ -33,7 +34,18 @@ def greet(name):
|
|
| 33 |
img_bg = cv2.merge([r,g,b])
|
| 34 |
p_bboxs, r_bboxs, bboxs, landmarks = mtcnn_detector.detect_face(img)
|
| 35 |
save_name = args.save_name
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
iface = gr.Interface(fn=greet,
|
| 38 |
inputs=gr.Image(type="filepath"),
|
| 39 |
outputs="image")
|
|
|
|
| 3 |
from utils.detect import create_mtcnn_net, MtcnnDetector
|
| 4 |
from utils.vision import vis_face
|
| 5 |
import argparse
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import numpy as np
|
| 8 |
|
| 9 |
MIN_FACE_SIZE = 3
|
| 10 |
|
|
|
|
| 34 |
img_bg = cv2.merge([r,g,b])
|
| 35 |
p_bboxs, r_bboxs, bboxs, landmarks = mtcnn_detector.detect_face(img)
|
| 36 |
save_name = args.save_name
|
| 37 |
+
fig = vis_face(img_bg, bboxs, landmarks, MIN_FACE_SIZE, save_name)
|
| 38 |
+
fig.canvas.draw()
|
| 39 |
+
|
| 40 |
+
# Get the RGB buffer from the figure
|
| 41 |
+
w, h = fig.canvas.get_width_height()
|
| 42 |
+
buf = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8)
|
| 43 |
+
buf.shape = (h, w, 3)
|
| 44 |
+
|
| 45 |
+
# canvas.tostring_rgb give pixmap in RGB mode.
|
| 46 |
+
# Roll the ALPHA channel to have it in RGBA mode
|
| 47 |
+
buf = np.roll(buf, 3, axis=2)
|
| 48 |
+
return Image.fromarray(buf)
|
| 49 |
iface = gr.Interface(fn=greet,
|
| 50 |
inputs=gr.Image(type="filepath"),
|
| 51 |
outputs="image")
|