new log, no plate still ocr

This commit is contained in:
sonnhh 2020-09-28 07:15:13 +00:00
parent 197c1b74c5
commit 63bc54a4ce
4 changed files with 20 additions and 19 deletions

39
app.py
View File

@ -83,18 +83,13 @@ def get_from_frame_automatic():
# cv2.imwrite("plate.jpg", Ilp)
Ilp, mode = plate_detect.run(img_np)
print("\t Mode:", mode)
if Ilp is None:
print("\t No plate found")
return make_automatic_res("", track_id, 0)
split_plate = mode == "square"
ocr_start_time = time.time()
ocr_result, elements = plate_ocr.run(mode, Ilp, "full", split_plate)
ocr_end_time = time.time()
print("\tOCR time:", ocr_end_time - ocr_start_time)
confidence = check_plate_quality(elements)
if confidence > 10 or confidence < 7:
@ -163,13 +158,10 @@ def get_from_vehicle():
# cv2.imwrite("plate.jpg", Ilp)
Ilps, modes = plate_detect.run2(img_np)
print("\t Mode:", mode)
if Ilps is None:
print("\t No plate found")
return make_automatic_res("", track_id, 0)
ocr_start_time = time.time()
longest = ''
longest_i = 0
for i, Ilp in enumerate(Ilps):
@ -177,7 +169,6 @@ def get_from_vehicle():
split_plate = mode == "square"
ocr_result, elements = plate_ocr.run(mode, Ilp, "full", split_plate)
ocr_end_time = time.time()
if len(ocr_result) > len(longest):
longest = ocr_result
longest_i = i
@ -185,8 +176,6 @@ def get_from_vehicle():
ocr_result = longest
Ilp = Ilps[longest_i]
print("\tOCR time:", ocr_end_time - ocr_start_time)
confidence = check_plate_quality(elements)
if confidence > 10 or confidence < 7:
print("\t [WARNING] Too long/short plate:", ocr_result)
@ -251,6 +240,7 @@ def get_from_plate():
print_current_time()
print (request.path)
start_time = time.time()
data = request.json
img64 = data.get("img64", "")
@ -268,6 +258,7 @@ def get_from_plate():
return {"ocr": ocr_result}
except Exception as ex:
print (ex)
return {"ocr": ""}
"""
@ -289,22 +280,28 @@ def get_from_frame():
try:
print_current_time()
print(request.path)
start_time = time.time()
data = request.json
img64 = data.get("img64", "")
if img64 == "": return {"ocr": "", "plate": ""}
mode = data.get("mode", "long") # ["long", "square"]
client_mode = data.get("mode", "long") # ["long", "square"]
display = data.get("display", "full") # ["full", "row2"]
img_binary = extract_from_base64_str(img64)
img_np = imageio.imread(io.BytesIO(img_binary))
Ilp, mode = plate_detect.run(img_np)
# detect_stop = time.time()
# print "Detect time:", detect_stop - detect_start
if Ilp is None: return {"ocr": "", "plate": ""}
print("\tMode:", mode)
split_plate = mode == "square"
ocr_result, elements = plate_ocr.run(mode, Ilp, display, split_plate)
Ilp, mode = plate_detect.run(img_np)
if Ilp is None:
Ilp = cv2.cvtColor(img_np, cv2.COLOR_RGB2GRAY)
Ilp = cv2.cvtColor(Ilp, cv2.COLOR_GRAY2BGR)
ocr_result, elements = plate_ocr.run(client_mode, Ilp, display, False)
end_time = time.time()
print("\tTotal time:", end_time - start_time)
return {"ocr": ocr_result, "plate": img64}
ocr_result, elements = plate_ocr.run(mode, Ilp, display, False)
plate_result = base64.b64encode(cv2.imencode(".jpg", Ilp)[1]).decode("utf-8")
end_time = time.time()
@ -315,4 +312,8 @@ def get_from_frame():
}
except Exception as ex:
return {
"ocr": "",
"plate": ""
}
print(ex)

BIN
app.pyc

Binary file not shown.

Binary file not shown.

Binary file not shown.