|
@@ -0,0 +1,210 @@
|
|
|
|
+import base64
|
|
|
|
+import unittest
|
|
|
|
+from dataclasses import dataclass
|
|
|
|
+from pathlib import Path
|
|
|
|
+
|
|
|
|
+import requests
|
|
|
|
+
|
|
|
|
+url = 'http://192.168.199.107:18088'
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+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': image_type})
|
|
|
|
+ print(r.json())
|
|
|
|
+ return r.json()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@dataclass
|
|
|
|
+class ResultItem:
|
|
|
|
+ status: str
|
|
|
|
+ orientation: int
|
|
|
|
+ name: str
|
|
|
|
+ id: str
|
|
|
|
+ ethnicity: str
|
|
|
|
+ gender: str
|
|
|
|
+ birthday: str
|
|
|
|
+ address: str
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class TestIdCard0(unittest.TestCase):
|
|
|
|
+ def _helper(self, image_path, item: ResultItem):
|
|
|
|
+ root = Path(__file__).parent
|
|
|
|
+ image_path = str(root / image_path)
|
|
|
|
+ r = send_request(image_path, '0')
|
|
|
|
+ self.assertEqual(item, ResultItem(status=r['status'],
|
|
|
|
+ orientation=r['result']['orientation'],
|
|
|
|
+ name=r['result']['name']['text'],
|
|
|
|
+ id=r['result']['id']['text'],
|
|
|
|
+ ethnicity=r['result']['ethnicity']['text'],
|
|
|
|
+ gender=r['result']['gender']['text'],
|
|
|
|
+ birthday=r['result']['birthday']['text'],
|
|
|
|
+ address=r['result']['address']['text']
|
|
|
|
+ ))
|
|
|
|
+
|
|
|
|
+ def test_01_0(self):
|
|
|
|
+ image_path = '../images/all/0/01_0.jpg'
|
|
|
|
+ self._helper(image_path, ResultItem(status='000',
|
|
|
|
+ orientation=0,
|
|
|
|
+ name='左翔宇',
|
|
|
|
+ id='220204199910123017',
|
|
|
|
+ ethnicity='蒙古',
|
|
|
|
+ gender='男',
|
|
|
|
+ birthday='1999年10月12日',
|
|
|
|
+ address='吉林省吉林市船营区鑫安小区2-6-60号'))
|
|
|
|
+
|
|
|
|
+ def test_02_90(self):
|
|
|
|
+ image_path = '../images/all/0/02_90.jpg'
|
|
|
|
+ self._helper(image_path, ResultItem(status='000',
|
|
|
|
+ orientation=1,
|
|
|
|
+ name='张开天',
|
|
|
|
+ id='622301199710247376',
|
|
|
|
+ ethnicity='汉',
|
|
|
|
+ gender='男',
|
|
|
|
+ birthday='1997年10月24日',
|
|
|
|
+ address='甘肃省武威市凉州区九墩乡平乐村四组23号'))
|
|
|
|
+
|
|
|
|
+ def test_03_0(self):
|
|
|
|
+ image_path = '../images/all/0/03_0(minor).jpg'
|
|
|
|
+ self._helper(image_path, ResultItem(status='000',
|
|
|
|
+ orientation=0,
|
|
|
|
+ name='张荣军',
|
|
|
|
+ id='654122199712254017',
|
|
|
|
+ ethnicity='锡伯',
|
|
|
|
+ gender='男',
|
|
|
|
+ birthday='1997年12月25日',
|
|
|
|
+ address='新疆察布查尔锡伯自治县堆齐牛录乡杜林拜北街西二巷29号'))
|
|
|
|
+
|
|
|
|
+ def test_04_180(self):
|
|
|
|
+ image_path = '../images/all/0/04_180.jpg'
|
|
|
|
+ self._helper(image_path, ResultItem(status='000',
|
|
|
|
+ orientation=2,
|
|
|
|
+ name='方势文',
|
|
|
|
+ id='360428199610220096',
|
|
|
|
+ ethnicity='汉',
|
|
|
|
+ gender='男',
|
|
|
|
+ birthday='1996年10月22日',
|
|
|
|
+ address='江西省九江市都昌县都昌镇沿湖路238号'))
|
|
|
|
+
|
|
|
|
+ def test_addreess(self):
|
|
|
|
+ image_path = '../images/all/0/address.png'
|
|
|
|
+ self._helper(image_path, ResultItem(status='000',
|
|
|
|
+ orientation=0,
|
|
|
|
+ name='王磊',
|
|
|
|
+ id='150203199308092110',
|
|
|
|
+ ethnicity='汉',
|
|
|
|
+ gender='男',
|
|
|
|
+ birthday='1993年08月09日',
|
|
|
|
+ address='内蒙古包头市昆都仑区昆河镇刘二圪梁村393号'))
|
|
|
|
+
|
|
|
|
+ def test_long_name(self):
|
|
|
|
+ image_path = '../images/all/0/long_name.png'
|
|
|
|
+ self._helper(image_path, ResultItem(status='000',
|
|
|
|
+ orientation=0,
|
|
|
|
+ name='叶干别尔地.坎吉巴依',
|
|
|
|
+ id='653024199812031239',
|
|
|
|
+ ethnicity='柯尔克孜',
|
|
|
|
+ gender='男',
|
|
|
|
+ birthday='1998年12月03日',
|
|
|
|
+ address='南京市栖霞区文苑路1号'))
|
|
|
|
+
|
|
|
|
+ def test_mohu(self):
|
|
|
|
+ image_path = '../images/all/0/mohu.jpg'
|
|
|
|
+ self._helper(image_path, ResultItem(status='000',
|
|
|
|
+ orientation=0,
|
|
|
|
+ name='田浩',
|
|
|
|
+ id='640221199702060618',
|
|
|
|
+ ethnicity='汉',
|
|
|
|
+ gender='男',
|
|
|
|
+ birthday='1997年02月06日',
|
|
|
|
+ address='宁夏平罗县黄渠桥镇侯家梁村二队29'))
|
|
|
|
+
|
|
|
|
+ def test_mohu_90(self):
|
|
|
|
+ image_path = '../images/all/0/mohu_90.jpg'
|
|
|
|
+ self._helper(image_path, ResultItem(status='000',
|
|
|
|
+ orientation=1,
|
|
|
|
+ name='王睿',
|
|
|
|
+ id='421202199506051096',
|
|
|
|
+ ethnicity='汉',
|
|
|
|
+ gender='男',
|
|
|
|
+ birthday='1995年06月05日',
|
|
|
|
+ address='湖北省咸宁市咸安区温泉淦河大道12号'))
|
|
|
|
+
|
|
|
|
+ def test_small(self):
|
|
|
|
+ image_path = '../images/all/0/small.jpg'
|
|
|
|
+ self._helper(image_path, ResultItem(status='000',
|
|
|
|
+ orientation=0,
|
|
|
|
+ name='董建',
|
|
|
|
+ id='654121199802042775',
|
|
|
|
+ ethnicity='回',
|
|
|
|
+ gender='男',
|
|
|
|
+ birthday='1998年02月04日',
|
|
|
|
+ address='新疆伊宁县愉群翁乡伊克翁村216号'))
|
|
|
|
+
|
|
|
|
+ def test_special1(self):
|
|
|
|
+ image_path = '../images/all/0/special1.jpg'
|
|
|
|
+ self._helper(image_path, ResultItem(status='000',
|
|
|
|
+ orientation=0,
|
|
|
|
+ name='宋宝磊',
|
|
|
|
+ id='150430199905051616',
|
|
|
|
+ ethnicity='汉',
|
|
|
|
+ gender='男',
|
|
|
|
+ birthday='1999年05月05日',
|
|
|
|
+ address='内蒙古赤峰市敖汉旗四家子镇林家地村唐坊沟七组'))
|
|
|
|
+
|
|
|
|
+ def test_special2(self):
|
|
|
|
+ image_path = '../images/all/0/special2.jpg'
|
|
|
|
+ self._helper(image_path, ResultItem(status='000',
|
|
|
|
+ orientation=0,
|
|
|
|
+ name='彭贤端',
|
|
|
|
+ id='450922199412083669',
|
|
|
|
+ ethnicity='汉',
|
|
|
|
+ gender='女',
|
|
|
|
+ birthday='1994年12月08日',
|
|
|
|
+ address='广西陆川县清湖镇塘寨村新屋队62号'))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class TestIdCard1(unittest.TestCase):
|
|
|
|
+ def _helper1(self, image_path, sta, orient, date):
|
|
|
|
+ root = Path(__file__).parent
|
|
|
|
+ image_path = str(root / image_path)
|
|
|
|
+ r = send_request(image_path, '1')
|
|
|
|
+ self.assertEqual(sta, r['status'], f'{image_path}status case error')
|
|
|
|
+ self.assertEqual(orient, r['result']['orientation'], f'{image_path} address case error')
|
|
|
|
+ self.assertEqual(date, r['result']['expire_date']['text'], f'{image_path} expire_date case error')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def test_01_0(self):
|
|
|
|
+ image_path = '../images/all/1/ 01_0.jpg'
|
|
|
|
+ self._helper1(image_path, '000', 0, '20220511-20410511')
|
|
|
|
+
|
|
|
|
+ def test_02_0(self):
|
|
|
|
+ image_path = '../images/all/1/ 02_0.jpg'
|
|
|
|
+ self._helper1(image_path, '000', 0, '20180531-20280531')
|
|
|
|
+
|
|
|
|
+ def test_03_180(self):
|
|
|
|
+ image_path = '../images/all/1/03_180.jpg'
|
|
|
|
+ self._helper1(image_path, '000', 2, '20170109-20270109')
|
|
|
|
+
|
|
|
|
+ def test_04_90(self):
|
|
|
|
+ image_path = '../images/all/1/04_90.jpg'
|
|
|
|
+ self._helper1(image_path, '000', 1, '20190715-20390715')
|
|
|
|
+
|
|
|
|
+ def test_05_270(self):
|
|
|
|
+ image_path = '../images/all/1/05-270.jpg'
|
|
|
|
+ self._helper1(image_path, '000', 0, '20140320-20240320')
|
|
|
|
+
|
|
|
|
+ def test_small(self):
|
|
|
|
+ image_path = '../images/all/1/small.png'
|
|
|
|
+ self._helper1(image_path, '000', 0, '20190620-20290620')
|
|
|
|
+
|
|
|
|
+ def test_special(self):
|
|
|
|
+ image_path = '../images/all/1/special.jpg'
|
|
|
|
+ self._helper1(image_path, '000', 0, '20190813-20290813')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
+ unittest.main()
|