Browse Source

add test case for expire date

Zhang Li 2 years ago
parent
commit
dfe720352c
3 changed files with 22 additions and 4 deletions
  1. 10 0
      core/parser.py
  2. BIN
      images/long-exp.png
  3. 12 4
      testing/ocr_test.py

+ 10 - 0
core/parser.py

@@ -181,6 +181,11 @@ class FrontParser(Parser):
             res = re.findall('\d{8}\-\d{8}', txt)
             if res:
                 self.res["expire_date"] = RecItem(res[0], conf)
+                break
+            res = re.findall('\d{8}\-长期', txt)
+            if res:
+                self.res["expire_date"] = RecItem(res[0], conf)
+                break
 
 
     def predict_name(self):
@@ -236,6 +241,11 @@ class BackParser(Parser):
             res = re.findall('\d{8}\-\d{8}', txt)
             if res:
                 self.res["expire_date"] = RecItem(res[0], conf)
+                break
+            res = re.findall('\d{8}\-长期', txt)
+            if res:
+                self.res["expire_date"] = RecItem(res[0], conf)
+                break
 
     @property
     def confidence(self):

BIN
images/long-exp.png


+ 12 - 4
testing/ocr_test.py

@@ -5,10 +5,10 @@ import requests
 url = 'http://localhost:8080'
 
 
-def send_request(image_path):
+def send_request(image_path, image_type):
     with open(image_path, 'rb') as f:
         img_str: str = base64.encodebytes(f.read()).decode('utf-8')
-        r = requests.post(f'{url}/ocr_system/idcard', json={'image': img_str, 'image_type': '0'})
+        r = requests.post(f'{url}/ocr_system/idcard', json={'image': img_str, 'image_type': image_type})
         return r.json()
 
 
@@ -18,13 +18,21 @@ class TestIdCardOcr(unittest.TestCase):
 
     def test_front_180(self):
         image_path = './images/front-180.png'
-        r = send_request(image_path)
+        r = send_request(image_path, '0')
         self.assertEqual(r['status'], '000', 'status case error')
         self.assertEqual(r['result']['orientation'], 2, 'orientation case error')
 
     def test_front_270(self):
         image_path = './images/front-270.png'
-        r = send_request(image_path)
+        r = send_request(image_path, '0')
         self.assertEqual(r['status'], '000', 'status case error')
         self.assertEqual(r['result']['orientation'], 3, 'orientation case error')
 
+    def test_long_exp(self):
+        image_path = './images/long-exp.png'
+        r = send_request(image_path, '1')
+        self.assertEqual(r['status'], '000', 'status case error')
+        self.assertEqual(r['result']['expire_date']['text'], '20180227-长期', 'expire date case error')
+
+
+