123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- import unittest
- import base64
- from dataclasses import dataclass
- from pathlib import Path
- import requests
- url = 'http://localhost:8080'
- # 带线框识别比较差 例:6.27_02.png
- 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/schoolcert', json={'image': img_str, 'image_type': image_type})
- 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='2'):
- 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']
- ))
- def test_case_01_0(self):
- image_path = '../images/2/10011800A11学籍学历证明001.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='向龙',
- gender='男',
- admission_time='2008年9月1日',
- education_time='2012年6月30日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='泰山学院',
- major='应用心理学',
- number='104531201205000925'))
- def test_case_02_0(self):
- image_path = '../images/2/10044867A11学籍学历证明001.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'))
- def test_case_03_0(self):
- image_path = '../images/2/10044923A11学籍学历证明001.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='李国栋',
- gender='男',
- admission_time='2015年9月7日',
- education_time='2018年6月30日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='烟台职业学院',
- major='电子商务',
- number='123961201806109089'))
- def test_case_04_0(self):
- image_path = '../images/2/10045022A11学籍学历证明001.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='张盛宇',
- gender='男',
- admission_time='2014年9月1日',
- education_time='2018年7月1日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='沈阳大学',
- major='环境工程',
- number='110351201805000659'))
- def test_case_05_0(self):
- image_path = '../images/2/10045286A11学籍学历证明001.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'))
- def test_case_06_0(self):
- image_path = '../images/2/10045455A11学籍学历证明001.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='王滢',
- gender='女',
- admission_time='2014年3月1日',
- education_time='2017年1月10日',
- education_level='专科',
- education_type='成人高等教育',
- learning_type='函授',
- school='黔南民族师范学院',
- major='语文教育',
- number='106705201706000196'))
- def test_case_07_0(self):
- image_path = '../images/2/10045568A11学籍学历证明001.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='温振雄',
- gender='男',
- admission_time='2009年9月1日',
- education_time='2013年6月30日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='桂林理工大学',
- major='信息与计算科学',
- number='105961201305003535'))
- def test_case_08_0(self):
- image_path = '../images/2/10045573A11学籍学历证明001.JPG'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='石福东',
- gender='男',
- admission_time='2012年9月12日',
- education_time='2015年7月15日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='内蒙古商贸职业学院',
- major='摄影摄像技术',
- number='126761201506003061'))
- def test_case_09_0(self):
- image_path = '../images/2/10046376A11学籍学历证明001.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='冯驹驰',
- gender='男',
- admission_time='2009年9月15日',
- education_time='2012年7月15日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='内蒙古商贸职业学院',
- major='市场营销',
- number='126761201206002319'))
- def test_case_10_0(self):
- image_path = '../images/2/10046536A11学籍学历证明001.png'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='张佳龙',
- gender='男',
- admission_time='2018年3月6日',
- education_time='2020年6月20日',
- education_level='本科',
- education_type='成人高等教育',
- learning_type='函授',
- school='青岛科技大学',
- major='制药工程',
- number='104265202005003447'))
|