Esempio n. 1
0
	def test_failed_read(self):
		import numpy as np
		res = zxing.read_barcode(np.zeros((100, 100), np.uint8), formats = BF.EAN_8 | BF.AZTEC, binarizer = zxing.BoolCast)

		self.assertFalse(res.valid)
		self.assertEqual(res.format, BF.NONE)
		self.assertEqual(res.text, '')
Esempio n. 2
0
    def test_failed_read(self):
        import numpy as np
        res = zxing.read_barcode(np.zeros((100, 100), np.uint8),
                                 formats=[BF.EAN_8, BF.AZTEC])

        self.assertFalse(res.valid)
        self.assertEqual(res.format, BF.INVALID)
        self.assertEqual(res.text, '')
Esempio n. 3
0
	def test_write_read_cycle_pil(self):
		from PIL import Image
		format = BF.QRCode
		text = "I have the best words."
		img = zxing.write_barcode(format, text)
		img = Image.fromarray(img, "L")

		res = zxing.read_barcode(img)
		self.assertTrue(res.valid)
		self.assertEqual(res.format, format)
		self.assertEqual(res.text, text)
		self.assertEqual(res.orientation, 0)
		self.assertEqual(res.position.top_left.x, 4)

		rgb_img = img.convert("RGB")
		res = zxing.read_barcode(rgb_img)
		self.assertTrue(res.valid)
		self.assertEqual(res.format, format)
		self.assertEqual(res.text, text)
		self.assertEqual(res.orientation, 0)
		self.assertEqual(res.position.top_left.x, 4)

		rgba_img = img.convert("RGBA")
		res = zxing.read_barcode(rgba_img)
		self.assertTrue(res.valid)
		self.assertEqual(res.format, format)
		self.assertEqual(res.text, text)
		self.assertEqual(res.orientation, 0)
		self.assertEqual(res.position.top_left.x, 4)

		bin_img = img.convert("1")
		res = zxing.read_barcode(bin_img)
		self.assertTrue(res.valid)
		self.assertEqual(res.format, format)
		self.assertEqual(res.text, text)
		self.assertEqual(res.orientation, 0)
		self.assertEqual(res.position.top_left.x, 4)

		cmyk_img = img.convert("CMYK")
		res = zxing.read_barcode(cmyk_img)
		self.assertTrue(res.valid)
		self.assertEqual(res.format, format)
		self.assertEqual(res.text, text)
		self.assertEqual(res.orientation, 0)
		self.assertEqual(res.position.top_left.x, 4)
Esempio n. 4
0
    def test_write_read_cycle(self):
        format = BF.QR_CODE
        text = "I have the best words."
        img = zxing.write_barcode(format, text)
        res = zxing.read_barcode(img)

        self.assertTrue(res.valid)
        self.assertEqual(res.format, format)
        self.assertEqual(res.text, text)
Esempio n. 5
0
	def test_write_read_cycle(self):
		format = BF.QRCode
		text = "I have the best words."
		img = zxing.write_barcode(format, text)

		res = zxing.read_barcode(img)
		self.assertTrue(res.valid)
		self.assertEqual(res.format, format)
		self.assertEqual(res.text, text)
		self.assertEqual(res.orientation, 0)
		self.assertEqual(res.position.top_left.x, 4)

		res = zxing.read_barcode(img, formats=format)
		self.assertTrue(res.valid)
		self.assertEqual(res.format, format)
		self.assertEqual(res.text, text)
		self.assertEqual(res.orientation, 0)
		self.assertEqual(res.position.top_left.x, 4)
Esempio n. 6
0
    def test_write_read_oned_cycle(self):
        format = BF.Code128
        text = "I have the best words."
        height = 80
        width = 400
        img = zxing.write_barcode(format, text, width=width, height=height)
        self.assertEqual(img.shape[0], height)
        self.assertEqual(img.shape[1], width)

        res = zxing.read_barcode(img)
        self.assertTrue(res.valid)
        self.assertEqual(res.format, format)
        self.assertEqual(res.text, text)
        self.assertEqual(res.orientation, 0)
        self.assertEqual(res.position.topLeft.x, 61)
Esempio n. 7
0
import sys, zxing
from PIL import Image

img = Image.open(sys.argv[1])
result = zxing.read_barcode(img)
if result.valid:
    print(
        "Found barcode:\n Text:    '{}'\n Format:   {}\n Position: {}".format(
            result.text, result.format, result.position))
else:
    print("Could not read barcode")