Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -55,6 +55,7 @@ def alpr():
|
|
55 |
result = "None"
|
56 |
license = {}
|
57 |
box = {}
|
|
|
58 |
|
59 |
file = request.files['file']
|
60 |
|
@@ -63,7 +64,7 @@ def alpr():
|
|
63 |
image = cv2.resize(image, (1024, 640))
|
64 |
except:
|
65 |
result = "Failed to open file1"
|
66 |
-
response = jsonify({"result": result, "plate number": license, "coordinate": box})
|
67 |
|
68 |
response.status_code = 200
|
69 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
@@ -73,6 +74,7 @@ def alpr():
|
|
73 |
img_byte = mat_to_bytes(image)
|
74 |
|
75 |
recog_array = (c_int * 1024)() # Assuming a maximum of 256 rectangles
|
|
|
76 |
|
77 |
license_plate_ptr = POINTER(c_char_p)()
|
78 |
cnt = getLicensePlate(img_byte, len(img_byte), byref(license_plate_ptr), recog_array)
|
@@ -81,13 +83,14 @@ def alpr():
|
|
81 |
rectangles = [
|
82 |
(recog_array[i * 4], recog_array[i * 4 + 1], recog_array[i * 4 + 2], recog_array[i * 4 + 3])
|
83 |
for i in range(cnt)]
|
|
|
84 |
|
85 |
freeLicenseResults(license_plate_ptr, cnt)
|
86 |
|
87 |
print("number: ", cnt, rectangles, license_plate)
|
88 |
if cnt == 0:
|
89 |
result = "Nothing Detected !"
|
90 |
-
response = jsonify({"result": result, "plate number": license, "coordinate": box})
|
91 |
|
92 |
response.status_code = 200
|
93 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
@@ -97,8 +100,9 @@ def alpr():
|
|
97 |
for i in range(cnt):
|
98 |
license[f"vehicle {i + 1}"] = license_plate[i]
|
99 |
box[f"vehicle {i + 1}"] = rectangles[i]
|
|
|
100 |
|
101 |
-
response = jsonify({"result": result, "plate number": license, "coordinate": box})
|
102 |
|
103 |
response.status_code = 200
|
104 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
@@ -110,6 +114,7 @@ def alpr_base64():
|
|
110 |
result = "None"
|
111 |
license = {}
|
112 |
box = {}
|
|
|
113 |
|
114 |
content = request.get_json()
|
115 |
|
@@ -121,7 +126,7 @@ def alpr_base64():
|
|
121 |
image = cv2.resize(image, (1024, 640))
|
122 |
except:
|
123 |
result = "Failed to open file1"
|
124 |
-
response = jsonify({"result": result, "plate number": license, "coordinate": box})
|
125 |
|
126 |
response.status_code = 200
|
127 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
@@ -131,6 +136,7 @@ def alpr_base64():
|
|
131 |
img_byte = mat_to_bytes(image)
|
132 |
|
133 |
recog_array = (c_int * 1024)() # Assuming a maximum of 256 rectangles
|
|
|
134 |
|
135 |
license_plate_ptr = POINTER(c_char_p)()
|
136 |
cnt = getLicensePlate(img_byte, len(img_byte), byref(license_plate_ptr), recog_array)
|
@@ -139,13 +145,14 @@ def alpr_base64():
|
|
139 |
rectangles = [
|
140 |
(recog_array[i * 4], recog_array[i * 4 + 1], recog_array[i * 4 + 2], recog_array[i * 4 + 3])
|
141 |
for i in range(cnt)]
|
|
|
142 |
|
143 |
freeLicenseResults(license_plate_ptr, cnt)
|
144 |
|
145 |
# print("number: ", cnt, rectangles, license_plate)
|
146 |
if cnt == 0:
|
147 |
result = "Nothing Detected !"
|
148 |
-
response = jsonify({"result": result, "plate number": license, "coordinate": box})
|
149 |
|
150 |
response.status_code = 200
|
151 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
@@ -155,8 +162,9 @@ def alpr_base64():
|
|
155 |
for i in range(cnt):
|
156 |
license[f"vehicle {i + 1}"] = license_plate[i]
|
157 |
box[f"vehicle {i + 1}"] = rectangles[i]
|
|
|
158 |
|
159 |
-
response = jsonify({"result": result, "plate number": license, "coordinate": box})
|
160 |
|
161 |
response.status_code = 200
|
162 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
|
|
55 |
result = "None"
|
56 |
license = {}
|
57 |
box = {}
|
58 |
+
pro = {}
|
59 |
|
60 |
file = request.files['file']
|
61 |
|
|
|
64 |
image = cv2.resize(image, (1024, 640))
|
65 |
except:
|
66 |
result = "Failed to open file1"
|
67 |
+
response = jsonify({"result": result, "plate number": license, "coordinate": box, "score": pro})
|
68 |
|
69 |
response.status_code = 200
|
70 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
|
|
74 |
img_byte = mat_to_bytes(image)
|
75 |
|
76 |
recog_array = (c_int * 1024)() # Assuming a maximum of 256 rectangles
|
77 |
+
score_array = (c_float * 1024)() # Assuming a maximum of 256 rectangles
|
78 |
|
79 |
license_plate_ptr = POINTER(c_char_p)()
|
80 |
cnt = getLicensePlate(img_byte, len(img_byte), byref(license_plate_ptr), recog_array)
|
|
|
83 |
rectangles = [
|
84 |
(recog_array[i * 4], recog_array[i * 4 + 1], recog_array[i * 4 + 2], recog_array[i * 4 + 3])
|
85 |
for i in range(cnt)]
|
86 |
+
scores = [score_array[i] for i in range(cnt)]
|
87 |
|
88 |
freeLicenseResults(license_plate_ptr, cnt)
|
89 |
|
90 |
print("number: ", cnt, rectangles, license_plate)
|
91 |
if cnt == 0:
|
92 |
result = "Nothing Detected !"
|
93 |
+
response = jsonify({"result": result, "plate number": license, "coordinate": box, "score": pro})
|
94 |
|
95 |
response.status_code = 200
|
96 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
|
|
100 |
for i in range(cnt):
|
101 |
license[f"vehicle {i + 1}"] = license_plate[i]
|
102 |
box[f"vehicle {i + 1}"] = rectangles[i]
|
103 |
+
pro[f"vehicle {i + 1}"] = scores[i]
|
104 |
|
105 |
+
response = jsonify({"result": result, "plate number": license, "coordinate": box, "score": pro})
|
106 |
|
107 |
response.status_code = 200
|
108 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
|
|
114 |
result = "None"
|
115 |
license = {}
|
116 |
box = {}
|
117 |
+
pro = {}
|
118 |
|
119 |
content = request.get_json()
|
120 |
|
|
|
126 |
image = cv2.resize(image, (1024, 640))
|
127 |
except:
|
128 |
result = "Failed to open file1"
|
129 |
+
response = jsonify({"result": result, "plate number": license, "coordinate": box, "score": pro})
|
130 |
|
131 |
response.status_code = 200
|
132 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
|
|
136 |
img_byte = mat_to_bytes(image)
|
137 |
|
138 |
recog_array = (c_int * 1024)() # Assuming a maximum of 256 rectangles
|
139 |
+
score_array = (c_float * 1024)() # Assuming a maximum of 256 rectangles
|
140 |
|
141 |
license_plate_ptr = POINTER(c_char_p)()
|
142 |
cnt = getLicensePlate(img_byte, len(img_byte), byref(license_plate_ptr), recog_array)
|
|
|
145 |
rectangles = [
|
146 |
(recog_array[i * 4], recog_array[i * 4 + 1], recog_array[i * 4 + 2], recog_array[i * 4 + 3])
|
147 |
for i in range(cnt)]
|
148 |
+
scores = [score_array[i] for i in range(cnt)]
|
149 |
|
150 |
freeLicenseResults(license_plate_ptr, cnt)
|
151 |
|
152 |
# print("number: ", cnt, rectangles, license_plate)
|
153 |
if cnt == 0:
|
154 |
result = "Nothing Detected !"
|
155 |
+
response = jsonify({"result": result, "plate number": license, "coordinate": box, "score": pro})
|
156 |
|
157 |
response.status_code = 200
|
158 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
|
|
162 |
for i in range(cnt):
|
163 |
license[f"vehicle {i + 1}"] = license_plate[i]
|
164 |
box[f"vehicle {i + 1}"] = rectangles[i]
|
165 |
+
pro[f"vehicle {i + 1}"] = scores[i]
|
166 |
|
167 |
+
response = jsonify({"result": result, "plate number": license, "coordinate": box, "score": pro})
|
168 |
|
169 |
response.status_code = 200
|
170 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|