From ec012b7d2b915db24cd8b23f723bf18dfe75b7d6 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 16 十二月 2024 11:13:31 +0800 Subject: [PATCH] 网页代码修改/结构调整 --- utils/ths_ocr_util.py | 32 ++++++++++++++++++++++++-------- 1 files changed, 24 insertions(+), 8 deletions(-) diff --git a/utils/ths_ocr_util.py b/utils/ths_ocr_util.py index 9c9ea66..ace41d4 100644 --- a/utils/ths_ocr_util.py +++ b/utils/ths_ocr_util.py @@ -18,7 +18,11 @@ 璇嗗埆鍚岃姳椤轰唬鐮� :return: """ - hwnd = ths_util.get_ths_main_content_hwnd() + start_time = time.time() + time_use_list = [] + hwnd = ths_util.get_ths_main_content_hwnd_cached() + time_use_list.append(("鑾峰彇鍙ユ焺", time.time() - start_time)) + start_time = time.time() if not hwnd: raise Exception("鐪嬬洏椤甸潰鍙ユ焺鏈幏鍙栧埌") # 鍙ユ焺鎴浘 @@ -27,26 +31,38 @@ # 鏍煎紡涓�:锛堜笂杈硅窛,瀹藉害,楂樺害,缂╂斁鍊嶆暟锛� rect_ = setting.get_ths_auto_code_rect() + + time_use_list.append(("鑾峰彇閰嶇疆鍙傛暟", time.time() - start_time)) + start_time = time.time() # 娴嬭瘯 # if len(rect_) > 3: # scale = rect_[3] width = int((rect[2] - rect[0]) * scale) left = width - rect_[1] img = win32_util.window_capture(hwnd, (left, rect_[0], width - 1, rect_[0] + rect_[2]), scale, always_save) - if int(time.time()) % 5 == 0: - cv2.imwrite(f"test2.png", opencv_util.gray_img(img)) - if always_save: - cv2.imwrite(f"test22.png", opencv_util.gray_img(img)) + time_use_list.append(("鎴浘", time.time() - start_time)) + start_time = time.time() + if always_save: + cv2.imwrite(f"test_clip_gray.png", opencv_util.gray_img(img)) clip_img, details = opencv_util.clip_ths_code_area(img) + if always_save: + cv2.imwrite(f"test_clip_gray_clip.png", clip_img) + + time_use_list.append(("鍒嗗壊", time.time() - start_time)) start_time = time.time() code = ocr_util.recognize_code(clip_img) - use_time = round((time.time() - start_time) * 1000) + time_use_list.append(("璇嗗埆", time.time() - start_time)) + start_time = time.time() if code is None: code = ocr_util.recognize_code(img) + time_use_list.append(("鍐嶆璇嗗埆", time.time() - start_time)) + start_time = time.time() if code != last_ocr_code[0]: print("淇濆瓨鍥剧墖", code) - debug_logger.info(f"浠g爜璇嗗埆缁撴灉:{code} 璇嗗埆鏃堕棿锛歿use_time}ms") + msg = " ".join( [f"{x[0]}:{int(x[1]*1000)}ms" for x in time_use_list]) + debug_logger.info(f"浠g爜璇嗗埆缁撴灉:{code} {msg}") last_ocr_code[0] = code - cv2.imwrite(f"datas/test/{code}.png", opencv_util.gray_img(img)) + if always_save: + cv2.imwrite(f"datas/test/{code}.png", opencv_util.gray_img(img)) return code -- Gitblit v1.8.0