Spaces:
Runtime error
Runtime error
init
Browse files- README.md +1 -1
- app.py +95 -0
- core.bin +3 -0
- imgs/2313.png +0 -0
- imgs/cc.png +0 -0
- imgs/face1.jpg +0 -0
- imgs/face2.jpg +0 -0
- mic.bin +3 -0
- requirements.txt +10 -0
- z_app_factory.so +0 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: Face Keypoint 3d
|
3 |
-
emoji:
|
4 |
colorFrom: red
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
title: Face Keypoint 3d
|
3 |
+
emoji: 👺
|
4 |
colorFrom: red
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import gradio as gr
|
3 |
+
import io
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
from z_app_factory import get_app
|
7 |
+
|
8 |
+
thickness = 3
|
9 |
+
lineType = 8
|
10 |
+
font = cv2.FONT_HERSHEY_SIMPLEX
|
11 |
+
|
12 |
+
def plot3(fig):
|
13 |
+
with io.BytesIO() as buff:
|
14 |
+
fig.savefig(buff, format='raw')
|
15 |
+
buff.seek(0)
|
16 |
+
data = np.frombuffer(buff.getvalue(), dtype=np.uint8)
|
17 |
+
w, h = fig.canvas.get_width_height()
|
18 |
+
im = data.reshape((int(h), int(w), -1))
|
19 |
+
im = im[:, :, :-1]
|
20 |
+
# im = im[:, :, ::-1]
|
21 |
+
im = im[125:350,220:440,:]
|
22 |
+
# cv2.imwrite("res.png", im)
|
23 |
+
# 90/0
|
24 |
+
return im
|
25 |
+
|
26 |
+
|
27 |
+
def inference(image):
|
28 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
29 |
+
code,lst2d_res = get_app(image)
|
30 |
+
msg = "aaa"
|
31 |
+
if code == 401:
|
32 |
+
msg = "Not RGB three channel picture"
|
33 |
+
elif code == 402:
|
34 |
+
msg = "Pixels less than 32 * 32"
|
35 |
+
elif code == 403:
|
36 |
+
msg = "Pixels greater than 4096 * 4096"
|
37 |
+
elif code == 404:
|
38 |
+
msg = "Files greater than 5MB"
|
39 |
+
elif code == 405:
|
40 |
+
msg = "System error, please contact\n the server for troubleshooting"
|
41 |
+
|
42 |
+
if code!=200:
|
43 |
+
img_out = np.zeros((500, 600,3),dtype=np.uint8)
|
44 |
+
cv2.putText(img_out, msg, (20, 200), font, 1, (0, 255, 0), 2)
|
45 |
+
return img_out
|
46 |
+
|
47 |
+
# img_out = np.zeros((500, 600, 3),dtype=np.uint8)
|
48 |
+
# cv2.putText(img_out, "ease contact the server for trouble", (20, 100), font, 0.8, (0, 255, 0), 2)
|
49 |
+
# return img_out
|
50 |
+
# img_out = np.zeros((500, 600, 3), dtype=np.uint8)
|
51 |
+
# cv2.putText(img_out, msg, (20, 20), font, 1, (0, 255, 0), 2)
|
52 |
+
# return img_out
|
53 |
+
landmarks = lst2d_res['landmarks']
|
54 |
+
import numpy as np # 用来处理数据
|
55 |
+
import matplotlib
|
56 |
+
import matplotlib.pyplot as plt
|
57 |
+
matplotlib.use('agg')
|
58 |
+
x = np.array([i[0] for i in landmarks])
|
59 |
+
y = np.array([i[1] for i in landmarks])
|
60 |
+
z = np.array([i[2] for i in landmarks])
|
61 |
+
z = z - z.min()
|
62 |
+
z = z / z.max()
|
63 |
+
fig = plt.figure()
|
64 |
+
ax = plt.subplot(projection='3d') # 创建一个三维的绘图工程
|
65 |
+
ax.scatter(x, y, z, c=[int(i) for i in z * 255]) # 绘制数据点 c: 'r'红色,'y'黄色,等颜色
|
66 |
+
|
67 |
+
# ax.set_xlabel('X') # 设置x坐标轴
|
68 |
+
# ax.set_ylabel('Y') # 设置y坐标轴
|
69 |
+
# ax.set_zlabel('Z') # 设置z坐标轴
|
70 |
+
ax.view_init(-90, -90)
|
71 |
+
im_plot = plot3(fig)
|
72 |
+
del fig
|
73 |
+
h, w, _ = im_plot.shape
|
74 |
+
# image[:h, :w] = im_plot
|
75 |
+
return im_plot
|
76 |
+
|
77 |
+
|
78 |
+
|
79 |
+
title = "Face Keypoint 3d"
|
80 |
+
description = "demo for Face Keypoint 3d. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
|
81 |
+
article = "<p style='text-align: center'><a href='https://www.yuque.com/itmorn/ability/face_keypoint_3d' target='_blank'>Project Documents</a> | <a href='https://www.bilibili.com/video/BV1GD4y1y77z' target='_blank'>Video Demo</a></p>"
|
82 |
+
|
83 |
+
gr.Interface(
|
84 |
+
inference,
|
85 |
+
[gr.inputs.Image(label="Input")],
|
86 |
+
gr.outputs.Image(type="pil", label="Output"),
|
87 |
+
title=title,
|
88 |
+
description=description,
|
89 |
+
article=article,
|
90 |
+
examples=[
|
91 |
+
["imgs/face1.jpg"],
|
92 |
+
["imgs/face2.jpg"],
|
93 |
+
["imgs/cc.png"],
|
94 |
+
["imgs/2313.png"]
|
95 |
+
]).launch(debug=True)
|
core.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3d2f8edde6016fc576d1bcb53e16ea3993770c752f25c72cdf39ed37d2876558
|
3 |
+
size 42449144
|
imgs/2313.png
ADDED
![]() |
imgs/cc.png
ADDED
![]() |
imgs/face1.jpg
ADDED
![]() |
imgs/face2.jpg
ADDED
![]() |
mic.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dff34b9c235adc7d6d87b5e62aa5602eb1e6f9e436e6acf89dbfdd4243ffac0b
|
3 |
+
size 1611712
|
requirements.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pyarmor
|
2 |
+
opencv-python
|
3 |
+
onnxruntime-gpu
|
4 |
+
onnx
|
5 |
+
py7zr
|
6 |
+
onnx
|
7 |
+
tqdm
|
8 |
+
scikit-image
|
9 |
+
fs
|
10 |
+
flask
|
z_app_factory.so
ADDED
Binary file (662 kB). View file
|
|