|
@@ -10,7 +10,7 @@ from paddleocr import PaddleOCR
|
|
|
from core.line_parser import LineParser
|
|
|
|
|
|
|
|
|
-class Directoin(Enum):
|
|
|
+class Direction(Enum):
|
|
|
TOP = 0
|
|
|
RIGHT = 1
|
|
|
BOTTOM = 2
|
|
@@ -21,7 +21,7 @@ class Directoin(Enum):
|
|
|
# 父类
|
|
|
class OcrAnchor(object):
|
|
|
# 输入识别anchor的名字, 如身份证号
|
|
|
- def __init__(self, name: str, d: Directoin):
|
|
|
+ def __init__(self, name: str, d: Direction):
|
|
|
self.name = name
|
|
|
# anchor位置
|
|
|
self.direction = d
|
|
@@ -51,10 +51,10 @@ class OcrAnchor(object):
|
|
|
return 1 if anchor[1] < c[1] else 3
|
|
|
|
|
|
self.direction_funcs = {
|
|
|
- Directoin.TOP: t_func,
|
|
|
- Directoin.BOTTOM: b_func,
|
|
|
- Directoin.LEFT: l_func,
|
|
|
- Directoin.RIGHT: r_func,
|
|
|
+ Direction.TOP: t_func,
|
|
|
+ Direction.BOTTOM: b_func,
|
|
|
+ Direction.LEFT: l_func,
|
|
|
+ Direction.RIGHT: r_func,
|
|
|
}
|
|
|
|
|
|
# 获取中心区域坐标 -> (x, y)
|
|
@@ -116,7 +116,7 @@ class OcrAnchor(object):
|
|
|
|
|
|
# 子类1 人像面
|
|
|
class FrontSideAnchor(OcrAnchor):
|
|
|
- def __init__(self, name: str, d: Directoin):
|
|
|
+ def __init__(self, name: str, d: Direction):
|
|
|
super(FrontSideAnchor, self).__init__(name, d)
|
|
|
|
|
|
def is_anchor(self, txt, box) -> bool:
|
|
@@ -131,7 +131,7 @@ class FrontSideAnchor(OcrAnchor):
|
|
|
|
|
|
# 子类2 国徽面
|
|
|
class BackSideAnchor(OcrAnchor):
|
|
|
- def __init__(self, name: str, d: Directoin):
|
|
|
+ def __init__(self, name: str, d: Direction):
|
|
|
super(BackSideAnchor, self).__init__(name, d)
|
|
|
|
|
|
def is_anchor(self, txt, box) -> bool:
|
|
@@ -174,8 +174,8 @@ class AngleDetector(object):
|
|
|
image_type = int(image_type)
|
|
|
|
|
|
# 初始化anchor对象
|
|
|
- ocr_anchor = BackSideAnchor('有效期', Directoin.BOTTOM) if image_type != 0 else FrontSideAnchor('身份证号',
|
|
|
- Directoin.BOTTOM)
|
|
|
+ ocr_anchor = BackSideAnchor('有效期', Direction.BOTTOM) if image_type != 0 else FrontSideAnchor('身份证号',
|
|
|
+ Direction.BOTTOM)
|
|
|
result = self.ocr.ocr(img, cls=True)
|
|
|
|
|
|
try:
|