diff --git a/app.py b/app.py index afb14e6..f3dce78 100644 --- a/app.py +++ b/app.py @@ -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) diff --git a/app.pyc b/app.pyc index ee074bb..a9bbed8 100644 Binary files a/app.pyc and b/app.pyc differ diff --git a/plate_detect.pyc b/plate_detect.pyc index cc9c192..9aaa95a 100644 Binary files a/plate_detect.pyc and b/plate_detect.pyc differ diff --git a/plate_ocr.pyc b/plate_ocr.pyc index 79cd897..add097d 100644 Binary files a/plate_ocr.pyc and b/plate_ocr.pyc differ