From c55f56b54cd89fa9bec7da4ee95dfd2724812cb9 Mon Sep 17 00:00:00 2001 From: sml2h3 Date: Sun, 23 Jan 2022 12:31:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=BB=91=E5=9D=97=E5=B0=8F?= =?UTF-8?q?=E5=9B=BE=E9=9D=9Epng=E9=80=8F=E6=98=8E=E5=9B=BE=E7=9A=84?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddddocr/__init__.py | 15 ++++++++++++--- setup.py | 2 +- test.py | 18 +++++++++--------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/ddddocr/__init__.py b/ddddocr/__init__.py index 1095707..dfc46ca 100644 --- a/ddddocr/__init__.py +++ b/ddddocr/__init__.py @@ -32,8 +32,12 @@ class DdddOcr(object): if show_ad: print("欢迎使用ddddocr,本项目专注带动行业内卷,个人博客:wenanzhe.com") print("训练数据支持来源于:http://146.56.204.113:19199/preview") + print("爬虫框架feapder可快速一键接入,快速开启爬虫之旅:https://github.com/Boris-code/feapder") + if det: + ocr = False + print("开启det后自动关闭ocr") self.__graph_path = os.path.join(os.path.dirname(__file__), 'common_det.onnx') self.__charset = [] if ocr: @@ -1639,9 +1643,14 @@ class DdddOcr(object): end_x = x return image.crop([starttx, startty, end_x, end_y]), startty - def slide_match(self, target_bytes: bytes = None, background_bytes: bytes = None): - target, target_y = self.get_target(target_bytes) - target = cv2.cvtColor(np.asarray(target), cv2.COLOR_RGBA2GRAY) + def slide_match(self, target_bytes: bytes = None, simple_target=False, background_bytes: bytes = None): + if simple_target: + target, target_y = self.get_target(target_bytes) + target = cv2.cvtColor(np.asarray(target), cv2.COLOR_RGBA2GRAY) + else: + target = cv2.imdecode(np.frombuffer(target_bytes, np.uint8), cv2.IMREAD_GRAYSCALE) + target_y = 0 + background = cv2.imdecode(np.frombuffer(background_bytes, np.uint8), cv2.IMREAD_GRAYSCALE) res = cv2.matchTemplate(background, target, cv2.TM_CCOEFF) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) diff --git a/setup.py b/setup.py index 78796de..51b31f4 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ with open("README.md", "r", encoding="utf-8") as fh: setup( name="ddddocr", - version="1.4.0", + version="1.4.1", author="sml2h3", description="带带弟弟OCR", long_description=long_description, diff --git a/test.py b/test.py index 8208c97..6f8fd89 100644 --- a/test.py +++ b/test.py @@ -1,18 +1,18 @@ import ddddocr -# 识别 -ocr = ddddocr.DdddOcr(old=True) - -with open('test.jpg', 'rb') as f: - img_bytes = f.read() - -res = ocr.classification(img_bytes) -print(res) +# # 识别 +# ocr = ddddocr.DdddOcr(old=True) +# +# with open('test.jpg', 'rb') as f: +# img_bytes = f.read() +# +# res = ocr.classification(img_bytes) +# print(res) # 目标检测 det = ddddocr.DdddOcr(det=True) -with open('test.jpg', 'rb') as f: +with open('微信图片_20220123122537.jpg', 'rb') as f: img_bytes = f.read() res = det.detection(img_bytes)