orient_test.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import unittest
  2. import base64
  3. from pathlib import Path
  4. import requests
  5. url = 'http://192.168.199.208:18081'
  6. def send_request(image_path, image_type):
  7. with open(image_path, 'rb') as f:
  8. img_str: str = base64.encodebytes(f.read()).decode('utf-8')
  9. r = requests.post(f'{url}/ocr_system/idcard', json={'image': img_str, 'image_type': image_type})
  10. print(r.json())
  11. return r.json()
  12. class TestIdCardAddress(unittest.TestCase):
  13. def _helper(self, image_path, orient):
  14. root = Path(__file__).parent
  15. image_path = str(root / image_path)
  16. r = send_request(image_path, '0')
  17. self.assertEqual(orient, r['result']['orientation'], f'{image_path} orientation case error')
  18. def _helper1(self, image_path, orient):
  19. root = Path(__file__).parent
  20. image_path = str(root / image_path)
  21. r = send_request(image_path, '1')
  22. self.assertEqual(orient, r['result']['orientation'], f'{image_path} orientation case error')
  23. def test_01_270(self):
  24. image_path = '../images/false/miss_orient/01_270.jpg'
  25. self._helper(image_path, 0)
  26. def test_02_270(self):
  27. image_path = '../images/false/miss_orient/02_270.jpg'
  28. self._helper(image_path, 3)
  29. def test_04(self):
  30. image_path = '../images/false/miss_orient/04.jpg'
  31. self._helper(image_path, 0)
  32. def test_05(self):
  33. image_path = '../images/false/miss_orient/05.jpg'
  34. self._helper(image_path, 0)
  35. def test_06(self):
  36. image_path = '../images/false/miss_orient/06.png'
  37. self._helper(image_path, 3)
  38. def test_07(self):
  39. image_path = '../images/false/miss_orient/07.jpg'
  40. self._helper(image_path, 0)
  41. if __name__ == '__main__':
  42. unittest.main()