Zhang Li %!s(int64=2) %!d(string=hai) anos
pai
achega
53d492f53c
Modificáronse 3 ficheiros con 23 adicións e 4 borrados
  1. 1 0
      core/direction.py
  2. 3 0
      core/ocr.py
  3. 19 4
      core/parser.py

+ 1 - 0
core/direction.py

@@ -8,6 +8,7 @@ from paddleocr import PaddleOCR
 
 
 @dataclass
+# 角度检测器
 class AngleDetector(object):
     ocr: PaddleOCR
 

+ 3 - 0
core/ocr.py

@@ -12,9 +12,12 @@ class IdCardOcr:
     ocr: PaddleOCR
     angle_detector: AngleDetector
 
+    # 检测
     def predict(self, image: np.ndarray, image_type: str = '0'):
         # image, angle = self._pre_process(image)
+        # 识别出的 => 字段、置信度、(字段,置信度)
         txts, confs, result = self._ocr(image)
+        # 角度
         angle = self.angle_detector.detect_angle(image, result)
 
 

+ 19 - 4
core/parser.py

@@ -114,16 +114,29 @@ class FrontParser(Parser):
         raise Exception('无法识别')
 
     def national(self):
-        # 性别女民族汉
-        if len(self.result[1]) == 1:
-            txt = self.result[1][0].txt
-            conf = self.result[1][0].conf
+        """
+        性别 <-- id
+        民族汉
+        """
+
+        for nation in self.result[1]:
+            txt = nation.txt
+            conf = nation.conf
             res = re.findall(".*民族[\u4e00-\u9fa5]+", txt)
 
             if len(res) > 0:
                 self.res["ethnicity"] = RecItem(res[0].split("族")[-1], conf)
                 return
 
+        # if len(self.result[1]) == 1:
+        #     txt = self.result[1][0].txt
+        #     conf = self.result[1][0].conf
+        #     res = re.findall(".*民族[\u4e00-\u9fa5]+", txt)
+        #
+        #     if len(res) > 0:
+        #         self.res["ethnicity"] = RecItem(res[0].split("族")[-1], conf)
+        #         return
+
     def address(self):
         """
         身份证地址
@@ -165,6 +178,8 @@ class FrontParser(Parser):
         raise Exception('无法识别')
 
     def split_addr(self):
+
+        print(self.res['address'].text, '=======')
         conf = self.res["address"].confidence
         df = cpca.transform([self.res["address"].text])
         # print(df)