1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import unittest
- import base64
- from pathlib import Path
- import requests
- url = 'http://192.168.199.208:18081'
- 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/idcard', json={'image': img_str, 'image_type': image_type})
- print(r.json())
- return r.json()
- class TestIdCardAddress(unittest.TestCase):
- def _helper(self, image_path, orient):
- root = Path(__file__).parent
- image_path = str(root / image_path)
- r = send_request(image_path, '0')
- self.assertEqual(orient, r['result']['orientation'], f'{image_path} orientation case error')
- def _helper1(self, image_path, orient):
- root = Path(__file__).parent
- image_path = str(root / image_path)
- r = send_request(image_path, '1')
- self.assertEqual(orient, r['result']['orientation'], f'{image_path} orientation case error')
- def test_01_270(self):
- image_path = '../images/false/miss_orient/01_270.jpg'
- self._helper(image_path, 0)
- def test_02_270(self):
- image_path = '../images/false/miss_orient/02_270.jpg'
- self._helper(image_path, 3)
- def test_04(self):
- image_path = '../images/false/miss_orient/04.jpg'
- self._helper(image_path, 0)
- def test_05(self):
- image_path = '../images/false/miss_orient/05.jpg'
- self._helper(image_path, 0)
- def test_06(self):
- image_path = '../images/false/miss_orient/06.png'
- self._helper(image_path, 3)
- def test_07(self):
- image_path = '../images/false/miss_orient/07.jpg'
- self._helper(image_path, 0)
- if __name__ == '__main__':
- unittest.main()
|