orient_test.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import unittest
  2. import base64
  3. from pathlib import Path
  4. import requests
  5. url = 'http://192.168.199.249: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, image_type='0'):
  14. root = Path(__file__).parent
  15. image_path = str(root / image_path)
  16. r = send_request(image_path, image_type)
  17. self.assertEqual(orient, r['result']['orientation'], f'{image_path} orientation case error')
  18. def test_01_270(self):
  19. image_path = '../images/false/miss_orient/01_270.jpg'
  20. self._helper(image_path, 3)
  21. def test_02_270(self):
  22. image_path = '../images/false/miss_orient/02_270.jpg'
  23. self._helper(image_path, 3)
  24. def test_04(self):
  25. image_path = '../images/false/miss_orient/04.jpg'
  26. self._helper(image_path, 0, '1')
  27. def test_05(self):
  28. image_path = '../images/false/miss_orient/05.jpg'
  29. self._helper(image_path, 3)
  30. def test_06(self):
  31. image_path = '../images/false/miss_orient/06.png'
  32. self._helper(image_path, 3)
  33. def test_07(self):
  34. image_path = '../images/false/miss_orient/07.jpg'
  35. self._helper(image_path, 0, '1')
  36. def test_08(self):
  37. image_path = '../images/false/miss_orient/08.jpg'
  38. self._helper(image_path, 2, '1')
  39. if __name__ == '__main__':
  40. unittest.main()