123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- 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=0):
- 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/0/18_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '罗子龙', 'gender': '男', 'admission_time': '2018年09月08日', 'education_time': '2022年06月16日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '江苏理工学院', 'major': '汽车服务工程(师范)', 'number': ''}
- 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/0/02_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '张文豪', 'gender': '男', 'admission_time': '2018年09月08日', 'education_time': '2022年07月01日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '昌吉学院', 'major': '自动化', 'number': ''}
- 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/0/17_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '周志伟', 'gender': '男', 'admission_time': '2019年09月06日', 'education_time': '2022年07月01日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '呼和浩特职业学院', 'major': '药品生物技术', 'number': ''}
- 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/0/12_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '王新宇', 'gender': '男', 'admission_time': '2019年09月01日', 'education_time': '2022年07月01日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '包头轻工职业技术学院', 'major': '农产品加工与质量检测', 'number': ''}
- 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/0/06_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '王振东', 'gender': '男', 'admission_time': '2014年09月11日', 'education_time': '2017年06月01日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '浙江水利水电学院', 'major': '物流管理', 'number': ''}
- 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/0/04_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '殷梦媛', 'gender': '女', 'admission_time': '2021年03月01日', 'education_time': '2024年03月01日', 'education_level': '本科', 'education_type': '成人高等教育', 'learning_type': '函授', 'school': '西北师范大学', 'major': '工商管理', 'number': ''}
- 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/0/19_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '杨超玉', 'gender': '男', 'admission_time': '2018年09月15日', 'education_time': '2022年06月30日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '浙江师范大学', 'major': '旅游管理', 'number': ''}
- 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/0/07_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '唐久桐', 'gender': '男', 'admission_time': '2017年09月01日', 'education_time': '2021年06月28日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '辽宁科技大学', 'major': '无机非金属材料工程', 'number': ''}
- 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/0/20_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '热依木别克·阿曼太', 'gender': '男', 'admission_time': '2020年10月26日', 'education_time': '2023年06月30日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '新疆建设职业技术学院', 'major': '房地产检测与估价', 'number': ''}
- 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/0/05_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '陈海涛', 'gender': '男', 'admission_time': '2005年09月01日', 'education_time': '2009年07月01日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '江苏广播电视大学', 'major': '应用电子技术', 'number': ''}
- 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/0/14_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '屈程祥', 'gender': '', 'admission_time': '2019年09月01日', 'education_time': '2022年07月01日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '包头轻工职业技术学院', 'major': '农产品加工与质量检测', 'number': ''}
- 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/0/10_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '陈可欣', 'gender': '女', 'admission_time': '2018年09月01日', 'education_time': '2022年07月03日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '内蒙古财经大学', 'major': '税收学', 'number': ''}
- 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/0/08_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '王锦', 'gender': '男', 'admission_time': '2019年09月06日', 'education_time': '2022年07月01日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '黄冈职业技术学院', 'major': '计算机应用技术', 'number': ''}
- 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/0/13_img.jpg'
- json_input = {'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': ''}
- 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/0/11_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '段泽煜', 'gender': '男', 'admission_time': '2018年09月01日', 'education_time': '2022年07月08日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '内蒙古农业大学', 'major': '信息管理与信息系统', 'number': ''}
- 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/0/09_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '常忠花', 'gender': '女', 'admission_time': '2017年09月16日', 'education_time': '2020年07月01日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '山西运城农业职业技术学院', 'major': '畜牧兽医', 'number': ''}
- 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/0/03_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '刘疆林', 'gender': '男', 'admission_time': '2018年09月08日', 'education_time': '2022年07月01日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '昌吉学院', 'major': '自动化', 'number': ''}
- 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/0/01_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '李铭清', 'gender': '男', 'admission_time': '2018年09月09日', 'education_time': '2022年06月30日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '武汉设计工程学院', 'major': '食品质量与安全', 'number': ''}
- 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/0/15_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '卢雪', 'gender': '女', 'admission_time': '2019年09月01日', 'education_time': '2022年07月01日', 'education_level': '专科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '乌兰察布医学高等专科学校', 'major': '助产', 'number': ''}
- 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/0/16_img.jpg'
- json_input = {'status': '000', 'orientation': 0, 'name': '刘烜阳', 'gender': '男', 'admission_time': '2020年09月01日', 'education_time': '2022年07月08日', 'education_level': '本科', 'education_type': '普通高等教育', 'learning_type': '普通全日制', 'school': '内蒙古农业大学', 'major': '车辆工程', 'number': ''}
- 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)
-
-
|