Spaces:
Sleeping
Sleeping
add logging and examples
Browse files- app.py +13 -2
- estonia_id_card.jpg +0 -0
- german_bundesdruckerei_passport.webp +0 -0
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import math
|
2 |
|
3 |
import cv2
|
@@ -6,6 +7,8 @@ import numpy as np
|
|
6 |
import onnxruntime as ort
|
7 |
from PIL import Image, ImageOps
|
8 |
|
|
|
|
|
9 |
MODEL_PATH = "model.onnx"
|
10 |
IMAGE_SIZE = 480
|
11 |
|
@@ -68,7 +71,7 @@ def rectify(img_np: np.ndarray, keypoints: np.ndarray):
|
|
68 |
w = h * wh_ratio
|
69 |
|
70 |
except:
|
71 |
-
|
72 |
w1 = distance(keypoints[0], keypoints[1])
|
73 |
w2 = distance(keypoints[3], keypoints[2])
|
74 |
w = (w1 + w2) * 0.5
|
@@ -86,7 +89,14 @@ def predict(img: Image.Image):
|
|
86 |
kpts_xy = pred_kpts[:, :2] * max(img.size) / IMAGE_SIZE
|
87 |
|
88 |
img_np = np.array(img)
|
89 |
-
cv2.polylines(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
if (pred_kpts[:, 2] >= 0.25).all():
|
92 |
cropped = rectify(np.array(img), kpts_xy)
|
@@ -100,4 +110,5 @@ gr.Interface(
|
|
100 |
predict,
|
101 |
inputs=[gr.Image(type="pil")],
|
102 |
outputs=["image", "image"],
|
|
|
103 |
).launch(server_name="0.0.0.0")
|
|
|
1 |
+
import logging
|
2 |
import math
|
3 |
|
4 |
import cv2
|
|
|
7 |
import onnxruntime as ort
|
8 |
from PIL import Image, ImageOps
|
9 |
|
10 |
+
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
11 |
+
|
12 |
MODEL_PATH = "model.onnx"
|
13 |
IMAGE_SIZE = 480
|
14 |
|
|
|
71 |
w = h * wh_ratio
|
72 |
|
73 |
except:
|
74 |
+
logging.exception("Failed to estimate aspect ratio from perspective")
|
75 |
w1 = distance(keypoints[0], keypoints[1])
|
76 |
w2 = distance(keypoints[3], keypoints[2])
|
77 |
w = (w1 + w2) * 0.5
|
|
|
89 |
kpts_xy = pred_kpts[:, :2] * max(img.size) / IMAGE_SIZE
|
90 |
|
91 |
img_np = np.array(img)
|
92 |
+
cv2.polylines(
|
93 |
+
img_np,
|
94 |
+
[kpts_xy.astype(int)],
|
95 |
+
True,
|
96 |
+
(0, 255, 0),
|
97 |
+
thickness=5,
|
98 |
+
lineType=cv2.LINE_AA,
|
99 |
+
)
|
100 |
|
101 |
if (pred_kpts[:, 2] >= 0.25).all():
|
102 |
cropped = rectify(np.array(img), kpts_xy)
|
|
|
110 |
predict,
|
111 |
inputs=[gr.Image(type="pil")],
|
112 |
outputs=["image", "image"],
|
113 |
+
examples=["estonia_id_card.jpg", "german_bundesdruckerei_passport.webp"],
|
114 |
).launch(server_name="0.0.0.0")
|
estonia_id_card.jpg
ADDED
![]() |
german_bundesdruckerei_passport.webp
ADDED
![]() |