new log, no plate still ocr
This commit is contained in:
parent
197c1b74c5
commit
63bc54a4ce
39
app.py
39
app.py
|
@ -83,18 +83,13 @@ def get_from_frame_automatic():
|
||||||
|
|
||||||
# cv2.imwrite("plate.jpg", Ilp)
|
# cv2.imwrite("plate.jpg", Ilp)
|
||||||
Ilp, mode = plate_detect.run(img_np)
|
Ilp, mode = plate_detect.run(img_np)
|
||||||
print("\t Mode:", mode)
|
|
||||||
|
|
||||||
if Ilp is None:
|
if Ilp is None:
|
||||||
print("\t No plate found")
|
|
||||||
return make_automatic_res("", track_id, 0)
|
return make_automatic_res("", track_id, 0)
|
||||||
|
|
||||||
split_plate = mode == "square"
|
split_plate = mode == "square"
|
||||||
|
|
||||||
ocr_start_time = time.time()
|
|
||||||
ocr_result, elements = plate_ocr.run(mode, Ilp, "full", split_plate)
|
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)
|
confidence = check_plate_quality(elements)
|
||||||
if confidence > 10 or confidence < 7:
|
if confidence > 10 or confidence < 7:
|
||||||
|
@ -163,13 +158,10 @@ def get_from_vehicle():
|
||||||
|
|
||||||
# cv2.imwrite("plate.jpg", Ilp)
|
# cv2.imwrite("plate.jpg", Ilp)
|
||||||
Ilps, modes = plate_detect.run2(img_np)
|
Ilps, modes = plate_detect.run2(img_np)
|
||||||
print("\t Mode:", mode)
|
|
||||||
|
|
||||||
if Ilps is None:
|
if Ilps is None:
|
||||||
print("\t No plate found")
|
|
||||||
return make_automatic_res("", track_id, 0)
|
return make_automatic_res("", track_id, 0)
|
||||||
|
|
||||||
ocr_start_time = time.time()
|
|
||||||
longest = ''
|
longest = ''
|
||||||
longest_i = 0
|
longest_i = 0
|
||||||
for i, Ilp in enumerate(Ilps):
|
for i, Ilp in enumerate(Ilps):
|
||||||
|
@ -177,7 +169,6 @@ def get_from_vehicle():
|
||||||
split_plate = mode == "square"
|
split_plate = mode == "square"
|
||||||
|
|
||||||
ocr_result, elements = plate_ocr.run(mode, Ilp, "full", split_plate)
|
ocr_result, elements = plate_ocr.run(mode, Ilp, "full", split_plate)
|
||||||
ocr_end_time = time.time()
|
|
||||||
if len(ocr_result) > len(longest):
|
if len(ocr_result) > len(longest):
|
||||||
longest = ocr_result
|
longest = ocr_result
|
||||||
longest_i = i
|
longest_i = i
|
||||||
|
@ -185,8 +176,6 @@ def get_from_vehicle():
|
||||||
ocr_result = longest
|
ocr_result = longest
|
||||||
Ilp = Ilps[longest_i]
|
Ilp = Ilps[longest_i]
|
||||||
|
|
||||||
print("\tOCR time:", ocr_end_time - ocr_start_time)
|
|
||||||
|
|
||||||
confidence = check_plate_quality(elements)
|
confidence = check_plate_quality(elements)
|
||||||
if confidence > 10 or confidence < 7:
|
if confidence > 10 or confidence < 7:
|
||||||
print("\t [WARNING] Too long/short plate:", ocr_result)
|
print("\t [WARNING] Too long/short plate:", ocr_result)
|
||||||
|
@ -251,6 +240,7 @@ def get_from_plate():
|
||||||
print_current_time()
|
print_current_time()
|
||||||
print (request.path)
|
print (request.path)
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
data = request.json
|
data = request.json
|
||||||
|
|
||||||
img64 = data.get("img64", "")
|
img64 = data.get("img64", "")
|
||||||
|
@ -268,6 +258,7 @@ def get_from_plate():
|
||||||
return {"ocr": ocr_result}
|
return {"ocr": ocr_result}
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print (ex)
|
print (ex)
|
||||||
|
return {"ocr": ""}
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -289,22 +280,28 @@ def get_from_frame():
|
||||||
try:
|
try:
|
||||||
print_current_time()
|
print_current_time()
|
||||||
print(request.path)
|
print(request.path)
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
data = request.json
|
data = request.json
|
||||||
img64 = data.get("img64", "")
|
img64 = data.get("img64", "")
|
||||||
if img64 == "": return {"ocr": "", "plate": ""}
|
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"]
|
display = data.get("display", "full") # ["full", "row2"]
|
||||||
|
|
||||||
img_binary = extract_from_base64_str(img64)
|
img_binary = extract_from_base64_str(img64)
|
||||||
img_np = imageio.imread(io.BytesIO(img_binary))
|
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"
|
Ilp, mode = plate_detect.run(img_np)
|
||||||
ocr_result, elements = plate_ocr.run(mode, Ilp, display, split_plate)
|
|
||||||
|
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")
|
plate_result = base64.b64encode(cv2.imencode(".jpg", Ilp)[1]).decode("utf-8")
|
||||||
|
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
|
@ -315,4 +312,8 @@ def get_from_frame():
|
||||||
}
|
}
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
return {
|
||||||
|
"ocr": "",
|
||||||
|
"plate": ""
|
||||||
|
}
|
||||||
print(ex)
|
print(ex)
|
||||||
|
|
BIN
plate_detect.pyc
BIN
plate_detect.pyc
Binary file not shown.
BIN
plate_ocr.pyc
BIN
plate_ocr.pyc
Binary file not shown.
Reference in New Issue
Block a user