Spaces:
Running
Running
Update demo.py
Browse files
demo.py
CHANGED
@@ -1,159 +1,77 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
import
|
5 |
-
import
|
6 |
-
import
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
(
|
76 |
-
|
77 |
-
|
78 |
-
freeLicenseResults(license_plate_ptr, cnt)
|
79 |
-
|
80 |
-
# print("number: ", cnt, rectangles, license_plate)
|
81 |
-
if cnt == 0:
|
82 |
-
result = "Nothing Detected !"
|
83 |
-
response = jsonify({"result": result, "plate number": license, "coordinate": box})
|
84 |
-
|
85 |
-
response.status_code = 200
|
86 |
-
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
87 |
-
return response
|
88 |
-
|
89 |
-
result = "License Plate Number Detected !"
|
90 |
-
for i in range(cnt):
|
91 |
-
license[f"vehicle {i + 1}"] = license_plate[i]
|
92 |
-
box[f"vehicle {i + 1}"] = rectangles[i]
|
93 |
-
|
94 |
-
response = jsonify({"result": result, "plate number": license, "coordinate": box})
|
95 |
-
|
96 |
-
response.status_code = 200
|
97 |
-
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
98 |
-
return response
|
99 |
-
|
100 |
-
@app.route('/alpr_base64', methods=['POST'])
|
101 |
-
def alpr_base64():
|
102 |
-
|
103 |
-
result = "None"
|
104 |
-
license = {}
|
105 |
-
box = {}
|
106 |
-
|
107 |
-
content = request.get_json()
|
108 |
-
|
109 |
-
try:
|
110 |
-
imageBase64 = content['base64']
|
111 |
-
image_data = base64.b64decode(imageBase64)
|
112 |
-
np_array = np.frombuffer(image_data, np.uint8)
|
113 |
-
image = cv2.imdecode(np_array, cv2.IMREAD_COLOR)
|
114 |
-
except:
|
115 |
-
result = "Failed to open file1"
|
116 |
-
response = jsonify({"result": result, "plate number": license, "coordinate": box})
|
117 |
-
|
118 |
-
response.status_code = 200
|
119 |
-
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
120 |
-
return response
|
121 |
-
|
122 |
-
|
123 |
-
img_byte = mat_to_bytes(image)
|
124 |
-
|
125 |
-
recog_array = (c_int * 1024)() # Assuming a maximum of 256 rectangles
|
126 |
-
|
127 |
-
license_plate_ptr = POINTER(c_char_p)()
|
128 |
-
cnt = getLicensePlate(img_byte, len(img_byte), byref(license_plate_ptr), recog_array)
|
129 |
-
|
130 |
-
license_plate = [license_plate_ptr[i].decode('utf-8') for i in range(cnt)]
|
131 |
-
rectangles = [
|
132 |
-
(recog_array[i * 4], recog_array[i * 4 + 1], recog_array[i * 4 + 2], recog_array[i * 4 + 3])
|
133 |
-
for i in range(cnt)]
|
134 |
-
|
135 |
-
freeLicenseResults(license_plate_ptr, cnt)
|
136 |
-
|
137 |
-
# print("number: ", cnt, rectangles, license_plate)
|
138 |
-
if cnt == 0:
|
139 |
-
result = "Nothing Detected !"
|
140 |
-
response = jsonify({"result": result, "plate number": license, "coordinate": box})
|
141 |
-
|
142 |
-
response.status_code = 200
|
143 |
-
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
144 |
-
return response
|
145 |
-
|
146 |
-
result = "License Plate Number Detected !"
|
147 |
-
for i in range(cnt):
|
148 |
-
license[f"vehicle {i + 1}"] = license_plate[i]
|
149 |
-
box[f"vehicle {i + 1}"] = rectangles[i]
|
150 |
-
|
151 |
-
response = jsonify({"result": result, "plate number": license, "coordinate": box})
|
152 |
-
|
153 |
-
response.status_code = 200
|
154 |
-
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
155 |
-
return response
|
156 |
-
|
157 |
-
if __name__ == '__main__':
|
158 |
-
port = int(os.environ.get("PORT", 8080))
|
159 |
-
app.run(host='0.0.0.0', port=port)
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from PIL import Image
|
4 |
+
import io
|
5 |
+
import cv2
|
6 |
+
import numpy as np
|
7 |
+
|
8 |
+
palmprint_count = 0
|
9 |
+
|
10 |
+
def compare_palmprint(frame1, frame2):
|
11 |
+
global palmprint_count
|
12 |
+
|
13 |
+
palmprint_count = palmprint_count + 1
|
14 |
+
|
15 |
+
url = "http://127.0.0.1:8080/compare_palmprint"
|
16 |
+
files = {'file1': open(frame1, 'rb'), 'file2': open(frame2, 'rb')}
|
17 |
+
|
18 |
+
r = requests.post(url=url, files=files)
|
19 |
+
|
20 |
+
html = None
|
21 |
+
|
22 |
+
compare_result = r.json().get('compare_result')
|
23 |
+
compare_similarity = r.json().get('compare_similarity')
|
24 |
+
|
25 |
+
html = ("<table>"
|
26 |
+
"<tr>"
|
27 |
+
"<th>Compare Result</th>"
|
28 |
+
"<th>Value</th>"
|
29 |
+
"</tr>"
|
30 |
+
"<tr>"
|
31 |
+
"<td>Result</td>"
|
32 |
+
"<td>{compare_result}</td>"
|
33 |
+
"</tr>"
|
34 |
+
"<tr>"
|
35 |
+
"<td>Similarity</td>"
|
36 |
+
"<td>{compare_similarity}</td>"
|
37 |
+
"</tr>"
|
38 |
+
"</table>".format(compare_result=compare_result, compare_similarity=compare_similarity))
|
39 |
+
|
40 |
+
return [html]
|
41 |
+
|
42 |
+
with gr.Blocks() as demo:
|
43 |
+
gr.Markdown(
|
44 |
+
"""
|
45 |
+
# KBY-AI License Plate Recognition
|
46 |
+
We offer SDKs for face recognition, liveness detection(anti-spoofing), ID card recognition and ID document liveness detection.
|
47 |
+
We also specialize in providing outsourcing services with a variety of technical stacks like AI(Computer Vision/Machine Learning), mobile apps, and web apps.
|
48 |
+
|
49 |
+
##### KYC Verification Demo - https://github.com/kby-ai/KYC-Verification-Demo-Android
|
50 |
+
##### ID Capture Web Demo - https://id-document-recognition-react-alpha.vercel.app
|
51 |
+
"""
|
52 |
+
)
|
53 |
+
|
54 |
+
with gr.TabItem("License Plate Recognition"):
|
55 |
+
gr.Markdown(
|
56 |
+
"""
|
57 |
+
##### Docker Hub - https://hub.docker.com/r/kbyai/license-plate-recognition
|
58 |
+
```bash
|
59 |
+
sudo docker pull kbyai/license-plate-recognition:latest
|
60 |
+
sudo docker run -v ./license.txt:/home/openvino/kby-ai-alpr/license.txt -p 8081:8080 -p 9001:9000 kbyai/license-plate-recognition:latest
|
61 |
+
```
|
62 |
+
"""
|
63 |
+
)
|
64 |
+
with gr.Row():
|
65 |
+
with gr.Column():
|
66 |
+
alpr_image_input = gr.Image(type='filepath', height=300)
|
67 |
+
gr.Examples(['alpr_examples/test1.jpg', 'alpr_examples/test2.jpg', 'alpr_examples/test3.jpg'],
|
68 |
+
inputs=alpr_image_input)
|
69 |
+
alpr_confirmation_button = gr.Button("Confirm")
|
70 |
+
with gr.Column():
|
71 |
+
with gr.Column():
|
72 |
+
alpr_output = gr.Image(type="numpy")
|
73 |
+
|
74 |
+
alpr_confirmation_button.click(alpr, inputs=alpr_image_input, outputs=alpr_output)
|
75 |
+
gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fweb.kby-ai.com%2F"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fweb.kby-ai.com%2F&label=VISITORS&countColor=%23263759" /></a>')
|
76 |
+
|
77 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|