5
0
mirror of https://github.com/sml2h3/ddddocr.git synced 2025-05-04 09:49:47 +08:00

增加滑块小图非png透明图的识别选项

This commit is contained in:
sml2h3 2022-01-23 12:31:09 +08:00
parent 3d9053c3b4
commit c55f56b54c
3 changed files with 22 additions and 13 deletions

View File

@ -32,8 +32,12 @@ class DdddOcr(object):
if show_ad: if show_ad:
print("欢迎使用ddddocr本项目专注带动行业内卷个人博客:wenanzhe.com") print("欢迎使用ddddocr本项目专注带动行业内卷个人博客:wenanzhe.com")
print("训练数据支持来源于:http://146.56.204.113:19199/preview") print("训练数据支持来源于:http://146.56.204.113:19199/preview")
print("爬虫框架feapder可快速一键接入快速开启爬虫之旅https://github.com/Boris-code/feapder")
if det: if det:
ocr = False
print("开启det后自动关闭ocr")
self.__graph_path = os.path.join(os.path.dirname(__file__), 'common_det.onnx') self.__graph_path = os.path.join(os.path.dirname(__file__), 'common_det.onnx')
self.__charset = [] self.__charset = []
if ocr: if ocr:
@ -1639,9 +1643,14 @@ class DdddOcr(object):
end_x = x end_x = x
return image.crop([starttx, startty, end_x, end_y]), startty return image.crop([starttx, startty, end_x, end_y]), startty
def slide_match(self, target_bytes: bytes = None, background_bytes: bytes = None): def slide_match(self, target_bytes: bytes = None, simple_target=False, background_bytes: bytes = None):
target, target_y = self.get_target(target_bytes) if simple_target:
target = cv2.cvtColor(np.asarray(target), cv2.COLOR_RGBA2GRAY) 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) background = cv2.imdecode(np.frombuffer(background_bytes, np.uint8), cv2.IMREAD_GRAYSCALE)
res = cv2.matchTemplate(background, target, cv2.TM_CCOEFF) res = cv2.matchTemplate(background, target, cv2.TM_CCOEFF)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)

View File

@ -14,7 +14,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
setup( setup(
name="ddddocr", name="ddddocr",
version="1.4.0", version="1.4.1",
author="sml2h3", author="sml2h3",
description="带带弟弟OCR", description="带带弟弟OCR",
long_description=long_description, long_description=long_description,

18
test.py
View File

@ -1,18 +1,18 @@
import ddddocr import ddddocr
# 识别 # # 识别
ocr = ddddocr.DdddOcr(old=True) # ocr = ddddocr.DdddOcr(old=True)
#
with open('test.jpg', 'rb') as f: # with open('test.jpg', 'rb') as f:
img_bytes = f.read() # img_bytes = f.read()
#
res = ocr.classification(img_bytes) # res = ocr.classification(img_bytes)
print(res) # print(res)
# 目标检测 # 目标检测
det = ddddocr.DdddOcr(det=True) det = ddddocr.DdddOcr(det=True)
with open('test.jpg', 'rb') as f: with open('微信图片_20220123122537.jpg', 'rb') as f:
img_bytes = f.read() img_bytes = f.read()
res = det.detection(img_bytes) res = det.detection(img_bytes)