123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- import unittest
- import base64
- from dataclasses import dataclass
- from pathlib import Path
- import requests
- # url = 'http://localhost:8080'
- url = 'http://192.168.199.249:38811'
- # header = {
- # 'Authorization': 'Bearer 9679c2b3-b90b-4029-a3c7-f347b4d242f7'
- # }
- # 带线框识别比较差 例:6.27_02.png
- def send_request(image_path, image_type='0'):
- with open(image_path, 'rb') as f:
- img_str: str = base64.encodebytes(f.read()).decode('utf-8')
- r = requests.post(f'{url}/ocr_system/regbook', json={'image': img_str, 'image_type': image_type})
- print(r.json())
- return r.json()
- @dataclass
- class ResultItem0:
- status: str
- orientation: int
- name: str
- id: str
- gender: str
- birthplace: str
- native_place: str
- blood_type: str
- religion: str
- @dataclass
- class ResultItem1:
- status: str
- orientation: int
- type: str
- address: str
- class TestSchoolCertOcr(unittest.TestCase):
- def _helper0(self, image_path, item: ResultItem0, image_type='0'):
- root = Path(__file__).parent
- image_path = str(root / image_path)
- r = send_request(image_path, image_type)
- self.assertEqual(item, ResultItem0(status=r['status'],
- orientation=r['result']['orientation'],
- name=r['result']['name']['text'],
- id=r['result']['id']['text'],
- gender=r['result']['gender']['text'],
- birthplace=r['result']['birthplace']['text'],
- native_place=r['result']['native_place']['text'],
- blood_type=r['result']['blood_type']['text'],
- religion=r['result']['religion']['text']
- ))
- def _helper1(self, image_path, item: ResultItem1, image_type='1'):
- root = Path(__file__).parent
- image_path = str(root / image_path)
- r = send_request(image_path, image_type)
- self.assertEqual(item, ResultItem1(status=r['status'],
- orientation=r['result']['orientation'],
- type=r['result']['type']['text'],
- address=r['result']['address']['text']
- ))
- # 0测试
- # 方向、专业识别错误
- def test_0_01(self):
- image_path = '../images/all/0/01.jpeg'
- self._helper0(image_path, ResultItem0(status='000',
- orientation=0,
- name='孙也桐',
- id='230125199603270066',
- gender='女',
- birthplace='黑龙江省宾县',
- native_place='黑龙江省宾县',
- blood_type='',
- religion=''))
- def test_0_02(self):
- image_path = '../images/all/0/02.jpg'
- self._helper0(image_path, ResultItem0(status='000',
- orientation=0,
- name='唐振宇',
- id='230826199211171418',
- gender='男',
- birthplace='黑龙江省佳木斯市桦川县',
- native_place='黑龙江省佳木斯市桦川县',
- blood_type='',
- religion=''))
- def test_0_03(self):
- image_path = '../images/all/0/03.jpg'
- self._helper0(image_path, ResultItem0(status='000',
- orientation=0,
- name='陈玉虎',
- id='622427199811114715',
- gender='男',
- birthplace='甘肃省临洮县',
- native_place='甘肃省临洮县',
- blood_type='不明',
- religion='无宗教信仰'))
- def test_0_04(self):
- image_path = '../images/all/0/04.jpg'
- self._helper0(image_path, ResultItem0(status='000',
- orientation=0,
- name='陈鑫',
- id='640382199605273716',
- gender='男',
- birthplace='宁夏回族自治区银川市灵武市',
- native_place='宁夏回族自治区银川市灵武市',
- blood_type='不明',
- religion='伊斯兰教'))
- def test_0_05_0(self):
- image_path = '../images/all/0/05_0.jpg'
- self._helper0(image_path, ResultItem0(status='000',
- orientation=0,
- name='马宁',
- id='64038219981016341x',
- gender='男',
- birthplace='宁夏灵武市无吴四队',
- native_place='宁夏',
- blood_type='B型',
- religion=''))
- def test_0_05_90(self):
- image_path = '../images/all/0/05_90.jpg'
- self._helper0(image_path, ResultItem0(status='000',
- orientation=1,
- name='马宁',
- id='64038219981016341x',
- gender='男',
- birthplace='宁夏灵武市无吴四队',
- native_place='宁夏',
- blood_type='B型',
- religion=''))
- def test_0_05_180(self):
- image_path = '../images/all/0/05_180.jpg'
- self._helper0(image_path, ResultItem0(status='000',
- orientation=2,
- name='马宁',
- id='64038219981016341x',
- gender='男',
- birthplace='宁夏灵武市无吴四队',
- native_place='宁夏',
- blood_type='B型',
- religion=''))
- def test_0_05_270(self):
- image_path = '../images/all/0/05_270.jpg'
- self._helper0(image_path, ResultItem0(status='000',
- orientation=3,
- name='马宁',
- id='64038219981016341x',
- gender='男',
- birthplace='宁夏灵武市无吴四队',
- native_place='宁夏',
- blood_type='B型',
- religion=''))
- def test_1_01_0(self):
- image_path = '../images/all/1/01_0.png'
- self._helper1(image_path, ResultItem1(status='000',
- orientation=0,
- type='居民家庭户口',
- address='江西省新余市渝水区胜利南路183号1栋1单元1402室'))
- def test_1_01_90(self):
- image_path = '../images/all/1/01_90.png'
- self._helper1(image_path, ResultItem1(status='000',
- orientation=1,
- type='居民家庭户口',
- address='江西省新余市渝水区胜利南路183号1栋1单元1402室'))
- def test_1_01_180(self):
- image_path = '../images/all/1/01_180.png'
- self._helper1(image_path, ResultItem1(status='000',
- orientation=2,
- type='居民家庭户口',
- address='江西省新余市渝水区胜利南路183号1栋1单元1402室'))
- def test_1_01_270(self):
- image_path = '../images/all/1/01_270.png'
- self._helper1(image_path, ResultItem1(status='000',
- orientation=3,
- type='居民家庭户口',
- address='江西省新余市渝水区胜利南路183号1栋1单元1402室'))
- def test_1_02(self):
- image_path = '../images/all/1/02.jpg'
- self._helper1(image_path, ResultItem1(status='000',
- orientation=0,
- type='非农业家庭户口',
- address='东岭东委9组东岭南街解困小区9栋1门201号'))
- def test_1_03(self):
- image_path = '../images/all/1/03.jpg'
- self._helper1(image_path, ResultItem1(status='000',
- orientation=0,
- type='居民户口',
- address='黑龙江省桦川县东河乡兴安村1组'))
- def test_1_04(self):
- image_path = '../images/all/1/04.jpg'
- self._helper1(image_path, ResultItem1(status='000',
- orientation=0,
- type='乡村家庭户',
- address='宁夏吴忠市利通区金积镇丁家湾子村18040号'))
- def test_1_05(self):
- image_path = '../images/all/1/05.jpg'
- self._helper1(image_path, ResultItem1(status='000',
- orientation=0,
- type='乡村家庭户',
- address='宁夏吴忠市利通区郭家桥乡吴桥村四队88号'))
- def test_1_mohu(self):
- image_path = '../images/all/1/mohu.jpg'
- self._helper1(image_path, ResultItem1(status='000',
- orientation=0,
- type='家庭户',
- address='甘肃省林洮县康家集乡大头山村羊角湾社'))
- def test_1_special(self):
- image_path = '../images/all/1/special.jpg'
- self._helper1(image_path, ResultItem1(status='000',
- orientation=0,
- type='居民家庭户',
- address='安徽省马鞍山市花山区湖北东路479号4栋405室'))
- if __name__ == '__main__':
- unittest.main()
|