| 12345678910111213141516171819202122 |
- import unittest
- from pyzbar.pyzbar import decode
- from PIL import Image
- class ScanTestCase(unittest.TestCase):
- def test_scan(self):
- from pyzbar.pyzbar import decode
- from PIL import Image
- # 打开包含二维码的图片
- image = Image.open('./tests/assert/alipay_code.jpg')
- # 解码图片中的二维码
- decoded_objects = decode(image)
- print(type(decoded_objects))
- print(decoded_objects)
- for obj in decoded_objects:
- print("类型:", obj.type)
- print("内容:", obj.data.decode("utf-8"))
- if __name__ == '__main__':
- unittest.main()
|