123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 |
- import unittest
- import base64
- from dataclasses import dataclass
- from pathlib import Path
- import requests
- # url = 'http://localhost:8080'
- url = 'http://aihub.digitalyili.com/aiSquare/openApi/reasoning-services'
- header = {
- 'Authorization': 'Bearer dcae8cc6-0e49-4db8-a2d2-94ef84da3636'
- }
- # 带线框识别比较差 例:6.27_02.png
- def send_request(image_path, image_type='1'):
- with open(image_path, 'rb') as f:
- img_str: str = base64.encodebytes(f.read()).decode('utf-8')
- r = requests.post(f'{url}/rlocrxm/xxw/schoolcert', json={'image': img_str, 'image_type': image_type}, headers=header)
- print(r.json())
- return r.json()
- @dataclass
- class ResultItem:
- status: str
- orientation: int
- name: str
- gender: str
- admission_time: str
- education_time: str
- education_level: str
- education_type: str
- learning_type: str
- school: str
- major: str
- number: str
- class TestSchoolCertOcr(unittest.TestCase):
- def _helper(self, image_path, item: ResultItem, image_type='1'):
- root = Path(__file__).parent
- image_path = str(root / image_path)
- r = send_request(image_path, image_type)
- self.assertEqual(item, ResultItem(status=r['status'],
- orientation=r['result']['orientation'],
- name=r['result']['name']['text'],
- gender=r['result']['gender']['text'],
- admission_time=r['result']['admission_time']['text'],
- education_time=r['result']['education_time']['text'],
- education_type=r['result']['education_type']['text'],
- education_level=r['result']['education_level']['text'],
- learning_type=r['result']['learning_type']['text'],
- school=r['result']['school']['text'],
- major=r['result']['major']['text'],
- number=r['result']['number']['text']
- ))
- # 0测试
- # 方向、专业识别错误
- def test_0_01_0(self):
- image_path = '../images/all/0/01_0.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='王海龙',
- gender='男',
- admission_time='2018年09月05日',
- education_time='2021年06月30日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='新疆农业职业技术学院',
- major='食品营养与检测',
- number=''))
- # 多种错误
- def test_0_01_90(self):
- image_path = '../images/all/0/01_90.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=1,
- name='王海龙',
- gender='男',
- admission_time='2018年09月05日',
- education_time='2021年06月30日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='新疆农业职业技术学院',
- major='食品营养与检测',
- number=''))
- # 方向、毕业时间识别错误
- def test_0_01_180(self):
- image_path = '../images/all/0/01_180.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=2,
- name='王海龙',
- gender='男',
- admission_time='2018年09月05日',
- education_time='2021年06月30日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='新疆农业职业技术学院',
- major='食品营养与检测',
- number=''))
- # 方向、专业识别错误
- def test_0_01_270(self):
- image_path = '../images/all/0/01_270.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=3,
- name='王海龙',
- gender='男',
- admission_time='2018年09月05日',
- education_time='2021年06月30日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='新疆农业职业技术学院',
- major='食品营养与检测',
- number=''))
- # 方向识别错误
- def test_0_02(self):
- image_path = '../images/all/0/02.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='张博渊',
- gender='男',
- admission_time='2018年09月12日',
- education_time='2022年07月01日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='内蒙古科技大学',
- major='应用化学',
- number=''))
- # 姓名、学校识别错误
- def test_0_03(self):
- image_path = '../images/all/0/03.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='徐志林',
- gender='男',
- admission_time='2019年09月01日',
- education_time='2021年07月01日',
- education_level='专科',
- education_type='普通',
- learning_type='普通全日制',
- school='四川工商职业技术学院',
- major='食品生物技术',
- number=''))
- # 入学时间识别错误
- def test_0_05_0(self):
- image_path = '../images/all/0/05_0.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='金泽丞',
- gender='男',
- admission_time='2020年09月01日',
- education_time='2022年07月10日',
- education_level='本科',
- education_type='普通',
- learning_type='普通全日制',
- school='内蒙古科技大学',
- major='自动化',
- number=''))
- # 入学时间识别错误
- def test_0_05_90(self):
- image_path = '../images/all/0/05_90.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=1,
- name='金泽丞',
- gender='男',
- admission_time='2020年09月01日',
- education_time='2022年07月10日',
- education_level='本科',
- education_type='普通',
- learning_type='普通全日制',
- school='内蒙古科技大学',
- major='自动化',
- number=''))
- # 多种错误
- def test_0_05_180(self):
- image_path = '../images/all/0/05_180.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=2,
- name='金泽丞',
- gender='男',
- admission_time='2020年09月01日',
- education_time='2022年07月10日',
- education_level='本科',
- education_type='普通',
- learning_type='普通全日制',
- school='内蒙古科技大学',
- major='自动化',
- number=''))
- # 入学时间识别错误
- def test_0_05_270(self):
- image_path = '../images/all/0/05_270.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=3,
- name='金泽丞',
- gender='男',
- admission_time='2020年09月01日',
- education_time='2022年07月10日',
- education_level='本科',
- education_type='普通',
- learning_type='普通全日制',
- school='内蒙古科技大学',
- major='自动化',
- number=''))
- # 学校识别错误
- def test_0_06(self):
- image_path = '../images/all/0/06.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='张豪',
- gender='男',
- admission_time='2020年10月10日',
- education_time='2022年06月30日',
- education_level='专科',
- education_type='普通',
- learning_type='普通全日制',
- school='四川工商职业技术学院',
- major='食品生物技术',
- number=''))
- # 1测试
- # 方向、姓名错误
- def test_1_01(self):
- image_path = '../images/all/1/01.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='陈默涵',
- gender='女',
- admission_time='2018年09月05日',
- education_time='2021年06月25日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='新疆农业职业技术学院',
- major='食品营养与检测',
- number='109951202106002702'),
- '0')
- # 多种错误
- def test_1_02_0(self):
- image_path = '../images/all/1/02_0.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='张敏',
- gender='男',
- admission_time='2016年09月10日',
- education_time='2020年06月30日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='大连科技学院',
- major='机械设计制造及其自动化',
- number='132071202005100273'),
- '0')
- # 多种错误
- def test_1_02_90(self):
- image_path = '../images/all/1/02_90.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=1,
- name='张敏',
- gender='男',
- admission_time='2016年09月10日',
- education_time='2020年06月30日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='大连科技学院',
- major='机械设计制造及其自动化',
- number='132071202005100273'),
- '0')
- # 多种错误
- def test_1_02_180(self):
- image_path = '../images/all/1/02_180.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=2,
- name='张敏',
- gender='男',
- admission_time='2016年09月10日',
- education_time='2020年06月30日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='大连科技学院',
- major='机械设计制造及其自动化',
- number='132071202005100273'),
- '0')
- # 多种错误
- def test_1_02_270(self):
- image_path = '../images/all/1/02_270.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=3,
- name='张敏',
- gender='男',
- admission_time='2016年09月10日',
- education_time='2020年06月30日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='大连科技学院',
- major='机械设计制造及其自动化',
- number='132071202005100273'),
- '0')
- def test_1_03(self):
- image_path = '../images/all/1/03.JPG'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='薛峰',
- gender='男',
- admission_time='2009年09月01日',
- education_time='2013年06月30日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='武汉纺织大学外经贸学院',
- major='高分子材料与工程',
- number='132401201305799592'),
- '0')
- # 多种错误
- def test_1_04(self):
- image_path = '../images/all/1/04.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='许星皓',
- gender='男',
- admission_time='',
- education_time='2012年12月30日',
- education_level='专科',
- education_type='高等教育自学考试',
- learning_type='',
- school='海南科技职业学院',
- major='数控技术应用(专科)',
- number='66460183101004424'),
- '0')
- # 方向错误
- def test_1_05(self):
- image_path = '../images/all/1/05.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='李婷婷',
- gender='女',
- admission_time='2015年09月01日',
- education_time='2019年07月01日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='广西财经学院',
- major='商务英语',
- number='115481201905007155'),
- '0')
- # 2测试
- # miss orientation、number
- def test_2_01_0(self):
- image_path = '../images/all/2/01_0.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='肖亮',
- gender='男',
- admission_time='2012年9月8日',
- education_time='2018年6月28日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='济南大学泉城学院',
- major='市场营销',
- number='140021201805000882'),
- '2')
- # 多种错误
- def test_2_01_90(self):
- image_path = '../images/all/2/01_90.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=1,
- name='肖亮',
- gender='男',
- admission_time='2012年9月8日',
- education_time='2018年6月28日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='济南大学泉城学院',
- major='市场营销',
- number='140021201805000882'),
- '2')
- # 多种错误
- def test_2_01_180(self):
- image_path = '../images/all/2/01_180.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=2,
- name='肖亮',
- gender='男',
- admission_time='2012年9月8日',
- education_time='2018年6月28日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='济南大学泉城学院',
- major='市场营销',
- number='140021201805000882'),
- '2')
- # 多种错误
- def test_2_01_270(self):
- image_path = '../images/all/2/01_180.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=3,
- name='肖亮',
- gender='男',
- admission_time='2012年9月8日',
- education_time='2018年6月28日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='济南大学泉城学院',
- major='市场营销',
- number='140021201805000882'),
- '2')
- # miss learning_type、number
- def test_2_02(self):
- image_path = '../images/all/2/02.jpeg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='提姆·库克',
- gender='男',
- admission_time='2001年09月01日',
- education_time='2004年07月01日',
- education_level='本科',
- education_type='高等教育',
- learning_type='',
- school='河北工业大学',
- major='人工智能之机器学习',
- number='100801200405001235'),
- '2')
- # 名字错误
- def test_2_03(self):
- image_path = '../images/all/2/03.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='胡磊',
- gender='男',
- admission_time='2012年9月1日',
- education_time='2016年7月1日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='红河学院',
- major='经济学',
- number='106871201605000620'),
- '2')
- # 正确
- def test_2_04(self):
- image_path = '../images/all/2/04.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='孟煜翔',
- gender='男',
- admission_time='2016年9月3日',
- education_time='2019年6月24日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='山东农业工程学院',
- major='环境艺术设计',
- number='144391201906001607'),
- '2')
- # 方向错误
- def test_2_05(self):
- image_path = '../images/all/2/05.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='黄浦村',
- gender='男',
- admission_time='2011年9月1日',
- education_time='2014年7月1日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='江西工程学院',
- major='装潢艺术设计',
- number='127661201406001009'),
- '2')
|