123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- import unittest
- import base64
- from dataclasses import dataclass
- from pathlib import Path
- import cv2
- import requests
- url = 'http://localhost:8080'
- def send_request(image_path, image_type, rotate=None):
- img = cv2.imread(str(image_path))
- img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
- if rotate is not None:
- img = cv2.rotate(img, rotate)
- _, im_arr = cv2.imencode('.jpg', img)
- img_str = base64.b64encode(im_arr).decode('utf-8')
- r = requests.post(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, rotate=None,image_type=2):
- root = Path(__file__).parent
- image_path = str(root / image_path)
- r = send_request(image_path, image_type, rotate)
- 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 case_18_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/18_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '何昊轩', 'gender': '男', 'admission_time': '2019年9月1日', 'education_time': '2022年7月1日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '包头轻工职业技术学院', 'major': '农产品加工与质量检测', 'number': '126711202206000186'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_18_0(self):
- self.case_18_0(0)
-
- def test_case_18_1(self):
- self.case_18_0(1)
-
- def test_case_18_2(self):
- self.case_18_0(2)
-
- def test_case_18_3(self):
- self.case_18_0(3)
-
-
- def case_02_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/02_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '刘杰', 'gender': '男', 'admission_time': '2011年9月1日', 'education_time': '2015年6月25日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '山东理工大学', 'major': '英语(师范类)', 'number': '104331201505208429'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_02_0(self):
- self.case_02_0(0)
-
- def test_case_02_1(self):
- self.case_02_0(1)
-
- def test_case_02_2(self):
- self.case_02_0(2)
-
- def test_case_02_3(self):
- self.case_02_0(3)
-
-
- def case_17_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/17_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '吕彩微', 'gender': '女', 'admission_time': '2018年9月1日', 'education_time': '2022年6月10日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '河北农业大学', 'major': '食品科学与工程', 'number': '100861202205003702'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_17_0(self):
- self.case_17_0(0)
-
- def test_case_17_1(self):
- self.case_17_0(1)
-
- def test_case_17_2(self):
- self.case_17_0(2)
-
- def test_case_17_3(self):
- self.case_17_0(3)
-
-
- def case_12_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/12_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '辛宇琦', 'gender': '男', 'admission_time': '2015年9月12日', 'education_time': '2018年7月1日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '黑龙江生物科技职业学院', 'major': '生物制药技术', 'number': '134471201806000362'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_12_0(self):
- self.case_12_0(0)
-
- def test_case_12_1(self):
- self.case_12_0(1)
-
- def test_case_12_2(self):
- self.case_12_0(2)
-
- def test_case_12_3(self):
- self.case_12_0(3)
-
-
- def case_06_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/06_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '韩坤鹏', 'gender': '男', 'admission_time': '2017年9月1日', 'education_time': '2021年6月21日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '四川大学', 'major': '国民经济管理', 'number': '106101202105000788'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_06_0(self):
- self.case_06_0(0)
-
- def test_case_06_1(self):
- self.case_06_0(1)
-
- def test_case_06_2(self):
- self.case_06_0(2)
-
- def test_case_06_3(self):
- self.case_06_0(3)
-
-
- def case_04_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/04_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '丁志勇', 'gender': '男', 'admission_time': '2014年9月1日', 'education_time': '2017年7月5日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '内蒙古电子信息职业技术学院', 'major': '园林技术(园林施工与监理方向)', 'number': '126731201706001174'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_04_0(self):
- self.case_04_0(0)
-
- def test_case_04_1(self):
- self.case_04_0(1)
-
- def test_case_04_2(self):
- self.case_04_0(2)
-
- def test_case_04_3(self):
- self.case_04_0(3)
-
-
- def case_19_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/19_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '袁石磊', 'gender': '男', 'admission_time': '2020年9月1日', 'education_time': '2022年6月22日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '内蒙古工业大学', 'major': '过程装备与控制工程', 'number': '101281202205103089'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_19_0(self):
- self.case_19_0(0)
-
- def test_case_19_1(self):
- self.case_19_0(1)
-
- def test_case_19_2(self):
- self.case_19_0(2)
-
- def test_case_19_3(self):
- self.case_19_0(3)
-
-
- def case_07_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/07_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '刘坤', 'gender': '男', 'admission_time': '2012年9月15日', 'education_time': '2015年6月24日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '山东商业职业技术学院', 'major': '计算机信息管理', 'number': '108321201506004465'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_07_0(self):
- self.case_07_0(0)
-
- def test_case_07_1(self):
- self.case_07_0(1)
-
- def test_case_07_2(self):
- self.case_07_0(2)
-
- def test_case_07_3(self):
- self.case_07_0(3)
-
-
- def case_20_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/20_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '赵艳鹏', 'gender': '男', 'admission_time': '2010年9月1日', 'education_time': '2014年7月10日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '内蒙古科技大学', 'major': '交通工程', 'number': '101271201405005140'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_20_0(self):
- self.case_20_0(0)
-
- def test_case_20_1(self):
- self.case_20_0(1)
-
- def test_case_20_2(self):
- self.case_20_0(2)
-
- def test_case_20_3(self):
- self.case_20_0(3)
-
-
- def case_05_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/05_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '赵吉磊', 'gender': '男', 'admission_time': '2016年9月1日', 'education_time': '2019年6月22日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '青岛黄海学院', 'major': '市场营销', 'number': '133201201906002050'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_05_0(self):
- self.case_05_0(0)
-
- def test_case_05_1(self):
- self.case_05_0(1)
-
- def test_case_05_2(self):
- self.case_05_0(2)
-
- def test_case_05_3(self):
- self.case_05_0(3)
-
-
- def case_14_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/14_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '王宏', 'gender': '男', 'admission_time': '2012年9月2日', 'education_time': '2016年6月17日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '河北工程大学', 'major': '地理信息系统', 'number': '100761201605102054'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_14_0(self):
- self.case_14_0(0)
-
- def test_case_14_1(self):
- self.case_14_0(1)
-
- def test_case_14_2(self):
- self.case_14_0(2)
-
- def test_case_14_3(self):
- self.case_14_0(3)
-
-
- def case_10_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/10_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '王飞鹏', 'gender': '男', 'admission_time': '2016年9月5日', 'education_time': '2020年7月5日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '烟台大学文经学院', 'major': '财务管理', 'number': '133591202005100874'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_10_0(self):
- self.case_10_0(0)
-
- def test_case_10_1(self):
- self.case_10_0(1)
-
- def test_case_10_2(self):
- self.case_10_0(2)
-
- def test_case_10_3(self):
- self.case_10_0(3)
-
-
- def case_08_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/08_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '马海龙', 'gender': '男', 'admission_time': '2018年9月1日', 'education_time': '2021年6月17日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '青岛港湾职业技术学院', 'major': '汽车营销与服务', 'number': '130141202106003583'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_08_0(self):
- self.case_08_0(0)
-
- def test_case_08_1(self):
- self.case_08_0(1)
-
- def test_case_08_2(self):
- self.case_08_0(2)
-
- def test_case_08_3(self):
- self.case_08_0(3)
-
-
- def case_13_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/13_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '边阔', 'gender': '男', 'admission_time': '2015年9月7日', 'education_time': '2020年7月1日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '安徽师范大学', 'major': '人力资源管理', 'number': '103701201905007317'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_13_0(self):
- self.case_13_0(0)
-
- def test_case_13_1(self):
- self.case_13_0(1)
-
- def test_case_13_2(self):
- self.case_13_0(2)
-
- def test_case_13_3(self):
- self.case_13_0(3)
-
-
- def case_11_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/11_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '赵一凡', 'gender': '男', 'admission_time': '2016年9月1日', 'education_time': '2020年6月15日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '陇东学院', 'major': '自动化', 'number': '107381202005002439'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_11_0(self):
- self.case_11_0(0)
-
- def test_case_11_1(self):
- self.case_11_0(1)
-
- def test_case_11_2(self):
- self.case_11_0(2)
-
- def test_case_11_3(self):
- self.case_11_0(3)
-
-
- def case_09_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/09_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '袁跃', 'gender': '男', 'admission_time': '2016年9月10日', 'education_time': '2020年6月24日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '山东科技大学', 'major': '高分子材料与工程', 'number': '104241202005002452'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_09_0(self):
- self.case_09_0(0)
-
- def test_case_09_1(self):
- self.case_09_0(1)
-
- def test_case_09_2(self):
- self.case_09_0(2)
-
- def test_case_09_3(self):
- self.case_09_0(3)
-
-
- def case_03_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/03_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '黄志昌', 'gender': '男', 'admission_time': '2013年9月1日', 'education_time': '2016年6月30日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '漳州职业技术学院', 'major': '市场营销', 'number': '113141201606002183'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_03_0(self):
- self.case_03_0(0)
-
- def test_case_03_1(self):
- self.case_03_0(1)
-
- def test_case_03_2(self):
- self.case_03_0(2)
-
- def test_case_03_3(self):
- self.case_03_0(3)
-
-
- def case_01_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/01_img.jpg'
- json_input = {'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'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_01_0(self):
- self.case_01_0(0)
-
- def test_case_01_1(self):
- self.case_01_0(1)
-
- def test_case_01_2(self):
- self.case_01_0(2)
-
- def test_case_01_3(self):
- self.case_01_0(3)
-
-
- def case_15_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/15_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '吕鹏', 'gender': '男', 'admission_time': '2014年9月13日', 'education_time': '2018年6月29日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '山东建筑大学', 'major': '房地产开发与管理', 'number': '104301201805011922'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_15_0(self):
- self.case_15_0(0)
-
- def test_case_15_1(self):
- self.case_15_0(1)
-
- def test_case_15_2(self):
- self.case_15_0(2)
-
- def test_case_15_3(self):
- self.case_15_0(3)
-
-
- def case_16_0(self, orientation=0):
- dict_orientation = {0: None, 1: 0, 2: 1, 3: 2}
- image_path = '../images/clean/2/16_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '李旻熹', 'gender': '女', 'admission_time': '2016年9月1日', 'education_time': '2020年6月10日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '北京体育大学', 'major': '运动训练', 'number': '100431202005000716'}
- json_input['orientation'] = orientation
- self._helper(image_path, ResultItem(**json_input), dict_orientation[orientation])
-
- def test_case_16_0(self):
- self.case_16_0(0)
-
- def test_case_16_1(self):
- self.case_16_0(1)
-
- def test_case_16_2(self):
- self.case_16_0(2)
-
- def test_case_16_3(self):
- self.case_16_0(3)
|